Display smart playlist query terms in a scrollable list instead of squishing them together when there are lots. Fixes issue 1065

This commit is contained in:
Jonathan Horvath 2012-01-15 15:42:12 +00:00 committed by David Sansome
parent da35fab076
commit fdf10af94a
4 changed files with 98 additions and 7 deletions

View File

@ -6,10 +6,16 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>400</width> <width>448</width>
<height>300</height> <height>450</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle"> <property name="windowTitle">
<string>Form</string> <string>Form</string>
</property> </property>
@ -47,10 +53,76 @@
</item> </item>
<item> <item>
<widget class="QGroupBox" name="terms_group"> <widget class="QGroupBox" name="terms_group">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>300</height>
</size>
</property>
<property name="title"> <property name="title">
<string>Search terms</string> <string>Search terms</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_5"/> <layout class="QVBoxLayout" name="verticalLayout_5">
<property name="margin">
<number>9</number>
</property>
<item>
<widget class="QScrollArea" name="terms_scrollArea">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="terms_scrollArea_content">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>422</width>
<height>264</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="margin">
<number>0</number>
</property>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget> </widget>
</item> </item>
</layout> </layout>

View File

@ -21,6 +21,7 @@
#include "ui_querysearchpage.h" #include "ui_querysearchpage.h"
#include "ui_querysortpage.h" #include "ui_querysortpage.h"
#include <QScrollBar>
#include <QWizardPage> #include <QWizardPage>
namespace smart_playlists { namespace smart_playlists {
@ -72,7 +73,8 @@ public:
QueryWizardPlugin::QueryWizardPlugin(LibraryBackend* library, QObject* parent) QueryWizardPlugin::QueryWizardPlugin(LibraryBackend* library, QObject* parent)
: WizardPlugin(library, parent), : WizardPlugin(library, parent),
search_page_(NULL) search_page_(NULL),
previous_scrollarea_max_(0)
{ {
} }
@ -105,10 +107,13 @@ int QueryWizardPlugin::CreatePages(QWizard* wizard, int finish_page_id) {
connect(search_page_->new_term_, SIGNAL(Clicked()), SLOT(AddSearchTerm())); connect(search_page_->new_term_, SIGNAL(Clicked()), SLOT(AddSearchTerm()));
// Add an empty initial term // Add an empty initial term
search_page_->layout_ = static_cast<QVBoxLayout*>(search_page_->ui_->terms_group->layout()); search_page_->layout_ = static_cast<QVBoxLayout*>(search_page_->ui_->terms_scrollArea_content->layout());
search_page_->layout_->addWidget(search_page_->new_term_); search_page_->layout_->addWidget(search_page_->new_term_);
AddSearchTerm(); AddSearchTerm();
// Ensure that the terms are scrolled to the bottom when a new one is added
connect(search_page_->ui_->terms_scrollArea->verticalScrollBar(), SIGNAL(rangeChanged(int,int)), this, SLOT(MoveTermListToBottom(int, int)));
// Add the preview widget at the bottom of the search terms page // Add the preview widget at the bottom of the search terms page
QVBoxLayout* terms_page_layout = static_cast<QVBoxLayout*>(search_page_->layout()); QVBoxLayout* terms_page_layout = static_cast<QVBoxLayout*>(search_page_->layout());
terms_page_layout->addStretch(); terms_page_layout->addStretch();
@ -291,9 +296,19 @@ Search QueryWizardPlugin::MakeSearch() const {
void QueryWizardPlugin::SearchTypeChanged() { void QueryWizardPlugin::SearchTypeChanged() {
const bool all = search_page_->ui_->type->currentIndex() == 2; const bool all = search_page_->ui_->type->currentIndex() == 2;
search_page_->ui_->terms_group->setEnabled(!all); search_page_->ui_->terms_scrollArea_content->setEnabled(!all);
UpdateTermPreview(); UpdateTermPreview();
} }
void QueryWizardPlugin::MoveTermListToBottom(int min, int max) {
Q_UNUSED(min);
// Only scroll to the bottom if a new term is added
if (previous_scrollarea_max_ < max)
search_page_->ui_->terms_scrollArea->verticalScrollBar()->setValue(max);
previous_scrollarea_max_ = max;
}
} // namespace smart_playlists } // namespace smart_playlists

View File

@ -61,6 +61,8 @@ private slots:
void UpdateSortPreview(); void UpdateSortPreview();
void UpdateSortOrder(); void UpdateSortOrder();
void MoveTermListToBottom(int min, int max);
private: private:
class SearchPage; class SearchPage;
class SortPage; class SortPage;
@ -69,6 +71,8 @@ private:
SearchPage* search_page_; SearchPage* search_page_;
boost::scoped_ptr<Ui_SmartPlaylistQuerySortPage> sort_ui_; boost::scoped_ptr<Ui_SmartPlaylistQuerySortPage> sort_ui_;
int previous_scrollarea_max_;
}; };
} // namespace smart_playlists } // namespace smart_playlists

View File

@ -65,7 +65,7 @@ Wizard::Wizard(LibraryBackend* library, QWidget* parent)
{ {
setWindowIcon(QIcon(":/icon.png")); setWindowIcon(QIcon(":/icon.png"));
setWindowTitle(tr("Smart playlist")); setWindowTitle(tr("Smart playlist"));
resize(687, 628); resize(788, 628);
// Type page // Type page
type_page_->setTitle(tr("Playlist type")); type_page_->setTitle(tr("Playlist type"));