Extra buttons in cover view
authorNikolay Tischenko <niktischenko@gmail.com>
Sun, 31 Oct 2010 20:24:30 +0000 (02:24 +0600)
committerNikolay Tischenko <niktischenko@gmail.com>
Sun, 31 Oct 2010 20:24:30 +0000 (02:24 +0600)
resources/black/tags.png [new file with mode: 0644]
resources/resources.qrc
resources/white/tags.png [new file with mode: 0644]
someplayer.pro
src/clickablelabel.cpp [new file with mode: 0644]
src/clickablelabel.h [new file with mode: 0644]
src/playerform.cpp
src/playerform.h
src/ui/playerform.ui

diff --git a/resources/black/tags.png b/resources/black/tags.png
new file mode 100644 (file)
index 0000000..28dc1cd
Binary files /dev/null and b/resources/black/tags.png differ
index 7f0c680..2b1e138 100644 (file)
         <file>white/home.png</file>
         <file>black/folder.png</file>
         <file>white/folder.png</file>
+        <file>black/fav.png</file>
+        <file>white/fav.png</file>
+        <file>black/tags.png</file>
+        <file>white/tags.png</file>
     </qresource>
     <qresource prefix="/images">
         <file>defaultcover.png</file>
diff --git a/resources/white/tags.png b/resources/white/tags.png
new file mode 100644 (file)
index 0000000..f51d9ce
Binary files /dev/null and b/resources/white/tags.png differ
index 3232dcc..4a00ffa 100644 (file)
@@ -125,7 +125,8 @@ SOURCES += src/main.cpp\
     src/toolswidget.cpp \
     src/managelibraryform.cpp \
     src/directoryview.cpp \
-    src/coverfinder.cpp
+    src/coverfinder.cpp \
+    src/clickablelabel.cpp
 
 HEADERS  += src/mainwindow.h \
                src/player/player.h \
@@ -229,7 +230,8 @@ HEADERS  += src/mainwindow.h \
     src/toolswidget.h \
     src/managelibraryform.h \
     src/directoryview.h \
-    src/coverfinder.h
+    src/coverfinder.h \
+    src/clickablelabel.h
 
 FORMS    += src/ui/mainwindow.ui \
     src/ui/playerform.ui \
diff --git a/src/clickablelabel.cpp b/src/clickablelabel.cpp
new file mode 100644 (file)
index 0000000..3d28bdb
--- /dev/null
@@ -0,0 +1,10 @@
+#include "clickablelabel.h"
+
+ClickableLabel::ClickableLabel(QWidget *parent) :
+               QLabel(parent)
+{
+}
+
+void ClickableLabel::mousePressEvent(QMouseEvent *ev) {
+       emit clicked();
+}
diff --git a/src/clickablelabel.h b/src/clickablelabel.h
new file mode 100644 (file)
index 0000000..9293db2
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * SomePlayer - An alternate music player for Maemo 5
+ * Copyright (C) 2010 Nikolay (somebody) Tischenko <niktischenko@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#ifndef CLICKABLELABEL_H
+#define CLICKABLELABEL_H
+
+#include <QLabel>
+
+class ClickableLabel : public QLabel
+{
+       Q_OBJECT
+public:
+       explicit ClickableLabel(QWidget *parent = 0);
+
+protected:
+       void mousePressEvent(QMouseEvent *ev);
+
+signals:
+       void clicked();
+
+public slots:
+
+};
+
+#endif // CLICKABLELABEL_H
index 027051b..ec52a4b 100644 (file)
@@ -103,6 +103,13 @@ PlayerForm::PlayerForm(Library* lib, QWidget *parent) :
        _tag_resolver = new TagResolver(this);
        _coverfinder = new CoverFinder(this);
 
+       _cover = new ClickableLabel(this);
+       _cover->setMinimumSize(300, 300);
+       _cover->setMaximumSize(300, 300);
+       _cover->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+       _cover->setScaledContents(true);
+       _cover->setPixmap(QPixmap::fromImage(_coverfinder->defaultCover()));
+
        connect(ui->libraryButton, SIGNAL(clicked()), this, SLOT(_library()));
        connect(ui->viewButton, SIGNAL(clicked()), this, SLOT(_toggle_view()));
        connect(ui->playlistView, SIGNAL(activated(QModelIndex)), this, SLOT(_process_click(QModelIndex)));
