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

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