working up/down/del controls on each row
authortmarki <tmarki@gmail.com>
Wed, 11 Aug 2010 22:43:07 +0000 (00:43 +0200)
committertmarki <tmarki@gmail.com>
Wed, 11 Aug 2010 22:43:07 +0000 (00:43 +0200)
mainwindow.cpp
mainwindow.h
playlistmanager.cpp
playlistmanager.h

index 6024d17..b627f1a 100644 (file)
@@ -22,6 +22,7 @@ MainWindow::MainWindow()
     connect(mediaObject, SIGNAL(aboutToFinish()), this, SLOT(aboutToFinish()));
     connect (&plman, SIGNAL (playlistChanged (int)), this, SLOT (playlistChanged(int)));
     connect (&plman, SIGNAL (itemUpdated(int)), this, SLOT (itemUpdated (int)));
+    connect (&plman, SIGNAL (itemRemoved(int)), this, SLOT (itemRemoved (int)));
 
     Phonon::createPath(mediaObject, audioOutput);
 
@@ -32,6 +33,7 @@ MainWindow::MainWindow()
     setupActions();
     setupMenus();
     setupUi();
+    show ();
     timeLcd->display("00:00:00");
     plman.addStringList(settings.value("lastPlaylist").toStringList());
     setupShuffleList();
@@ -769,18 +771,29 @@ void MainWindow::setRowFromItem (int row, const PlaylistItem& item)
         item3->setFlags(item3->flags() ^ Qt::ItemIsEditable);
         musicTable->setItem(row, 2, item3);
     }
-    qDebug () << "Widget: " << musicTable->cellWidget(row, 3);
 
     if (!musicTable->cellWidget(row, 3))
     {
         QToolBar* bar = new QToolBar;
-        QPushButton* up = new QPushButton;
-        up->setText("up");
+        QLabel* up = new QLabel;
+        up->setText(QString::fromUtf8("<b><a href='up'>▲</a></b>"));
+        up->setStyleSheet("padding-right:3px;");
         up->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
-        bar->setProperty("row", row);
         bar->addWidget(up);
+        QLabel* down = new QLabel;
+        down->setText(QString::fromUtf8("<b><a href='down'>▼</a></b>"));
+        down->setStyleSheet("padding-right:3px;");
+        bar->addWidget(down);
+        QLabel* del = new QLabel;
+        del->setText(QString::fromUtf8("<b><a href='del'>╳</a></b>"));
+        del->setStyleSheet("padding-right:3px;");
+        bar->addWidget(del);
+        down->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
+        bar->setProperty("row", row);
         musicTable->setCellWidget(row, 3, bar);
-        connect (up, SIGNAL (clicked ()),  this, SLOT (buttonUp ()));
+        connect (up, SIGNAL (linkActivated (const QString&)),  this, SLOT (buttonUp ()));
+        connect (down, SIGNAL (linkActivated (const QString&)),  this, SLOT (buttonDown ()));
+        connect (del, SIGNAL (linkActivated (const QString&)),  this, SLOT (buttonDel ()));
     }
 }
 
@@ -799,6 +812,31 @@ void MainWindow::buttonUp()
     }
 }
 
+void MainWindow::buttonDown()
+{
+    int i = sender()->parent()->property("row").toInt();
+    qDebug () << "Presses down on " << i;
+    if (i < plman.size() - 1)
+    {
+        plman.moveItemDown(i);
+        setRowFromItem (i, plman.getItem(i));
+        setRowFromItem (i + 1, plman.getItem(i + 1));
+        musicTable->cellWidget(i, 3)->setProperty("row", i);
+        musicTable->cellWidget(i + 1, 3)->setProperty("row", i + 1);
+        musicTable->selectRow(i + 1);
+    }
+}
+
+void MainWindow::buttonDel()
+{
+    int i = sender()->parent()->property("row").toInt();
+    qDebug () << "Presses del on " << i;
+    if (i < plman.size())
+    {
+        plman.removeItem(i);
+    }
+}
+
 void MainWindow::itemUpdated(int index)
 {
     if (plman.indexOf(mediaObject->currentSource()) < 0 && plman.getItem (index).playable)
@@ -812,3 +850,13 @@ void MainWindow::itemUpdated(int index)
         setItem (index, false);
     }
 }
+
+void MainWindow::itemRemoved (int i)
+{
+    musicTable->removeRow(i);
+    for (int j = i ? (i - 1) : 0; j < musicTable->rowCount(); ++j)
+    {
+        if (musicTable->cellWidget(j, 3))
+            musicTable->cellWidget(j, 3)->setProperty("row", j);
+    }
+}
index 5376287..ce4edca 100644 (file)
@@ -99,6 +99,9 @@ private slots:
     void highlightRow (int i);
     void unhighlightRow (int i);
     void buttonUp ();
+    void buttonDown ();
+    void buttonDel ();
+    void itemRemoved (int i);
 
 protected:
     void contextMenuEvent (QContextMenuEvent*e);
index c70ae1d..61681a2 100644 (file)
@@ -306,9 +306,10 @@ QStringList PlaylistManager::playlistStrings() const
 void PlaylistManager::removeItem(int i)
 {
     items.removeAt (i);
-    emit playlistChanged(i);
+    emit itemRemoved(i);
 }
 
+
 bool PlaylistManager::fileSupported (const QString& fname) const
 {
     QString ext = fname.right(3).toLower();
@@ -333,3 +334,16 @@ bool PlaylistManager::moveItemUp (int i)
     }
     return false;
 }
+
+bool PlaylistManager::moveItemDown (int i)
+{
+    if (i < items.size () - 1)
+    {
+        PlaylistItem tmp = items[i + 1];
+        items[i + 1] = items[i];
+        items[i] = tmp;
+        return true;
+//        emit playlistChanged(i - 1);
+    }
+    return false;
+}
index df87b4b..d1bbaba 100644 (file)
@@ -35,6 +35,7 @@ public:
     const Phonon::MediaSource& at (int i) { return items[i].source; }
     const PlaylistItem& getItem (int i) const { return items[i]; }
     bool moveItemUp (int i);
+    bool moveItemDown (int i);
 public slots:
     void savePlaylist(const QString& filename);
     void loadPlaylist(const QString& filename);
@@ -42,6 +43,7 @@ public slots:
     void addPlaylist (const QString& filename);
 signals:
     void playlistChanged (int from);
+    void itemRemoved (int i);
     void itemUpdated (int index);
 private slots:
     void metaStateChanged(Phonon::State newState, Phonon::State oldState);