summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--BeetPlayer.pro6
-rw-r--r--helper.cpp26
-rw-r--r--helper.h14
-rw-r--r--playerwidget.cpp32
-rw-r--r--playerwidget.h2
5 files changed, 75 insertions, 5 deletions
diff --git a/BeetPlayer.pro b/BeetPlayer.pro
index 4a208a8..a2aa13f 100644
--- a/BeetPlayer.pro
+++ b/BeetPlayer.pro
@@ -30,7 +30,8 @@ SOURCES += main.cpp\
globals.cpp \
playerwidget.cpp \
beetview.cpp \
- indexerdialog.cpp
+ indexerdialog.cpp \
+ helper.cpp
HEADERS += beetplayer.h \
configurationdialog.h \
@@ -38,7 +39,8 @@ HEADERS += beetplayer.h \
globals.h \
playerwidget.h \
beetview.h \
- indexerdialog.h
+ indexerdialog.h \
+ helper.h
LIBS += -ltag
diff --git a/helper.cpp b/helper.cpp
new file mode 100644
index 0000000..91e4d7f
--- /dev/null
+++ b/helper.cpp
@@ -0,0 +1,26 @@
+#include <QPainter>
+#include <QPalette>
+#include <QAction>
+#include <QApplication>
+
+#include "helper.h"
+
+namespace Helper {
+ QIcon iconFromQChar(const QChar &c, int pixelSize){
+ QPixmap pm(QSize(64,64));
+ QPainter p(&pm);
+ QFont f = p.font();
+ f.setPixelSize(pixelSize);
+ p.setFont(f);
+ p.fillRect(pm.rect(), qApp->palette().color(QPalette::Window));
+ p.setBrush(QBrush(Qt::black));
+ p.drawText(pm.rect(), Qt::AlignCenter, c);
+ return QIcon(pm);
+ }
+
+ QAction* createSeparator(QObject *parent){
+ QAction *a = new QAction(parent);
+ a->setSeparator(true);
+ return a;
+ }
+}
diff --git a/helper.h b/helper.h
new file mode 100644
index 0000000..9b4a5c9
--- /dev/null
+++ b/helper.h
@@ -0,0 +1,14 @@
+#ifndef HELPER_H
+#define HELPER_H
+
+#include <QIcon>
+#include <QChar>
+
+class QAction;
+
+namespace Helper {
+ QIcon iconFromQChar(const QChar &c, int pixelSize);
+ QAction* createSeparator(QObject *parent);
+}
+
+#endif // HELPER_H
diff --git a/playerwidget.cpp b/playerwidget.cpp
index 1bd8ac6..deddfe6 100644
--- a/playerwidget.cpp
+++ b/playerwidget.cpp
@@ -15,6 +15,7 @@
#include <QAction>
#include <QToolBar>
#include <QHash>
+#include <QPainter>
#include <QApplication>
#include <algorithm>
@@ -25,6 +26,7 @@
#include "beetview.h"
#include "indexerdialog.h"
#include "globals.h"
+#include "helper.h"
PlayerWidget::PlayerWidget(QWidget *parent) : QWidget(parent){
setupGui();
@@ -203,6 +205,10 @@ void PlayerWidget::createActions(){
connect(addToPlayListA, SIGNAL(triggered()), this, SLOT(addToPlayList()));
QAction *addToPlayListAndClearA = new QAction(QIcon(":/belly_right_and_clear.png"), tr("Clear and add"), this);
connect(addToPlayListAndClearA, SIGNAL(triggered()), this, SLOT(addToPlayListAndClear()));
+ QAction *expandA = new QAction(Helper::iconFromQChar(QChar(0x2640), 90), tr("Expand"), this);
+ connect(expandA, SIGNAL(triggered()), this, SLOT(expand()));
+ QAction *collapseAllA = new QAction(Helper::iconFromQChar(QChar(0x2642), 120), tr("Collapse all"), this);
+ connect(collapseAllA, SIGNAL(triggered()), mView, SLOT(collapseAll()));
QAction *removeFromPlayListA = new QAction(QIcon(":/belly_left.png"), tr("Remove from playlist"), this);
connect(removeFromPlayListA, SIGNAL(triggered()), this, SLOT(removeFromPlayList()));
QAction *clearPlayListA = new QAction(QIcon(":/delete.png"), tr("Clear Playlist"), this);
@@ -219,9 +225,10 @@ void PlayerWidget::createActions(){
QAction *configA = Globals::instance()->action(Globals::ConfigAction);
mView->addAction(addToPlayListA);
mView->addAction(addToPlayListAndClearA);
- QAction *mViewAS1 = new QAction(this);
- mViewAS1->setSeparator(true);
- mView->addAction(mViewAS1);
+ mView->addAction(Helper::createSeparator(this));
+ mView->addAction(expandA);
+ mView->addAction(collapseAllA);
+ mView->addAction(Helper::createSeparator(this));
mView->addAction(randomPlayA);
mPlayListView->addAction(removeFromPlayListA);
mPlayListView->addAction(shufflePlayistA);
@@ -720,3 +727,22 @@ void PlayerWidget::continuePlaying(QMediaPlayer::State state){
next();
}
}
+
+void PlayerWidget::expand(){
+ QModelIndexList sel = mView->selectionModel()->selectedRows();
+ foreach(QModelIndex i, sel){
+ mView->expand(i);
+ expandRecursive(i);
+ }
+}
+
+void PlayerWidget::expandRecursive(const QModelIndex &idx){
+ const QStandardItemModel *model = static_cast<const QStandardItemModel*>(idx.model());
+ QStandardItem *item = model->itemFromIndex(idx);
+ for(int i = 0; i < item->rowCount(); ++i){
+ QModelIndex cur = model->indexFromItem(item->child(i, 0));
+ if(cur.isValid()){
+ mView->expand(cur);
+ }
+ }
+}
diff --git a/playerwidget.h b/playerwidget.h
index e2ac24d..5f9210c 100644
--- a/playerwidget.h
+++ b/playerwidget.h
@@ -47,6 +47,7 @@ class PlayerWidget : public QWidget {
void setDuration(qint64 dur);
void slide(int value);
void continuePlaying(QMediaPlayer::State state);
+ void expand();
private:
void setupGui();
@@ -59,6 +60,7 @@ class PlayerWidget : public QWidget {
void addSong(const QModelIndex &idx);
void play(const QString &fullPath);
void advance(int numSongs);
+ void expandRecursive(const QModelIndex &idx);
QLineEdit *mSearch;
QMediaPlayer *mPlayer;
BeetView *mView;