From 0a659c977b089c9f519c3dab9b2cec2eef197eed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20Ker=C3=A4nen?= Date: Wed, 16 Mar 2016 22:18:44 +0200 Subject: [PATCH] Refactor|libappfw: Using color theme enums in popups --- .../include/de/widgets/popupmenuwidget.h | 1 + .../libappfw/include/de/widgets/popupwidget.h | 2 ++ .../sdk/libappfw/src/widgets/focuswidget.cpp | 1 + .../libappfw/src/widgets/popupmenuwidget.cpp | 22 ++++++++++++------- .../sdk/libappfw/src/widgets/popupwidget.cpp | 15 ++++++++----- 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/doomsday/sdk/libappfw/include/de/widgets/popupmenuwidget.h b/doomsday/sdk/libappfw/include/de/widgets/popupmenuwidget.h index 747ef60eb4..8e333d6041 100644 --- a/doomsday/sdk/libappfw/include/de/widgets/popupmenuwidget.h +++ b/doomsday/sdk/libappfw/include/de/widgets/popupmenuwidget.h @@ -39,6 +39,7 @@ class LIBAPPFW_PUBLIC PopupMenuWidget : public PopupWidget ui::Data &items() { return menu().items(); } void useInfoStyle(bool yes = true); + void setColorTheme(ColorTheme theme); // Events. void update(); diff --git a/doomsday/sdk/libappfw/include/de/widgets/popupwidget.h b/doomsday/sdk/libappfw/include/de/widgets/popupwidget.h index 3314b357c2..3c9a569d5d 100644 --- a/doomsday/sdk/libappfw/include/de/widgets/popupwidget.h +++ b/doomsday/sdk/libappfw/include/de/widgets/popupwidget.h @@ -98,6 +98,8 @@ class LIBAPPFW_PUBLIC PopupWidget : public PanelWidget Background infoStyleBackground() const; + void setColorTheme(ColorTheme theme); + // Events. bool handleEvent(Event const &event); diff --git a/doomsday/sdk/libappfw/src/widgets/focuswidget.cpp b/doomsday/sdk/libappfw/src/widgets/focuswidget.cpp index fd7066257f..f6f2593f02 100644 --- a/doomsday/sdk/libappfw/src/widgets/focuswidget.cpp +++ b/doomsday/sdk/libappfw/src/widgets/focuswidget.cpp @@ -66,6 +66,7 @@ FocusWidget::FocusWidget(String const &name) : LabelWidget(name) , d(new Instance(this)) { + hide(); connect(&d->flashing, SIGNAL(timeout()), this, SLOT(updateFlash())); } diff --git a/doomsday/sdk/libappfw/src/widgets/popupmenuwidget.cpp b/doomsday/sdk/libappfw/src/widgets/popupmenuwidget.cpp index 7ae52fca59..0f0814828a 100644 --- a/doomsday/sdk/libappfw/src/widgets/popupmenuwidget.cpp +++ b/doomsday/sdk/libappfw/src/widgets/popupmenuwidget.cpp @@ -89,7 +89,7 @@ DENG_GUI_PIMPL(PopupMenuWidget) Id _id; }; - bool infoStyle = false; + ColorTheme colorTheme = Normal; ButtonWidget *hover; int oldScrollY; Rule const *widestItem; @@ -206,8 +206,8 @@ DENG_GUI_PIMPL(PopupMenuWidget) void setButtonColors(ButtonWidget &button) { bool const hovering = (hover == &button); - button.setTextColor(!hovering ^ infoStyle? "text" : "inverted.text"); - button.setHoverTextColor(!hovering ^ infoStyle? "inverted.text" : "text", + button.setTextColor(!hovering ^ (colorTheme == Inverted)? "text" : "inverted.text"); + button.setHoverTextColor(!hovering ^ (colorTheme == Inverted)? "inverted.text" : "text", ButtonWidget::ReplaceColor); } @@ -310,7 +310,8 @@ DENG_GUI_PIMPL(PopupMenuWidget) void updateImageColor(ButtonWidget &button, bool invert = false) { - button.setImageColor(style().colors().colorf(invert ^ infoStyle? "inverted.text" : "text")); + button.setImageColor(style().colors().colorf(invert ^ (colorTheme == Inverted)? "inverted.text" + : "text")); } void buttonStateChanged(ButtonWidget &button, ButtonWidget::State state) @@ -419,8 +420,13 @@ MenuWidget &PopupMenuWidget::menu() const void PopupMenuWidget::useInfoStyle(bool yes) { - PopupWidget::useInfoStyle(yes); - d->infoStyle = yes; + setColorTheme(yes? Inverted : Normal); +} + +void PopupMenuWidget::setColorTheme(ColorTheme theme) +{ + PopupWidget::setColorTheme(theme); + d->colorTheme = theme; d->updateButtonColors(); } @@ -438,8 +444,8 @@ void PopupMenuWidget::glMakeGeometry(DefaultVertexBuf::Builder &verts) { verts.makeQuad(d->highlightRect(), d->hover->state() == ButtonWidget::Hover? - style().colors().colorf(!d->infoStyle? "inverted.background" : "background") : - style().colors().colorf(!d->infoStyle? "accent" : "inverted.accent"), + style().colors().colorf(d->colorTheme == Normal? "inverted.background" : "background") : + style().colors().colorf(d->colorTheme == Normal? "accent" : "inverted.accent"), root().atlas().imageRectf(root().solidWhitePixel()).middle()); } } diff --git a/doomsday/sdk/libappfw/src/widgets/popupwidget.cpp b/doomsday/sdk/libappfw/src/widgets/popupwidget.cpp index 50beb8bccd..2d987def7a 100644 --- a/doomsday/sdk/libappfw/src/widgets/popupwidget.cpp +++ b/doomsday/sdk/libappfw/src/widgets/popupwidget.cpp @@ -35,7 +35,7 @@ DENG_GUI_PIMPL(PopupWidget) , DENG2_OBSERVES(Widget, Deletion) { bool flexibleDir = true; - bool useInfoStyle = false; + ColorTheme colorTheme = Normal; bool deleteAfterDismiss = false; bool clickToClose = true; bool outsideClickOngoing = false; @@ -204,7 +204,7 @@ DENG_GUI_PIMPL(PopupWidget) Style const &st = style(); bool const opaqueBackground = (self.levelOfNesting() > 0); - if(useInfoStyle) + if(colorTheme == Inverted) { self.set(self.infoStyleBackground()); } @@ -346,13 +346,18 @@ void PopupWidget::setClickToClose(bool clickCloses) void PopupWidget::useInfoStyle(bool yes) { - d->useInfoStyle = yes; - d->updateStyle(); + setColorTheme(yes? Inverted : Normal); } bool PopupWidget::isUsingInfoStyle() { - return d->useInfoStyle; + return d->colorTheme == Inverted; +} + +void PopupWidget::setColorTheme(ColorTheme theme) +{ + d->colorTheme = theme; + d->updateStyle(); } GuiWidget::Background PopupWidget::infoStyleBackground() const