OTHER: removed PixWidget

PixWidget sole purpose was to paint a given pixmap. Some of PixWidgets
child classes had to create that pixmap from some other pixmaps. Thus
PixWidget introduced some kind of unnecessary double buffering.
Furthermore, those pixmaps where created even if a widget wasn't
visible. Painting directly to the widget and calling the 'update ()'
method on changes might allow Qt to do some performance optimizations.
Most likely they will be to small to be noticable though.

I also disabled the shortcuts of the titlebarmenu. They were diplayed in
the menu but didn't work. As soon as I figure out how to get them
working again I will enable them again
This commit is contained in:
Thomas Frauendorfer 2008-10-03 01:22:40 +02:00
parent 6cf0ad2614
commit 096ac37121
11 changed files with 130 additions and 167 deletions

View file

@ -1,58 +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 "Skin.h"
#include "PixWidget.h"
#include <QPainter>
#include <QPixmap>
PixWidget::PixWidget (QWidget *parent) : QWidget (parent)
{
Skin *skin = Skin::getInstance();
m_pixmap = QPixmap(0,0);
connect (skin, SIGNAL (skinChanged (Skin *)),
this, SLOT (setPixmaps(Skin *)));
}
PixWidget::~PixWidget ()
{
}
void
PixWidget::setPixmaps(Skin *skin)
{
}
/*
* Since almost every Widget I have here
* is done by drawing self.pixmap onto self
* we define this a generic PaintEvent handler
*/
void
PixWidget::paintEvent (QPaintEvent *event)
{
if (m_pixmap.isNull ()) {
return;
}
QPainter (paint);
paint.begin (this);
paint.drawPixmap (rect (), m_pixmap, m_pixmap.rect ());
paint.end ();
}

View file

@ -1,37 +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 __PIXWIDGET_H__
#define __PIXWIDGET_H__
#include <QWidget>
class QPixmap;
class Skin;
class PixWidget : public QWidget
{
Q_OBJECT
public:
PixWidget(QWidget *parent = 0);
~PixWidget();
void paintEvent (QPaintEvent *event);
public slots:
virtual void setPixmaps(Skin *skin);
protected:
QPixmap m_pixmap;
};
#endif

View file

@ -16,8 +16,15 @@
#include "clutterbar.h"
#include "Skin.h"
ClutterBar::ClutterBar (QWidget *parent) : PixWidget (parent)
#include <QMouseEvent>
#include <QPainter>
ClutterBar::ClutterBar (QWidget *parent) : QWidget (parent)
{
Skin *skin = Skin::getInstance();
connect (skin, SIGNAL (skinChanged (Skin *)),
this, SLOT (setPixmaps(Skin *)));
}
ClutterBar::~ClutterBar ()
@ -39,8 +46,7 @@ ClutterBar::setPixmaps(Skin *skin)
m_pixmap = m_clutter_on;
setMinimumSize (m_clutter_on.size ());
setMaximumSize (m_clutter_on.size ());
setFixedSize (m_clutter_on.size ());
update();
}
@ -74,4 +80,13 @@ ClutterBar::mouseReleaseEvent (QMouseEvent *event)
}
void
ClutterBar::paintEvent (QPaintEvent *event)
{
if (m_pixmap.isNull ()) {
return;
}
QPainter p (this);
p.drawPixmap (rect (), m_pixmap, m_pixmap.rect ());
}

View file

@ -16,10 +16,13 @@
#ifndef __CLUTTERBAR_H__
#define __CLUTTERBAR_H__
#include <QMouseEvent>
#include "PixWidget.h"
#include "QWidget"
class QMouseEvent;
class QPaintEvent;
class ClutterBar : public PixWidget
class Skin;
class ClutterBar : public QWidget
{
Q_OBJECT
public:
@ -30,6 +33,8 @@ class ClutterBar : public PixWidget
void setPixmaps(Skin *skin);
protected:
void paintEvent (QPaintEvent *event);
void mousePressEvent (QMouseEvent *event);
void mouseReleaseEvent (QMouseEvent *event);
@ -44,7 +49,7 @@ class ClutterBar : public PixWidget
bool enabled;
int m_ypos;
QPixmap m_pixmap;
};

View file

