From 058e2d09874fab87a080b6487de0f31cef7526d8 Mon Sep 17 00:00:00 2001 From: Thomas Frauendorfer Date: Fri, 11 Jul 2008 03:41:45 +0200 Subject: [PATCH] OTHER: Replaced SmallNumberDisplay --- src/Skin.cpp | 2 + src/SmallNumberDisplay.cpp | 65 ----------------------- src/SmallNumberDisplay.h | 44 ---------------- src/mainwindow/maindisplay.cpp | 26 ++++++---- src/mainwindow/maindisplay.h | 8 +-- src/mainwindow/shadeddisplay.cpp | 1 - src/src.pri | 2 - src/widgets/pixmapnumberdisplay.cpp | 80 +++++++++++++++++++++++++++++ src/widgets/pixmapnumberdisplay.h | 49 ++++++++++++++++++ src/widgets/widgets.pri | 2 + 10 files changed, 153 insertions(+), 126 deletions(-) delete mode 100644 src/SmallNumberDisplay.cpp delete mode 100644 src/SmallNumberDisplay.h create mode 100644 src/widgets/pixmapnumberdisplay.cpp create mode 100644 src/widgets/pixmapnumberdisplay.h diff --git a/src/Skin.cpp b/src/Skin.cpp index 806ebc5..6c7593e 100644 --- a/src/Skin.cpp +++ b/src/Skin.cpp @@ -457,6 +457,7 @@ Skin::BuildLetterMap (void) m_items[TEXTBG] = letters[2][6]; m_smallNumbers[10] = letters[2][6]; + m_smallNumbers[-1] = m_smallNumbers[10]; // also add Blank to index -1 m_smallNumbers[11] = letters[1][15]; } else @@ -747,6 +748,7 @@ Skin::BuildNumbers (void) for (int i = 0; i < num; i++) { m_numbers[i] = img->copy (i*9, 0, 9, qMin (13, img->height ())); } + m_numbers[-1] = m_numbers[10]; // add Blank space to index -1 if (num < 12) { // We do not yet have a '-' Symbol, so we create one // from the '2' character and the blank as background diff --git a/src/SmallNumberDisplay.cpp b/src/SmallNumberDisplay.cpp deleted file mode 100644 index d6da37b..0000000 --- a/src/SmallNumberDisplay.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/** - * This file is a part of Promoe, an XMMS2 Client. - * - * Copyright (C) 2005-2008 XMMS2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - */ - -#include "SmallNumberDisplay.h" -#include "Skin.h" - -#include - -SmallNumberDisplay::SmallNumberDisplay (QWidget *parent, int w) : PixWidget (parent) -{ - m_w = w; - setMinimumSize (w, 6); - setMaximumSize (w, 6); - m_pixmap = QPixmap (w, 6); -} - -void -SmallNumberDisplay::setPixmaps (Skin *skin) -{ - drawNumber (); -} - -void -SmallNumberDisplay::setNumber (int num, int len) -{ - snprintf (m_nums, len+1, "%02d", num); - m_num = len; - - drawNumber (); - - update (); -} - -void -SmallNumberDisplay::drawNumber () -{ - Skin *skin = Skin::getInstance (); - - QPainter paint; - paint.begin (&m_pixmap); - paint.drawPixmap (m_pixmap.rect (), - skin->getItem (Skin::TEXTBG), - m_pixmap.rect ()); - - for (int i = 0; i < m_num; i++) { - paint.drawPixmap (QRect (i*5, 0, 5, 6), - skin->getLetter (m_nums[i]), - skin->getLetter (m_nums[i]).rect ()); - } - - paint.end (); -} - diff --git a/src/SmallNumberDisplay.h b/src/SmallNumberDisplay.h deleted file mode 100644 index 7b92914..0000000 --- a/src/SmallNumberDisplay.h +++ /dev/null @@ -1,44 +0,0 @@ -/** - * This file is a part of Promoe, an XMMS2 Client. - * - * Copyright (C) 2005-2008 XMMS2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - */ - -#ifndef __SMALLNUMBERDISPLAY_H__ -#define __SMALLNUMBERDISPLAY_H__ - -#include "PixWidget.h" - - -class SmallNumberDisplay : public PixWidget -{ - Q_OBJECT; - - public: - SmallNumberDisplay (QWidget *parent, int w); - ~SmallNumberDisplay () { }; - - void setNumber (int num, int len); - int getNumber (void) const { return m_num; } - - public slots: - void setPixmaps (Skin *skin); - - private: - char m_nums[2]; - int m_num; - int m_w; - - void drawNumber (void); -}; - -#endif diff --git a/src/mainwindow/maindisplay.cpp b/src/mainwindow/maindisplay.cpp index 9fd315b..f79d72f 100644 --- a/src/mainwindow/maindisplay.cpp +++ b/src/mainwindow/maindisplay.cpp @@ -28,7 +28,7 @@ #include "TextBar.h" #include "timedisplay.h" #include "Skin.h" -#include "SmallNumberDisplay.h" +#include "pixmapnumberdisplay.h" #include "stereomono.h" #include "posbar.h" #include "playstatus.h" @@ -63,13 +63,17 @@ MainDisplay::MainDisplay (QWidget *parent) : SkinDisplay(parent) m_time->move (36, 26); connect (m_time, SIGNAL(clicked()), m_mw, SLOT(toggleTime())); - m_kbps = new SmallNumberDisplay (this, 15); + m_kbps = new PixmapNumberDisplay (this); + m_kbps->resize (15, 6); m_kbps->move (111, 43); - m_kbps->setNumber (128, 3); + m_kbps->setDigits (3); + m_kbps->setValue (0); - m_khz = new SmallNumberDisplay (this, 10); + m_khz = new PixmapNumberDisplay (this); + m_khz->resize (10, 6); m_khz->move (156, 43); - m_khz->setNumber (44, 2); + m_khz->setDigits (2); + m_khz->setValue (0); m_stereo = new StereoMono (this); m_stereo->move (212, 41); @@ -119,7 +123,7 @@ MainDisplay::MainDisplay (QWidget *parent) : SkinDisplay(parent) void MainDisplay::handleDisconnected () { - QMessageBox::critical( this, "xmms2 daemon disconnecte", + QMessageBox::critical( this, "xmms2 daemon disconnected", "The xmms2 deamon has disconnected\n" "This could be because the server crashed\n" "or because another client has shut down the sever.", @@ -173,6 +177,8 @@ MainDisplay::setPixmaps (Skin *skin) /* update some other widgets */ m_time->setPixmaps (skin->getNumbers ()); + m_kbps->setPixmaps (skin->getSmallNumbers ()); + m_khz->setPixmaps (skin->getSmallNumbers ()); } void @@ -236,15 +242,15 @@ MainDisplay::setMediainfo (const Xmms::PropDict &info) m_text->setText (n); if (info.contains ("bitrate")) { - m_kbps->setNumber (info.get ("bitrate")/1000, 3); + m_kbps->setValue (info.get ("bitrate")/1000); } else { - m_kbps->setNumber (0, 1); + m_kbps->setValue (0); } if (info.contains ("samplerate")) { - m_khz->setNumber (info.get ("samplerate")/1000, 2); + m_khz->setValue (info.get ("samplerate")/1000); } else { - m_khz->setNumber(0, 1); + m_khz->setValue(0); } if (info.contains ("channels") && info.get ("channels") > 1) { diff --git a/src/mainwindow/maindisplay.h b/src/mainwindow/maindisplay.h index 7388bad..1ce36ab 100644 --- a/src/mainwindow/maindisplay.h +++ b/src/mainwindow/maindisplay.h @@ -33,10 +33,10 @@ class MainDisplay; #include "Display.h" class PixmapButton; +class PixmapNumberDisplay; class PixmapSlider; class TextScroller; class TimeDisplay; -class SmallNumberDisplay; class StereoMono; class PosBar; class Slider; @@ -55,9 +55,6 @@ class MainDisplay : public SkinDisplay TextScroller *m_text; TimeDisplay *m_time; - SmallNumberDisplay *m_kbps; - SmallNumberDisplay *m_khz; - StereoMono *m_stereo; PosBar *m_posbar; PixmapSlider *m_vslider; @@ -94,6 +91,9 @@ class MainDisplay : public SkinDisplay PixmapButton *m_shuffle; PixmapButton *m_repeat; + PixmapNumberDisplay *m_kbps; + PixmapNumberDisplay *m_khz; + MainWindow *m_mw; ClutterBar *m_clutterbar; diff --git a/src/mainwindow/shadeddisplay.cpp b/src/mainwindow/shadeddisplay.cpp index 4e076c9..432c838 100644 --- a/src/mainwindow/shadeddisplay.cpp +++ b/src/mainwindow/shadeddisplay.cpp @@ -23,7 +23,6 @@ #include "pixmapbutton.h" #include "timedisplay.h" -#include "SmallNumberDisplay.h" #include "TextBar.h" #include "Skin.h" #include "mainwindow.h" diff --git a/src/src.pri b/src/src.pri index 14cc0cc..a8f14a0 100644 --- a/src/src.pri +++ b/src/src.pri @@ -10,7 +10,6 @@ HEADERS += PixWidget.h \ TitleBar.h \ TextBar.h \ XMMSHandler.h \ - SmallNumberDisplay.h \ SkinChooser.h \ settingsdialog.h \ basewindow.h \ @@ -25,7 +24,6 @@ SOURCES += main.cpp \ TitleBar.cpp \ TextBar.cpp \ XMMSHandler.cpp \ - SmallNumberDisplay.cpp \ SkinChooser.cpp \ settingsdialog.cpp \ basewindow.cpp \ diff --git a/src/widgets/pixmapnumberdisplay.cpp b/src/widgets/pixmapnumberdisplay.cpp new file mode 100644 index 0000000..f6e8187 --- /dev/null +++ b/src/widgets/pixmapnumberdisplay.cpp @@ -0,0 +1,80 @@ +/** + * This file is a part of Promoe, an XMMS2 Client. + * + * Copyright (C) 2005-2008 XMMS2 Team + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include "pixmapnumberdisplay.h" +#include "math.h" + +#include + +PixmapNumberDisplay::PixmapNumberDisplay (QWidget *parent) : QWidget (parent) +{ +} + +void +PixmapNumberDisplay::setPixmaps (PixmapMap numbers) +{ + m_numbers = numbers; + update (); +} + +void +PixmapNumberDisplay::setValue (int value) +{ + if (m_value == value) + return; + + m_value = value; + update (); +} + +void +PixmapNumberDisplay::setDigits (unsigned int digits) +{ + if (m_digits == digits) + return; + + m_digits = digits; + update (); +} + +int +PixmapNumberDisplay::getDigitAtPos (unsigned int position) { + if (m_value == 0) { + if (position == 1) + return 0; + else + return -1; + } + if ( m_value / (unsigned int) pow (10, position - 1) == 0) + return -1; + + return (unsigned int) (m_value / pow (10, position - 1)) % 10; +} + +void +PixmapNumberDisplay::paintEvent (QPaintEvent *event) +{ + QPainter paint; + paint.begin (this); + + for (unsigned int i = 0; i < m_digits; i++) { + paint.drawPixmap (i*5, 0, + m_numbers[getDigitAtPos (m_digits - i)]); + } + + paint.end (); +} + diff --git a/src/widgets/pixmapnumberdisplay.h b/src/widgets/pixmapnumberdisplay.h new file mode 100644 index 0000000..169575e --- /dev/null +++ b/src/widgets/pixmapnumberdisplay.h @@ -0,0 +1,49 @@ +/** + * This file is a part of Promoe, an XMMS2 Client. + * + * Copyright (C) 2005-2008 XMMS2 Team + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifndef __PIXMAPNUMBERDISPLAY_H__ +#define __PIXMAPNUMBERDISPLAY_H__ + +#include +#include + +class QPaintEvent; +class Skin; + +typedef QMap PixmapMap; + +class PixmapNumberDisplay : public QWidget +{ + Q_OBJECT; + + public: + PixmapNumberDisplay (QWidget *parent); + ~PixmapNumberDisplay () { }; + + void setValue (int value); + void setDigits (unsigned int digits); + void setPixmaps (PixmapMap numbers); + + private: + int m_value; + unsigned int m_digits; + PixmapMap m_numbers; + + int getDigitAtPos (unsigned int position); + void paintEvent (QPaintEvent *event); +}; + +#endif diff --git a/src/widgets/widgets.pri b/src/widgets/widgets.pri index 970db7e..7e83c4a 100644 --- a/src/widgets/widgets.pri +++ b/src/widgets/widgets.pri @@ -1,7 +1,9 @@ HEADERS += pixmapbutton.h \ + pixmapnumberdisplay.h \ pixmapslider.h SOURCES += pixmapbutton.cpp \ + pixmapnumberdisplay.cpp \ pixmapslider.cpp INCLUDEPATH += $$PWD