From c135ebfcc5801a2275a57c041a5addc5f5b9755c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Sat, 1 May 2010 11:43:39 +0000 Subject: [PATCH] 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 --- clients/aurorae/src/lib/auroraebutton.cpp | 49 +++++++++++++++++++++++ clients/aurorae/src/lib/auroraebutton.h | 16 ++++++++ clients/aurorae/src/lib/auroraescene.cpp | 4 +- 3 files changed, 67 insertions(+), 2 deletions(-) diff --git a/clients/aurorae/src/lib/auroraebutton.cpp b/clients/aurorae/src/lib/auroraebutton.cpp index 10cfef511c..a2294ebd5d 100644 --- a/clients/aurorae/src/lib/auroraebutton.cpp +++ b/clients/aurorae/src/lib/auroraebutton.cpp @@ -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(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) diff --git a/clients/aurorae/src/lib/auroraebutton.h b/clients/aurorae/src/lib/auroraebutton.h index 846814e9dd..cc1f1f2512 100644 --- a/clients/aurorae/src/lib/auroraebutton.h +++ b/clients/aurorae/src/lib/auroraebutton.h @@ -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 diff --git a/clients/aurorae/src/lib/auroraescene.cpp b/clients/aurorae/src/lib/auroraescene.cpp index 33de82b474..c69b6fc4d7 100644 --- a/clients/aurorae/src/lib/auroraescene.cpp +++ b/clients/aurorae/src/lib/auroraescene.cpp @@ -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);