@@ -135,16 +142,34 @@ PlayerForm::PlayerForm(Library* lib, QWidget *parent) :
        connect(_fscreen_button, SIGNAL(clicked(bool)), this, SIGNAL(fullscreen(bool)));
        connect(_fscreen_button, SIGNAL(clicked(bool)), _tools_widget, SLOT(setFullscreenState(bool)));
        connect(_coverfinder, SIGNAL(found(QImage)), this, SLOT(_display_cover(QImage)));
+       connect(ui->caddButton, SIGNAL(clicked()), this, SLOT(_c_add_to_playlists()));
+       connect(ui->cdeleteButton, SIGNAL(clicked()), this, SLOT(_c_delete_track()));
+       connect(ui->cfavButton, SIGNAL(clicked()), this, SLOT(_c_add_to_favorites()));
+       connect(ui->ctagButton, SIGNAL(clicked()), this, SLOT(_c_edit_tags()));
+       connect(_cover, SIGNAL(clicked()), this, SLOT(_toggle_extra_buttons()));
        ui->viewButton->setIcon(QIcon(":/icons/"+_icons_theme+"/playback.png"));
        _top_gradient = ui->topWidget->styleSheet();
        _bottom_gradient = ui->bottomWidget->styleSheet();
        ui->countdownWidget->hide();
 
+       // constructing cover layout
+       ui->coverLayout->removeItem(ui->clverticalLayout_0);
+       ui->coverLayout->removeItem(ui->clverticalLayout_1);
+       ui->coverLayout->removeItem(ui->cbverticalSpacer);
+       ui->coverLayout->removeItem(ui->ctverticalSpacer);
+       ((QGridLayout *)ui->coverLayout)->addItem(ui->ctverticalSpacer, 0, 1);
+       ((QGridLayout *)ui->coverLayout)->addItem(ui->cbverticalSpacer, 2, 1);
+       ((QGridLayout *)ui->coverLayout)->addItem(ui->clverticalLayout_0, 1, 0);
+       ((QGridLayout *)ui->coverLayout)->addItem(ui->clverticalLayout_1, 1, 2);
+       ((QGridLayout *)ui->coverLayout)->addWidget(_cover, 1, 1);
+       //
+
        // dbus
        _dbusadaptor = new DBusAdaptop(_player);
        QDBusConnection connection = QDBusConnection::sessionBus();
        bool ret = connection.registerService(_SERVICE_NAME_);
        ret = connection.registerObject("/", _player);
+       _show_extra_buttons = false;
 }
 
 PlayerForm::~PlayerForm()
