OTHER: skin handling cleanups

This commit is contained in:
Thomas Frauendorfer 2010-03-19 21:50:20 +01:00
parent 8509c3d15d
commit e99f0e4325
9 changed files with 161 additions and 133 deletions

View file

@ -0,0 +1,89 @@
/**
* This file is a part of Promoe, an XMMS2 CLient
*
* Copyright (C) 2008-2010 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; 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.
*/
#ifndef __BUTTONPIXMAPS_H__
#define __BUTTONPIXMAPS_H__
#include <QMap>
#include <QPixmap>
typedef QMap <int, QPixmap> PixmapMap;
/*
* QIcon::Normal for normal apperance
* QIcon::Active for pressed state
*
* QIcon::Off for uncecked state
* QIcon::On for checked state
*
* only QIcon::Normal QIcon::Off combination is necessary
*/
class ButtonPixmaps
{
public:
ButtonPixmaps () :
m_pixmaps() {}
ButtonPixmaps (const ButtonPixmaps &p) :
m_pixmaps(p.m_pixmaps) {}
enum Mode {
Normal = 0, // Used when button is in active Window
Inactive = 1, // Used when button is in inactive Window
Pressed = 2 // used when button is pressed
};
enum State {
Unchecked = 0, // used when button is unchecked
Checked = 1 // used when button is checked
};
void addPixmap (const QPixmap & pixmap, Mode m = Normal,
State s = Unchecked) {
m_pixmaps[getKey(m, s)] = pixmap;
if (!m_pixmaps.contains (getKey (Normal, Unchecked))) {
m_pixmaps[getKey (Normal, Unchecked)] = pixmap;
}
}
QPixmap pixmap (Mode m = Normal, State s = Unchecked) const {
if (m_pixmaps.contains (getKey (m, s))) {
return m_pixmaps.value (getKey (m, s));
} else if (s == Checked && m != Normal &&
m_pixmaps.contains (getKey (Normal, s))) {
return m_pixmaps.value (getKey (Normal, s));
} else {
return m_pixmaps.value (getKey (Normal, Unchecked));
}
}
ButtonPixmaps & operator= (const ButtonPixmaps & p) {
m_pixmaps = p.m_pixmaps;
}
protected:
PixmapMap m_pixmaps;
// get the key to be used in the PixmapMap
inline int getKey (Mode m, State s) const { return (m + s*3); }
};
typedef ButtonPixmaps PBPixmaps;
typedef ButtonPixmaps PixmapButtonPixmaps;
#endif

View file

@ -21,75 +21,13 @@
#include <QMap>
#include <QPixmap>
#include "buttonpixmaps.h"
typedef QMap <int, QPixmap> PixmapMap;
class QPaintEvent;
class QWidget;
/*
* QIcon::Normal for normal apperance
* QIcon::Active for pressed state
*
* QIcon::Off for uncecked state
* QIcon::On for checked state
*
* only QIcon::Normal QIcon::Off combination is necessary
*/
class PixmapButtonPixmaps
{
public:
PixmapButtonPixmaps () :
m_pixmaps() {}
PixmapButtonPixmaps (const PixmapButtonPixmaps &p) :
m_pixmaps(p.m_pixmaps) {}
enum Mode {
Normal = 0, // Used when button is in active Window
Inactive = 1, // Used when button is in inactive Window
Pressed = 2 // used when button is pressed
};
enum State {
Unchecked = 0, // used when button is unchecked
Checked = 1 // used when button is checked
};
void addPixmap (const QPixmap & pixmap, Mode m = Normal,
State s = Unchecked) {
m_pixmaps[getKey(m, s)] = pixmap;
if (!m_pixmaps.contains (getKey (Normal, Unchecked))) {
m_pixmaps[getKey (Normal, Unchecked)] = pixmap;
}
}
QPixmap pixmap (Mode m = Normal, State s = Unchecked) const {
if (m_pixmaps.contains (getKey (m, s))) {
return m_pixmaps.value (getKey (m, s));
} else if (s == Checked && m != Normal &&
m_pixmaps.contains (getKey (Normal, s))) {
return m_pixmaps.value (getKey (Normal, s));
} else {
return m_pixmaps.value (getKey (Normal, Unchecked));
}
}
PixmapButtonPixmaps & operator= (const PixmapButtonPixmaps & p) {
m_pixmaps = p.m_pixmaps;
}
protected:
PixmapMap m_pixmaps;
// get the key to be used in the PixmapMap
inline int getKey (Mode m, State s) const { return (m + s*3); }
};
typedef PixmapButtonPixmaps PBPixmaps;
class PixmapButton : public QAbstractButton
{
Q_OBJECT
@ -98,7 +36,7 @@ class PixmapButton : public QAbstractButton
PixmapButton (QWidget *parent) : QAbstractButton (parent) {}
~PixmapButton () {};
void setPixmaps (const PixmapButtonPixmaps & p);
void setPixmaps (const ButtonPixmaps & p);
protected:
void paintEvent ( QPaintEvent * event );

View file

@ -43,11 +43,17 @@ PixmapSlider::setBackground (const QPixmapList &list)
m_background_index = -1;
}
void
PixmapSlider::setButton (const ButtonPixmaps &p)
{
m_button = p;
}
void
PixmapSlider::setSliders (QPixmap normal, QPixmap pressed)
{
m_normal = normal;
m_pressed = pressed;
m_button.addPixmap (normal, ButtonPixmaps::Normal);
m_button.addPixmap (pressed, ButtonPixmaps::Pressed);
}
void
@ -107,10 +113,11 @@ int
PixmapSlider::sliderMovePosition (QMouseEvent *event)
{
int ret;
QPixmap p = m_button.pixmap (ButtonPixmaps::Pressed);
if (orientation () == Qt::Vertical) {
ret = sliderValueFromPosition (event->y() - m_pressed.height () /2);
ret = sliderValueFromPosition (event->y() - p.height () /2);
} else {
ret = sliderValueFromPosition (event->x() - m_pressed.width () /2);
ret = sliderValueFromPosition (event->x() - p.width () /2);
}
// Make sliders snap to center. Usefull for equalizer sliders and balance
@ -149,8 +156,9 @@ PixmapSlider::paintEvent (QPaintEvent *event)
p.drawPixmap (0, 0, bg.width(), bg.height(), bg);
}
// draw slider
QPixmap *slider = isSliderDown () ? &m_pressed : &m_normal;
QRect rect (slider->rect ());
QPixmap slider = m_button.pixmap (isSliderDown () ? ButtonPixmaps::Pressed
: ButtonPixmaps::Normal);
QRect rect (slider.rect ());
if (orientation () == Qt::Vertical) {
rect.moveTop (sliderPositionFromValue () + m_slider_offset.y ());
rect.moveLeft (m_slider_offset.x ());
@ -158,7 +166,7 @@ PixmapSlider::paintEvent (QPaintEvent *event)
rect.moveLeft (sliderPositionFromValue () + m_slider_offset.x ());
rect.moveTop (m_slider_offset.y ());
}
p.drawPixmap (rect , *slider, slider->rect ());
p.drawPixmap (rect , slider, slider.rect ());
p.end ();
}
@ -166,10 +174,11 @@ int
PixmapSlider::sliderPositionFromValue ()
{
int span;
QPixmap p = m_button.pixmap (ButtonPixmaps::Normal);
if (orientation () == Qt::Vertical) {
span = height () - m_normal.height ();
span = height () - p.height ();
} else {
span = width () - m_normal.width ();
span = width () - p.width ();
}
return QStyle::sliderPositionFromValue (minimum (), maximum (),
@ -181,10 +190,11 @@ int
PixmapSlider::sliderValueFromPosition (int pos)
{
int span;
QPixmap p = m_button.pixmap (ButtonPixmaps::Normal);
if (orientation () == Qt::Vertical) {
span = height () - m_normal.height ();
span = height () - p.height ();
} else {
span = width () - m_normal.width ();
span = width () - p.width ();
}
return QStyle::sliderValueFromPosition (minimum (), maximum (), pos,

View file

@ -1,7 +1,7 @@
/**
* This file is a part of Promoe, an XMMS2 CLient
*
* Copyright (C) 2008 XMMS2 Team
* Copyright (C) 2008-2010 XMMS2 Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -21,6 +21,8 @@
#include <QList>
#include <QPoint>
#include "buttonpixmaps.h"
class QWidget;
class QPixmap;
class QPaintEvent;
@ -41,9 +43,13 @@ class PixmapSlider : public QAbstractSlider
void setBackground (const QPixmapList &);
QPixmapList backgrounds () const { return m_backgrounds; }
void setButton (const ButtonPixmaps &);
void setSliders (QPixmap normal, QPixmap pressed = QPixmap ());
QPixmap normalSlider () const { return m_normal; }
QPixmap pressedSlider () const { return m_pressed; }
QPixmap normalSlider () const
{ return m_button.pixmap (ButtonPixmaps::Normal); }
QPixmap pressedSlider () const
{ return m_button.pixmap (ButtonPixmaps::Pressed); }
void setSliderOffset (QPoint offset) { m_slider_offset = offset; }
@ -63,8 +69,7 @@ class PixmapSlider : public QAbstractSlider
private:
QPixmapList m_backgrounds;
QPixmap m_normal;
QPixmap m_pressed;
ButtonPixmaps m_button;
QPoint m_slider_offset;
int m_background_index;