Merge lp:~aacid/unity-2d/unity-2d_panel_style_split into lp:unity-2d

Proposed by Albert Astals Cid
Status: Merged
Approved by: Michał Sawicz
Approved revision: 945
Merged at revision: 958
Proposed branch: lp:~aacid/unity-2d/unity-2d_panel_style_split
Merge into: lp:unity-2d
Diff against target: 309 lines (+149/-54)
6 files modified
libunity-2d-private/src/CMakeLists.txt (+1/-0)
libunity-2d-private/src/panelpalettemanager.cpp (+87/-0)
libunity-2d-private/src/panelpalettemanager.h (+52/-0)
libunity-2d-private/src/panelstyle.cpp (+4/-43)
libunity-2d-private/src/panelstyle.h (+3/-11)
libunity-2d-private/src/unity2dpanel.cpp (+2/-0)
To merge this branch: bzr merge lp:~aacid/unity-2d/unity-2d_panel_style_split
Reviewer Review Type Date Requested Status
Michał Sawicz Approve
Review via email: mp+95370@code.launchpad.net

Description of the change

Split panelstyle into panelstyle and panalpalettemanager so you can have different palettes per panel

To post a comment you must log in.
Revision history for this message
Michał Sawicz (saviq) :
review: Approve
945. By Albert Astals Cid

