From efa16e923684d8ba774a27d8c4dbc426e3c2f5cd Mon Sep 17 00:00:00 2001 From: Thomas Frauendorfer Date: Sun, 27 Jan 2008 07:58:02 +0100 Subject: [PATCH] rewrote Button and ToggleButton to use the new PixmapButton as baseclass. --- lib/lib.pro | 3 + src/Button.cpp | 107 +++++++++++++--------------------- src/Button.h | 34 ++--------- src/MainDisplay.cpp | 6 +- src/MainWindow.cpp | 5 +- src/PosBar.cpp | 2 + src/PosBar.h | 2 + src/VolumeSlider.h | 2 + src/equalizer/equalizer.cpp | 8 +++ src/playlist/playlist.cpp | 29 +++------ src/playlist/playlist.h | 22 +++---- src/playlist/playlistview.cpp | 12 ++-- src/src.pri | 1 + src/widgets/pixmapbutton.cpp | 24 +++++--- src/widgets/pixmapbutton.h | 4 +- 15 files changed, 115 insertions(+), 146 deletions(-) diff --git a/lib/lib.pro b/lib/lib.pro index efbd664..b7666e2 100644 --- a/lib/lib.pro +++ b/lib/lib.pro @@ -2,6 +2,9 @@ TEMPLATE = lib CONFIG += static include (../config.pri) +MOC_DIR = .moc +OBJECTS_DIR = .obj + SOURCES += xclient.cpp \ xclientcache.cpp \ xsettings.cpp \ diff --git a/src/Button.cpp b/src/Button.cpp index cee0b21..f187a9d 100644 --- a/src/Button.cpp +++ b/src/Button.cpp @@ -18,21 +18,30 @@ #include "Skin.h" +#include +#include #include -Button::Button (QWidget *parent) : PixWidget (parent) +Button::Button (QWidget *parent) : PixmapButton (parent) { m_name_normal = 0; m_name_pressed = 0; + + Skin *skin = Skin::getInstance(); + connect (skin, SIGNAL (skinChanged (Skin *)), + this, SLOT (setPixmaps(Skin *))); + } -Button::Button (QWidget *parent, uint normal, uint pressed, bool pls) : PixWidget (parent) +Button::Button (QWidget *parent, uint normal, uint pressed, bool pls) : PixmapButton (parent) { m_name_normal = normal; m_name_pressed = pressed; - m_diffx = 0; - m_diffy = 0; m_pls = pls; + + Skin *skin = Skin::getInstance(); + connect (skin, SIGNAL (skinChanged (Skin *)), + this, SLOT (setPixmaps(Skin *))); } Button::~Button () @@ -46,6 +55,9 @@ Button::setPixmaps(Skin *skin) return; } + QIcon icon; + QPixmap m_pixmap_normal, m_pixmap_pressed; + if (m_pls) { m_pixmap_normal = skin->getPls (m_name_normal); m_pixmap_pressed = skin->getPls (m_name_pressed); @@ -53,7 +65,8 @@ Button::setPixmaps(Skin *skin) m_pixmap_normal = skin->getItem (m_name_normal); m_pixmap_pressed = skin->getItem (m_name_pressed); } - m_pixmap = m_pixmap_normal; + icon.addPixmap(m_pixmap_normal); + icon.addPixmap(m_pixmap_pressed, QIcon::Active); if (!m_pixmap_normal || m_pixmap_normal.isNull()) { qDebug ("OPPP! %d return NULL!", m_name_normal); @@ -62,89 +75,53 @@ Button::setPixmaps(Skin *skin) qDebug ("OPPP! %d return NULL!", m_name_pressed); } - setMinimumSize (m_pixmap.size ()); - setMaximumSize (m_pixmap.size ()); - + setIcon(icon); + setFixedSize (m_pixmap_normal.size ()); update(); } -void -Button::mousePressEvent (QMouseEvent *event) -{ - m_pixmap = m_pixmap_pressed; - - m_diffx = event->pos().x(); - m_diffy = event->pos().y(); - - update (); -} - -void -Button::mouseReleaseEvent (QMouseEvent *event) -{ - m_pixmap = m_pixmap_normal; - update(); - emit clicked(); -} - +/* + * + * ToggleButton + * + */ ToggleButton::ToggleButton (QWidget *parent, uint on_normal, uint on_pressed, - uint off_normal, uint off_pressed) : - Button (parent, off_normal, off_pressed) + uint off_normal, uint off_pressed) : + PixmapButton (parent) { + setCheckable (true); m_name_on_normal = on_normal; m_name_on_pressed = on_pressed; m_name_off_normal = off_normal; m_name_off_pressed = off_pressed; - m_toggled_on = false; - connect (this, SIGNAL(clicked()), this, SLOT (toggleOn())); + Skin *skin = Skin::getInstance(); + connect (skin, SIGNAL (skinChanged (Skin *)), + this, SLOT (setPixmaps(Skin *))); } void ToggleButton::setPixmaps(Skin *skin) { - m_pixmap_on_normal = skin->getItem(m_name_on_normal); - m_pixmap_on_pressed = skin->getItem(m_name_on_pressed); - m_pixmap_off_normal = skin->getItem(m_name_off_normal); - m_pixmap_off_pressed = skin->getItem(m_name_off_pressed); + QIcon icon; + QPixmap p = skin->getItem( m_name_on_normal ); - setCurrentPix (); + icon.addPixmap( p, QIcon::Normal, QIcon::On ); + icon.addPixmap( skin->getItem(m_name_on_pressed), QIcon::Active, + QIcon::On ); + icon.addPixmap( skin->getItem(m_name_off_normal), QIcon::Normal, + QIcon::Off ); + icon.addPixmap( skin->getItem(m_name_off_pressed), QIcon::Active, + QIcon::Off ); + setIcon(icon); - setMinimumSize (m_pixmap.size ()); - setMaximumSize (m_pixmap.size ()); + setFixedSize (p.size ()); update(); } -void -ToggleButton::setCurrentPix () -{ - if (m_toggled_on) { - m_pixmap_normal = m_pixmap_on_normal; - m_pixmap_pressed = m_pixmap_on_pressed; - } else { - m_pixmap_normal = m_pixmap_off_normal; - m_pixmap_pressed = m_pixmap_off_pressed; - } - - m_pixmap = m_pixmap_normal; -} - -void -ToggleButton::toggleOn () -{ - if (!m_toggled_on) { - m_toggled_on = true; - } else { - m_toggled_on = false; - } - - setCurrentPix (); - update (); -} - ToggleButton::~ToggleButton () { } diff --git a/src/Button.h b/src/Button.h index 070486c..b92287b 100644 --- a/src/Button.h +++ b/src/Button.h @@ -16,9 +16,11 @@ #ifndef __BUTTON_H__ #define __BUTTON_H__ -#include "PixWidget.h" +#include "pixmapbutton.h" -class Button : public PixWidget +class Skin; + +class Button : public PixmapButton { Q_OBJECT public: @@ -29,54 +31,28 @@ class Button : public PixWidget public slots: void setPixmaps (Skin *skin); - signals: - void clicked (void); - protected: - void mousePressEvent (QMouseEvent *event); - void mouseReleaseEvent (QMouseEvent *event); - void mouseMoveEvent (QMouseEvent *event) {} - uint m_name_normal; uint m_name_pressed; - uint m_diffx; - uint m_diffy; - - QPixmap m_pixmap_normal; - QPixmap m_pixmap_pressed; - - bool m_nodrag; bool m_pls; }; -class ToggleButton : public Button +class ToggleButton : public PixmapButton { Q_OBJECT public: ToggleButton (QWidget *parent, uint, uint, uint, uint); ~ToggleButton (); - bool getOn () const { return m_toggled_on; } - public slots: void setPixmaps(Skin *skin); - void toggleOn (); private: uint m_name_on_normal; uint m_name_on_pressed; uint m_name_off_normal; uint m_name_off_pressed; - - QPixmap m_pixmap_on_normal; - QPixmap m_pixmap_on_pressed; - QPixmap m_pixmap_off_normal; - QPixmap m_pixmap_off_pressed; - - bool m_toggled_on; - - void setCurrentPix (); }; #endif diff --git a/src/MainDisplay.cpp b/src/MainDisplay.cpp index 53f4c09..f8f7f12 100644 --- a/src/MainDisplay.cpp +++ b/src/MainDisplay.cpp @@ -220,7 +220,7 @@ MainDisplay::SetupToggleButtons (void) Skin::PLS_OFF_0, Skin::PLS_OFF_1); m_pls->move(242, 58); if (!s.value ("playlist/hidden").toBool ()) - m_pls->toggleOn (); + m_pls->toggle (); connect (m_pls, SIGNAL(clicked()), this, SLOT(togglePL())); @@ -228,8 +228,8 @@ MainDisplay::SetupToggleButtons (void) Skin::EQ_OFF_0, Skin::EQ_OFF_1); m_eq->move(219, 58); if (!s.value ("equalizer/hidden").toBool ()) - m_pls->toggleOn (); - m_eq->setEnabled(false); // FIXME: Disabled for now, equalizer is not yet usable + m_pls->toggle (); + m_eq->setEnabled(false); // FIXME: Disabled for now, equalizer doesn't work yet connect (m_eq, SIGNAL(clicked()), this, SLOT(toggleEQ())); diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index c9a8d34..49a462b 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -113,9 +113,10 @@ MainWindow::togglePL (bool UpdateButton) if(UpdateButton) { - getMD()->GetPls()->toggleOn(); + getMD()->GetPls()->toggle(); } + if (s.value ("playlist/hidden").toBool ()) { m_playlistwin->move (s.value("playlist/pos").toPoint ()); m_playlistwin->show (); @@ -134,7 +135,7 @@ MainWindow::toggleEQ (bool UpdateButton) if(UpdateButton) { - getMD()->GetEq()->toggleOn(); + getMD()->GetEq()->toggle(); } if (s.value ("equalizer/hidden").toBool ()) { diff --git a/src/PosBar.cpp b/src/PosBar.cpp index 270dedb..d272284 100644 --- a/src/PosBar.cpp +++ b/src/PosBar.cpp @@ -44,12 +44,14 @@ PosButton::getPos (void) return m_pos; } + void PosButton::mousePressEvent (QMouseEvent *event) { QPoint p (event->pos ()); m_diffx = p.x(); + m_diffy = p.y(); m_moving = true; } diff --git a/src/PosBar.h b/src/PosBar.h index b87c327..3abf3b2 100644 --- a/src/PosBar.h +++ b/src/PosBar.h @@ -37,6 +37,8 @@ class PosButton : public Button PosBar *m_slider; bool m_moving; uint m_pos; + uint m_diffx; + uint m_diffy; }; class PosBar : public PixWidget diff --git a/src/VolumeSlider.h b/src/VolumeSlider.h index f18b540..6f855f1 100644 --- a/src/VolumeSlider.h +++ b/src/VolumeSlider.h @@ -21,6 +21,8 @@ class MainDisplay; class Button; #include "Button.h" +#include "PixWidget.h" +#include "Skin.h" class SliderButton : public Button { diff --git a/src/equalizer/equalizer.cpp b/src/equalizer/equalizer.cpp index 45f0ec4..78b1206 100644 --- a/src/equalizer/equalizer.cpp +++ b/src/equalizer/equalizer.cpp @@ -66,6 +66,11 @@ EqualizerWindow::moveEvent (QMoveEvent *event) s.setValue ("equalizer/pos", pos ()); } +/** + * + * EqualizerWidget + * + */ EqualizerWidget::EqualizerWidget (QWidget *parent) : QWidget (parent) { Skin *skin = Skin::getInstance (); @@ -76,17 +81,20 @@ EqualizerWidget::EqualizerWidget (QWidget *parent) : QWidget (parent) m_enable = new ToggleButton(this, Skin::EQ_WIN_ON_0, Skin::EQ_WIN_ON_1, Skin::EQ_WIN_OFF_0, Skin::EQ_WIN_OFF_1); m_enable->move(14, 18); + m_enable->setEnabled(false); // FIXME: needs to be implemented connect(m_enable, SIGNAL(clicked()), parent, SLOT(setEnabled())); m_auto = new ToggleButton(this, Skin::EQ_WIN_AUTO_ON_0, Skin::EQ_WIN_AUTO_ON_1, Skin::EQ_WIN_AUTO_OFF_0, Skin::EQ_WIN_AUTO_OFF_1); m_auto->move(39, 18); + m_auto->setEnabled(false); // FIXME: needs to be implemented connect(m_auto, SIGNAL(clicked()), parent, SLOT(setEnabled())); m_preset = new Button(this, Skin::EQ_WIN_PRESET_0, Skin::EQ_WIN_PRESET_1); m_preset->move(217, 18); + m_preset->setEnabled(false); // FIXME: needs to be implemented connect(m_preset, SIGNAL(clicked()), parent, SLOT(setEnabled())); diff --git a/src/playlist/playlist.cpp b/src/playlist/playlist.cpp index 626bfd8..fd55be9 100644 --- a/src/playlist/playlist.cpp +++ b/src/playlist/playlist.cpp @@ -162,18 +162,6 @@ PlaylistScrollBar::sliderValueFromPosition (int position) } -/* - * dragButton - */ -void -dragButton::mouseMoveEvent (QMouseEvent *event) -{ - PlaylistWindow *pw = dynamic_cast(window ()); - pw->resize (pw->size().width()+(event->pos().x()-m_diffx), - pw->size().height()+(event->pos().y()-m_diffy)); -} - - /* * PlaylistWindow */ @@ -210,11 +198,13 @@ PlaylistWindow::PlaylistWindow (QWidget *parent) : QMainWindow (parent) s.setValue ("shaded", false); else s.setValue ("shaded", !s.value("shaded").toBool ()); - + switchDisplay (); s.endGroup (); + // FIXME: flickering + //setSizeIncrement (25, 29); } void @@ -340,17 +330,16 @@ PlaylistWidget::PlaylistWidget (QWidget *parent) : QWidget (parent) connect (m_scrollBar, SIGNAL(valueChanged (int)), m_view, SLOT(verticalScrollbarValueChanged (int))); + m_sizegrip = new PlaylistSizeGrip(this); + m_sizegrip->resize (20, 20); - m_drag = new dragButton (this); - m_drag->resize (30, 30); - addButtons (); setMinimumSize (275, 116); resize (275, 300); } -void +void PlaylistWidget::addButtons (void) { PlaylistMenuButton *b; @@ -493,9 +482,9 @@ PlaylistWidget::resizeEvent (QResizeEvent *event) m_scrollBar->resize (m_rfill2.width(), size().height()-m_corner2.height()-m_corner4.height()); - /* drag corner */ - m_drag->move (size().width()-30, - size().height()-30); + /* place the sizegrip in the lower right corner */ + m_sizegrip->move( size().width() - m_sizegrip->width(), + size().height() - m_sizegrip->height() ); /* move menus */ m_add->move (11, height() - m_add->height() - 12); diff --git a/src/playlist/playlist.h b/src/playlist/playlist.h index 56d34e9..914fded 100644 --- a/src/playlist/playlist.h +++ b/src/playlist/playlist.h @@ -22,6 +22,7 @@ #include #include #include +#include class MainWindow; class PlaylistWidget; @@ -35,7 +36,17 @@ class PlaylistView; class PlaylistShade; class PlaylistMenu; +class PlaylistSizeGrip : public QSizeGrip { + Q_OBJECT + + public: + PlaylistSizeGrip (QWidget *parent) : QSizeGrip (parent) {} + ~PlaylistSizeGrip () {} + public slots: + void paintEvent (QPaintEvent *event) {} + +}; class PlaylistScrollBar : public QScrollBar { Q_OBJECT @@ -62,15 +73,6 @@ class PlaylistScrollBar : public QScrollBar { }; -class dragButton : public Button { - public: - dragButton (QWidget *parent) : Button (parent) {} - ~dragButton () {} - - void mouseMoveEvent (QMouseEvent *event); -}; - - class PlaylistWidget : public QWidget { Q_OBJECT @@ -112,7 +114,7 @@ class PlaylistWidget : public QWidget { PlaylistView *m_view; QScrollBar *m_scrollBar; - dragButton *m_drag; + PlaylistSizeGrip *m_sizegrip; PlaylistMenu *m_add; PlaylistMenu *m_del; diff --git a/src/playlist/playlistview.cpp b/src/playlist/playlistview.cpp index f376754..0ebc157 100644 --- a/src/playlist/playlistview.cpp +++ b/src/playlist/playlistview.cpp @@ -94,18 +94,18 @@ PlaylistView::PlaylistView (QWidget *parent) : QListView (parent) if (!s.contains ("playlist/fontsize")) s.setValue ("playlist/fontsize", 10); + // Background is painted by PlaylistWidget setAttribute (Qt::WA_NoBackground); - // TODO make drag and drop work - setDragEnabled(true); - setAcceptDrops(true); - // end DragandDrop setFrameStyle(QFrame::NoFrame); setFocusPolicy (Qt::StrongFocus); - setSelectionMode (QAbstractItemView::ExtendedSelection); - setUniformItemSizes(true); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + setSelectionMode (QAbstractItemView::ExtendedSelection); + setUniformItemSizes(true); + setDragEnabled(true); + setAcceptDrops(true); + // TODO make sure delegate gets deleted setItemDelegate (new PlaylistDelegate (this)); diff --git a/src/src.pri b/src/src.pri index 6215614..18f0c2b 100644 --- a/src/src.pri +++ b/src/src.pri @@ -1,3 +1,4 @@ +include($$PWD/widgets/widgets.pri) include($$PWD/playlist/playlist.pri) include($$PWD/equalizer/equalizer.pri) diff --git a/src/widgets/pixmapbutton.cpp b/src/widgets/pixmapbutton.cpp index 2814319..79a560c 100644 --- a/src/widgets/pixmapbutton.cpp +++ b/src/widgets/pixmapbutton.cpp @@ -1,4 +1,18 @@ - +/** + * This file is a part of Promoe, an XMMS2 Client + * + * Copyright (C) 2008 Thomas Frauendorfer + * + * 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 "pixmapbutton.h" @@ -7,14 +21,6 @@ #include #include -PixmapButton::PixmapButton (QWidget *parent) : QAbstractButton (parent) -{ -} - -PixmapButton::~PixmapButton () -{ -} - void PixmapButton::paintEvent( QPaintEvent * event ) { diff --git a/src/widgets/pixmapbutton.h b/src/widgets/pixmapbutton.h index 7d8cff3..e9206dd 100644 --- a/src/widgets/pixmapbutton.h +++ b/src/widgets/pixmapbutton.h @@ -26,8 +26,8 @@ class PixmapButton : public QAbstractButton { Q_OBJECT public: - PixmapButton (QWidget *parent); - ~PixmapButton (); + PixmapButton (QWidget *parent) : QAbstractButton (parent) {} + ~PixmapButton () {}; protected: void paintEvent ( QPaintEvent * event );