[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-28 20:10:24
Message-ID: 1217275824.529088.23830.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 838821 by alexmerry:
Split out the grid of text labels into its own class.
And make the control panel a QWidget, rather than containing a QLayoutItem, which was \
always a stupid idea.
M +2 -1 CMakeLists.txt
M +8 -27 controls.cpp
M +5 -6 controls.h
A infopanel.cpp [License: GPL (v2+)]
A infopanel.h [License: GPL (v2+)]
M +50 -46 nowplaying.cpp
M +13 -10 nowplaying.h
--- trunk/KDE/kdeplasma-addons/applets/nowplaying/CMakeLists.txt #838820:838821
@@ -5,7 +5,8 @@
set(nowplaying_SRCS
nowplaying.cpp
- controls.cpp)
+ controls.cpp
+ infopanel.cpp)
kde4_add_plugin(plasma_applet_nowplaying ${nowplaying_SRCS})
target_link_libraries(plasma_applet_nowplaying ${PLASMA_LIBS} ${KDE4_KDEUI_LIBS})
--- trunk/KDE/kdeplasma-addons/applets/nowplaying/controls.cpp #838820:838821
@@ -24,41 +24,22 @@
setCaps(NoCaps);
- QGraphicsLinearLayout* layout = new QGraphicsLinearLayout(Qt::Horizontal);
+ QGraphicsLinearLayout* m_layout = new QGraphicsLinearLayout(Qt::Horizontal);
// adding stretches -> segfault
- //layout->addStretch(1);
- layout->addItem(m_prev);
- layout->addItem(m_playpause);
- layout->addItem(m_stop);
- layout->addItem(m_next);
- //layout->addStretch(1);
+ //m_layout->addStretch(1);
+ m_layout->addItem(m_prev);
+ m_layout->addItem(m_playpause);
+ m_layout->addItem(m_stop);
+ m_layout->addItem(m_next);
+ //m_layout->addStretch(1);
- m_layout = layout;
+ setLayout(m_layout);
}
Controls::~Controls()
{
- // FIXME: mem leak if the widget isn't on a canvas, vs. crash if it is...
- // delete m_layout;
- if (!m_playpause->scene()) {
- delete m_playpause;
- }
- if (!m_stop->scene()) {
- delete m_stop;
- }
- if (!m_prev->scene()) {
- delete m_prev;
- }
- if (!m_next->scene()) {
- delete m_next;
- }
}
-QGraphicsLayoutItem* Controls::widget() const
-{
- return m_layout;
-}
-
void Controls::playPauseClicked()
{
if (m_state == Playing) {
--- trunk/KDE/kdeplasma-addons/applets/nowplaying/controls.h #838820:838821
@@ -19,17 +19,16 @@
#ifndef CONTROLS_H
#define CONTROLS_H
-#include <QObject>
+#include <QGraphicsWidget>
#include "nowplaying.h"
namespace Plasma {
class Icon;
}
-class QGraphicsLayoutItem;
class QGraphicsLayout;
-class Controls : public QObject
+class Controls : public QGraphicsWidget
{
Q_OBJECT
@@ -37,8 +36,6 @@
Controls();
~Controls();
- QGraphicsLayoutItem* widget() const;
-
public slots:
void stateChanged(State state);
void setCaps(Caps caps);
@@ -58,7 +55,9 @@
Plasma::Icon* m_stop;
Plasma::Icon* m_prev;
Plasma::Icon* m_next;
- QGraphicsLayout* m_layout;
+
+ QGraphicsLinearLayout* m_layout;
+
State m_state;
Caps m_caps;
};
--- trunk/KDE/kdeplasma-addons/applets/nowplaying/nowplaying.cpp #838820:838821
@@ -22,8 +22,8 @@
#include "nowplaying.h"
#include "controls.h"
+#include "infopanel.h"
-
#include <Plasma/Theme>
#include <Plasma/Label>
@@ -40,15 +40,9 @@
m_controller(0),
m_state(NoPlayer),
m_caps(NoCaps),
- m_artistLabel(new Plasma::Label),
- m_titleLabel(new Plasma::Label),
- m_albumLabel(new Plasma::Label),
- m_timeLabel(new Plasma::Label),
- m_artistText(new Plasma::Label),
- m_titleText(new Plasma::Label),
- m_albumText(new Plasma::Label),
- m_timeText(new Plasma::Label),
- m_textPanel(0),
+ m_volume(0),
+ m_length(0),
+ m_textPanel(new InfoPanel),
m_buttonPanel(new Controls)
{
setAspectRatioMode(Plasma::IgnoreAspectRatio);
@@ -64,6 +58,9 @@
m_buttonPanel, SLOT(stateChanged(State)));
connect(this, SIGNAL(capsChanged(Caps)),
m_buttonPanel, SLOT(setCaps(Caps)));
+
+ connect(this, SIGNAL(metadataChanged(QMap<QString,QString>)),
+ m_textPanel, SLOT(updateMetadata(QMap<QString,QString>)));
}
NowPlaying::~NowPlaying()
@@ -72,34 +69,9 @@
void NowPlaying::init()
{
- // set up labels
- m_textPanel = new QGraphicsGridLayout;
- m_textPanel->setColumnStretchFactor(0, 0);
- m_textPanel->setColumnSpacing(0, 10);
- m_textPanel->setColumnAlignment(0, Qt::AlignRight);
-
- m_artistLabel->setText(i18nc("For a song or other music", "Artist:"));
- m_artistLabel->nativeWidget()->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
- m_titleLabel->setText(i18nc("For a song or other music", "Title:"));
- m_titleLabel->nativeWidget()->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
- m_albumLabel->setText(i18nc("For a song or other music", "Album:"));
- m_albumLabel->nativeWidget()->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
- m_timeLabel->setText(i18nc("Position in a song", "Time:"));
- m_timeLabel->nativeWidget()->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
-
- // TODO: make this configurable
- m_textPanel->addItem(m_artistLabel, 0, 0);
- m_textPanel->addItem(m_artistText, 0, 1);
- m_textPanel->addItem(m_titleLabel, 1, 0);
- m_textPanel->addItem(m_titleText, 1, 1);
- m_textPanel->addItem(m_albumLabel, 2, 0);
- m_textPanel->addItem(m_albumText, 2, 1);
- m_textPanel->addItem(m_timeLabel, 3, 0);
- m_textPanel->addItem(m_timeText, 3, 1);
-
m_layout = new QGraphicsLinearLayout(Qt::Vertical);
m_layout->addItem(m_textPanel);
- m_layout->addItem(m_buttonPanel->widget());
+ m_layout->addItem(m_buttonPanel);
setLayout(m_layout);
@@ -145,21 +117,53 @@
m_state = newstate;
}
- m_artistText->setText(data["Artist"].toString());
- m_albumText->setText(data["Album"].toString());
- m_titleText->setText(data["Title"].toString());
-
+ QString timeText;
int length = data["Length"].toInt();
+ if (length != m_length) {
+ m_length = length;
+ if (length == 0) {
+ emit positionChanged(0);
+ }
+ emit lengthChanged(m_length);
+ }
if (length != 0) {
int pos = data["Position"].toInt();
- m_timeText->setText(QString::number(pos / 60) + ':' +
- QString::number(pos % 60).rightJustified(2, '0') + " / \
" +
- QString::number(length / 60) + ':' +
- QString::number(length % 60).rightJustified(2, '0'));
- } else {
- m_timeText->setText(QString());
+ timeText = QString::number(pos / 60) + ':' +
+ QString::number(pos % 60).rightJustified(2, '0') + " / " +
+ QString::number(length / 60) + ':' +
+ QString::number(length % 60).rightJustified(2, '0');
+ // we assume it's changed
+ emit positionChanged(pos);
}
+ QMap<QString,QString> metadata;
+ metadata["Artist"] = data["Artist"].toString();
+ metadata["Album"] = data["Album"].toString();
+ metadata["Title"] = data["Title"].toString();
+ metadata["Time"] = timeText;
+ metadata["Track number"] = QString::number(data["Track number"].toInt());
+ metadata["Comment"] = data["Comment"].toString();
+ metadata["Genre"] = data["Genre"].toString();
+
+ // the time should usually have changed
+ emit metadataChanged(metadata);
+
+ if (data["Volume"].toDouble() != m_volume) {
+ m_volume = data["Volume"].toDouble();
+ emit volumeChanged(m_volume * 100);
+ }
+
+ // used for seeing when the track has changed
+ QString track = metadata["Artist"] + " - " + metadata["Title"];
+
+ // assume the artwork didn't change unless the track did
+ if (track != m_track) {
+ m_track = track;
+
+ m_artwork = data["Artwork"].value<QPixmap>();
+ emit coverChanged(m_artwork);
+ }
+
Caps newcaps = NoCaps;
if (data["Can play"].toBool()) {
newcaps |= CanPlay;
--- trunk/KDE/kdeplasma-addons/applets/nowplaying/nowplaying.h #838820:838821
@@ -24,6 +24,8 @@
#include <plasma/dataengine.h>
#include <plasma/service.h>
+#include <QPixmap>
+
class QGraphicsGridLayout;
class QGraphicsLinearLayout;
namespace Plasma {
@@ -31,6 +33,7 @@
class Icon;
}
class Controls;
+class InfoPanel;
enum State {
Playing,
@@ -63,6 +66,11 @@
signals:
void stateChanged(State state);
void capsChanged(Caps caps);
+ void metadataChanged(const QMap<QString,QString>& metadata);
+ void coverChanged(const QPixmap& picture);
+ void volumeChanged(int volumePercent);
+ void positionChanged(int position);
+ void lengthChanged(int length);
public slots:
void dataUpdated(const QString &name,
@@ -85,18 +93,13 @@
State m_state;
Caps m_caps;
- Plasma::Label* m_artistLabel;
- Plasma::Label* m_titleLabel;
- Plasma::Label* m_albumLabel;
- Plasma::Label* m_timeLabel;
+ qreal m_volume;
+ int m_length;
+ QString m_track;
+ QPixmap m_artwork;
- Plasma::Label* m_artistText;
- Plasma::Label* m_titleText;
- Plasma::Label* m_albumText;
- Plasma::Label* m_timeText;
-
QGraphicsLinearLayout* m_layout;
- QGraphicsGridLayout* m_textPanel;
+ InfoPanel* m_textPanel;
Controls* m_buttonPanel;
};
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic