1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-20 15:59:42 +01:00

Properly manage additional questions in SourceTreePopupWidget.

This commit is contained in:
Teo Mrnjavac 2014-01-13 18:54:23 +01:00
parent f81cf2c517
commit d24807bd71
2 changed files with 38 additions and 10 deletions

View File

@ -1,7 +1,7 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2012 Leo Franchi <lfranchi@kde.org>
* Copyright 2012 Teo Mrnjavac <teo@kde.org>
* Copyright 2012 Leo Franchi <lfranchi@kde.org>
* Copyright 2012-2014 Teo Mrnjavac <teo@kde.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -88,6 +88,12 @@ SourceTreePopupDialog::SourceTreePopupDialog()
TomahawkStyle::BORDER_LINE.name() + "; }" );
m_layout->addWidget( m_separatorLine );
m_layout->addWidget( m_label );
QHBoxLayout* questionsSpacerLayout = new QHBoxLayout;
m_layout->addLayout( questionsSpacerLayout );
m_questionsLayout = new QVBoxLayout;
questionsSpacerLayout->addStretch( 1 );
questionsSpacerLayout->addLayout( m_questionsLayout );
TomahawkUtils::unmarginLayout( questionsSpacerLayout );
m_layout->addWidget( m_buttons );
setContentsMargins( contentsMargins().left() + 12,
contentsMargins().top() + 8,
@ -155,25 +161,22 @@ SourceTreePopupDialog::setOkButtonText( const QString& text )
void
SourceTreePopupDialog::setExtraQuestions( const Tomahawk::PlaylistDeleteQuestions& questions )
{
//First we clear
clearQuestionWidgets();
m_questions = questions;
int baseHeight = 80;
int idx = m_layout->indexOf( m_label ) + 1;
foreach ( const Tomahawk::PlaylistDeleteQuestion& question, m_questions )
{
QCheckBox* cb = new QCheckBox( question.first, this );
cb->setLayoutDirection( Qt::RightToLeft );
cb->setProperty( "data", question.second );
QHBoxLayout* h = new QHBoxLayout;
h->addStretch( 1 );
h->addWidget( cb );
// m_layout->insertLayout( h, cb, 0 );
m_layout->insertLayout( idx, h, 0 );
m_questionsLayout->addWidget( cb );
m_questionCheckboxes << cb;
idx++;
baseHeight += cb->height() + m_layout->spacing();
baseHeight += cb->height() + m_questionsLayout->spacing();
}
setFixedHeight( baseHeight );
}
@ -233,6 +236,15 @@ SourceTreePopupDialog::showEvent( QShowEvent* )
}
void
SourceTreePopupDialog::hideEvent( QHideEvent* e )
{
clearQuestionWidgets();
QWidget::hideEvent( e );
}
void
SourceTreePopupDialog::onAccepted()
{
@ -264,3 +276,15 @@ SourceTreePopupDialog::calculateResults()
}
}
}
void
SourceTreePopupDialog::clearQuestionWidgets()
{
while ( QLayoutItem* item = m_questionsLayout->takeAt( 0 ) )
if ( QWidget* widget = item->widget() )
delete widget;
m_questionCheckboxes.clear();
setFixedHeight( 80 );
}

View File

@ -1,6 +1,7 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2012 Leo Franchi <lfranchi@kde.org>
* Copyright 2014 Teo Mrnjavac <teo@kde.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -59,6 +60,7 @@ protected:
virtual void paintEvent( QPaintEvent* );
virtual void focusOutEvent( QFocusEvent* );
virtual void showEvent( QShowEvent* );
virtual void hideEvent( QHideEvent* );
private slots:
void onAccepted();
@ -66,8 +68,10 @@ private slots:
private:
void calculateResults();
void clearQuestionWidgets();
QVBoxLayout* m_layout;
QVBoxLayout* m_questionsLayout;
QList< QCheckBox* > m_questionCheckboxes;
bool m_result;