[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdeplasma-addons/applets/nowplaying
From:       Alex Merry <huntedhacker () tiscali ! co ! uk>
Date:       2008-07-29 0:32:28
Message-ID: 1217291548.343227.1202.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 838895 by alexmerry:

Use the new Plasma::Slider widgets: a volume control and a seek control



 M  +60 -7     nowplaying.cpp  
 M  +9 -4      nowplaying.h  


--- trunk/KDE/kdeplasma-addons/applets/nowplaying/nowplaying.cpp #838894:838895
@@ -24,12 +24,10 @@
 #include "controls.h"
 #include "infopanel.h"
 
-#include <Plasma/Theme>
-#include <Plasma/Label>
+#include <Plasma/Slider>
 
 #include <QGraphicsGridLayout>
 #include <QGraphicsLinearLayout>
-#include <QLabel>
 
 
 K_EXPORT_PLASMA_APPLET(nowplaying, NowPlaying)
@@ -43,7 +41,9 @@
       m_volume(0),
       m_length(0),
       m_textPanel(new InfoPanel),
-      m_buttonPanel(new Controls)
+      m_buttonPanel(new Controls),
+      m_volumeSlider(new Plasma::Slider(Qt::Vertical)),
+      m_positionSlider(new Plasma::Slider(Qt::Horizontal))
 {
     setAspectRatioMode(Plasma::IgnoreAspectRatio);
     resize(300, 165);
@@ -61,6 +61,26 @@
 
     connect(this, SIGNAL(metadataChanged(QMap<QString,QString>)),
             m_textPanel, SLOT(updateMetadata(QMap<QString,QString>)));
+
+    m_volumeSlider->setMinimum(0);
+    m_volumeSlider->setMaximum(100);
+    m_volumeSlider->setValue(0);
+    connect(this, SIGNAL(volumeChanged(int)),
+            m_volumeSlider, SLOT(setValue(int)));
+    connect(m_volumeSlider, SIGNAL(sliderMoved(int)),
+            this, SLOT(setVolume(int)));
+    m_volumeSlider->setEnabled(false);
+
+    m_positionSlider->setMinimum(0);
+    m_positionSlider->setMaximum(0);
+    m_positionSlider->setValue(0);
+    connect(this, SIGNAL(positionChanged(int)),
+            m_positionSlider, SLOT(setValue(int)));
+    connect(this, SIGNAL(lengthChanged(int)),
+            m_positionSlider, SLOT(setMaximum(int)));
+    connect(m_positionSlider, SIGNAL(sliderMoved(int)),
+            this, SLOT(setPosition(int)));
+    m_positionSlider->setEnabled(false);
 }
 
 NowPlaying::~NowPlaying()
@@ -69,9 +89,11 @@
 
 void NowPlaying::init()
 {
-    m_layout = new QGraphicsLinearLayout(Qt::Vertical);
-    m_layout->addItem(m_textPanel);
-    m_layout->addItem(m_buttonPanel);
+    m_layout = new QGraphicsGridLayout();
+    m_layout->addItem(m_textPanel, 0, 0);
+    m_layout->addItem(m_buttonPanel, 1, 0);
+    m_layout->addItem(m_positionSlider, 2, 0);
+    m_layout->addItem(m_volumeSlider, 0, 1, 3, 1); // rowspan, colspan
 
     setLayout(m_layout);
 
@@ -148,6 +170,8 @@
     // the time should usually have changed
     emit metadataChanged(metadata);
 
+    // TODO: we should set a tooltip with the timeText on the position slider
+
     if (data["Volume"].toDouble() != m_volume) {
         m_volume = data["Volume"].toDouble();
         emit volumeChanged(m_volume * 100);
@@ -180,9 +204,17 @@
     if (data["Can skip forward"].toBool()) {
         newcaps |= CanGoNext;
     }
+    if (data["Can seek"].toBool()) {
+        newcaps |= CanSeek;
+    }
+    if (data["Can set volume"].toBool()) {
+        newcaps |= CanSetVolume;
+    }
     if (newcaps != m_caps) {
         emit capsChanged(newcaps);
         m_caps = newcaps;
+        m_positionSlider->setEnabled(m_caps & CanSeek);
+        m_volumeSlider->setEnabled(m_caps & CanSetVolume);
     }
 
     update();
@@ -218,6 +250,8 @@
 
         emit stateChanged(m_state);
         emit capsChanged(m_caps);
+        m_positionSlider->setEnabled(false);
+        m_volumeSlider->setEnabled(false);
         update();
     } else {
         m_watchingPlayer = players.first();
@@ -262,4 +296,23 @@
     }
 }
 
+void NowPlaying::setVolume(int volumePercent)
+{
+    qreal volume = ((qreal)qBound(0, volumePercent, 100)) / 100;
+    if (m_controller) {
+        KConfigGroup op = m_controller->operationDescription("volume");
+        op.writeEntry("level", volume);
+        m_controller->startOperationCall(op);
+    }
+}
+
+void NowPlaying::seek(int position)
+{
+    if (m_controller) {
+        KConfigGroup op = m_controller->operationDescription("seek");
+        op.writeEntry("seconds", position);
+        m_controller->startOperationCall(op);
+    }
+}
+
 #include "nowplaying.moc"
--- trunk/KDE/kdeplasma-addons/applets/nowplaying/nowplaying.h #838894:838895
@@ -29,8 +29,7 @@
 class QGraphicsGridLayout;
 class QGraphicsLinearLayout;
 namespace Plasma {
-    class Label;
-    class Icon;
+    class Slider;
 }
 class Controls;
 class InfoPanel;
@@ -48,7 +47,9 @@
     CanPause = 2,
     CanStop = 4,
     CanGoPrevious = 8,
-    CanGoNext = 16
+    CanGoNext = 16,
+    CanSeek = 32,
+    CanSetVolume = 64
 };
 Q_DECLARE_FLAGS(Caps, CapsFlags)
 Q_DECLARE_OPERATORS_FOR_FLAGS(Caps)
@@ -84,6 +85,8 @@
     void stop();
     void prev();
     void next();
+    void setVolume(int volumePercent);
+    void seek(int position);
 
 private:
     void findPlayer();
@@ -98,9 +101,11 @@
     QString m_track;
     QPixmap m_artwork;
 
-    QGraphicsLinearLayout* m_layout;
+    QGraphicsGridLayout* m_layout;
     InfoPanel* m_textPanel;
     Controls* m_buttonPanel;
+    Plasma::Slider* m_volumeSlider;
+    Plasma::Slider* m_positionSlider;
 };
 
 #endif // NOWPLAYING_H
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic