Aurorae supports painting a custom background behind the button group.

Inspired by new Ubuntu Lucid Metacity themes.

svn path=/trunk/KDE/kdebase/workspace/; revision=1121484
This commit is contained in:
Martin Gräßlin 2010-05-01 11:43:39 +00:00
parent 18092d25d9
commit c135ebfcc5
3 changed files with 67 additions and 2 deletions

View file

@ -37,6 +37,55 @@
namespace Aurorae {
AuroraeButtonGroup::AuroraeButtonGroup(AuroraeTheme *theme, AuroraeButtonGroup::ButtonGroup group)
: QGraphicsWidget()
, m_theme(theme)
, m_group(group)
{
}
void AuroraeButtonGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option)
Q_UNUSED(widget)
Plasma::FrameSvg *decoration = m_theme->decoration();
QString basePrefix;
QString prefix;
AuroraeScene *s = static_cast<AuroraeScene*>(scene());
switch (m_group) {
case LeftGroup:
basePrefix = "buttongroup-left";
break;
case RightGroup:
basePrefix = "buttongroup-right";
break;
}
if (!decoration->hasElementPrefix(basePrefix)) {
return;
}
if (!s->isActive() && decoration->hasElementPrefix(basePrefix + "-inactive")) {
prefix = basePrefix + "-inactive";
} else {
prefix = basePrefix;
}
decoration->setElementPrefix(prefix);
decoration->setEnabledBorders(Plasma::FrameSvg::AllBorders);
decoration->resizeFrame(size());
if (s->isAnimating() && decoration->hasElementPrefix(basePrefix + "-inactive")) {
QPixmap target = decoration->framePixmap();
decoration->setElementPrefix(basePrefix + "-inactive");
if (!s->isActive()) {
decoration->setElementPrefix(basePrefix);
}
decoration->resizeFrame(size());
QPixmap result = Plasma::PaintUtils::transition(decoration->framePixmap(),
target, s->animationProgress());
painter->drawPixmap(0, 0, result);
} else {
decoration->paintFrame(painter);
}
}
AuroraeButton::AuroraeButton(AuroraeTheme* theme, AuroraeButtonType type)
: QGraphicsWidget()
, m_theme(theme)

View file

@ -36,6 +36,22 @@ namespace Aurorae {
class AuroraeTheme;
class AuroraeButtonGroup : public QGraphicsWidget
{
Q_OBJECT
public:
enum ButtonGroup {
LeftGroup = 0,
RightGroup
};
AuroraeButtonGroup(AuroraeTheme *theme, ButtonGroup group);
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
private:
AuroraeTheme *m_theme;
ButtonGroup m_group;
};
class AuroraeButton : public QGraphicsWidget
{
Q_OBJECT

View file

@ -88,7 +88,7 @@ void AuroraeScene::init()
leftButtonsLayout->setOrientation(orientation);
initButtons(leftButtonsLayout, buttonsToDirection(m_leftButtonOrder));
m_leftButtons = new QGraphicsWidget;
m_leftButtons = new AuroraeButtonGroup(m_theme, AuroraeButtonGroup::LeftGroup);
m_leftButtons->setLayout(leftButtonsLayout);
addItem(m_leftButtons);
@ -99,7 +99,7 @@ void AuroraeScene::init()
rightButtonsLayout->setOrientation(orientation);
initButtons(rightButtonsLayout, buttonsToDirection(m_rightButtonOrder));
m_rightButtons = new QGraphicsWidget;
m_rightButtons = new AuroraeButtonGroup(m_theme, AuroraeButtonGroup::RightGroup);
m_rightButtons->setLayout(rightButtonsLayout);
addItem(m_rightButtons);