rewrote Button and ToggleButton to use the new PixmapButton as baseclass.

This commit is contained in:
Thomas Frauendorfer 2008-01-27 07:58:02 +01:00
parent e2fdb4e009
commit efa16e9236
15 changed files with 115 additions and 146 deletions

View file

@ -2,6 +2,9 @@ TEMPLATE = lib
CONFIG += static
include (../config.pri)
MOC_DIR = .moc
OBJECTS_DIR = .obj
SOURCES += xclient.cpp \
xclientcache.cpp \
xsettings.cpp \

View file

@ -18,21 +18,30 @@
#include "Skin.h"
#include <QIcon>
#include <QPixmap>
#include <QMouseEvent>
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 ()
{
}

View file

@ -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

View file

@ -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()));

View file

@ -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 ()) {

View file

@ -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;
}

View file

@ -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

View file

@ -21,6 +21,8 @@ class MainDisplay;
class Button;
#include "Button.h"
#include "PixWidget.h"
#include "Skin.h"
class SliderButton : public Button
{

View file

@ -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()));

View file

@ -162,18 +162,6 @@ PlaylistScrollBar::sliderValueFromPosition (int position)
}
/*
* dragButton
*/
void
dragButton::mouseMoveEvent (QMouseEvent *event)
{
PlaylistWindow *pw = dynamic_cast<PlaylistWindow *>(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);

View file

@ -22,6 +22,7 @@
#include <QMainWindow>
#include <QFont>
#include <QScrollBar>
#include <QSizeGrip>
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;

View file

@ -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));

View file

@ -1,3 +1,4 @@
include($$PWD/widgets/widgets.pri)
include($$PWD/playlist/playlist.pri)
include($$PWD/equalizer/equalizer.pri)

View file

@ -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 <QPaintEvent>
#include <QPixmap>
PixmapButton::PixmapButton (QWidget *parent) : QAbstractButton (parent)
{
}
PixmapButton::~PixmapButton ()
{
}
void
PixmapButton::paintEvent( QPaintEvent * event )
{

View file

@ -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 );