@ -18,12 +18,13 @@
#include <QPainter>
StereoMono::StereoMono (QWidget *parent) : PixWidget (parent)
StereoMono::StereoMono (QWidget *parent) : QWidget (parent)
{
setMinimumSize (56, 12);
setMaximumSize (56, 12);
setFixedSize (56, 12);
m_pixmap = QPixmap (56, 12);
Skin *skin = Skin::getInstance();
connect (skin, SIGNAL (skinChanged (Skin *)),
this, SLOT (setPixmaps (Skin *)));
}
void
@ -34,47 +35,27 @@ StereoMono::setPixmaps (Skin *skin)
m_pixmap_mono_on = skin->getItem (Skin::MONO_1);
m_pixmap_mono_off = skin->getItem (Skin::MONO_0);
setStereoMono (m_stereo, m_mono);
update ();
}
void
StereoMono::drawPixmaps ()
StereoMono::paintEvent (QPaintEvent *event)
{
QPainter paint;
paint.begin (&m_pixmap);
QPainter p (this);
paint.drawPixmap (QRect (0, 0, 27, 12),
m_pixmap_mono,
m_pixmap_mono.rect ());
paint.drawPixmap (QRect (27, 0, 29, 12),
m_pixmap_stereo,
m_pixmap_stereo.rect ());
paint.end ();
update();
p.drawPixmap (0, 0, m_mono ? m_pixmap_mono_on : m_pixmap_mono_off);
p.drawPixmap (27, 0, m_stereo ? m_pixmap_stereo_on : m_pixmap_stereo_off);
}
void
StereoMono::setStereoMono (bool stereo, bool mono)
{
if (stereo) {
m_pixmap_stereo = m_pixmap_stereo_on;
} else {
m_pixmap_stereo = m_pixmap_stereo_off;
}
if (mono) {
m_pixmap_mono = m_pixmap_mono_on;
} else {
m_pixmap_mono = m_pixmap_mono_off;
}
// if nothing changes, just return
if ((m_stereo == stereo) && (m_mono == mono))
return;
m_stereo = stereo;
m_mono = mono;
drawPixmaps ();
update ();
}

View file

@ -16,10 +16,14 @@
#ifndef __STEREOMONO_H__
#define __STEREOMONO_H__
#include "PixWidget.h"
#include <QWidget>
class StereoMono : public PixWidget
class QPaintEvent;
class Skin;
class StereoMono : public QWidget
{
Q_OBJECT
public:
StereoMono (QWidget *parent);
~StereoMono () { }
@ -29,8 +33,10 @@ class StereoMono : public PixWidget
public slots:
void setPixmaps (Skin *skin);
protected slots:
void paintEvent (QPaintEvent *event);
private:
void drawPixmaps ();
bool m_stereo;
bool m_mono;
@ -38,9 +44,6 @@ class StereoMono : public PixWidget
QPixmap m_pixmap_stereo_off;
QPixmap m_pixmap_mono_on;
QPixmap m_pixmap_mono_off;
QPixmap m_pixmap_mono;
QPixmap m_pixmap_stereo;
};
#endif

View file