Merge lp:unity-2d

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libunity-2d-private/src/CMakeLists.txt'
2--- libunity-2d-private/src/CMakeLists.txt 2012-03-05 16:38:47 +0000
3+++ libunity-2d-private/src/CMakeLists.txt 2012-03-06 15:27:19 +0000
4@@ -70,6 +70,7 @@
5 indicatorswidget.cpp
6 panelapplet.cpp
7 panelstyle.cpp
8+ panelpalettemanager.cpp
9 percentcoder.cpp
10 windowsintersectmonitor.cpp
11 abstractdbusservicemonitor.cpp
12
13=== added file 'libunity-2d-private/src/panelpalettemanager.cpp'
14--- libunity-2d-private/src/panelpalettemanager.cpp 1970-01-01 00:00:00 +0000
15+++ libunity-2d-private/src/panelpalettemanager.cpp 2012-03-06 15:27:19 +0000
16@@ -0,0 +1,87 @@
17+/*
18+ * This file is part of unity-2d
19+ *
20+ * Copyright 2012 Canonical Ltd.
21+ *
22+ * This program is free software; you can redistribute it and/or modify
23+ * it under the terms of the GNU General Public License as published
24+ * by the Free Software Foundation; version 3.
25+ *
26+ * This program is distributed in the hope that it will be useful,
27+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
28+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29+ * GNU General Public License for more details.
30+ *
31+ * You should have received a copy of the GNU General Public License
32+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
33+ */
34+
35+#include "panelpalettemanager.h"
36+
37+// libunity-2d
38+#include <cairoutils.h>
39+#include <dashclient.h>
40+#include <hudclient.h>
41+#include <panelstyle.h>
42+#include <unity2dpanel.h>
43+
44+// Qt
45+#include <QBrush>
46+#include <QPalette>
47+
48+// GTK
49+#include <gtk/gtk.h>
50+
51+namespace Unity2d
52+{
53+
54+static void onThemeChanged(GObject*, GParamSpec*, gpointer data)
55+{
56+ PanelPaletteManager* priv = reinterpret_cast<PanelPaletteManager*>(data);
57+ priv->updatePalette();
58+}
59+
60+PanelPaletteManager::PanelPaletteManager(Unity2dPanel* panel)
61+ : m_panel(panel)
62+{
63+ connect(DashClient::instance(), SIGNAL(activeChanged(bool)), this, SLOT(updatePalette()));
64+ connect(HUDClient::instance(), SIGNAL(activeChanged(bool)), this, SLOT(updatePalette()));
65+
66+ m_gConnector.connect(gtk_settings_get_default(), "notify::gtk-theme-name", G_CALLBACK(onThemeChanged), this);
67+ updatePalette();
68+}
69+
70+static QBrush generateBackgroundBrush()
71+{
72+ QImage image(100, 24, QImage::Format_ARGB32_Premultiplied); // FIXME: Hardcoded
73+ image.fill(Qt::transparent);
74+ CairoUtils::SurfacePointer surface(CairoUtils::createSurfaceForQImage(&image));
75+ CairoUtils::Pointer cr(cairo_create(surface.data()));
76+ GtkStyleContext* context = PanelStyle::instance()->styleContext();
77+ gtk_render_background(context, cr.data(), 0, 0, image.width(), image.height());
78+ gtk_render_frame(context, cr.data(), 0, 0, image.width(), image.height());
79+ return QBrush(image);
80+}
81+
82+void PanelPaletteManager::updatePalette()
83+{
84+ GtkStyleContext* context = PanelStyle::instance()->styleContext();
85+ gtk_style_context_invalidate(context);
86+
87+ // Without this line, it seems the GtkStyleContext is not correctly
88+ // initialized and we get some uninitialized pixels in the background
89+ // brush.
90+ gtk_style_context_get(context, GTK_STATE_FLAG_NORMAL, NULL);
91+
92+ QPalette pal;
93+ if (DashClient::instance()->active() || HUDClient::instance()->active()) {
94+ pal.setBrush(QPalette::Window, QColor(0, 0, 0, 168));
95+ } else {
96+ pal.setBrush(QPalette::Window, generateBackgroundBrush());
97+ }
98+ m_panel->setPalette(pal);
99+}
100+
101+} // namespace Unity2d
102+
103+#include "panelpalettemanager.moc"
104\ No newline at end of file
105
106=== added file 'libunity-2d-private/src/panelpalettemanager.h'
107--- libunity-2d-private/src/panelpalettemanager.h 1970-01-01 00:00:00 +0000
108+++ libunity-2d-private/src/panelpalettemanager.h 2012-03-06 15:27:19 +0000
109@@ -0,0 +1,52 @@
110+/*
111+ * This file is part of unity-2d
112+ *
113+ * Copyright 2012 Canonical Ltd.
114+ *
115+ * This program is free software; you can redistribute it and/or modify
116+ * it under the terms of the GNU General Public License as published
117+ * by the Free Software Foundation; version 3.
118+ *
119+ * This program is distributed in the hope that it will be useful,
120+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
121+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
122+ * GNU General Public License for more details.
123+ *
124+ * You should have received a copy of the GNU General Public License
125+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
126+ */
127+
128+#ifndef PANELPALETTEMANAGER_H
129+#define PANELPALETTEMANAGER_H
130+
131+// Local
132+class Unity2dPanel;
133+
134+// libunity-2d
135+#include <gconnector.h>
136+
137+// Qt
138+#include <QObject>
139+
140+namespace Unity2d
141+{
142+
143+class PanelPaletteManager : public QObject
144+{
145+ Q_OBJECT
146+public:
147+ explicit PanelPaletteManager(Unity2dPanel* panel);
148+
149+public Q_SLOTS:
150+ void updatePalette();
151+
152+private:
153+ Q_DISABLE_COPY(PanelPaletteManager)
154+
155+ Unity2dPanel* m_panel;
156+ GConnector m_gConnector;
157+};
158+
159+} // namespace Unity2d
160+
161+#endif // PANELPALETTEMANAGER_H
162
163=== modified file 'libunity-2d-private/src/panelstyle.cpp'
164--- libunity-2d-private/src/panelstyle.cpp 2012-03-05 16:38:47 +0000
165+++ libunity-2d-private/src/panelstyle.cpp 2012-03-06 15:27:19 +0000
166@@ -22,12 +22,9 @@
167 #include "panelstyle.h"
168
169 // libunity-2d
170-#include <cairoutils.h>
171 #include <debug_p.h>
172 #include <gconnector.h>
173 #include <gscopedpointer.h>
174-#include <dashclient.h>
175-#include <hudclient.h>
176
177 // Qt
178 #include <QApplication>
179@@ -51,42 +48,15 @@
180 static void onThemeChanged(GObject*, GParamSpec*, gpointer data)
181 {
182 PanelStylePrivate* priv = reinterpret_cast<PanelStylePrivate*>(data);
183- priv->updatePalette();
184+ priv->updateTheme();
185 }
186
187- void updatePalette()
188+ void updateTheme()
189 {
190 gchar* themeName = 0;
191 g_object_get(gtk_settings_get_default(), "gtk-theme-name", &themeName, NULL);
192 m_themeName = QString::fromUtf8(themeName);
193 g_free(themeName);
194-
195- GtkStyleContext* context = m_styleContext.data();
196- gtk_style_context_invalidate(context);
197-
198- // Without this line, it seems the GtkStyleContext is not correctly
199- // initialized and we get some uninitialized pixels in the background
200- // brush.
201- gtk_style_context_get(context, GTK_STATE_FLAG_NORMAL, NULL);
202-
203- QPalette pal;
204- if (DashClient::instance()->active() || HUDClient::instance()->active()) {
205- pal.setBrush(QPalette::Window, QColor(0, 0, 0, 168));
206- } else {
207- pal.setBrush(QPalette::Window, generateBackgroundBrush());
208- }
209- QApplication::setPalette(pal);
210- }
211-
212- QBrush generateBackgroundBrush()
213- {
214- QImage image(100, 24, QImage::Format_ARGB32_Premultiplied); // FIXME: Hardcoded
215- image.fill(Qt::transparent);
216- CairoUtils::SurfacePointer surface(CairoUtils::createSurfaceForQImage(&image));
217- CairoUtils::Pointer cr(cairo_create(surface.data()));
218- gtk_render_background(m_styleContext.data(), cr.data(), 0, 0, image.width(), image.height());
219- gtk_render_frame(m_styleContext.data(), cr.data(), 0, 0, image.width(), image.height());
220- return QBrush(image);
221 }
222
223 QPixmap windowButtonPixmapFromWMTheme(PanelStyle::WindowButtonType type, PanelStyle::WindowButtonState state)
224@@ -161,7 +131,7 @@
225 }
226 };
227
228-PanelStyle::PanelStyle(QObject* parent)
229+PanelStyle::PanelStyle()
230 : d(new PanelStylePrivate)
231 {
232 d->q = this;
233@@ -180,9 +150,7 @@
234 d->m_gConnector.connect(gtk_settings_get_default(), "notify::gtk-theme-name",
235 G_CALLBACK(PanelStylePrivate::onThemeChanged), d);
236
237- QObject::connect(DashClient::instance(), SIGNAL(activeChanged(bool)), this, SLOT(onDashActiveChanged(bool)));
238- QObject::connect(HUDClient::instance(), SIGNAL(activeChanged(bool)), this, SLOT(onDashActiveChanged(bool)));
239- d->updatePalette();
240+ d->updateTheme();
241 }
242
243 PanelStyle::~PanelStyle()
244@@ -212,10 +180,3 @@
245 return d->genericWindowButtonPixmap(type, state);
246 }
247 }
248-
249-void PanelStyle::onDashActiveChanged(bool active)
250-{
251- d->updatePalette();
252-}
253-
254-#include "panelstyle.moc"
255
256=== modified file 'libunity-2d-private/src/panelstyle.h'
257--- libunity-2d-private/src/panelstyle.h 2012-02-12 15:12:46 +0000
258+++ libunity-2d-private/src/panelstyle.h 2012-03-06 15:27:19 +0000
259@@ -32,17 +32,12 @@
260
261 class PanelStylePrivate;
262 /**
263- * Provides easy access to panel style context and track platform theme to
264- * ensure we have the correct background brush.
265- *
266- * FIXME: This class does not have a very clear focus and has side-effects
267- * (background brush handling). It should be refactored.
268+ * Provides easy access to panel style context and track platform theme.
269 */
270-class PanelStyle : public QObject
271+class PanelStyle
272 {
273- Q_OBJECT
274 public:
275- PanelStyle(QObject* parent = 0);
276+ PanelStyle();
277 ~PanelStyle();
278
279 enum WindowButtonType {
280@@ -64,9 +59,6 @@
281
282 QPixmap windowButtonPixmap(WindowButtonType, WindowButtonState);
283
284-private Q_SLOTS:
285- void onDashActiveChanged(bool active);
286-
287 private:
288 friend class PanelStylePrivate;
289 // Use a pimpl to avoid the need for gtk includes here
290
291=== modified file 'libunity-2d-private/src/unity2dpanel.cpp'
292--- libunity-2d-private/src/unity2dpanel.cpp 2012-02-09 09:27:03 +0000
293+++ libunity-2d-private/src/unity2dpanel.cpp 2012-03-06 15:27:19 +0000
294@@ -34,6 +34,7 @@
295 #include <QX11Info>
296
297 // unity-2d
298+#include "panelpalettemanager.h"
299 #include "screeninfo.h"
300
301 static const int SLIDE_DURATION = 125;
302@@ -116,6 +117,7 @@
303 } else {
304 d->m_screenInfo = new ScreenInfo(this, this);
305 }
306+ new Unity2d::PanelPaletteManager(this);
307
308 setAttribute(Qt::WA_X11NetWmWindowTypeDock);
309 setAttribute(Qt::WA_Hover);

Subscribers

People subscribed via source and target branches