@@ -263,6 +288,7 @@ void PlayerForm::_add_to_favorites() {
                return;
        int id = idx.first().row();
        _lib->addToFavorites(_current_playlist.tracks().at(id));
+       qWarning() << "added to favorites: " << id << _current_playlist.tracks().at(id).metadata().title();
 }
 
 void PlayerForm::_state_changed(PlayerState state) {
@@ -468,6 +494,7 @@ void PlayerForm::portraitMode() {
 
        ui->widget->layout()->removeItem(ui->coverLayout);
        ui->widget->layout()->removeItem(ui->controlLayout);
+
        ui->controlLayout->removeItem(ui->countHLayout);
        ui->controlLayout->removeItem(ui->cverticalSpacer_0);
        ui->controlLayout->removeWidget(ui->titleLabel);
@@ -550,6 +577,21 @@ void PlayerForm::updateIcons() {
        _icons_theme = config.getValue("ui/iconstheme").toString();
        _tools_widget->updateIcons();
        _track_renderer->updateIcons();
+       if (_show_extra_buttons) {
+               ui->caddButton->setIcon(QIcon(":/icons/"+_icons_theme+"/add.png"));
+               ui->cdeleteButton->setIcon(QIcon(":/icons/"+_icons_theme+"/delete.png"));
+               ui->cfavButton->setIcon(QIcon(":/icons/"+_icons_theme+"/fav.png"));
+               ui->ctagButton->setIcon(QIcon(":/icons/"+_icons_theme+"/tags.png"));
+       } else {
+               ui->caddButton->setIcon(QIcon());
+               ui->cdeleteButton->setIcon(QIcon());
+               ui->cfavButton->setIcon(QIcon());
+               ui->ctagButton->setIcon(QIcon());
+               ui->caddButton->setEnabled(false);
+               ui->cdeleteButton->setEnabled(false);
+               ui->cfavButton->setEnabled(false);
+               ui->ctagButton->setEnabled(false);
+       }
        ui->libraryButton->setIcon(QIcon(":/icons/"+_icons_theme+"/library.png"));
        if (_tools_widget->isVisible()) {
                ui->moreButton->setIcon(QIcon(landscape ? ":/icons/" + _icons_theme + "/unmore.png" : ":/icons/" + _icons_theme + "/more.png"));
@@ -560,6 +602,7 @@ void PlayerForm::updateIcons() {
        ui->stopButton->setIcon(QIcon(":/icons/"+_icons_theme+"/stop.png"));
        ui->prevButton->setIcon(QIcon(":/icons/"+_icons_theme+"/prev.png"));
        ui->dirButton->setIcon(QIcon(":/icons/"+_icons_theme+"/directory.png"));
+
        if (_player->state() == PLAYER_PLAYING) {
                ui->playpauseButton->setIcon(QIcon(":/icons/"+_icons_theme+"/pause.png"));
        } else {
@@ -620,5 +663,64 @@ void PlayerForm::hideCountdown() {
 }
 
 void PlayerForm::_display_cover(QImage image) {
-       ui->coverLabel->setPixmap(QPixmap::fromImage(image));
+       _cover->setPixmap(QPixmap::fromImage(image));
+}
+
+void PlayerForm::_c_add_to_favorites() {
+       int id = _track_renderer->activeRow();
+       qWarning() << id;
+       if (id >= 0 && id < _current_playlist.tracks().count()) {
+               ui->playlistView->selectRow(id);
+               _add_to_favorites();
+       }
+}
+
+void PlayerForm::_c_delete_track() {
+       int id = _track_renderer->activeRow();
+       qWarning() << id;
+       if (id >= 0 && id < _current_playlist.tracks().count()) {
+               ui->playlistView->selectRow(id);
+               _delete_track();
+       }
+}
+
+void PlayerForm::_c_add_to_playlists() {
+       int id = _track_renderer->activeRow();
+       qWarning() << id;
+       if (id >= 0 && id < _current_playlist.tracks().count()) {
+               ui->playlistView->selectRow(id);
+               _add_to_playlists();
+       }
+}
+
+void PlayerForm::_c_edit_tags() {
+       int id = _track_renderer->activeRow();
+       qWarning() << id;
+       if (id >= 0 && id < _current_playlist.tracks().count()) {
+               ui->playlistView->selectRow(id);
+               _edit_tags();
+       }
+}
+
+void PlayerForm::_toggle_extra_buttons() {
+       _show_extra_buttons = !_show_extra_buttons;
+       if (_show_extra_buttons) {
+               ui->caddButton->setEnabled(true);
+               ui->cdeleteButton->setEnabled(true);
+               ui->cfavButton->setEnabled(true);
+               ui->ctagButton->setEnabled(true);
+               ui->caddButton->setIcon(QIcon(":/icons/"+_icons_theme+"/add.png"));
+               ui->cdeleteButton->setIcon(QIcon(":/icons/"+_icons_theme+"/delete.png"));
+               ui->cfavButton->setIcon(QIcon(":/icons/"+_icons_theme+"/fav.png"));
+               ui->ctagButton->setIcon(QIcon(":/icons/"+_icons_theme+"/tags.png"));
+       } else {
+               ui->caddButton->setEnabled(false);
+               ui->cdeleteButton->setEnabled(false);
+               ui->cfavButton->setEnabled(false);
+               ui->ctagButton->setEnabled(false);
+               ui->caddButton->setIcon(QIcon());
+               ui->cdeleteButton->setIcon(QIcon());
+               ui->cfavButton->setIcon(QIcon());
+               ui->ctagButton->setIcon(QIcon());
+       }
 }
index 919834d..bd66e8d 100644 (file)
@@ -34,6 +34,7 @@
 #include "dbusadaptor.h"
 #include "toolswidget.h"
 #include "coverfinder.h"
+#include "clickablelabel.h"
 
 namespace Ui {
     class PlayerForm;
@@ -93,21 +94,27 @@ private slots:
        void _slider_released();
        void _custom_context_menu_requested ( const QPoint & pos );
        void _delete_track();
+       void _c_delete_track();
        void _enqueue_track();
        void _add_to_favorites();
+       void _c_add_to_favorites();
        void _add_to_playlists();
+       void _c_add_to_playlists();
        void _edit_tags();
+       void _c_edit_tags();
        void _state_changed(PlayerState);
        void _toggle_repeat();
        void _toggle_random();
        void _track_decoded(Track);
        void _tools_widget_toggle();
        void _display_cover(QImage);
+       void _toggle_extra_buttons();
 
 private:
     Ui::PlayerForm *ui;
        Library *_lib;
        Playlist _current_playlist;
+       ClickableLabel *_cover;
        QTime *_time;
        QStandardItemModel *_model;
        CoverFinder *_coverfinder;
@@ -121,6 +128,7 @@ private:
        QString _icons_theme;
        QString _top_gradient;
        QString _bottom_gradient;
+       bool _show_extra_buttons;
 
        TrackRenderer *_track_renderer;
        TagResolver *_tag_resolver;
index 2c96c3c..10111c3 100644 (file)
@@ -95,7 +95,7 @@
      <item>
       <widget class="QStackedWidget" name="stackedWidget">
        <property name="currentIndex">
-        <number>0</number>
+        <number>1</number>
        </property>
        <widget class="QWidget" name="page">
         <layout class="QVBoxLayout" name="verticalLayout_4">
             </property>
             <item row="0" column="0">
              <layout class="QGridLayout" name="coverLayout">
-              <item row="2" column="1">
-               <widget class="QLabel" name="coverLabel">
-                <property name="sizePolicy">
-                 <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
-                  <horstretch>0</horstretch>
-                  <verstretch>0</verstretch>
-                 </sizepolicy>
-                </property>
-                <property name="minimumSize">
-                 <size>
-                  <width>300</width>
-                  <height>300</height>
-                 </size>
-                </property>
-                <property name="maximumSize">
-                 <size>
-                  <width>300</width>
-                  <height>300</height>
-                 </size>
-                </property>
-                <property name="text">
-                 <string/>
-                </property>
-                <property name="pixmap">
-                 <pixmap resource="../../resources/resources.qrc">:/images/defaultcover.png</pixmap>
-                </property>
-                <property name="scaledContents">
-                 <bool>true</bool>
-                </property>
-                <property name="indent">
-                 <number>0</number>
-                </property>
-               </widget>
+              <item row="2" column="2">
+               <layout class="QVBoxLayout" name="clverticalLayout_1">
+                <item>
+                 <spacer name="verticalSpacer_2">
+                  <property name="orientation">
+                   <enum>Qt::Vertical</enum>
+                  </property>
+                  <property name="sizeHint" stdset="0">
+                   <size>
+                    <width>20</width>
+                    <height>40</height>
+                   </size>
+                  </property>
+                 </spacer>
+                </item>
+                <item>
+                 <widget class="QPushButton" name="ctagButton">
+                  <property name="sizePolicy">
+                   <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+                    <horstretch>0</horstretch>
+                    <verstretch>0</verstretch>
+                   </sizepolicy>
+                  </property>
+                  <property name="minimumSize">
+                   <size>
+                    <width>70</width>
+                    <height>70</height>
+                   </size>
+                  </property>
+                  <property name="maximumSize">
+                   <size>
+                    <width>70</width>
+                    <height>70</height>
+                   </size>
+                  </property>
+                  <property name="text">
+                   <string/>
+                  </property>
+                  <property name="icon">
+                   <iconset resource="../../resources/resources.qrc">
+                    <normaloff>:/icons/white/tags.png</normaloff>:/icons/white/tags.png</iconset>
+                  </property>
+                  <property name="flat">
+                   <bool>true</bool>
+                  </property>
+                 </widget>
+                </item>
+                <item>
+                 <spacer name="verticalSpacer">
+                  <property name="orientation">
+                   <enum>Qt::Vertical</enum>
+                  </property>
+                  <property name="sizeHint" stdset="0">
+                   <size>
+                    <width>20</width>
+                    <height>40</height>
+                   </size>
+                  </property>
+                 </spacer>
+                </item>
+                <item>
+                 <widget class="QPushButton" name="cfavButton">
+                  <property name="sizePolicy">
+                   <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+                    <horstretch>0</horstretch>
+                    <verstretch>0</verstretch>
+                   </sizepolicy>
+                  </property>
+                  <property name="minimumSize">
+                   <size>
+                    <width>70</width>
+                    <height>70</height>
+                   </size>
+                  </property>
+                  <property name="maximumSize">
+                   <size>
+                    <width>70</width>
+                    <height>70</height>
+                   </size>
+                  </property>
+                  <property name="text">
+                   <string/>
+                  </property>
+                  <property name="icon">
+                   <iconset resource="../../resources/resources.qrc">
+                    <normaloff>:/icons/white/fav.png</normaloff>:/icons/white/fav.png</iconset>
+                  </property>
+                  <property name="flat">
+                   <bool>true</bool>
+                  </property>
+                 </widget>
+                </item>
+                <item>
+                 <spacer name="verticalSpacer_3">
+                  <property name="orientation">
+                   <enum>Qt::Vertical</enum>
+                  </property>
+                  <property name="sizeHint" stdset="0">
+                   <size>
+                    <width>20</width>
+                    <height>40</height>
+                   </size>
+                  </property>
+                 </spacer>
+                </item>
+               </layout>
               </item>
               <item row="2" column="0">
-               <spacer name="horizontalSpacer">
-                <property name="orientation">
-                 <enum>Qt::Horizontal</enum>
-                </property>
-                <property name="sizeHint" stdset="0">
-                 <size>
-                  <width>40</width>
-                  <height>20</height>
-                 </size>
-                </property>
-               </spacer>
-              </item>
-              <item row="2" column="2">
-               <spacer name="chorizontalSpacer">
-                <property name="orientation">
-                 <enum>Qt::Horizontal</enum>
-                </property>
-                <property name="sizeHint" stdset="0">
-                 <size>
-                  <width>40</width>
-                  <height>20</height>
-                 </size>
-                </property>
-               </spacer>
+               <layout class="QVBoxLayout" name="clverticalLayout_0">
+                <item>
+                 <spacer name="verticalSpacer_4">
+                  <property name="orientation">
+                   <enum>Qt::Vertical</enum>
+                  </property>
+                  <property name="sizeHint" stdset="0">
+                   <size>
+                    <width>20</width>
+                    <height>40</height>
+                   </size>
+                  </property>
+                 </spacer>
+                </item>
+                <item>
+                 <widget class="QPushButton" name="caddButton">
+                  <property name="sizePolicy">
+                   <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+                    <horstretch>0</horstretch>
+                    <verstretch>0</verstretch>
+                   </sizepolicy>
+                  </property>
+                  <property name="minimumSize">
+                   <size>
+                    <width>70</width>
+                    <height>70</height>
+                   </size>
+                  </property>
+                  <property name="maximumSize">
+                   <size>
+                    <width>70</width>
+                    <height>70</height>
+                   </size>
+                  </property>
+                  <property name="text">
+                   <string/>
+                  </property>
+                  <property name="icon">
+                   <iconset resource="../../resources/resources.qrc">
+                    <normaloff>:/icons/white/add.png</normaloff>:/icons/white/add.png</iconset>
+                  </property>
+                  <property name="flat">
+                   <bool>true</bool>
+                  </property>
+                 </widget>
+                </item>
+                <item>
+                 <spacer name="verticalSpacer_8">
+                  <property name="orientation">
+                   <enum>Qt::Vertical</enum>
+                  </property>
+                  <property name="sizeHint" stdset="0">
+                   <size>
+                    <width>20</width>
+                    <height>40</height>
+                   </size>
+                  </property>
+                 </spacer>
+                </item>
+                <item>
+                 <widget class="QPushButton" name="cdeleteButton">
+                  <property name="sizePolicy">
+                   <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+                    <horstretch>0</horstretch>
+                    <verstretch>0</verstretch>
+                   </sizepolicy>
+                  </property>
+                  <property name="minimumSize">
+                   <size>
+                    <width>70</width>
+                    <height>70</height>
+                   </size>
+                  </property>
+                  <property name="maximumSize">
+                   <size>
+                    <width>70</width>
+                    <height>70</height>
+                   </size>
+                  </property>
+                  <property name="text">
+                   <string/>
+                  </property>
+                  <property name="icon">
+                   <iconset resource="../../resources/resources.qrc">
+                    <normaloff>:/icons/white/delete.png</normaloff>:/icons/white/delete.png</iconset>
+                  </property>
+                  <property name="flat">
+                   <bool>true</bool>
+                  </property>
+                 </widget>
+                </item>
+                <item>
+                 <spacer name="verticalSpacer_7">
+                  <property name="orientation">
+                   <enum>Qt::Vertical</enum>
+                  </property>
+                  <property name="sizeHint" stdset="0">
+                   <size>
+                    <width>20</width>
+                    <height>40</height>
+                   </size>
+                  </property>
+                 </spacer>
+                </item>
+               </layout>
               </item>
-              <item row="3" column="1">
-               <spacer name="verticalSpacer_5">
+              <item row="1" column="1">
+               <spacer name="ctverticalSpacer">
                 <property name="orientation">
                  <enum>Qt::Vertical</enum>
                 </property>
                 </property>
                </spacer>
               </item>
-              <item row="1" column="1">
-               <spacer name="verticalSpacer_6">
+              <item row="3" column="1">
+               <spacer name="cbverticalSpacer">
                 <property name="orientation">
                  <enum>Qt::Vertical</enum>
                 </property>