@ -26,8 +26,9 @@
#include "Skin.h"
#include <QMenu>
#include <QPainter>
TitleBar::TitleBar (QWidget *parent, bool shaded) : PixWidget (parent)
TitleBar::TitleBar (QWidget *parent, bool shaded) : QWidget (parent)
{
MainWindow *mw = dynamic_cast<MainWindow*>(window ());
m_shaded = shaded;
@ -61,6 +62,9 @@ TitleBar::TitleBar (QWidget *parent, bool shaded) : PixWidget (parent)
m_closebtn->move (skin->getPos (Skin::BUTTON_MW_CLOSE));
connect (m_closebtn, SIGNAL (clicked()), qApp, SLOT (quit ()));
m_pixmap = QPixmap(0,0);
connect (skin, SIGNAL (skinChanged (Skin *)),
this, SLOT (setPixmaps(Skin *)));
}
void
@ -71,30 +75,30 @@ TitleBar::showMenu (void)
QAction *a;
a = new QAction (tr ("Medialib browser"), this);
a->setShortcut (tr ("Alt+M"));
// a->setShortcut (tr ("Alt+M"));
connect (a, SIGNAL (triggered ()), this, SLOT (showMlib ()));
a->setEnabled(false); // FIXME: disabled for now, as Mlib-browser doesn't work
qm.addAction (a);
a = new QAction (tr ("Server-side browser"), this);
a->setShortcut (tr ("Alt+S"));
// a->setShortcut (tr ("Alt+S"));
connect (a, SIGNAL (triggered ()), this, SLOT (showServerB ()));
qm.addAction (a);
qm.addSeparator ();
a = new QAction (tr ("Theme settings"), this);
a->setShortcut (tr ("Alt+T"));
// a->setShortcut (tr ("Alt+T"));
connect (a, SIGNAL (triggered ()), this, SLOT (showTheme ()));
qm.addAction (a);
a = new QAction (tr ("Application settings"), this);
a->setShortcut (tr ("Alt+A"));
// a->setShortcut (tr ("Alt+A"));
connect (a, SIGNAL (triggered ()), this, SLOT (showSettings ()));
qm.addAction (a);
a = new QAction (tr ("Server settings"), this);
a->setShortcut (tr ("Alt+S"));
// a->setShortcut (tr ("Alt+S"));
a->setEnabled(false); // FIXME: disabled for now, not yet implemented
qm.addAction (a);
qm.addSeparator ();
a = new QAction (tr ("Quit"), this);
a->setShortcut (tr ("Ctrl+Q"));
// a->setShortcut (tr ("Ctrl+Q"));
connect (a, SIGNAL (triggered ()), qApp, SLOT (quit ()));
qm.addAction (a);
@ -177,6 +181,15 @@ TitleBar::setActive (bool active)
}
}
void
TitleBar::paintEvent (QPaintEvent *event)
{
QPainter p;
p.begin (this);
p.drawPixmap (rect (), m_pixmap);
p.end ();
}
void
TitleBar::mouseDoubleClickEvent (QMouseEvent *event)
{

View file

@ -16,14 +16,13 @@
#ifndef __TITLEBAR_H__
#define __TITLEBAR_H__
class TitleBar;
#include "PixWidget.h"
#include "QWidget"
class QPaintEvent;
class PixmapButton;
class Skin;
class TitleBar : public PixWidget
class TitleBar : public QWidget
{
Q_OBJECT
public:
@ -39,6 +38,9 @@ class TitleBar : public PixWidget
void showMlib (void);
void showSettings (void);
protected slots:
void paintEvent (QPaintEvent *event);
protected:
void mouseDoubleClickEvent (QMouseEvent *event);
@ -52,6 +54,7 @@ class TitleBar : public PixWidget
PixmapButton *m_minimize;
bool m_shaded;
QPixmap m_pixmap;
};
#endif

View file

@ -21,6 +21,28 @@
#include <QPoint>
#include <QPainter>
PlaylistMenuBar::PlaylistMenuBar (QWidget *parent, uint id) : QWidget (parent)
{
m_id = id;
Skin *skin = Skin::getInstance ();
m_pixmap = QPixmap (0,0);
connect (skin, SIGNAL (skinChanged (Skin *)),
this, SLOT (setPixmaps (Skin *)));
}
void
PlaylistMenuBar::paintEvent (QPaintEvent *event)
{
QPainter p;
p.begin (this);
p.drawPixmap (rect (), m_pixmap, m_pixmap.rect ());
p.end ();
}
PlaylistMenuButton::PlaylistMenuButton (PlaylistMenu *menu,
uint pix1, uint pix2) : QWidget (menu)
{
@ -59,7 +81,7 @@ PlaylistMenuButton::setPixmaps (Skin *skin)
* PlaylistMenu
*/
PlaylistMenu::PlaylistMenu (QWidget *parent, uint pix,
uint decoration) : PixWidget (parent)
uint decoration) : QWidget (parent)
{
setFixedSize (25, 18);
@ -70,6 +92,21 @@ PlaylistMenu::PlaylistMenu (QWidget *parent, uint pix,
m_decbar->move (0, 0);
m_pixid = pix;
Skin *skin = Skin::getInstance ();
m_pixmap = QPixmap (0,0);
connect (skin, SIGNAL (skinChanged (Skin *)),
this, SLOT (setPixmaps (Skin *)));
}
void
PlaylistMenu::paintEvent (QPaintEvent *event)
{
QPainter p;
p.begin (this);
p.drawPixmap (rect (), m_pixmap, m_pixmap.rect ());
p.end ();
}
void

View file

@ -16,26 +16,25 @@
#ifndef __PLAYLISTMENU_H__
#define __PLAYLISTMENU_H__
class PlaylistMenu;
//#include "XMMSHandler.h"
#include "PixWidget.h"
#include <QWidget>
#include "Skin.h"
#include <QWidget>
class PlaylistMenu;
class PlaylistMenuBar : public PixWidget {
class PlaylistMenuBar : public QWidget {
Q_OBJECT
public:
PlaylistMenuBar (QWidget *parent, uint id) : PixWidget (parent)
{
m_id = id;
}
PlaylistMenuBar (QWidget *parent, uint id);
public slots:
void setPixmaps (Skin *skin) { m_pixmap = skin->getPls (m_id); }
protected slots:
void paintEvent (QPaintEvent *event);
private:
uint m_id;
QPixmap m_pixmap;
};
class PlaylistMenuButton : public QWidget {
@ -65,7 +64,7 @@ class PlaylistMenuButton : public QWidget {
QPixmap m_pixmap;
};
class PlaylistMenu : public PixWidget {
class PlaylistMenu : public QWidget {
Q_OBJECT
public:
PlaylistMenu (QWidget *, uint, uint);
@ -81,6 +80,9 @@ class PlaylistMenu : public PixWidget {
public slots:
void setPixmaps (Skin *skin);
protected slots:
void paintEvent (QPaintEvent *event);
private:
uint m_pixid;
uint m_dec;
@ -90,6 +92,7 @@ class PlaylistMenu : public PixWidget {
PlaylistMenuBar *m_decbar;
QPixmap m_pixmap;
};
#endif

View file

@ -4,8 +4,7 @@ include($$PWD/playlist/playlist.pri)
include($$PWD/equalizer/equalizer.pri)
include($$PWD/dialogs/dialogs.pri)
HEADERS += PixWidget.h \
Skin.h \
HEADERS += Skin.h \
XMMSHandler.h \
SkinChooser.h \
settingsdialog.h \
@ -15,7 +14,6 @@ HEADERS += PixWidget.h \
BrowseDialog.h
SOURCES += main.cpp \
PixWidget.cpp \
Skin.cpp \
XMMSHandler.cpp \
SkinChooser.cpp \