OTHER: Update ShadedDisplay to use new SmallTimeDisplay
split Timedisplay into a common class and a specialised class and make new SmallTimeDisplay inherit from the common class. Thus as much code as possible is reused in SmallTimeDisplay
This commit is contained in:
parent
1fa72bd3f0
commit
221e1255d0
9 changed files with 115 additions and 54 deletions
|
@ -334,6 +334,7 @@ Skin::setSkin (const QString& name)
|
|||
BuildEqualizer ();
|
||||
|
||||
m_letterMap.clear();
|
||||
m_smallNumbers.clear ();
|
||||
BuildLetterMap();
|
||||
|
||||
BuildSliders();
|
||||
|
@ -418,6 +419,7 @@ Skin::BuildLetterMap (void)
|
|||
/* digits */
|
||||
for (uint i = 0; i <= 9; i++) {
|
||||
m_letterMap[i+48] = letters[1][i];
|
||||
m_smallNumbers [i] = letters[1][i];
|
||||
}
|
||||
|
||||
/* special characters */
|
||||
|
@ -453,6 +455,9 @@ Skin::BuildLetterMap (void)
|
|||
|
||||
/* text background */
|
||||
m_items[TEXTBG] = letters[2][6];
|
||||
|
||||
m_smallNumbers[10] = letters[2][6];
|
||||
m_smallNumbers[11] = letters[1][15];
|
||||
}
|
||||
else
|
||||
setSkin(":CleanAMP/");
|
||||
|
|
|
@ -45,6 +45,7 @@ class Skin : public QObject
|
|||
const QPixmapList getBackgrounds (uint item) const
|
||||
{ return m_backgrounds.value(item); };
|
||||
const PixmapMap getNumbers () const { return m_numbers; }
|
||||
const PixmapMap getSmallNumbers () const { return m_smallNumbers; }
|
||||
|
||||
const QPixmap getItem (uint part) const { return m_items[part]; }
|
||||
const QPixmap getPls (uint part) const { return m_playlist[part]; }
|
||||
|
@ -258,6 +259,7 @@ class Skin : public QObject
|
|||
QMap<uint, QPixmapList> m_backgrounds;
|
||||
|
||||
QMap<int, QPixmap> m_numbers;
|
||||
QMap<int, QPixmap> m_smallNumbers;
|
||||
QMap<uint, QPixmap> m_items;
|
||||
QMap<uint, QPixmap> m_letterMap;
|
||||
QMap<uint, QPixmap> m_playlist;
|
||||
|
|
|
@ -60,7 +60,7 @@ MainDisplay::MainDisplay (QWidget *parent) : SkinDisplay(parent)
|
|||
|
||||
m_time = new TimeDisplay(this);
|
||||
m_time->move (36, 26);
|
||||
connect (m_time, SIGNAL(clicked()), this, SLOT(toggleTime()));
|
||||
connect (m_time, SIGNAL(clicked()), m_mw, SLOT(toggleTime()));
|
||||
|
||||
m_kbps = new SmallNumberDisplay (this, 15);
|
||||
m_kbps->move (111, 43);
|
||||
|
@ -187,7 +187,7 @@ MainDisplay::setStatus (Xmms::Playback::Status status)
|
|||
void
|
||||
MainDisplay::setPlaytime (uint32_t time)
|
||||
{
|
||||
uint32_t showtime;
|
||||
int32_t showtime;
|
||||
if (m_mw->isTimemodeReverse()) {
|
||||
uint maxtime = m_posbar->maximum ();
|
||||
showtime = (time/1000 - maxtime/1000);
|
||||
|
@ -243,6 +243,7 @@ MainDisplay::setMediainfo (const Xmms::PropDict &info)
|
|||
m_posbar->setMaximum (info.get<int32_t> ("duration"));
|
||||
m_posbar->show ();
|
||||
} else {
|
||||
m_posbar->setMaximum (0);
|
||||
m_posbar->hide ();
|
||||
}
|
||||
}
|
||||
|
@ -289,13 +290,6 @@ MainDisplay::SetupToggleButtons (void)
|
|||
this, SLOT (setRepeatAllEnabled (bool)));
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MainDisplay::toggleTime (void)
|
||||
{
|
||||
m_mw->setTimemodeReverse (!m_mw->isTimemodeReverse());
|
||||
}
|
||||
|
||||
void
|
||||
MainDisplay::SetupPushButtons (void)
|
||||
{
|
||||
|
|
|
@ -71,7 +71,6 @@ class MainDisplay : public SkinDisplay
|
|||
void setStatus (Xmms::Playback::Status status);
|
||||
void setPlaytime (uint32_t time);
|
||||
void setMediainfo (const Xmms::PropDict &);
|
||||
void toggleTime(void);
|
||||
void updateVolume (uint volume);
|
||||
void setVolume (int volume);
|
||||
|
||||
|
|
|
@ -51,6 +51,7 @@ class MainWindow : public BaseWindow
|
|||
public slots:
|
||||
void switchDisplay ();
|
||||
void mouseMoveEvent (QMouseEvent *event);
|
||||
void toggleTime () { setTimemodeReverse (!isTimemodeReverse ()); }
|
||||
|
||||
private:
|
||||
bool isShaded (void) { QSettings s; return s.value("MainWindow/shaded").toBool(); }
|
||||
|
|
|
@ -22,26 +22,25 @@
|
|||
#include "TitleBar.h"
|
||||
#include "pixmapbutton.h"
|
||||
|
||||
#include "timedisplay.h"
|
||||
#include "SmallNumberDisplay.h"
|
||||
#include "TextBar.h"
|
||||
#include "Skin.h"
|
||||
#include "mainwindow.h"
|
||||
|
||||
ShadedDisplay::ShadedDisplay (QWidget *parent) : SkinDisplay (parent)
|
||||
{
|
||||
XMMSHandler &client = XMMSHandler::getInstance ();
|
||||
|
||||
setMinimumSize (275, 14);
|
||||
setMaximumSize (275, 14);
|
||||
setFixedSize (275, 14);
|
||||
|
||||
m_tbar = new TitleBar(this, true);
|
||||
m_tbar->move (0, 0);
|
||||
|
||||
m_number = new SmallNumberDisplay (this, 10);
|
||||
m_number->move (135, 4);
|
||||
m_number->setNumber (0, 2);
|
||||
|
||||
m_number2 = new SmallNumberDisplay (this, 10);
|
||||
m_number2->move (147, 4);
|
||||
m_number2->setNumber (0, 2);
|
||||
m_time = new SmallTimeDisplay (this);
|
||||
m_time->move (130, 4);
|
||||
MainWindow *mw = dynamic_cast<MainWindow *>(parent);
|
||||
connect (m_time, SIGNAL(clicked()), mw, SLOT(toggleTime()));
|
||||
|
||||
m_title = new TextScroller (this, 39, 7, "shaded");
|
||||
m_title->move (79, 4);
|
||||
|
@ -50,7 +49,7 @@ ShadedDisplay::ShadedDisplay (QWidget *parent) : SkinDisplay (parent)
|
|||
m_prev->move(169, 4);
|
||||
m_prev->resize (8, 7);
|
||||
connect (m_prev, SIGNAL(clicked()), client.xplayback (), SLOT(prev ()));
|
||||
|
||||
|
||||
m_play = new PixmapButton (this);
|
||||
m_play->move(177, 4);
|
||||
m_play->resize (10, 7);
|
||||
|
@ -85,6 +84,12 @@ ShadedDisplay::ShadedDisplay (QWidget *parent) : SkinDisplay (parent)
|
|||
this, SLOT(setMediainfo (const Xmms::PropDict &)));
|
||||
}
|
||||
|
||||
void
|
||||
ShadedDisplay::setPixmaps (Skin *skin)
|
||||
{
|
||||
m_time->setPixmaps (skin->getSmallNumbers ());
|
||||
}
|
||||
|
||||
void
|
||||
ShadedDisplay::setMediainfo (const Xmms::PropDict &info)
|
||||
{
|
||||
|
@ -99,6 +104,12 @@ ShadedDisplay::setMediainfo (const Xmms::PropDict &info)
|
|||
} else {
|
||||
n = QString::fromUtf8 (info.get<std::string> ("url").c_str ());
|
||||
}
|
||||
|
||||
if (info.contains ("duration")) {
|
||||
m_duration = (info.get<int32_t> ("duration"));
|
||||
} else {
|
||||
m_duration = 0;
|
||||
}
|
||||
m_title->setText (n);
|
||||
}
|
||||
|
||||
|
@ -106,21 +117,21 @@ void
|
|||
ShadedDisplay::setStatus (Xmms::Playback::Status status)
|
||||
{
|
||||
if (status == Xmms::Playback::STOPPED) {
|
||||
m_number->setNumber (0, 2);
|
||||
m_number2->setNumber (0, 2);
|
||||
//m_number->setNumber (0, 2);
|
||||
//nm_number2->setNumber (0, 2);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ShadedDisplay::setPlaytime (uint32_t time)
|
||||
{
|
||||
uint sec, min;
|
||||
|
||||
sec = (time / 1000) % 60;
|
||||
min = (time / 1000) / 60;
|
||||
|
||||
m_number2->setNumber (sec, 2);
|
||||
m_number->setNumber (min, 2);
|
||||
int32_t showtime;
|
||||
if (dynamic_cast<MainWindow *>(m_mw)->isTimemodeReverse()) {
|
||||
showtime = (time/1000 - m_duration/1000);
|
||||
} else {
|
||||
showtime = time/1000;
|
||||
}
|
||||
m_time->setTime (showtime);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -22,7 +22,9 @@ class ShadedDisplay;
|
|||
#include "Display.h"
|
||||
|
||||
class MainWindow;
|
||||
class Skin;
|
||||
class PixmapButton;
|
||||
class SmallTimeDisplay;
|
||||
class SmallNumberDisplay;
|
||||
class TextScroller;
|
||||
|
||||
|
@ -38,6 +40,9 @@ class ShadedDisplay : public SkinDisplay
|
|||
TextScroller *m_title;
|
||||
|
||||
private:
|
||||
int32_t m_duration;
|
||||
SmallTimeDisplay *m_time;
|
||||
|
||||
PixmapButton *m_prev;
|
||||
PixmapButton *m_play;
|
||||
PixmapButton *m_pause;
|
||||
|
@ -49,6 +54,7 @@ class ShadedDisplay : public SkinDisplay
|
|||
void setStatus (Xmms::Playback::Status status);
|
||||
void setPlaytime (uint32_t time);
|
||||
void setMediainfo (const Xmms::PropDict &info);
|
||||
void setPixmaps (Skin *skin);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -20,15 +20,32 @@
|
|||
#include <QMap>
|
||||
|
||||
|
||||
TimeDisplay::TimeDisplay (QWidget *parent) : QWidget (parent)
|
||||
TimeDisplay::TimeDisplay (QWidget *parent) : AbstractTimeDisplay (parent)
|
||||
{
|
||||
setFixedSize (63, 13);
|
||||
|
||||
m_d1_x_pos = 12;
|
||||
m_d2_x_pos = 24;
|
||||
m_d3_x_pos = 42;
|
||||
m_d4_x_pos = 54;
|
||||
}
|
||||
|
||||
SmallTimeDisplay::SmallTimeDisplay (QWidget *parent)
|
||||
: AbstractTimeDisplay (parent)
|
||||
{
|
||||
setFixedSize (28, 6);
|
||||
|
||||
m_d1_x_pos = 5;
|
||||
m_d2_x_pos = 10;
|
||||
m_d3_x_pos = 18;
|
||||
m_d4_x_pos = 23;
|
||||
}
|
||||
|
||||
/*
|
||||
* This method takes the playtime in seconds
|
||||
*/
|
||||
void TimeDisplay::setTime (int time)
|
||||
void
|
||||
AbstractTimeDisplay::setTime (int time)
|
||||
{
|
||||
// Hack to make display hours and seconds instead of seconds and minutes
|
||||
// if time (or reversetime) is 100 Minutes or longer
|
||||
|
@ -43,12 +60,24 @@ void TimeDisplay::setTime (int time)
|
|||
}
|
||||
|
||||
void
|
||||
TimeDisplay::paintEvent (QPaintEvent *event)
|
||||
{
|
||||
if (m_pixmaps.size () < 11) {
|
||||
qDebug ("too small");
|
||||
AbstractTimeDisplay::setPixmaps (const PixmapMap &p) {
|
||||
if (p.size () < 11) {
|
||||
// This shouldn't happen, if it does then there is a bug in Skin.cpp
|
||||
qDebug ("TimeDisplay: PixmapMap has not enough elements");
|
||||
return;
|
||||
}
|
||||
m_pixmaps = p;
|
||||
}
|
||||
|
||||
void
|
||||
AbstractTimeDisplay::mouseReleaseEvent (QMouseEvent *event)
|
||||
{
|
||||
emit clicked();
|
||||
}
|
||||
|
||||
void
|
||||
AbstractTimeDisplay::paintEvent (QPaintEvent *event)
|
||||
{
|
||||
QPainter paint;
|
||||
paint.begin (this);
|
||||
|
||||
|
@ -63,26 +92,19 @@ TimeDisplay::paintEvent (QPaintEvent *event)
|
|||
if (showtime < 6000) {
|
||||
// draw minutes
|
||||
uint min = showtime / 60;
|
||||
paint.drawPixmap (12, 0, m_pixmaps[min/10]);
|
||||
paint.drawPixmap (24, 0, m_pixmaps[min%10]);
|
||||
paint.drawPixmap (m_d1_x_pos, 0, m_pixmaps[min/10]);
|
||||
paint.drawPixmap (m_d2_x_pos, 0, m_pixmaps[min%10]);
|
||||
// draw seconds
|
||||
uint sec = showtime % 60;
|
||||
paint.drawPixmap (42, 0, m_pixmaps[sec/10]);
|
||||
paint.drawPixmap (54, 0, m_pixmaps[sec%10]);
|
||||
paint.drawPixmap (m_d3_x_pos, 0, m_pixmaps[sec/10]);
|
||||
paint.drawPixmap (m_d4_x_pos, 0, m_pixmaps[sec%10]);
|
||||
} else {
|
||||
// Just give up and draw '-' if min would become 100 or bigger
|
||||
paint.drawPixmap (12, 0, m_pixmaps[11]);
|
||||
paint.drawPixmap (24, 0, m_pixmaps[11]);
|
||||
paint.drawPixmap (42, 0, m_pixmaps[11]);
|
||||
paint.drawPixmap (54, 0, m_pixmaps[11]);
|
||||
paint.drawPixmap (m_d1_x_pos, 0, m_pixmaps[11]);
|
||||
paint.drawPixmap (m_d2_x_pos, 0, m_pixmaps[11]);
|
||||
paint.drawPixmap (m_d3_x_pos, 0, m_pixmaps[11]);
|
||||
paint.drawPixmap (m_d4_x_pos, 0, m_pixmaps[11]);
|
||||
|
||||
}
|
||||
paint.end ();
|
||||
}
|
||||
|
||||
void
|
||||
TimeDisplay::mouseReleaseEvent (QMouseEvent *event)
|
||||
{
|
||||
emit clicked();
|
||||
}
|
||||
|
||||
|
|
|
@ -25,16 +25,17 @@ class QPixmap;
|
|||
|
||||
typedef QMap<int, QPixmap> PixmapMap;
|
||||
|
||||
class TimeDisplay : public QWidget
|
||||
// This class is not really abstract, but named so anyway
|
||||
class AbstractTimeDisplay : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
TimeDisplay (QWidget *parent);
|
||||
~TimeDisplay () {};
|
||||
AbstractTimeDisplay (QWidget *parent) : QWidget (parent) {};
|
||||
~AbstractTimeDisplay () {};
|
||||
void setTime (int);
|
||||
|
||||
public slots:
|
||||
void setPixmaps (const PixmapMap &p) {m_pixmaps = p;}
|
||||
void setPixmaps (const PixmapMap &p);
|
||||
|
||||
signals:
|
||||
void clicked(void);
|
||||
|
@ -44,8 +45,28 @@ class TimeDisplay : public QWidget
|
|||
void mouseReleaseEvent (QMouseEvent *event);
|
||||
void paintEvent (QPaintEvent *event);
|
||||
|
||||
// positions for the digits, numbered from left to right
|
||||
int m_d1_x_pos;
|
||||
int m_d2_x_pos;
|
||||
int m_d3_x_pos;
|
||||
int m_d4_x_pos;
|
||||
|
||||
int m_time;
|
||||
PixmapMap m_pixmaps;
|
||||
};
|
||||
|
||||
class TimeDisplay : public AbstractTimeDisplay
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
TimeDisplay (QWidget *parent);
|
||||
};
|
||||
|
||||
class SmallTimeDisplay : public AbstractTimeDisplay
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
SmallTimeDisplay (QWidget *parent);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue