From 9343fc6c77da8678df98ceb6330c61f43aa48737 Mon Sep 17 00:00:00 2001 From: Arno Date: Sun, 5 Mar 2017 05:51:22 +0100 Subject: Implement expand and collapse for DB view Sounds easy, right? It is, if you don't try to create a QIcon from a QChar. That took me a while... First, it's not a good idea to fill the QPixmap for the QIcon with transparency. That gives you a random background. Fill it with palette color instead. Then there's QFont's pixelSize(). I have absolutely no idea how it corresponds to the pixmap's size, but roughly double the width of the pixmap is a good guess... --- playerwidget.cpp | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'playerwidget.cpp') diff --git a/playerwidget.cpp b/playerwidget.cpp index 1bd8ac6..deddfe6 100644 --- a/playerwidget.cpp +++ b/playerwidget.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -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(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); + } + } +} -- cgit v1.2.3-70-g09d2