From d24807bd71c8c8aa1f224fdd9c64d9fbd283d037 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Mon, 13 Jan 2014 18:54:23 +0100 Subject: [PATCH] Properly manage additional questions in SourceTreePopupWidget. --- .../widgets/SourceTreePopupDialog.cpp | 44 ++++++++++++++----- .../widgets/SourceTreePopupDialog.h | 4 ++ 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/src/libtomahawk/widgets/SourceTreePopupDialog.cpp b/src/libtomahawk/widgets/SourceTreePopupDialog.cpp index 347735c0b..807eb354a 100644 --- a/src/libtomahawk/widgets/SourceTreePopupDialog.cpp +++ b/src/libtomahawk/widgets/SourceTreePopupDialog.cpp @@ -1,7 +1,7 @@ /* === This file is part of Tomahawk Player - === * - * Copyright 2012 Leo Franchi - * Copyright 2012 Teo Mrnjavac + * Copyright 2012 Leo Franchi + * Copyright 2012-2014 Teo Mrnjavac * * 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 ); +} diff --git a/src/libtomahawk/widgets/SourceTreePopupDialog.h b/src/libtomahawk/widgets/SourceTreePopupDialog.h index 29f747ca4..8e5d74eaa 100644 --- a/src/libtomahawk/widgets/SourceTreePopupDialog.h +++ b/src/libtomahawk/widgets/SourceTreePopupDialog.h @@ -1,6 +1,7 @@ /* === This file is part of Tomahawk Player - === * * Copyright 2012 Leo Franchi + * Copyright 2014 Teo Mrnjavac * * 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;