From kde-commits Tue Jul 29 00:32:28 2008 From: Alex Merry Date: Tue, 29 Jul 2008 00:32:28 +0000 To: kde-commits Subject: KDE/kdeplasma-addons/applets/nowplaying Message-Id: <1217291548.343227.1202.nullmailer () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=121729155620719 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 -#include +#include #include #include -#include 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)), m_textPanel, SLOT(updateMetadata(QMap))); + + 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