summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--BeetPlayer.pro6
-rw-r--r--beetplayerproxy.cpp19
-rw-r--r--beetplayerproxy.h15
-rw-r--r--playerwidget.cpp60
-rw-r--r--playerwidget.h14
5 files changed, 68 insertions, 46 deletions
diff --git a/BeetPlayer.pro b/BeetPlayer.pro
index 5e319f0..dc6e019 100644
--- a/BeetPlayer.pro
+++ b/BeetPlayer.pro
@@ -28,13 +28,15 @@ SOURCES += main.cpp\
configurationdialog.cpp \
indexerwidget.cpp \
globals.cpp \
- playerwidget.cpp
+ playerwidget.cpp \
+ beetplayerproxy.cpp
HEADERS += beetplayer.h \
configurationdialog.h \
indexerwidget.h \
globals.h \
- playerwidget.h
+ playerwidget.h \
+ beetplayerproxy.h
LIBS += -ltag
diff --git a/beetplayerproxy.cpp b/beetplayerproxy.cpp
new file mode 100644
index 0000000..115bd3a
--- /dev/null
+++ b/beetplayerproxy.cpp
@@ -0,0 +1,19 @@
+#include <QModelIndex>
+#include "beetplayerproxy.h"
+
+#include <QDebug>
+
+BeetPlayerProxy::BeetPlayerProxy(QObject *parent) : QSortFilterProxyModel(parent) {
+}
+
+bool BeetPlayerProxy::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const{
+ QRegExp filter = filterRegExp();
+ QModelIndex curIdx = sourceModel()->index(source_row, 0, source_parent);
+ while(curIdx.isValid()){
+ if(curIdx.data().toString().contains(filter)){
+ return true;
+ }
+ curIdx = curIdx.parent();
+ }
+ return false;
+}
diff --git a/beetplayerproxy.h b/beetplayerproxy.h
new file mode 100644
index 0000000..b50b972
--- /dev/null
+++ b/beetplayerproxy.h
@@ -0,0 +1,15 @@
+#ifndef BEETPLAYERPROXY_H
+#define BEETPLAYERPROXY_H
+
+#include <QSortFilterProxyModel>
+
+class BeetPlayerProxy : public QSortFilterProxyModel {
+ Q_OBJECT
+ public:
+ BeetPlayerProxy(QObject *parent = 0);
+
+ protected:
+ virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
+};
+
+#endif // BEETPLAYERPROXY_H
diff --git a/playerwidget.cpp b/playerwidget.cpp
index e46990e..5df9951 100644
--- a/playerwidget.cpp
+++ b/playerwidget.cpp
@@ -1,4 +1,3 @@
-#include <QComboBox>
#include <QGroupBox>
#include <QLineEdit>
#include <QPushButton>
@@ -9,54 +8,43 @@
#include <QSplitter>
#include <QStandardItemModel>
#include <QStandardItem>
-#include <QSortFilterProxyModel>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QSqlDatabase>
#include <QSqlQuery>
#include "playerwidget.h"
+#include "beetplayerproxy.h"
PlayerWidget::PlayerWidget(QWidget *parent) : QWidget(parent){
setupGui();
}
void PlayerWidget::setupGui(){
+ //THE view
+ mView = new QTreeView;
+ mViewModel = new QStandardItemModel;
+ mViewProxy = new BeetPlayerProxy;
+ mViewProxy->setSourceModel(mViewModel);
+ mView->setModel(mViewProxy);
+
//filter
QGroupBox *filterGB = new QGroupBox(tr("Filter"));
mFilter = new QLineEdit;
connect(mFilter, SIGNAL(returnPressed()), this, SLOT(doFilter()));
QPushButton *filterB = new QPushButton(tr("Go!"));
connect(filterB, SIGNAL(clicked()), this, SLOT(doFilter()));
+ QPushButton *clearFilterB = new QPushButton(tr("Clear"));
+ connect(clearFilterB, SIGNAL(clicked()), this, SLOT(clearFilter()));
QHBoxLayout *filterLayout = new QHBoxLayout;
filterLayout->addWidget(mFilter);
filterLayout->addWidget(filterB);
+ filterLayout->addWidget(clearFilterB);
filterGB->setLayout(filterLayout);
- //show by
- QGroupBox *sortByGB = new QGroupBox(tr("Show by"));
- mSortBy = new QComboBox;
- mSortBy->addItems(QStringList() << tr("Artists") << tr("Albums") << tr("Genres"));
- connect(mSortBy, SIGNAL(currentIndexChanged(QString)), this, SLOT(populateBy(QString)));
- QPushButton *refreshSortB = new QPushButton(tr("Refresh"));
- connect(refreshSortB, SIGNAL(clicked()), this, SLOT(refreshSort()));
- QHBoxLayout *sortByL = new QHBoxLayout;
- sortByL->addWidget(mSortBy);
- sortByL->addWidget(refreshSortB);
- sortByL->setStretchFactor(mSortBy, 3);
- sortByGB->setLayout(sortByL);
-
- //THE view
- mView = new QTreeView;
- mViewModel = new QStandardItemModel;
- mViewProxy = new QSortFilterProxyModel;
- mViewProxy->setSourceModel(mViewModel);
- mView->setModel(mViewProxy);
-
//left widget
QWidget *leftWidget = new QWidget;
QVBoxLayout *leftWidgetL = new QVBoxLayout;
- leftWidgetL->addWidget(sortByGB);
leftWidgetL->addWidget(filterGB);
leftWidgetL->addWidget(mView);
leftWidget->setLayout(leftWidgetL);
@@ -110,20 +98,10 @@ void PlayerWidget::setupGui(){
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(splitter);
setLayout(mainLayout);
- refreshSort();
-}
-
-void PlayerWidget::populateBy(QString selector){
- if(selector == tr("Artists")){
- populateByArtist();
- }
+ populate();
}
-void PlayerWidget::refreshSort(){
- populateBy(mSortBy->currentText());
-}
-
-void PlayerWidget::populateByArtist(){
+void PlayerWidget::populate(){
//prepare Queries
QSqlDatabase db = QSqlDatabase::database("beetplayerdb");
QSqlQuery artistsQ(db);
@@ -131,7 +109,7 @@ void PlayerWidget::populateByArtist(){
QSqlQuery albumQ(db);
albumQ.prepare("SELECT DISTINCT(songs.ialbums_id), talbum_name, siyear FROM songs, albums WHERE songs.iartists_id = :artistid AND songs.ialbums_id = albums.ialbums_id ORDER BY siyear ASC");
QSqlQuery songQ(db);
- songQ.prepare("SELECT sipos, ttitle, tfullpath FROM songs WHERE ialbums_id = :alid AND iartists_id = :arid ORDER BY sipos ASC");
+ songQ.prepare("SELECT sipos, ttitle, tfullpath, igenres_id FROM songs WHERE ialbums_id = :alid AND iartists_id = :arid ORDER BY sipos ASC");
//reset view+model
mView->setSortingEnabled(false);
@@ -170,8 +148,18 @@ void PlayerWidget::populateByArtist(){
curSong->setData(Song, TypeRole);
curSong->setData(songQ.value(0), IdRole);
curSong->setData(songQ.value(2), FullPathRole);
+ curSong->setData(songQ.value(3), GenreRole);
curAlbum->appendRow(curSong);
}
}
}
}
+
+void PlayerWidget::doFilter(){
+ mViewProxy->setFilterRegExp(QRegExp(mFilter->text()));
+}
+
+void PlayerWidget::clearFilter(){
+ mFilter->setText(QString());
+ doFilter();
+}
diff --git a/playerwidget.h b/playerwidget.h
index e6e20d5..c9206cd 100644
--- a/playerwidget.h
+++ b/playerwidget.h
@@ -7,33 +7,31 @@ class QTreeView;
class QStandardItemModel;
class QSortFilterProxyModel;
class QLineEdit;
-class QComboBox;
class QLabel;
class QSlider;
class QTextEdit;
class QMediaPlayer;
+class BeetPlayerProxy;
class PlayerWidget : public QWidget {
Q_OBJECT
public:
enum ItemType { Artist, Album, Song };
- enum CustomRoles { TypeRole = Qt::UserRole + 1, IdRole = Qt::UserRole + 2, FullPathRole = Qt::UserRole + 3 };
+ enum CustomRoles { TypeRole = Qt::UserRole + 1, IdRole = Qt::UserRole + 2, FullPathRole = Qt::UserRole + 3, GenreRole = Qt::UserRole + 4 };
explicit PlayerWidget(QWidget *parent = 0);
public slots:
- //void doFilter();
- void populateBy(QString selector);
- void refreshSort();
+ void populate();
+ void doFilter();
+ void clearFilter();
private:
void setupGui();
- void populateByArtist();
- QComboBox *mSortBy;
QLineEdit *mFilter;
QMediaPlayer *mPlayer;
QTreeView *mView;
QStandardItemModel *mViewModel;
- QSortFilterProxyModel *mViewProxy;
+ BeetPlayerProxy *mViewProxy;
QLabel *mNowPlayingL;
QSlider *mSlider;
QTextEdit *mCurrentTE;