From 221e1255d07db6f30c099ce454ae95d1bde6bd06 Mon Sep 17 00:00:00 2001 From: Thomas Frauendorfer Date: Mon, 19 May 2008 21:16:32 +0200 Subject: [PATCH] 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 --- src/Skin.cpp | 5 +++ src/Skin.h | 2 + src/mainwindow/maindisplay.cpp | 12 ++---- src/mainwindow/maindisplay.h | 1 - src/mainwindow/mainwindow.h | 1 + src/mainwindow/shadeddisplay.cpp | 49 ++++++++++++++---------- src/mainwindow/shadeddisplay.h | 6 +++ src/mainwindow/timedisplay.cpp | 64 +++++++++++++++++++++----------- src/mainwindow/timedisplay.h | 29 +++++++++++++-- 9 files changed, 115 insertions(+), 54 deletions(-) diff --git a/src/Skin.cpp b/src/Skin.cpp index 10d15b3..806ebc5 100644 --- a/src/Skin.cpp +++ b/src/Skin.cpp @@ -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/"); diff --git a/src/Skin.h b/src/Skin.h index 49f19f4..98f3376 100644 --- a/src/Skin.h +++ b/src/Skin.h @@ -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 m_backgrounds; QMap m_numbers; + QMap m_smallNumbers; QMap m_items; QMap m_letterMap; QMap m_playlist; diff --git a/src/mainwindow/maindisplay.cpp b/src/mainwindow/maindisplay.cpp index 70c1e4b..ae25383 100644 --- a/src/mainwindow/maindisplay.cpp +++ b/src/mainwindow/maindisplay.cpp @@ -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 ("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) { diff --git a/src/mainwindow/maindisplay.h b/src/mainwindow/maindisplay.h index 9c125cf..7f3e358 100644 --- a/src/mainwindow/maindisplay.h +++ b/src/mainwindow/maindisplay.h @@ -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); diff --git a/src/mainwindow/mainwindow.h b/src/mainwindow/mainwindow.h index 736e71c..e3f3a42 100644 --- a/src/mainwindow/mainwindow.h +++ b/src/mainwindow/mainwindow.h @@ -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(); } diff --git a/src/mainwindow/shadeddisplay.cpp b/src/mainwindow/shadeddisplay.cpp index 0cbf30f..4e076c9 100644 --- a/src/mainwindow/shadeddisplay.cpp +++ b/src/mainwindow/shadeddisplay.cpp @@ -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(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 ("url").c_str ()); } + + if (info.contains ("duration")) { + m_duration = (info.get ("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(m_mw)->isTimemodeReverse()) { + showtime = (time/1000 - m_duration/1000); + } else { + showtime = time/1000; + } + m_time->setTime (showtime); } diff --git a/src/mainwindow/shadeddisplay.h b/src/mainwindow/shadeddisplay.h index 924ea68..7795152 100644 --- a/src/mainwindow/shadeddisplay.h +++ b/src/mainwindow/shadeddisplay.h @@ -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 diff --git a/src/mainwindow/timedisplay.cpp b/src/mainwindow/timedisplay.cpp index 953cba8..7c161e2 100644 --- a/src/mainwindow/timedisplay.cpp +++ b/src/mainwindow/timedisplay.cpp @@ -20,15 +20,32 @@ #include -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(); -} - diff --git a/src/mainwindow/timedisplay.h b/src/mainwindow/timedisplay.h index 866d608..b8f9ad3 100644 --- a/src/mainwindow/timedisplay.h +++ b/src/mainwindow/timedisplay.h @@ -25,16 +25,17 @@ class QPixmap; typedef QMap 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