diff --git a/Equalizer.cpp b/Equalizer.cpp index faba4dd..0838edd 100644 --- a/Equalizer.cpp +++ b/Equalizer.cpp @@ -2,6 +2,7 @@ #include "TitleBar.h" #include "Equalizer.h" #include "Button.h" +#include "VolumeSlider.h" EqualizerWindow::EqualizerWindow (QWidget *parent) : QMainWindow (parent) { @@ -30,6 +31,27 @@ EqualizerWindow::setEnabled (void) } +void +EqualizerWindow::mousePressEvent (QMouseEvent *event) +{ + m_diffx = event->pos().x(); + m_diffy = event->pos().y(); +} + +void +EqualizerWindow::mouseMoveEvent (QMouseEvent *event) +{ + move(event->globalPos().x() - m_diffx, + event->globalPos().y() - m_diffy); +} + +void +EqualizerWindow::moveEvent (QMoveEvent *event) +{ + QSettings s; + s.setValue ("equalizer/pos", pos ()); +} + EqualizerWidget::EqualizerWidget (QWidget *parent) : QWidget (parent) { Skin *skin = Skin::getInstance (); @@ -53,17 +75,22 @@ EqualizerWidget::EqualizerWidget (QWidget *parent) : QWidget (parent) m_preset->move(217, 18); connect(m_preset, SIGNAL(clicked()), parent, SLOT(setEnabled())); + + m_preamp = new Slider(this, Skin::EQ_WIN_BAR_POS_0, Skin::EQ_WIN_BAR_POS_27, + Skin::EQ_WIN_BAR_BTN_0, Skin::EQ_WIN_BAR_BTN_1, -20, 20); + m_preamp->move(21, 38); + + for (int i=0; i < 10; i++) { + m_bands[i] = new Slider(this, Skin::EQ_WIN_BAR_POS_0, Skin::EQ_WIN_BAR_POS_27, + Skin::EQ_WIN_BAR_BTN_0, Skin::EQ_WIN_BAR_BTN_1, -20, 20); + m_bands[i]->move(78+i*18, 38); + } } EqualizerWidget::~EqualizerWidget (void) { } -void -EqualizerWidget::mouseMoveEvent (QMouseEvent *event) -{ -} - void EqualizerWidget::setPixmaps (Skin *skin) { diff --git a/Equalizer.h b/Equalizer.h index 98e0068..b2d2ad4 100644 --- a/Equalizer.h +++ b/Equalizer.h @@ -6,6 +6,7 @@ class Button; class MainWindow; class TitleBar; class ToggleButton; +class Slider; #include @@ -23,7 +24,6 @@ class EqualizerWidget : public QWidget public: EqualizerWidget(QWidget *parent); ~EqualizerWidget(); - void mouseMoveEvent(QMouseEvent *); void paintEvent (QPaintEvent *event); public slots: @@ -34,6 +34,8 @@ class EqualizerWidget : public QWidget ToggleButton *m_enable; ToggleButton *m_auto; Button *m_preset; + Slider *m_preamp; + Slider *m_bands[10]; }; class EqualizerWindow : public QMainWindow @@ -42,6 +44,9 @@ class EqualizerWindow : public QMainWindow public: EqualizerWindow(QWidget *parent); ~EqualizerWindow(); + void mouseMoveEvent(QMouseEvent *); + void mousePressEvent(QMouseEvent *); + void moveEvent(QMoveEvent *event); public slots: void setEnabled (void); @@ -49,6 +54,8 @@ class EqualizerWindow : public QMainWindow private: MainWindow *m_mw; EqualizerWidget *m_equalizer; + int m_diffx; + int m_diffy; }; diff --git a/MainDisplay.cpp b/MainDisplay.cpp index 9001b2c..461f946 100644 --- a/MainDisplay.cpp +++ b/MainDisplay.cpp @@ -10,7 +10,7 @@ #include "TimeDisplay.h" #include "SmallNumberDisplay.h" #include "StereoMono.h" -#include "Slider.h" +#include "PosBar.h" #include "PlayStatus.h" #include "VolumeSlider.h" #include "Playlist.h" @@ -51,17 +51,22 @@ MainDisplay::MainDisplay (QWidget *parent) : SkinDisplay(parent) m_clutterbar = new ClutterBar (this); m_clutterbar->move (10, 22); - m_slider = new Slider (this, Skin::POSBAR, + m_posbar = new PosBar (this, Skin::POSBAR, Skin::POSBAR_BTN_0, Skin::POSBAR_BTN_1); - m_slider->move (16, 72); + m_posbar->move (16, 72); m_playstatus = new PlayStatus (this); m_playstatus->move (24, 28); - m_vslider = new VolumeSlider(this); + m_vslider = new Slider(this, Skin::VOLUMEBAR_POS_0, Skin::VOLUMEBAR_POS_27, + Skin::VOLBAR_BTN_0, Skin::VOLBAR_BTN_1, 0, 100); m_vslider->move (107, 57); + m_bslider = new Slider(this, Skin::BALANCE_POS_0, Skin::BALANCE_POS_27, + Skin::BALANCE_BTN_0, Skin::BALANCE_BTN_1, -20, 20); + m_bslider->move (177, 57); + XMMSHandler &xmmsh = XMMSHandler::getInstance (); connect (&xmmsh, SIGNAL(currentSong (const Xmms::PropDict &)), this, SLOT(setMediainfo (const Xmms::PropDict &))); @@ -69,6 +74,23 @@ MainDisplay::MainDisplay (QWidget *parent) : SkinDisplay(parent) this, SLOT(setStatus(Xmms::Playback::Status))); connect (&xmmsh, SIGNAL(playtimeChanged(uint)), this, SLOT(setPlaytime(uint))); + connect (&xmmsh, SIGNAL(getVolume(uint)), this, SLOT(updateVolume(uint))); + connect (m_vslider, SIGNAL(valueChanged(int)), this, SLOT(setVolume(int))); + xmmsh.volumeGet(); +} + + +void +MainDisplay::updateVolume (uint volume) +{ + m_vslider->setValue((int)volume); +} + +void +MainDisplay::setVolume (int volume) +{ + XMMSHandler &xmmsh = XMMSHandler::getInstance(); + xmmsh.volumeSet((uint)volume); } void @@ -105,8 +127,8 @@ MainDisplay::setStatus (Xmms::Playback::Status status) { if (status == Xmms::Playback::STOPPED) { m_time->setTime(0); - m_slider->setPos (0); - m_slider->hideBar (true); + m_posbar->setPos (0); + m_posbar->hideBar (true); } } @@ -115,7 +137,7 @@ MainDisplay::setPlaytime (uint time) { uint showtime; if (m_mw->isTimemodeReverse()) { - uint maxtime = m_slider->getMax(); + uint maxtime = m_posbar->getMax(); showtime = -(maxtime - time); } else { showtime = time; @@ -123,7 +145,7 @@ MainDisplay::setPlaytime (uint time) m_time->setTime (showtime); // update slider - m_slider->setPos (time); + m_posbar->setPos (time); } void @@ -166,10 +188,10 @@ MainDisplay::setMediainfo (const Xmms::PropDict &info) } if (info.contains ("duration")) { - m_slider->setMax (info.get ("duration")); - m_slider->hideBar (false); + m_posbar->setMax (info.get ("duration")); + m_posbar->hideBar (false); } else { - m_slider->hideBar (true); + m_posbar->hideBar (true); } } diff --git a/MainDisplay.h b/MainDisplay.h index 03f77f8..b28e8f6 100644 --- a/MainDisplay.h +++ b/MainDisplay.h @@ -36,8 +36,8 @@ class TextScroller; class TimeDisplay; class SmallNumberDisplay; class StereoMono; +class PosBar; class Slider; -class VolumeSlider; class PlayStatus; class MainWindow; class ClutterBar; @@ -58,8 +58,9 @@ class MainDisplay : public SkinDisplay SmallNumberDisplay *m_khz; StereoMono *m_stereo; - Slider *m_slider; - VolumeSlider *m_vslider; + PosBar *m_posbar; + Slider *m_vslider; + Slider *m_bslider; PlayStatus *m_playstatus; MainWindow *getMW(void) { return m_mw; } @@ -74,6 +75,8 @@ class MainDisplay : public SkinDisplay void togglePL(void); void toggleEQ(void); void toggleTime(void); + void updateVolume (uint volume); + void setVolume (int volume); protected: void SetupPushButtons (void); diff --git a/MainWindow.cpp b/MainWindow.cpp index ba5af16..c7eb697 100644 --- a/MainWindow.cpp +++ b/MainWindow.cpp @@ -123,6 +123,7 @@ MainWindow::toggleEQ (bool UpdateButton) } if (s.value ("equalizer/hidden").toBool ()) { + m_equalizer->move (s.value("equalizer/pos").toPoint ()); m_equalizer->show (); s.setValue ("equalizer/hidden", false); } else { @@ -174,7 +175,6 @@ main (int argc, char **argv) settings.setValue ("playlist/pos", QPoint (mw->pos().x(), mw->pos().y()+mw->size().height())); playlistwin->move (settings.value("playlist/pos").toPoint ()); - playlistwin->move (settings.value("playlist/pos").toPoint ()); if (!settings.contains ("playlist/hidden")) settings.setValue ("playlist/hidden", true); @@ -184,6 +184,15 @@ main (int argc, char **argv) else playlistwin->show (); + + if (!settings.contains ("equalizer/pos")) + settings.setValue ("equalizer/pos", QPoint (mw->pos().x(), + mw->pos().y()+mw->size().height())); + eqwin->move (settings.value("equalizer/pos").toPoint ()); + + if (!settings.contains ("equalizer/hidden")) + settings.setValue ("equalizer/hidden", true); + if (settings.value("equalizer/hidden").toBool ()) eqwin->hide (); else diff --git a/Slider.cpp b/PosBar.cpp similarity index 79% rename from Slider.cpp rename to PosBar.cpp index b74584e..9c36165 100644 --- a/Slider.cpp +++ b/PosBar.cpp @@ -1,21 +1,21 @@ #include "MainWindow.h" -#include "Slider.h" +#include "PosBar.h" #include "Skin.h" #include #include -BarButton::BarButton (QWidget *parent, uint normal, uint pressed) : Button (parent, normal, pressed) +PosButton::PosButton (QWidget *parent, uint normal, uint pressed) : Button (parent, normal, pressed) { - m_slider = dynamic_cast(parent); + m_slider = dynamic_cast(parent); setMinimumSize (29, 10); setMaximumSize (29, 10); m_moving = false; } void -BarButton::setPos (uint pos) +PosButton::setPos (uint pos) { m_pos = pos; if (!m_moving) { @@ -24,13 +24,13 @@ BarButton::setPos (uint pos) } uint -BarButton::getPos (void) +PosButton::getPos (void) { return m_pos; } void -BarButton::mousePressEvent (QMouseEvent *event) +PosButton::mousePressEvent (QMouseEvent *event) { QPoint p (event->pos ()); @@ -39,7 +39,7 @@ BarButton::mousePressEvent (QMouseEvent *event) } void -BarButton::mouseReleaseEvent (QMouseEvent *event) +PosButton::mouseReleaseEvent (QMouseEvent *event) { m_moving = false; @@ -49,7 +49,7 @@ BarButton::mouseReleaseEvent (QMouseEvent *event) } void -BarButton::mouseMoveEvent (QMouseEvent *event) +PosButton::mouseMoveEvent (QMouseEvent *event) { QPoint p (event->pos ()); @@ -77,7 +77,7 @@ BarButton::mouseMoveEvent (QMouseEvent *event) } -Slider::Slider (QWidget *parent, uint bg, uint bnormal, uint bpressed, bool vertical) : PixWidget (parent) +PosBar::PosBar (QWidget *parent, uint bg, uint bnormal, uint bpressed, bool vertical) : PixWidget (parent) { m_bg = bg; m_vertical = vertical; @@ -87,7 +87,7 @@ Slider::Slider (QWidget *parent, uint bg, uint bnormal, uint bpressed, bool vert m_max = 0; - m_button = new BarButton (this, bnormal, bpressed); + m_button = new PosButton (this, bnormal, bpressed); m_button->move (0, 0); if (m_vertical) { @@ -101,7 +101,7 @@ Slider::Slider (QWidget *parent, uint bg, uint bnormal, uint bpressed, bool vert } void -Slider::setSize (uint x, uint y) +PosBar::setSize (uint x, uint y) { setMinimumSize (x, y); setMaximumSize (x, y); @@ -115,7 +115,7 @@ Slider::setSize (uint x, uint y) } uint -Slider::getPos (void) +PosBar::getPos (void) { if (m_vertical) { @@ -126,7 +126,7 @@ Slider::getPos (void) } void -Slider::hideBar (bool b) +PosBar::hideBar (bool b) { if (b) { @@ -139,7 +139,7 @@ Slider::hideBar (bool b) } void -Slider::setPos (uint p) +PosBar::setPos (uint p) { if (!m_max) { return; @@ -153,13 +153,13 @@ Slider::setPos (uint p) } void -Slider::requestPos (float value) +PosBar::requestPos (float value) { XMMSHandler::getInstance ().setPlaytime (m_max * value); } void -Slider::setPixmaps (Skin *skin) +PosBar::setPixmaps (Skin *skin) { m_pixmap = skin->getItem (m_bg); } diff --git a/Slider.h b/PosBar.h similarity index 75% rename from Slider.h rename to PosBar.h index 005381e..fafa62a 100644 --- a/Slider.h +++ b/PosBar.h @@ -4,12 +4,12 @@ #include "PixWidget.h" #include "Button.h" -class Slider; +class PosBar; -class BarButton : public Button +class PosButton : public Button { public: - BarButton (QWidget *, uint, uint); + PosButton (QWidget *, uint, uint); void mouseMoveEvent (QMouseEvent *); void mousePressEvent (QMouseEvent *); @@ -19,18 +19,18 @@ class BarButton : public Button uint getPos (void); private: - Slider *m_slider; + PosBar *m_slider; bool m_moving; uint m_pos; }; -class Slider : public PixWidget +class PosBar : public PixWidget { Q_OBJECT public: - Slider (QWidget *parent, uint bg, uint bnormal, uint bpressed, bool vertical=true); - ~Slider () { } + PosBar (QWidget *parent, uint bg, uint bnormal, uint bpressed, bool vertical=true); + ~PosBar () { } void setSize (uint, uint); uint getPos (void); @@ -50,7 +50,7 @@ class Slider : public PixWidget int m_bg; uint m_max; uint m_pix; - BarButton *m_button; + PosButton *m_button; }; diff --git a/Skin.cpp b/Skin.cpp index 59dc7c5..d2364e4 100644 --- a/Skin.cpp +++ b/Skin.cpp @@ -32,6 +32,16 @@ Skin::BuildEqualizer (void) m_items[EQ_WIN_GRAPH_BG] = img->copy (0, 294, 113, 19); + for (int i = 0; i < 14; i++) { + m_items[EQ_WIN_BAR_POS_0+i] = img->copy (13+15*i, 164, 14, 63); + } + for (int i = 0; i < 14; i++) { + m_items[EQ_WIN_BAR_POS_14+i] = img->copy (13+15*i, 229, 14, 63); + } + + m_items[EQ_WIN_BAR_BTN_1] = img->copy (0, 164, 11, 11); + m_items[EQ_WIN_BAR_BTN_0] = img->copy (0, 176, 11, 11); + delete img; } else { setSkin(":CleanAMP/"); @@ -481,52 +491,51 @@ Skin::BuildSliders (void) QPixmap *img; img = getPixmap("posbar"); - if(img) - { + if (img) { m_items[POSBAR] = img->copy (0, 0, 248, 10); m_items[POSBAR_BTN_0] = img->copy (248, 0, 29, 10); m_items[POSBAR_BTN_1] = img->copy (278, 0, 29, 10); + delete img; - } - else + } else { setSkin(":CleanAMP/"); + } img = getPixmap("volume"); - if(img) - { - for (int i = VOLUMEBAR_POS_MIN; i <= VOLUMEBAR_POS_MAX; i++) { - m_volume_bar[i] = img->copy(0, i*15, 68, 13); + if (img) { + for (int i = 0; i <= 27; i++) { + m_items[VOLUMEBAR_POS_0+i] = img->copy(0, i*15, 68, 13); } - if(img->height() > 420) - { + + if (img->height() > 420) { m_items[VOLBAR_BTN_1] = img->copy (0, 422, 14, 11); m_items[VOLBAR_BTN_0] = img->copy (15, 422, 14, 11); - m_volbtn = true; - } - else - { - m_volbtn = false; } delete img; - } - else + } else { setSkin(":CleanAMP/"); + } img = getPixmap("balance"); if (!img) { img = getPixmap("volume"); } - if(img) - { - for (int i = BALANCE_POS_MIN; i <= BALANCE_POS_MAX; i++) { - m_balance[i] = img->copy(9, i*15, 38, 13); + if (img) { + for (int i = 0; i < 28; i++) { + m_items[BALANCE_POS_0+i] = img->copy(9, i*15, 38, 13); } + + if (img->height() > 421) { + m_items[BALANCE_BTN_0] = img->copy(0, 422, 14, 11); + m_items[BALANCE_BTN_1] = img->copy(15, 422, 14, 11); + } + delete img; - } - else + } else { setSkin(":CleanAMP/"); + } } diff --git a/Skin.h b/Skin.h index d32aea5..a13ed74 100644 --- a/Skin.h +++ b/Skin.h @@ -20,78 +20,13 @@ class Skin : public QWidget const QPixmap getItem (uint part) const { return m_items[part]; } const QPixmap getPls (uint part) const { return m_playlist[part]; } - const QPixmap getVol (uint p) const { return m_volume_bar[p]; } - const QPixmap getBal (uint p) const { return m_balance[p]; } const QPixmap getLetter (uint c) const { return m_letterMap[c]; } const QPixmap getNumber (uint c) const { return m_numbers[c]; } uint getNumberSize () { return m_numbers.size(); } const QByteArray getPLeditValue (QByteArray c) const { return m_pledit_txt[c]; } - const bool getVolBtn(void) const { return m_volbtn; } - const bool getBalBtn(void) const { return m_balbtn; } - - enum Volume { - VOLUMEBAR_POS_MIN, - VOLUMEBAR_POS_1, - VOLUMEBAR_POS_2, - VOLUMEBAR_POS_3, - VOLUMEBAR_POS_4, - VOLUMEBAR_POS_5, - VOLUMEBAR_POS_6, - VOLUMEBAR_POS_7, - VOLUMEBAR_POS_8, - VOLUMEBAR_POS_9, - VOLUMEBAR_POS_10, - VOLUMEBAR_POS_11, - VOLUMEBAR_POS_12, - VOLUMEBAR_POS_13, - VOLUMEBAR_POS_14, - VOLUMEBAR_POS_15, - VOLUMEBAR_POS_16, - VOLUMEBAR_POS_17, - VOLUMEBAR_POS_18, - VOLUMEBAR_POS_19, - VOLUMEBAR_POS_20, - VOLUMEBAR_POS_21, - VOLUMEBAR_POS_22, - VOLUMEBAR_POS_23, - VOLUMEBAR_POS_24, - VOLUMEBAR_POS_25, - VOLUMEBAR_POS_26, - VOLUMEBAR_POS_MAX - }; - - enum Balance { - BALANCE_POS_MIN, - BALANCE_POS_1, - BALANCE_POS_2, - BALANCE_POS_3, - BALANCE_POS_4, - BALANCE_POS_5, - BALANCE_POS_6, - BALANCE_POS_7, - BALANCE_POS_8, - BALANCE_POS_9, - BALANCE_POS_10, - BALANCE_POS_11, - BALANCE_POS_12, - BALANCE_POS_13, - BALANCE_POS_14, - BALANCE_POS_15, - BALANCE_POS_16, - BALANCE_POS_17, - BALANCE_POS_18, - BALANCE_POS_19, - BALANCE_POS_20, - BALANCE_POS_21, - BALANCE_POS_22, - BALANCE_POS_23, - BALANCE_POS_24, - BALANCE_POS_25, - BALANCE_POS_26, - BALANCE_POS_MAX - }; enum Part { + NONE, MAIN_WINDOW, ABOUT_0, ABOUT_1, @@ -151,6 +86,34 @@ class Skin : public QWidget POSBAR, POSBAR_BTN_0, POSBAR_BTN_1, + VOLUMEBAR_POS_0, + VOLUMEBAR_POS_1, + VOLUMEBAR_POS_2, + VOLUMEBAR_POS_3, + VOLUMEBAR_POS_4, + VOLUMEBAR_POS_5, + VOLUMEBAR_POS_6, + VOLUMEBAR_POS_7, + VOLUMEBAR_POS_8, + VOLUMEBAR_POS_9, + VOLUMEBAR_POS_10, + VOLUMEBAR_POS_11, + VOLUMEBAR_POS_12, + VOLUMEBAR_POS_13, + VOLUMEBAR_POS_14, + VOLUMEBAR_POS_15, + VOLUMEBAR_POS_16, + VOLUMEBAR_POS_17, + VOLUMEBAR_POS_18, + VOLUMEBAR_POS_19, + VOLUMEBAR_POS_20, + VOLUMEBAR_POS_21, + VOLUMEBAR_POS_22, + VOLUMEBAR_POS_23, + VOLUMEBAR_POS_24, + VOLUMEBAR_POS_25, + VOLUMEBAR_POS_26, + VOLUMEBAR_POS_27, VOLBAR_BTN_0, VOLBAR_BTN_1, CLUTTER_ON, @@ -172,6 +135,66 @@ class Skin : public QWidget EQ_WIN_PRESET_0, EQ_WIN_PRESET_1, EQ_WIN_GRAPH_BG, + EQ_WIN_BAR_POS_0, + EQ_WIN_BAR_POS_1, + EQ_WIN_BAR_POS_2, + EQ_WIN_BAR_POS_3, + EQ_WIN_BAR_POS_4, + EQ_WIN_BAR_POS_5, + EQ_WIN_BAR_POS_6, + EQ_WIN_BAR_POS_7, + EQ_WIN_BAR_POS_8, + EQ_WIN_BAR_POS_9, + EQ_WIN_BAR_POS_10, + EQ_WIN_BAR_POS_11, + EQ_WIN_BAR_POS_12, + EQ_WIN_BAR_POS_13, + EQ_WIN_BAR_POS_14, + EQ_WIN_BAR_POS_15, + EQ_WIN_BAR_POS_16, + EQ_WIN_BAR_POS_17, + EQ_WIN_BAR_POS_18, + EQ_WIN_BAR_POS_19, + EQ_WIN_BAR_POS_20, + EQ_WIN_BAR_POS_21, + EQ_WIN_BAR_POS_22, + EQ_WIN_BAR_POS_23, + EQ_WIN_BAR_POS_24, + EQ_WIN_BAR_POS_25, + EQ_WIN_BAR_POS_26, + EQ_WIN_BAR_POS_27, + EQ_WIN_BAR_BTN_0, + EQ_WIN_BAR_BTN_1, + BALANCE_POS_0, + BALANCE_POS_1, + BALANCE_POS_2, + BALANCE_POS_3, + BALANCE_POS_4, + BALANCE_POS_5, + BALANCE_POS_6, + BALANCE_POS_7, + BALANCE_POS_8, + BALANCE_POS_9, + BALANCE_POS_10, + BALANCE_POS_11, + BALANCE_POS_12, + BALANCE_POS_13, + BALANCE_POS_14, + BALANCE_POS_15, + BALANCE_POS_16, + BALANCE_POS_17, + BALANCE_POS_18, + BALANCE_POS_19, + BALANCE_POS_20, + BALANCE_POS_21, + BALANCE_POS_22, + BALANCE_POS_23, + BALANCE_POS_24, + BALANCE_POS_25, + BALANCE_POS_26, + BALANCE_POS_27, + BALANCE_BTN_0, + BALANCE_BTN_1, }; enum PlaylistParts { diff --git a/VolumeSlider.cpp b/VolumeSlider.cpp index 7131a10..8479d78 100644 --- a/VolumeSlider.cpp +++ b/VolumeSlider.cpp @@ -1,297 +1,227 @@ #include "XMMSHandler.h" +#include #include "VolumeSlider.h" #include #include "Skin.h" +#include "Button.h" -// NOTE! -// This file has lots of seemingly strange math. -// I will document it as we go, but please keep in mind -// that all of the coord-space and normalization is pixel-space dependent. +#define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x))) -VolumeSlider::VolumeSlider (QWidget *parent) : PixWidget (parent) +Slider::Slider (QWidget *parent, uint name_min, uint name_max, + uint name_on, uint name_off, int min, int max) : PixWidget (parent) { - XMMSHandler &xmmsh = XMMSHandler::getInstance (); + m_name_min = name_min; + m_name_max = name_max; + m_name_on = name_on; + m_name_off = name_off; + + m_min = min; + m_max = max; - setMinimumSize (68, 13); - setMaximumSize (68, 13); - m_volume = 0; - m_position = 0; - m_hasvolbtn = false; - m_volbtn = NULL; - - m_pixmap = QPixmap (68, 13); - - connect (&xmmsh, SIGNAL(getVolume (uint)), - this, SLOT(setVolume (uint))); - - xmmsh.volumeGet (); -} - -VolumeSlider::~VolumeSlider () -{ + m_button = 0; + m_value = 0; + m_value_index = (uint)((abs(m_min) / (double)(abs(m_min)+abs(m_max))) * (name_max-name_min)); } void -VolumeSlider::setPixmaps (Skin *skin) +Slider::setPixmaps (Skin *skin) { m_skin = skin; - if(m_skin->getVolBtn()) - { - m_hasvolbtn = true; - if(m_volbtn) - delete m_volbtn; + m_pixmap_slider = m_skin->getItem(m_name_min+m_value_index); + m_vertical = (m_pixmap_slider.height() > m_pixmap_slider.width()) ? true : false; - m_volbtn = new VolButton (this, Skin::VOLBAR_BTN_0, Skin::VOLBAR_BTN_1); + setMinimumSize(m_pixmap_slider.size()); + setMaximumSize(m_pixmap_slider.size()); - // If we are out of scope high or low, we clamp the values. - if(m_volume <= 0) - m_volbtn->move (0, 1); - else if(m_volume >= 27) - m_volbtn->move (54, 1); - else - { - // If we are not.. we do two things. + resize(m_pixmap_slider.size()); - // First, we normalize the difference between the current position - // and the maximum position. This will give us the progress ratio. - float temp = ((float)(m_volume) / (float)(27.0f)); - - // Now, we multiply that by the number of possible positions in our - // space. This gives us our relative position according to the progress - // ratio. - m_volbtn->move ((int)(49 * temp), 1); + if (!skin->getItem(m_name_on).isNull() && !skin->getItem(m_name_off).isNull()) { + if (m_button) { + delete m_button; } - m_volbtn->setPixmaps (m_skin); - m_volbtn->show (); - } - else - { - m_hasvolbtn = false; - if(m_volbtn) - { - delete m_volbtn; - m_volbtn = NULL; + + m_button = new SliderButton (this, m_name_on, m_name_off, m_vertical); + m_button->setPixmaps (m_skin); + m_button->show (); + + int tmp = (uint)((ceil(abs(m_min) / (double)(abs(m_min)+abs(m_max)))) * (m_name_max-m_name_min)); + if (m_vertical) { + m_button->move(1, height()-m_button->height()-tmp); + } else { + m_button->move(tmp, 1); + } + } else { + if (m_button) { + delete m_button; + m_button = NULL; } } - m_volslider = m_skin->getVol (m_volume); - - drawPixmaps (); + update(); } void -VolumeSlider::changePixmap () +Slider::changePixmap () { - XMMSHandler::getInstance ().volumeSet (m_volume_base100); - - m_volslider = m_skin->getVol (m_volume); - drawPixmaps (); + m_pixmap_slider = m_skin->getItem (m_name_min+m_value_index); + update(); } void -VolumeSlider::drawPixmaps () +Slider::paintEvent (QPaintEvent *event) { QPainter paint; - paint.begin (&m_pixmap); - - paint.drawPixmap (QRect (0, 0, 68, 13), - m_volslider, - m_pixmap.rect ()); + paint.begin (this); + paint.drawPixmap (rect(), m_pixmap_slider, m_pixmap_slider.rect ()); paint.end (); - - update (); } void -VolumeSlider::mousePressEvent (QMouseEvent *event) +Slider::mousePressEvent (QMouseEvent *event) { updatePos (event); - if(m_hasvolbtn) - { - m_volbtn->mousePressEvent (event); - } } void -VolumeSlider::mouseMoveEvent (QMouseEvent *event) +Slider::mouseMoveEvent (QMouseEvent *event) { updatePos (event); - if(m_hasvolbtn) - { - m_volbtn->mouseMoveEvent (event); - } } void -VolumeSlider::mouseReleaseEvent (QMouseEvent *event) +Slider::mouseReleaseEvent (QMouseEvent *event) { updatePos (event); - if(m_hasvolbtn) - { - m_volbtn->mouseReleaseEvent (event); - } } void -VolumeSlider::updatePos (QMouseEvent *event) +Slider::updatePos (QMouseEvent *event) { QPoint p (event->pos ()); + int value; - int curx = p.x (); - - // Check for scope and clamp. - if(curx <= 0) - { - m_volume = 0; - m_volume_base100 = 0; - } - else if(curx >= 68) - { - m_volume = 27; - m_volume_base100 = 100; - } - else - { - // Normalize the same way we do above, except this time - // we calculate a base-100 value as well. - float temp = ((float)(curx - 5) / (float)(width() - 5)); - m_volume_base100 = (int)(100 * temp); - m_volume = (int)(28 * temp); + if (m_vertical) { + value = CLAMP(p.y(), 0, height()); + } else { + value = CLAMP(p.x(), 0, width()); } - changePixmap (); -} - -void -VolumeSlider::setVolume (uint volume_base100) -{ - m_volume_base100 = volume_base100; - if(volume_base100 > 100) - volume_base100 = 100; - - m_volume = (int)((float)(volume_base100) *.28); - if(m_volume > 27) - m_volume = 27; - - if(m_hasvolbtn) - m_volbtn->setVolume (volume_base100); - - changePixmap (); -} - -VolButton::VolButton (QWidget *parent, uint normal, uint pressed) : PixWidget (parent) -{ - m_volslider = dynamic_cast(parent); - setMinimumSize (14, 11); - setMaximumSize (14, 11); - - m_normal = normal; - m_pressed = pressed; - - m_pixmap = QPixmap (14, 11); -} - -VolButton::~VolButton () -{ - -} - -void -VolButton::mousePressEvent (QMouseEvent *event) -{ - QPoint p (event->globalPos ()); - QPoint np = m_volslider->mapFromGlobal (p); - - move (np.x() - 7, 1); - - changePixmap (true); -} - -void -VolButton::mouseReleaseEvent (QMouseEvent *event) -{ - changePixmap (false); -} - -void -VolButton::mouseMoveEvent (QMouseEvent *event) -{ - QPoint p = m_volslider->mapFromGlobal (event->globalPos ()); - int volume = 0; - int curx = p.x (); - - // Same deal, clamp then normalize. - if(curx < 7) - { - volume = 0; - m_volslider->setVolume (0); - } - else if(curx > 61) - { - volume = 54; - m_volslider->setVolume (100); - } - else - { - float temp = ((float)(((float)curx) / (float)(68.0f))); - float b100temp = ((float)(((float)curx - 12) / (float)(68.0f - 19))); - volume = (int)(68 * temp) - 7; - // This is to make sure the volume slider itself reflects our changes. - m_volslider->setVolume ((int)(100 * b100temp)); + setPos(value, true); + if (m_button != 0) { + m_button->setPos(value); } - move (volume, 1); + emit valueChanged (m_value); } void -VolButton::setVolume (uint volume_base100) +Slider::setValue (int value) { - int volume = (int)((float)(volume_base100) *.68); + double frac; + int pos; - if(volume < 0) - volume = 0; - else if(volume > 54) - volume = 54; + frac = abs(value)/(double)(abs(m_min)+abs(m_max)); + if (m_vertical) { + pos = (int)(height() * frac); + } else { + pos = (int)(width() * frac); + } - move (volume,1); + setPos(pos, false); + if (m_button != 0) { + m_button->setPos(pos); + } +} + +void +Slider::setPos (int value, bool tell) +{ + double frac; + + if (m_vertical) { + frac = (height() - value) / (double) height(); + } else { + frac = value / (double) width(); + } + + /* calculate m_min <= m_value <= m_max */ + m_value = (uint)(frac * (abs(m_min) + abs(m_max)) + m_min); + + /* calculate m_name_min <= m_value_index <= m_name_max */ + m_value_index = (uint) ceil (frac * (m_name_max - m_name_min)); + + + changePixmap(); + + if (tell) { + emit valueChanged (m_value); + } +} + + +SliderButton::SliderButton (QWidget *parent, uint normal, uint pressed, + bool vertical) : Button (parent, normal, pressed, false) +{ + m_slider = dynamic_cast(parent); + m_vertical = vertical; + m_diff = 0; + m_moving = false; + + if (m_vertical) { + move(1, 0); + } else { + move(0, 1); + } } void -VolButton::setPixmaps (Skin *skin) +SliderButton::mousePressEvent (QMouseEvent *event) { - m_skin = skin; - - m_volbtn = m_skin->getItem (m_normal); - - drawPixmaps (); + if (m_vertical) { + m_diff = y() - event->pos().y(); + } else { + m_diff = x() - event->pos().x(); + } + m_moving = true; } + void -VolButton::changePixmap (bool pressed) +SliderButton::mouseReleaseEvent (QMouseEvent *event) { - if(pressed) - m_volbtn = m_skin->getItem (m_pressed); - else - m_volbtn = m_skin->getItem (m_normal); - - drawPixmaps (); + m_moving = false; } + void -VolButton::drawPixmaps () +SliderButton::setPos (uint pos) { - QPainter paint; - paint.begin (&m_pixmap); - - paint.drawPixmap (QRect (0, 0, 14, 11), - m_volbtn, - m_pixmap.rect ()); - paint.end (); - - update (); + if (m_vertical) { + int ypos = MIN(pos, (uint)m_slider->height()-height()); + move(1, ypos); + } else { + int xpos = MIN(pos, (uint)m_slider->width()-width()); + move(xpos, 1); + } +} + + +void +SliderButton::mouseMoveEvent (QMouseEvent *event) +{ + QPoint p = m_slider->mapFromGlobal (event->globalPos ()); + int value; + if (m_vertical) { + value = CLAMP(p.y(), 0, m_slider->height()); + } else { + value = CLAMP(p.x(), 0, m_slider->width()); + } + + m_slider->setPos(value, true); + setPos (value); } diff --git a/VolumeSlider.h b/VolumeSlider.h index e8f5a05..b020b6a 100644 --- a/VolumeSlider.h +++ b/VolumeSlider.h @@ -1,67 +1,77 @@ #ifndef __VOLUMESLIDER_H__ #define __VOLUMESLIDER_H__ -#include "PixWidget.h" - -class VolumeSlider; +class Slider; class MainDisplay; class Button; -class VolButton : public PixWidget +#include "Button.h" + +class SliderButton : public Button { Q_OBJECT public: - VolButton (QWidget *, uint, uint); - ~VolButton (); - + SliderButton (QWidget *parent, uint normal, uint pressed, bool dir); void mouseMoveEvent (QMouseEvent *); void mousePressEvent (QMouseEvent *); void mouseReleaseEvent (QMouseEvent *); + void setPos (uint); + public slots: - void setPixmaps (Skin *skin); - void setVolume (uint volume_base100); + //void setValue (uint volume_base100); private: void changePixmap (bool pressed); - void drawPixmaps(); - - VolumeSlider *m_volslider; - Skin *m_skin; - QPixmap m_volbtn; - uint m_normal; - uint m_pressed; + Slider *m_slider; + bool m_vertical; + int m_diff; + bool m_moving; }; -class VolumeSlider : public PixWidget +class Slider : public PixWidget { Q_OBJECT public: - VolumeSlider (QWidget *parent); - ~VolumeSlider (); + Slider (QWidget *parent, uint min, uint max, uint on, uint off, int, int); + + void paintEvent (QPaintEvent *event); + void mouseMoveEvent (QMouseEvent *); void mousePressEvent (QMouseEvent *); void mouseReleaseEvent (QMouseEvent *); - uint getVolume (void) { return m_volume_base100; }; - public slots: void setPixmaps (Skin *skin); - void setVolume (uint volume_base100); + void setPos (int value, bool tell); + void setValue (int value); + + signals: + void valueChanged (int val); private: - void drawPixmaps (); void updatePos (QMouseEvent *event); void changePixmap (); - QPixmap m_volslider; - VolButton *m_volbtn; + QPixmap m_pixmap_slider; + SliderButton *m_button; + Skin *m_skin; - int m_volume; + + uint m_value_index; + int m_value; + int m_position; - uint m_volume_base100; - bool m_hasvolbtn; - + + uint m_name_min; + uint m_name_max; + uint m_name_on; + uint m_name_off; + + int m_min; + int m_max; + + bool m_vertical; }; #endif diff --git a/XMMSHandler.h b/XMMSHandler.h index 8b747e2..4374f1d 100644 --- a/XMMSHandler.h +++ b/XMMSHandler.h @@ -42,7 +42,6 @@ class XMMSHandler : public QObject { void medialibQueryAdd (QString q) { delete m_xmmsc->medialib_add_to_playlist (q.toUtf8 ()); } */ - void volumeSet (uint volume); void volumeGet (); //const XMMSClient *getXMMS () { return m_xmmsc; } @@ -59,6 +58,7 @@ class XMMSHandler : public QObject { void pause (); void next (); void prev (); + void volumeSet (uint volume); signals: void settingsSaved (); diff --git a/promoe.pro b/promoe.pro index 23a8962..2803852 100644 --- a/promoe.pro +++ b/promoe.pro @@ -12,7 +12,7 @@ SOURCES += XmmsQT4.cpp \ XMMSHandler.cpp \ SmallNumberDisplay.cpp \ StereoMono.cpp \ - Slider.cpp \ + PosBar.cpp \ PlayStatus.cpp \ ShadedDisplay.cpp \ Playlist.cpp \ @@ -42,7 +42,7 @@ HEADERS += XmmsQT4.h \ XMMSHandler.h \ SmallNumberDisplay.h \ StereoMono.h \ - Slider.h \ + PosBar.h \ PlayStatus.h \ ShadedDisplay.h \ Playlist.h \