Add search line-edits, and expand/collapse all, to sync dialog.

This commit is contained in:
craig.p.drummond
2012-11-23 19:42:32 +00:00
committed by craig.p.drummond
parent b59cae9182
commit 85137b0a02
4 changed files with 78 additions and 3 deletions

View File

@@ -106,6 +106,7 @@
to re-reading all songs from mpd/device.
59. If window is minimized to system tray when Cantata is terminated, then
restore to this state when restarted.
60. Add search line-edits, and expand/collapse all, to sync dialog.
0.8.3.1
-------

View File

@@ -25,10 +25,15 @@
#include "treeview.h"
#include "musiclibraryproxymodel.h"
#include "icon.h"
#include "localize.h"
#include "actioncollection.h"
#include <QtCore/QTimer>
#include <QtGui/QAction>
#include <QtCore/QDebug>
SyncCollectionWidget::SyncCollectionWidget(QWidget *parent, const QString &title, const QString &action, bool showCovers)
: QWidget(parent)
, searchTimer(0)
{
setupUi(this);
groupBox->setTitle(title);
@@ -41,12 +46,25 @@ SyncCollectionWidget::SyncCollectionWidget(QWidget *parent, const QString &title
proxy->setSourceModel(model);
tree->setModel(proxy);
tree->setPageDefaults();
search->setText(QString());
search->setPlaceholderText(i18n("Search"));
connect(tree, SIGNAL(itemsSelected(bool)), button, SLOT(setEnabled(bool)));
connect(button, SIGNAL(clicked()), SLOT(copySongs()));
connect(search, SIGNAL(returnPressed()), this, SLOT(delaySearchItems()));
connect(search, SIGNAL(textChanged(const QString)), this, SLOT(delaySearchItems()));
QAction *act=new QAction(action, this);
connect(act, SIGNAL(triggered(bool)), SLOT(copySongs()));
tree->addAction(act);
QAction *expand=ActionCollection::get()->action("expandall");
QAction *collapse=ActionCollection::get()->action("collapseall");
if (expand && collapse) {
addAction(expand);
addAction(collapse);
connect(expand, SIGNAL(triggered(bool)), this, SLOT(expandAll()));
connect(collapse, SIGNAL(triggered(bool)), this, SLOT(collapseAll()));
}
}
SyncCollectionWidget::~SyncCollectionWidget()
@@ -68,3 +86,45 @@ void SyncCollectionWidget::copySongs()
emit copy(model->songs(mapped));
}
void SyncCollectionWidget::delaySearchItems()
{
if (search->text().trimmed().isEmpty()) {
if (searchTimer) {
searchTimer->stop();
}
searchItems();
} else {
if (!searchTimer) {
searchTimer=new QTimer(this);
searchTimer->setSingleShot(true);
connect(searchTimer, SIGNAL(timeout()), SLOT(searchItems()));
}
searchTimer->start(500);
}
}
void SyncCollectionWidget::searchItems()
{
QString text=search->text().trimmed();
proxy->update(text);
if (proxy->enabled() && !text.isEmpty()) {
tree->expandAll();
}
}
void SyncCollectionWidget::expandAll()
{
QWidget *f=QApplication::focusWidget();
if (f && qobject_cast<QTreeView *>(f)) {
static_cast<QTreeView *>(f)->expandAll();
}
}
void SyncCollectionWidget::collapseAll()
{
QWidget *f=QApplication::focusWidget();
if (f && qobject_cast<QTreeView *>(f)) {
static_cast<QTreeView *>(f)->collapseAll();
}
}

View File

@@ -29,6 +29,7 @@
#include "musiclibrarymodel.h"
#include <QtCore/QSet>
class QTimer;
class MusicLibraryProxyModel;
class SyncCollectionWidget : public QWidget, Ui::SyncCollectionWidget
@@ -48,10 +49,15 @@ Q_SIGNALS:
private Q_SLOTS:
void copySongs();
void delaySearchItems();
void searchItems();
void expandAll();
void collapseAll();
private:
MusicLibraryModel *model;
MusicLibraryProxyModel *proxy;
QTimer *searchTimer;
};
#endif

View File

@@ -17,10 +17,10 @@
<item>
<widget class="QGroupBox" name="groupBox">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="2">
<item row="1" column="0" colspan="2">
<widget class="TreeView" name="tree"/>
</item>
<item row="2" column="0">
<item row="3" column="0">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@@ -33,15 +33,23 @@
</property>
</spacer>
</item>
<item row="2" column="1">
<item row="3" column="1">
<widget class="QPushButton" name="button"/>
</item>
<item row="0" column="0" colspan="2">
<widget class="LineEdit" name="search"/>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>LineEdit</class>
<extends>QLineEdit</extends>
<header>lineedit.h</header>
</customwidget>
<customwidget>
<class>TreeView</class>
<extends>QTreeView</extends>