Merge lp:~agateau/unity-2d/use-gtk-rendering into lp:unity-2d

Proposed by Aurélien Gâteau
Status: Superseded
Proposed branch: lp:~agateau/unity-2d/use-gtk-rendering
Merge into: lp:unity-2d
Prerequisite: lp:~agateau/unity-2d/unity-core
Diff against target: 1345 lines (+523/-434)
16 files modified
CMakeLists.txt (+1/-0)
libunity-2d-private/src/CMakeLists.txt (+4/-0)
libunity-2d-private/src/unity2dapplication.cpp (+49/-1)
libunity-2d-private/src/unity2dapplication.h (+3/-0)
panel/applets/CMakeLists.txt (+4/-0)
panel/applets/appname/appnameapplet.cpp (+2/-47)
panel/applets/appname/croppedlabel.cpp (+140/-0)
panel/applets/appname/croppedlabel.h (+45/-0)
panel/applets/common/cairoutils.cpp (+42/-0)
panel/applets/common/cairoutils.h (+47/-0)
panel/applets/common/fakecairo.h (+0/-125)
panel/applets/common/indicatorentrywidget.cpp (+135/-157)
panel/applets/common/indicatorentrywidget.h (+10/-1)
panel/applets/common/panelstyle.cpp (+30/-91)
panel/applets/common/panelstyle.h (+7/-10)
panel/applets/homebutton/homebutton.cpp (+4/-2)
To merge this branch: bzr merge lp:~agateau/unity-2d/use-gtk-rendering
Reviewer Review Type Date Requested Status
Florian Boucault Pending
Review via email: mp+69489@code.launchpad.net

This proposal supersedes a proposal from 2011-07-25.

This proposal has been superseded by a proposal from 2011-07-27.

Description of the change

This branch uses GTK3 primitives to draw labels and active menubar item background instead of the Cairo code which was copied from unity-3d.

To post a comment you must log in.
Revision history for this message
Bob The Builder (bobthebuilder-deactivatedaccount) wrote :

No proposals found for merge of lp:~agateau/unity-2d/unity-core into lp:unity-2d/4.0.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2011-07-27 11:59:05 +0000
3+++ CMakeLists.txt 2011-07-27 15:51:26 +0000
4@@ -29,6 +29,7 @@
5 pkg_check_modules(GTK REQUIRED gtk+-3.0)
6 pkg_check_modules(GIO REQUIRED gio-2.0)
7 pkg_check_modules(WNCK REQUIRED libwnck-3.0)
8+pkg_check_modules(QTGCONF REQUIRED libqtgconf)
9
10
11 # GSettings schemas
12
13=== modified file 'libunity-2d-private/src/CMakeLists.txt'
14--- libunity-2d-private/src/CMakeLists.txt 2011-07-27 11:59:05 +0000
15+++ libunity-2d-private/src/CMakeLists.txt 2011-07-27 15:51:26 +0000
16@@ -31,6 +31,8 @@
17 ${CMAKE_CURRENT_BINARY_DIR}
18 ${CMAKE_CURRENT_SOURCE_DIR}
19 ${GLIB_INCLUDE_DIRS}
20+ ${GTK_INCLUDE_DIRS}
21+ ${PANGO_INCLUDE_DIRS}
22 ${WNCK_INCLUDE_DIRS}
23 )
24
25@@ -48,6 +50,8 @@
26 ${QT_QTOPENGL_LIBRARIES}
27 ${X11_LIBRARIES}
28 ${GLIB_LDFLAGS}
29+ ${GTK_LDFLAGS}
30+ ${PANGO_LDFLAGS}
31 ${WNCK_LDFLAGS}
32 )
33
34
35=== modified file 'libunity-2d-private/src/unity2dapplication.cpp'
36--- libunity-2d-private/src/unity2dapplication.cpp 2011-07-27 11:59:05 +0000
37+++ libunity-2d-private/src/unity2dapplication.cpp 2011-07-27 15:51:26 +0000
38@@ -25,14 +25,59 @@
39
40 // libunity-2d
41 #include <debug_p.h>
42+#include <gconnector.h>
43+#include <gscopedpointer.h>
44 #include <unity2ddebug.h>
45
46 // Qt
47+#include <QFont>
48 #include <QWindowsStyle>
49
50 // GTK
51 #include <gtk/gtk.h>
52-
53+#include <pango/pango.h>
54+
55+///////////////////////////////
56+class PlatformFontTracker
57+{
58+public:
59+ PlatformFontTracker()
60+ {
61+ m_gConnector.connect(gtk_settings_get_default(), "notify::gtk-font-name",
62+ G_CALLBACK(PlatformFontTracker::onFontChanged), this);
63+
64+ updateFont();
65+ }
66+
67+private:
68+ void updateFont()
69+ {
70+ gchar* fontName = 0;
71+ g_object_get(gtk_settings_get_default(), "gtk-font-name", &fontName, NULL);
72+ GScopedPointer<PangoFontDescription, pango_font_description_free> fontDescription(
73+ pango_font_description_from_string(fontName)
74+ );
75+ g_free(fontName);
76+
77+ int size = pango_font_description_get_size(fontDescription.data());
78+
79+ QFont font = QFont(
80+ pango_font_description_get_family(fontDescription.data()),
81+ size / PANGO_SCALE
82+ );
83+
84+ QApplication::setFont(font);
85+ }
86+
87+ static void onFontChanged(GObject*, GParamSpec*, PlatformFontTracker* obj)
88+ {
89+ obj->updateFont();
90+ }
91+
92+ GConnector m_gConnector;
93+};
94+
95+///////////////////////////////
96 AbstractX11EventFilter::~AbstractX11EventFilter()
97 {
98 Unity2dApplication* application = Unity2dApplication::instance();
99@@ -41,6 +86,7 @@
100 }
101 }
102
103+///////////////////////////////
104 static bool arrayContains(char** begin, char** end, const char* string)
105 {
106 for (char** ptr = begin; ptr != end; ++ptr) {
107@@ -83,6 +129,7 @@
108
109 Unity2dApplication::Unity2dApplication(int& argc, char** argv)
110 : QApplication(argc, argv)
111+, m_platformFontTracker(new PlatformFontTracker)
112 {
113 /* Allow developers to run Unity 2D uninstalled by telling dconf-qt
114 where to look for Unity 2D's schemas.
115@@ -96,6 +143,7 @@
116 Unity2dApplication::~Unity2dApplication()
117 {
118 qDeleteAll(m_x11EventFilters);
119+ delete m_platformFontTracker;
120 }
121
122 Unity2dApplication* Unity2dApplication::instance()
123
124=== modified file 'libunity-2d-private/src/unity2dapplication.h'
125--- libunity-2d-private/src/unity2dapplication.h 2011-07-18 14:36:34 +0000
126+++ libunity-2d-private/src/unity2dapplication.h 2011-07-27 15:51:26 +0000
127@@ -27,6 +27,8 @@
128
129 class Unity2dApplication;
130
131+class PlatformFontTracker;
132+
133 class AbstractX11EventFilter
134 {
135 public:
136@@ -65,6 +67,7 @@
137
138 private:
139 QList<AbstractX11EventFilter*> m_x11EventFilters;
140+ PlatformFontTracker* m_platformFontTracker;
141 };
142
143 #endif // UNITY2DAPPLICATION_H
144
145=== modified file 'panel/applets/CMakeLists.txt'
146--- panel/applets/CMakeLists.txt 2011-07-27 12:44:39 +0000
147+++ panel/applets/CMakeLists.txt 2011-07-27 15:51:26 +0000
148@@ -12,12 +12,14 @@
149 appindicator/appindicatorapplet.cpp
150 appindicator/sniitem.cpp
151 appname/appnameapplet.cpp
152+ appname/croppedlabel.cpp
153 appname/menubarwidget.cpp
154 appname/windowhelper.cpp
155 common/applet.cpp
156 common/indicatorentrywidget.cpp
157 common/indicatorsmanager.cpp
158 common/indicatorwidget.cpp
159+ common/cairoutils.cpp
160 common/panelstyle.cpp
161 homebutton/homebuttonapplet.cpp
162 homebutton/homebutton.cpp
163@@ -41,6 +43,7 @@
164 ${CMAKE_CURRENT_SOURCE_DIR}/indicator
165 ${CMAKE_CURRENT_SOURCE_DIR}/unitycore
166 ${QTBAMF_INCLUDE_DIRS}
167+ ${QTGCONF_INCLUDE_DIRS}
168 ${DBUSMENUQT_INCLUDE_DIRS}
169 ${GTK_INCLUDE_DIRS}
170 ${WNCK_INCLUDE_DIRS}
171@@ -58,6 +61,7 @@
172 ${QT_QTCORE_LIBRARIES}
173 ${DBUSMENUQT_LDFLAGS}
174 ${QTBAMF_LDFLAGS}
175+ ${QTGCONF_LDFLAGS}
176 ${GTK_LDFLAGS}
177 ${WNCK_LDFLAGS}
178 ${X11_LIBRARIES}
179
180=== modified file 'panel/applets/appname/appnameapplet.cpp'
181--- panel/applets/appname/appnameapplet.cpp 2011-07-27 11:59:05 +0000
182+++ panel/applets/appname/appnameapplet.cpp 2011-07-27 15:51:26 +0000
183@@ -23,6 +23,7 @@
184 #include "appnameapplet.h"
185
186 // Local
187+#include "croppedlabel.h"
188 #include "menubarwidget.h"
189 #include "windowhelper.h"
190
191@@ -49,9 +50,7 @@
192
193 static const int WINDOW_BUTTONS_RIGHT_MARGIN = 4;
194
195-static const int APPNAME_LABEL_LEFT_MARGIN = 12;
196-
197-static const int FADEOUT_WIDTH = 16;
198+static const int APPNAME_LABEL_LEFT_MARGIN = 6;
199
200 namespace Unity2d
201 {
202@@ -106,50 +105,6 @@
203 }
204 };
205
206-/**
207- * This label makes sure minimumSizeHint() is not set. This ensures the applet
208- * does not get wider if a window title is very long
209- */
210-class CroppedLabel : public QLabel
211-{
212-public:
213- CroppedLabel(QWidget* parent = 0)
214- : QLabel(parent)
215- {}
216-
217- QSize minimumSizeHint() const
218- {
219- return QWidget::minimumSizeHint();
220- }
221-
222-protected:
223- void paintEvent(QPaintEvent* event)
224- {
225- QImage image(width(), height(), QImage::Format_ARGB32_Premultiplied);
226- {
227- QPainter painter(&image);
228- painter.initFrom(this);
229- painter.setCompositionMode(QPainter::CompositionMode_Source);
230- painter.fillRect(rect(), Qt::transparent);
231-
232- painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
233- painter.drawText(contentsRect(), Qt::AlignLeft | Qt::AlignVCenter, text());
234-
235- if (QLabel::minimumSizeHint().width() > contentsRect().width()) {
236- // Text does not fit, fade the end
237- painter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
238- QRect gradientRect(width() - FADEOUT_WIDTH, 0, FADEOUT_WIDTH, height());
239- QLinearGradient gradient(gradientRect.topLeft(), gradientRect.topRight());
240- gradient.setColorAt(0, Qt::white);
241- gradient.setColorAt(1, Qt::transparent);
242- painter.fillRect(gradientRect, gradient);
243- }
244- }
245- QPainter painter(this);
246- painter.drawImage(0, 0, image);
247- }
248-};
249-
250 struct AppNameAppletPrivate
251 {
252 AppNameApplet* q;
253
254=== added file 'panel/applets/appname/croppedlabel.cpp'
255--- panel/applets/appname/croppedlabel.cpp 1970-01-01 00:00:00 +0000
256+++ panel/applets/appname/croppedlabel.cpp 2011-07-27 15:51:26 +0000
257@@ -0,0 +1,140 @@
258+/*
259+ * This file is part of unity-2d
260+ *
261+ * Copyright 2011 Canonical Ltd.
262+ *
263+ * Authors:
264+ * - Aurélien Gâteau <aurelien.gateau@canonical.com>
265+ *
266+ * This program is free software; you can redistribute it and/or modify
267+ * it under the terms of the GNU General Public License as published by
268+ * the Free Software Foundation; version 3.
269+ *
270+ * This program is distributed in the hope that it will be useful,
271+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
272+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
273+ * GNU General Public License for more details.
274+ *
275+ * You should have received a copy of the GNU General Public License
276+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
277+ */
278+// Self
279+#include "croppedlabel.h"
280+
281+// Local
282+#include <cairoutils.h>
283+#include <panelstyle.h>
284+
285+// unity-2d
286+#include <debug_p.h>
287+
288+// libqtgconf
289+#include <gconfitem-qml-wrapper.h>
290+
291+// Qt
292+#include <QImage>
293+#include <QPainter>
294+
295+// GTK
296+#include <gtk/gtk.h>
297+
298+static const int FADEOUT_WIDTH = 30;
299+
300+static const char* WINDOW_TITLE_FONT_KEY = "/apps/metacity/general/titlebar_font";
301+
302+CroppedLabel::CroppedLabel(QWidget* parent)
303+: QLabel(parent)
304+{
305+}
306+
307+QSize CroppedLabel::minimumSizeHint() const
308+{
309+ return QWidget::minimumSizeHint();
310+}
311+
312+static void paintFadeoutGradient(QImage* image)
313+{
314+ QPainter painter(image);
315+ painter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
316+ QRect gradientRect(image->width() - FADEOUT_WIDTH, 0, FADEOUT_WIDTH, image->height());
317+ QLinearGradient gradient(gradientRect.topLeft(), gradientRect.topRight());
318+ gradient.setColorAt(0, Qt::white);
319+ gradient.setColorAt(1, Qt::transparent);
320+ painter.fillRect(gradientRect, gradient);
321+}
322+
323+static QString getWindowTitleFontName()
324+{
325+ GConfItemQmlWrapper client;
326+ client.setKey(WINDOW_TITLE_FONT_KEY);
327+ return client.getValue().toString();
328+}
329+
330+void CroppedLabel::paintEvent(QPaintEvent* event)
331+{
332+ // Create an image filled with background brush (to avoid subpixel hinting
333+ // artefacts around text)
334+ QImage image(width(), height(), QImage::Format_ARGB32_Premultiplied);
335+ {
336+ QPainter painter(&image);
337+ painter.initFrom(this);
338+ painter.eraseRect(rect());
339+ }
340+
341+ // Create a pango layout
342+ GObjectScopedPointer<PangoContext> pangoContext(gdk_pango_context_get());
343+ GObjectScopedPointer<PangoLayout> layout(pango_layout_new(pangoContext.data()));
344+
345+ // Set font
346+ QByteArray fontName = getWindowTitleFontName().toUtf8();
347+ PangoFontDescription* desc = pango_font_description_from_string(fontName.data());
348+ pango_layout_set_font_description(layout.data(), desc);
349+ pango_font_description_free(desc);
350+
351+ // Set text
352+ QByteArray utf8Text = text().toUtf8();
353+ pango_layout_set_text (layout.data(), utf8Text.data(), -1);
354+
355+ // Get text size
356+ int textWidth = 0;
357+ int textHeight = 0;
358+ pango_layout_get_pixel_size(layout.data(), &textWidth, &textHeight);
359+
360+ // Draw text
361+ CairoUtils::SurfacePointer surface(CairoUtils::createSurfaceForQImage(&image));
362+ CairoUtils::Pointer cr(cairo_create(surface.data()));
363+
364+ PanelStyle* style = PanelStyle::instance();
365+ GtkStyleContext* style_context = style->styleContext();
366+
367+ gtk_style_context_save(style_context);
368+
369+ GtkWidgetPath* widget_path = gtk_widget_path_new();
370+ gtk_widget_path_append_type(widget_path, GTK_TYPE_MENU_BAR);
371+ gtk_widget_path_append_type(widget_path, GTK_TYPE_MENU_ITEM);
372+ gtk_widget_path_iter_set_name(widget_path, -1 , "UnityPanelWidget");
373+
374+ gtk_style_context_set_path(style_context, widget_path);
375+ gtk_style_context_add_class(style_context, GTK_STYLE_CLASS_MENUBAR);
376+ gtk_style_context_add_class(style_context, GTK_STYLE_CLASS_MENUITEM);
377+
378+ gtk_render_layout(style_context, cr.data(),
379+ contentsRect().left(),
380+ contentsRect().top() + (height() - textHeight) / 2,
381+ layout.data());
382+
383+ gtk_widget_path_free(widget_path);
384+
385+ gtk_style_context_restore(style_context);
386+
387+ // Fade if necessary
388+ if (textWidth > contentsRect().width()) {
389+ paintFadeoutGradient(&image);
390+ }
391+
392+ // Paint on our widget
393+ QPainter painter(this);
394+ painter.drawImage(0, 0, image);
395+}
396+
397+#include "croppedlabel.moc"
398
399=== added file 'panel/applets/appname/croppedlabel.h'
400--- panel/applets/appname/croppedlabel.h 1970-01-01 00:00:00 +0000
401+++ panel/applets/appname/croppedlabel.h 2011-07-27 15:51:26 +0000
402@@ -0,0 +1,45 @@
403+/*
404+ * This file is part of unity-2d
405+ *
406+ * Copyright 2011 Canonical Ltd.
407+ *
408+ * Authors:
409+ * - Aurélien Gâteau <aurelien.gateau@canonical.com>
410+ *
411+ * This program is free software; you can redistribute it and/or modify
412+ * it under the terms of the GNU General Public License as published by
413+ * the Free Software Foundation; version 3.
414+ *
415+ * This program is distributed in the hope that it will be useful,
416+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
417+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
418+ * GNU General Public License for more details.
419+ *
420+ * You should have received a copy of the GNU General Public License
421+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
422+ */
423+#ifndef CROPPEDLABEL_H
424+#define CROPPEDLABEL_H
425+
426+// Local
427+
428+// Qt
429+#include <QLabel>
430+
431+/**
432+ * This label makes sure minimumSizeHint() is not set. This ensures the applet
433+ * does not get wider if a window title is very long
434+ */
435+class CroppedLabel : public QLabel
436+{
437+ Q_OBJECT
438+public:
439+ CroppedLabel(QWidget* parent = 0);
440+
441+ QSize minimumSizeHint() const;
442+
443+protected:
444+ void paintEvent(QPaintEvent*);
445+};
446+
447+#endif /* CROPPEDLABEL_H */
448
449=== added file 'panel/applets/common/cairoutils.cpp'
450--- panel/applets/common/cairoutils.cpp 1970-01-01 00:00:00 +0000
451+++ panel/applets/common/cairoutils.cpp 2011-07-27 15:51:26 +0000
452@@ -0,0 +1,42 @@
453+/*
454+ * This file is part of unity-2d
455+ *
456+ * Copyright 2011 Canonical Ltd.
457+ *
458+ * Authors:
459+ * - Aurélien Gâteau <aurelien.gateau@canonical.com>
460+ *
461+ * This program is free software; you can redistribute it and/or modify
462+ * it under the terms of the GNU General Public License as published by
463+ * the Free Software Foundation; version 3.
464+ *
465+ * This program is distributed in the hope that it will be useful,
466+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
467+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
468+ * GNU General Public License for more details.
469+ *
470+ * You should have received a copy of the GNU General Public License
471+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
472+ */
473+// Self
474+#include "cairoutils.h"
475+
476+// Local
477+
478+// Qt
479+#include <QImage>
480+
481+namespace CairoUtils {
482+
483+cairo_surface_t* createSurfaceForQImage(QImage* image)
484+{
485+ return cairo_image_surface_create_for_data(
486+ image->bits(),
487+ CAIRO_FORMAT_ARGB32,
488+ image->width(),
489+ image->height(),
490+ image->bytesPerLine()
491+ );
492+}
493+
494+} // namespace
495
496=== added file 'panel/applets/common/cairoutils.h'
497--- panel/applets/common/cairoutils.h 1970-01-01 00:00:00 +0000
498+++ panel/applets/common/cairoutils.h 2011-07-27 15:51:26 +0000
499@@ -0,0 +1,47 @@
500+/*
501+ * This file is part of unity-2d
502+ *
503+ * Copyright 2011 Canonical Ltd.
504+ *
505+ * Authors:
506+ * - Aurélien Gâteau <aurelien.gateau@canonical.com>
507+ *
508+ * This program is free software; you can redistribute it and/or modify
509+ * it under the terms of the GNU General Public License as published by
510+ * the Free Software Foundation; version 3.
511+ *
512+ * This program is distributed in the hope that it will be useful,
513+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
514+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
515+ * GNU General Public License for more details.
516+ *
517+ * You should have received a copy of the GNU General Public License
518+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
519+ */
520+#ifndef CAIROUTILS_H
521+#define CAIROUTILS_H
522+
523+// Local
524+#include <gscopedpointer.h>
525+
526+// Qt
527+
528+// Cairo
529+#include <cairo.h>
530+
531+class QImage;
532+
533+namespace CairoUtils {
534+
535+typedef GScopedPointer<cairo_surface_t, cairo_surface_destroy> SurfacePointer;
536+typedef GScopedPointer<cairo_t, cairo_destroy> Pointer;
537+
538+/**
539+ * Creates a Cairo surface for a QImage.
540+ * QImage format must be Format_ARGB32_Premultiplied.
541+ */
542+cairo_surface_t* createSurfaceForQImage(QImage*);
543+
544+} // namespace
545+
546+#endif /* CAIROUTILS_H */
547
548=== removed file 'panel/applets/common/fakecairo.h'
549--- panel/applets/common/fakecairo.h 2011-07-12 15:49:40 +0000
550+++ panel/applets/common/fakecairo.h 1970-01-01 00:00:00 +0000
551@@ -1,125 +0,0 @@
552-/*
553- * This file is part of unity-2d
554- *
555- * Copyright 2011 Canonical Ltd.
556- *
557- * Authors:
558- * - Aurélien Gâteau <aurelien.gateau@canonical.com>
559- *
560- * This program is free software; you can redistribute it and/or modify
561- * it under the terms of the GNU General Public License as published by
562- * the Free Software Foundation; version 3.
563- *
564- * This program is distributed in the hope that it will be useful,
565- * but WITHOUT ANY WARRANTY; without even the implied warranty of
566- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
567- * GNU General Public License for more details.
568- *
569- * You should have received a copy of the GNU General Public License
570- * along with this program. If not, see <http://www.gnu.org/licenses/>.
571- */
572-#ifndef FAKECAIRO_H
573-#define FAKECAIRO_H
574-
575-// NuxCore
576-#include <NuxCore/Color.h>
577-
578-// Qt
579-#include <QPainter>
580-#include <QPainterPath>
581-
582-/*
583- * This module attempts to fake Cairo calls using QPainter, making it easier to
584- * port Cairo paint operations to Qt
585- */
586-struct fcairo_t
587-{
588- fcairo_t(QPainter* _painter)
589- : painter(_painter)
590- {
591- painter->save();
592- }
593-
594- ~fcairo_t()
595- {
596- painter->restore();
597- }
598-
599- QPainter* painter;
600- QPainterPath path;
601-};
602-
603-inline void fcairo_arc(fcairo_t& cr, qreal xc, qreal yc, qreal radius, qreal angle1, qreal angle2)
604-{
605- QRectF rect(xc - radius, yc - radius, radius * 2, radius * 2);
606-
607- while (angle2 < angle1) {
608- angle2 += 2 * M_PI;
609- }
610-
611- qreal start = (2. - angle1 / M_PI) * 180;
612- qreal stop = (2. - angle2 / M_PI) * 180;
613- cr.path.arcTo(rect, start, stop - start);
614-}
615-
616-inline void fcairo_move_to(fcairo_t& cr, qreal x, qreal y)
617-{
618- cr.path.moveTo(x, y);
619-}
620-
621-inline void fcairo_line_to(fcairo_t& cr, qreal x, qreal y)
622-{
623- cr.path.lineTo(x, y);
624-}
625-
626-inline void fcairo_fill_preserve(fcairo_t& cr)
627-{
628- cr.painter->fillPath(cr.path, cr.painter->brush());
629-}
630-
631-inline void fcairo_stroke(fcairo_t& cr)
632-{
633- QPen pen(cr.painter->brush().color(), 1);
634- cr.painter->strokePath(cr.path, pen);
635- cr.path = QPainterPath();
636-}
637-
638-typedef QGradient fcairo_pattern_t;
639-
640-inline fcairo_pattern_t* fcairo_pattern_create_linear (qreal x1, qreal y1, qreal x2, qreal y2)
641-{
642- return new QLinearGradient(x1, y1, x2, y2);
643-}
644-
645-inline void fcairo_pattern_destroy(fcairo_pattern_t* pattern)
646-{
647- delete pattern;
648-}
649-
650-inline void fcairo_pattern_add_color_stop_rgba(fcairo_pattern_t* pattern, qreal offset, qreal r, qreal g, qreal b, qreal a)
651-{
652- pattern->setColorAt(offset, QColor::fromRgbF(r, g, b, a));
653-}
654-
655-inline void fcairo_set_source(fcairo_t& cr, fcairo_pattern_t* pattern)
656-{
657- cr.painter->setPen(Qt::NoPen);
658- cr.painter->setBrush(*pattern);
659-}
660-
661-inline void fcairo_set_source_rgb(fcairo_t& cr, qreal r, qreal g, qreal b)
662-{
663- cr.painter->setBrush(QColor::fromRgbF(r, g, b));
664-}
665-
666-inline nux::color::Color nuxColorFromQColor(const QColor& qColor)
667-{
668- nux::color::Color color;
669- color.red = qColor.redF();
670- color.green = qColor.greenF();
671- color.blue = qColor.blueF();
672- color.alpha = qColor.alphaF();
673- return color;
674-}
675-
676-#endif /* FAKECAIRO_H */
677
678=== modified file 'panel/applets/common/indicatorentrywidget.cpp'
679--- panel/applets/common/indicatorentrywidget.cpp 2011-07-12 15:50:20 +0000
680+++ panel/applets/common/indicatorentrywidget.cpp 2011-07-27 15:51:26 +0000
681@@ -22,8 +22,9 @@
682 #include "indicatorentrywidget.h"
683
684 // Local
685+#include <cairoutils.h>
686 #include <debug_p.h>
687-#include <fakecairo.h>
688+#include <gscopedpointer.h>
689 #include <panelstyle.h>
690
691 // Qt
692@@ -42,56 +43,25 @@
693
694 using namespace unity::indicator;
695
696-// Copied from libdbusmenu-qt
697-static QString swapMnemonicChar(const QString &in, const char src, const char dst)
698-{
699- QString out;
700- bool mnemonicFound = false;
701-
702- for (int pos = 0; pos < in.length(); ) {
703- QChar ch = in[pos];
704- if (ch == src) {
705- if (pos == in.length() - 1) {
706- // 'src' at the end of string, skip it
707- ++pos;
708- } else {
709- if (in[pos + 1] == src) {
710- // A real 'src'
711- out += src;
712- pos += 2;
713- } else if (!mnemonicFound) {
714- // We found the mnemonic
715- mnemonicFound = true;
716- out += dst;
717- ++pos;
718- } else {
719- // We already have a mnemonic, just skip the char
720- ++pos;
721- }
722- }
723- } else if (ch == dst) {
724- // Escape 'dst'
725- out += dst;
726- out += dst;
727- ++pos;
728- } else {
729- out += ch;
730- ++pos;
731- }
732- }
733-
734- return out;
735-}
736-
737 IndicatorEntryWidget::IndicatorEntryWidget(const Entry::Ptr& entry)
738 : m_entry(entry)
739 , m_padding(PADDING)
740 , m_hasIcon(false)
741 , m_hasLabel(false)
742+, m_gtkWidgetPath(gtk_widget_path_new())
743 {
744+ gtk_widget_path_append_type(m_gtkWidgetPath, GTK_TYPE_WINDOW);
745+ gtk_widget_path_iter_set_name(m_gtkWidgetPath, -1 , "UnityPanelWidget");
746+ gtk_widget_path_append_type(m_gtkWidgetPath, GTK_TYPE_MENU_BAR);
747+ gtk_widget_path_append_type(m_gtkWidgetPath, GTK_TYPE_MENU_ITEM);
748+
749 setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum);
750 m_entry->updated.connect(sigc::mem_fun(this, &IndicatorEntryWidget::updatePix));
751- updatePix();
752+}
753+
754+IndicatorEntryWidget::~IndicatorEntryWidget()
755+{
756+ gtk_widget_path_free(m_gtkWidgetPath);
757 }
758
759 QSize IndicatorEntryWidget::minimumSizeHint() const
760@@ -104,105 +74,47 @@
761 return m_pix.size();
762 }
763
764+void IndicatorEntryWidget::resizeEvent(QResizeEvent* event)
765+{
766+ QWidget::resizeEvent(event);
767+ updatePix();
768+}
769+
770 void IndicatorEntryWidget::paintEvent(QPaintEvent*)
771 {
772 if (!m_pix.isNull()) {
773 QPainter painter(this);
774- if (m_entry->active()) {
775- paintActiveBackground(&painter);
776- }
777 painter.drawPixmap(0, 0, m_pix);
778 }
779 }
780
781
782-void IndicatorEntryWidget::paintActiveBackground(QPainter* painter)
783+void IndicatorEntryWidget::paintActiveBackground(QImage* image)
784 {
785- // This code should be kept in sync with the draw_menu_bg() function from
786+ // This code should be kept in sync with corresponding unityshell code from
787 // plugins/unityshell/src/PanelIndicatorObjectEntryView.cpp
788- int radius = 4;
789- double x = 0;
790- double y = 0;
791- double xos = 0.5;
792- double yos = 0.5;
793- /* FIXME */
794- double mpi = 3.14159265358979323846;
795-
796- PanelStyle* style = PanelStyle::instance();
797- nux::color::Color bgtop = nuxColorFromQColor(style->backgroundTopColor());
798- nux::color::Color bgbot = nuxColorFromQColor(style->backgroundBottomColor());
799- nux::color::Color line = nuxColorFromQColor(style->lineColor());
800-
801- painter->setRenderHint(QPainter::Antialiasing);
802-
803- fcairo_t cr(painter);
804-
805- fcairo_move_to (cr, x+xos+radius, y+yos);
806- fcairo_arc (cr, x+xos+width()-xos*2-radius, y+yos+radius, radius, mpi*1.5, mpi*2);
807- fcairo_line_to (cr, x+xos+width()-xos*2, y+yos+height()-yos*2+2);
808- fcairo_line_to (cr, x+xos, y+yos+height()-yos*2+2);
809- fcairo_arc (cr, x+xos+radius, y+yos+radius, radius, mpi, mpi*1.5);
810-
811- fcairo_pattern_t * pat = fcairo_pattern_create_linear (x+xos, y, x+xos, y+height()-yos*2+2);
812- fcairo_pattern_add_color_stop_rgba (pat, 0.0,
813- bgtop.red,
814- bgtop.green,
815- bgtop.blue,
816- 1.0f - bgbot.red);
817- fcairo_pattern_add_color_stop_rgba (pat, 1.0,
818- bgbot.red,
819- bgbot.green,
820- bgbot.blue,
821- 1.0f - bgtop.red);
822- fcairo_set_source (cr, pat);
823- fcairo_fill_preserve (cr);
824- fcairo_pattern_destroy (pat);
825-
826- /*
827- pat = fcairo_pattern_create_linear (x+xos, y, x+xos, y+height()-yos*2+2);
828- fcairo_pattern_add_color_stop_rgba (pat, 0.0,
829- line.red,
830- line.green,
831- line.blue,
832- 1.0f);
833- fcairo_pattern_add_color_stop_rgba (pat, 1.0,
834- line.red,
835- line.green,
836- line.blue,
837- 1.0f);
838- fcairo_set_source (cr, pat);
839- */
840- fcairo_set_source_rgb (cr, line.red, line.green, line.blue);
841- fcairo_stroke (cr);
842- //fcairo_pattern_destroy (pat);
843-
844- xos++;
845- yos++;
846-
847- /* enlarging the area to not draw the lightborder at bottom, ugly trick :P */
848- fcairo_move_to (cr, x+radius+xos, y+yos);
849- fcairo_arc (cr, x+xos+width()-xos*2-radius, y+yos+radius, radius, mpi*1.5, mpi*2);
850- fcairo_line_to (cr, x+xos+width()-xos*2, y+yos+height()-yos*2+3);
851- fcairo_line_to (cr, x+xos, y+yos+height()-yos*2+3);
852- fcairo_arc (cr, x+xos+radius, y+yos+radius, radius, mpi, mpi*1.5);
853-
854- /*
855- pat = fcairo_pattern_create_linear (x+xos, y, x+xos, y+height()-yos*2+3);
856- fcairo_pattern_add_color_stop_rgba (pat, 0.0,
857- bgbot.red,
858- bgbot.green,
859- bgbot.blue,
860- 1.0f);
861- fcairo_pattern_add_color_stop_rgba (pat, 1.0,
862- bgbot.red,
863- bgbot.green,
864- bgbot.blue,
865- 1.0f);
866- fcairo_set_source (cr, pat);
867- */
868- fcairo_set_source_rgb (cr, bgbot.red, bgbot.green, bgbot.blue);
869- fcairo_stroke (cr);
870- //fcairo_pattern_destroy (pat);
871+
872+ // Get a surface and a context
873+ CairoUtils::SurfacePointer surface(CairoUtils::createSurfaceForQImage(image));
874+ CairoUtils::Pointer cr(cairo_create(surface.data()));
875+
876+ // Init style
877+ GtkStyleContext* styleContext = PanelStyle::instance()->styleContext();
878+
879+ gtk_style_context_save(styleContext);
880+
881+ gtk_style_context_set_path(styleContext, m_gtkWidgetPath);
882+ gtk_style_context_add_class(styleContext, GTK_STYLE_CLASS_MENUBAR);
883+ gtk_style_context_add_class(styleContext, GTK_STYLE_CLASS_MENUITEM);
884+ gtk_style_context_set_state(styleContext, GTK_STATE_FLAG_PRELIGHT);
885+
886+ // Draw
887+ // FIXME(Cimi) probably some padding is needed here.
888+ gtk_render_background(styleContext, cr.data(), 0, 0, width(), height());
889+ gtk_render_frame(styleContext, cr.data(), 0, 0, width(), height());
890+
891+ // Clean up
892+ gtk_style_context_restore(styleContext);
893 }
894
895 void IndicatorEntryWidget::updatePix()
896@@ -213,6 +125,8 @@
897 int iconX = m_padding;
898 int labelX = 0;
899
900+ GObjectScopedPointer<PangoLayout> pangoLayout;
901+
902 // Compute width, labelX and update m_has{Icon,Label}
903 QPixmap iconPix;
904 if (m_entry->image_visible()) {
905@@ -225,17 +139,18 @@
906 width += iconPix.width();
907 }
908
909- QString label = QString::fromUtf8(m_entry->label().c_str());
910- label = swapMnemonicChar(label, '_', '&');
911- m_hasLabel = !label.isEmpty() && m_entry->label_visible();
912+ m_hasLabel = !m_entry->label().empty() && m_entry->label_visible();
913 if (m_hasLabel) {
914 if (m_hasIcon) {
915 width += SPACING;
916 }
917 labelX = width;
918- QString visibleLabel = label;
919- visibleLabel.remove('&');
920- width += fontMetrics().width(visibleLabel);
921+ pangoLayout.reset(createPangoLayout());
922+ int labelWidth;
923+ int labelHeight;
924+ pango_layout_get_pixel_size(pangoLayout.data(), &labelWidth, &labelHeight);
925+
926+ width += labelWidth;
927 }
928
929 width += m_padding;
930@@ -245,38 +160,27 @@
931 if (!m_hasIcon && !m_hasLabel) {
932 m_pix = QPixmap();
933 } else {
934- m_pix = QPixmap(width, 24);
935- m_pix.fill(Qt::transparent);
936- QPainter painter(&m_pix);
937+ QImage img(width, height(), QImage::Format_ARGB32_Premultiplied);
938+ QPainter painter(&img);
939 painter.initFrom(this);
940+ painter.eraseRect(img.rect());
941+ if (m_entry->active()) {
942+ paintActiveBackground(&img);
943+ }
944 if (m_hasIcon) {
945 bool disabled = !m_entry->image_sensitive();
946 if (disabled) {
947 painter.setOpacity(0.5);
948 }
949- painter.drawPixmap(iconX, 0, iconPix);
950+ painter.drawPixmap(iconX, (height() - iconPix.height()) / 2, iconPix);
951 if (disabled) {
952 painter.setOpacity(1);
953 }
954 }
955 if (m_hasLabel) {
956- PanelStyle* style = PanelStyle::instance();
957-
958- int flags = Qt::AlignLeft | Qt::AlignVCenter;
959- flags |= m_entry->show_now() ? Qt::TextShowMnemonic : Qt::TextHideMnemonic;
960-
961- // Shadow
962- QColor color = style->textShadowColor();
963- color.setAlphaF(1. - color.redF());
964- painter.setPen(color);
965- painter.drawText(labelX, 1, width - labelX, m_pix.height(), flags, label);
966-
967- // Text
968- color = style->textColor();
969- color.setAlphaF(m_entry->label_sensitive() ? 1. : .5);
970- painter.setPen(color);
971- painter.drawText(labelX, 0, width - labelX, m_pix.height(), flags, label);
972+ paintLabel(&img, pangoLayout.data(), labelX);
973 }
974+ m_pix = QPixmap::fromImage(img);
975 }
976
977 // Notify others we changed, but only trigger a layout update if necessary
978@@ -294,6 +198,80 @@
979 }
980 }
981
982+PangoLayout* IndicatorEntryWidget::createPangoLayout()
983+{
984+ // Parse
985+ PangoAttrList* attrs = NULL;
986+ if (m_entry->show_now()) {
987+ if (!pango_parse_markup(m_entry->label().c_str(),
988+ -1,
989+ '_',
990+ &attrs,
991+ NULL,
992+ NULL,
993+ NULL))
994+ {
995+ UQ_WARNING << "pango_parse_markup failed";
996+ }
997+ }
998+
999+ // Create layout
1000+ GObjectScopedPointer<PangoContext> pangoContext(gdk_pango_context_get());
1001+ PangoLayout* layout = pango_layout_new(pangoContext.data());
1002+
1003+ if (attrs) {
1004+ pango_layout_set_attributes(layout, attrs);
1005+ pango_attr_list_unref(attrs);
1006+ }
1007+
1008+ // Set font
1009+ char* font_description = NULL;
1010+ GtkSettings *settings = gtk_settings_get_default();
1011+ g_object_get(settings,
1012+ "gtk-font-name", &font_description,
1013+ NULL);
1014+ PangoFontDescription* desc = pango_font_description_from_string(font_description);
1015+ pango_font_description_set_weight(desc, PANGO_WEIGHT_NORMAL);
1016+ pango_layout_set_font_description(layout, desc);
1017+ pango_font_description_free(desc);
1018+ g_free(font_description);
1019+
1020+ // Set text
1021+ QString label = QString::fromUtf8(m_entry->label().c_str());
1022+ label.replace('_', QString());
1023+ QByteArray utf8Label = label.toUtf8();
1024+ pango_layout_set_text(layout, utf8Label.data(), -1);
1025+
1026+ return layout;
1027+}
1028+
1029+void IndicatorEntryWidget::paintLabel(QImage* image, PangoLayout* layout, int labelX)
1030+{
1031+ // This code should be kept in sync with corresponding unityshell code from
1032+ // plugins/unityshell/src/PanelIndicatorObjectEntryView.cpp
1033+ int labelWidth, labelHeight;
1034+ pango_layout_get_pixel_size(layout, &labelWidth, &labelHeight);
1035+ CairoUtils::SurfacePointer surface(CairoUtils::createSurfaceForQImage(image));
1036+ CairoUtils::Pointer cr(cairo_create(surface.data()));
1037+ pango_cairo_update_layout(cr.data(), layout);
1038+
1039+ PanelStyle* style = PanelStyle::instance();
1040+ GtkStyleContext* styleContext = style->styleContext();
1041+
1042+ gtk_style_context_save(styleContext);
1043+
1044+ gtk_style_context_set_path(styleContext, m_gtkWidgetPath);
1045+ gtk_style_context_add_class(styleContext, GTK_STYLE_CLASS_MENUBAR);
1046+ gtk_style_context_add_class(styleContext, GTK_STYLE_CLASS_MENUITEM);
1047+
1048+ if (m_entry->active()) {
1049+ gtk_style_context_set_state(styleContext, GTK_STATE_FLAG_PRELIGHT);
1050+ }
1051+
1052+ gtk_render_layout(styleContext, cr.data(), labelX, (image->height() - labelHeight) / 2, layout);
1053+ gtk_style_context_restore(styleContext);
1054+}
1055+
1056 QPixmap IndicatorEntryWidget::decodeIcon()
1057 {
1058 QPixmap pix;
1059
1060=== modified file 'panel/applets/common/indicatorentrywidget.h'
1061--- panel/applets/common/indicatorentrywidget.h 2011-07-26 10:11:23 +0000
1062+++ panel/applets/common/indicatorentrywidget.h 2011-07-27 15:51:26 +0000
1063@@ -29,6 +29,9 @@
1064 // Qt
1065 #include <QWidget>
1066
1067+struct _GtkWidgetPath;
1068+struct _PangoLayout;
1069+
1070 class QPainter;
1071
1072 class IndicatorEntryWidget : public QWidget, public sigc::trackable
1073@@ -36,6 +39,7 @@
1074 Q_OBJECT
1075 public:
1076 IndicatorEntryWidget(const unity::indicator::Entry::Ptr& entry);
1077+ ~IndicatorEntryWidget();
1078
1079 QSize minimumSizeHint() const;
1080 QSize sizeHint() const;
1081@@ -61,6 +65,7 @@
1082 void isEmptyChanged();
1083
1084 protected:
1085+ void resizeEvent(QResizeEvent*);
1086 void paintEvent(QPaintEvent*);
1087 void mousePressEvent(QMouseEvent*);
1088 void mouseReleaseEvent(QMouseEvent*);
1089@@ -73,9 +78,13 @@
1090 int m_padding;
1091 bool m_hasIcon;
1092 bool m_hasLabel;
1093+ struct _GtkWidgetPath* m_gtkWidgetPath;
1094 void updatePix();
1095 QPixmap decodeIcon();
1096- void paintActiveBackground(QPainter*);
1097+ void paintActiveBackground(QImage*);
1098+
1099+ struct _PangoLayout* createPangoLayout();
1100+ void paintLabel(QImage*, struct _PangoLayout*, int labelX);
1101 };
1102
1103 #endif /* INDICATORENTRYWIDGET_H */
1104
1105=== modified file 'panel/applets/common/panelstyle.cpp'
1106--- panel/applets/common/panelstyle.cpp 2011-07-19 09:22:55 +0000
1107+++ panel/applets/common/panelstyle.cpp 2011-07-27 15:51:26 +0000
1108@@ -22,92 +22,54 @@
1109 #include "panelstyle.h"
1110
1111 // libunity-2d
1112+#include <cairoutils.h>
1113 #include <debug_p.h>
1114 #include <gconnector.h>
1115 #include <gscopedpointer.h>
1116
1117 // Qt
1118 #include <QApplication>
1119-#include <QColor>
1120-#include <QFont>
1121 #include <QPalette>
1122
1123 // GTK
1124 #include <gtk/gtk.h>
1125-#include <pango/pango.h>
1126-
1127-typedef void (*ColorGetter)(GtkStyleContext*, GtkStateFlags, GdkRGBA*);
1128-
1129-inline QColor colorFromContext(ColorGetter getter, GtkStyleContext* context, GtkStateFlags state)
1130-{
1131- GdkRGBA color;
1132- getter(context, state, &color);
1133- return QColor::fromRgbF(color.red, color.green, color.blue, color.alpha);
1134-}
1135
1136 class PanelStylePrivate
1137 {
1138 public:
1139 PanelStyle* q;
1140- GtkWidget* m_offScreenWindow;
1141+ GObjectScopedPointer<GtkStyleContext> m_styleContext;
1142 GConnector m_gConnector;
1143
1144- QColor m_textColor;
1145- QColor m_backgroundTopColor;
1146- QColor m_backgroundBottomColor;
1147- QColor m_textShadowColor;
1148- QColor m_lineColor;
1149- QFont m_font;
1150-
1151 static void onThemeChanged(GObject*, GParamSpec*, gpointer data)
1152 {
1153 PanelStylePrivate* priv = reinterpret_cast<PanelStylePrivate*>(data);
1154 priv->updatePalette();
1155 }
1156
1157- static void onFontChanged(GObject*, GParamSpec*, gpointer data)
1158- {
1159- PanelStylePrivate* priv = reinterpret_cast<PanelStylePrivate*>(data);
1160- priv->updateFont();
1161- }
1162-
1163 void updatePalette()
1164 {
1165- GtkStyleContext* context = gtk_widget_get_style_context(m_offScreenWindow);
1166- UQ_RETURN_IF_FAIL(context);
1167+ GtkStyleContext* context = m_styleContext.data();
1168+ gtk_style_context_invalidate(context);
1169
1170- m_textColor = colorFromContext(gtk_style_context_get_color, context, GTK_STATE_FLAG_NORMAL);
1171- m_textShadowColor = colorFromContext(gtk_style_context_get_color, context, GTK_STATE_FLAG_SELECTED);
1172- m_lineColor = colorFromContext(gtk_style_context_get_background_color, context, GTK_STATE_FLAG_NORMAL).darker(130);
1173- m_backgroundTopColor = colorFromContext(gtk_style_context_get_background_color, context, GTK_STATE_FLAG_ACTIVE);
1174- m_backgroundBottomColor = colorFromContext(gtk_style_context_get_background_color, context, GTK_STATE_FLAG_NORMAL);
1175+ // Without this line, it seems the GtkStyleContext is not correctly
1176+ // initialized and we get some uninitialized pixels in the background
1177+ // brush.
1178+ gtk_style_context_get(context, GTK_STATE_FLAG_NORMAL, NULL);
1179
1180 QPalette pal;
1181- pal.setColor(QPalette::Window, m_backgroundTopColor);
1182- pal.setColor(QPalette::Button, m_backgroundTopColor);
1183- pal.setColor(QPalette::Text, m_textColor);
1184- pal.setColor(QPalette::WindowText, m_textColor);
1185- pal.setColor(QPalette::ButtonText, m_textColor);
1186+ pal.setBrush(QPalette::Window, generateBackgroundBrush());
1187 QApplication::setPalette(pal);
1188 }
1189
1190- void updateFont()
1191+ QBrush generateBackgroundBrush()
1192 {
1193- gchar* fontName = 0;
1194- g_object_get(gtk_settings_get_default(), "gtk-font-name", &fontName, NULL);
1195- GScopedPointer<PangoFontDescription, pango_font_description_free> fontDescription(
1196- pango_font_description_from_string(fontName)
1197- );
1198- g_free(fontName);
1199-
1200- int size = pango_font_description_get_size(fontDescription.data());
1201-
1202- m_font = QFont(
1203- pango_font_description_get_family(fontDescription.data()),
1204- size / PANGO_SCALE
1205- );
1206-
1207- QApplication::setFont(m_font);
1208+ QImage image(100, 24, QImage::Format_ARGB32_Premultiplied); // FIXME: Hardcoded
1209+ image.fill(Qt::transparent);
1210+ CairoUtils::SurfacePointer surface(CairoUtils::createSurfaceForQImage(&image));
1211+ CairoUtils::Pointer cr(cairo_create(surface.data()));
1212+ gtk_render_background(m_styleContext.data(), cr.data(), 0, 0, image.width(), image.height());
1213+ return QBrush(image);
1214 }
1215 };
1216
1217@@ -115,24 +77,26 @@
1218 : d(new PanelStylePrivate)
1219 {
1220 d->q = this;
1221- d->m_offScreenWindow = gtk_offscreen_window_new();
1222- gtk_widget_set_name(d->m_offScreenWindow, "UnityPanelWidget");
1223- gtk_widget_set_size_request(d->m_offScreenWindow, 100, 24);
1224- gtk_style_context_add_class(gtk_widget_get_style_context(d->m_offScreenWindow), "menubar");
1225- gtk_widget_show_all(d->m_offScreenWindow);
1226+ d->m_styleContext.reset(gtk_style_context_new());
1227+
1228+ GtkWidgetPath* widgetPath = gtk_widget_path_new ();
1229+ gtk_widget_path_append_type(widgetPath, GTK_TYPE_WINDOW);
1230+ gtk_widget_path_iter_set_name(widgetPath, -1 , "UnityPanelWidget");
1231+
1232+ gtk_style_context_set_path(d->m_styleContext.data(), widgetPath);
1233+ gtk_style_context_add_class(d->m_styleContext.data(), "gnome-panel-menu-bar");
1234+ gtk_style_context_add_class(d->m_styleContext.data(), "unity-panel");
1235+
1236+ gtk_widget_path_free (widgetPath);
1237
1238 d->m_gConnector.connect(gtk_settings_get_default(), "notify::gtk-theme-name",
1239 G_CALLBACK(PanelStylePrivate::onThemeChanged), d);
1240- d->m_gConnector.connect(gtk_settings_get_default(), "notify::gtk-font-name",
1241- G_CALLBACK(PanelStylePrivate::onFontChanged), d);
1242
1243 d->updatePalette();
1244- d->updateFont();
1245 }
1246
1247 PanelStyle::~PanelStyle()
1248 {
1249- gtk_widget_destroy(d->m_offScreenWindow);
1250 delete d;
1251 }
1252
1253@@ -142,34 +106,9 @@
1254 return &style;
1255 }
1256
1257-QColor PanelStyle::textColor() const
1258-{
1259- return d->m_textColor;
1260-}
1261-
1262-QColor PanelStyle::backgroundTopColor() const
1263-{
1264- return d->m_backgroundTopColor;
1265-}
1266-
1267-QColor PanelStyle::backgroundBottomColor() const
1268-{
1269- return d->m_backgroundBottomColor;
1270-}
1271-
1272-QColor PanelStyle::textShadowColor() const
1273-{
1274- return d->m_textShadowColor;
1275-}
1276-
1277-QColor PanelStyle::lineColor() const
1278-{
1279- return d->m_lineColor;
1280-}
1281-
1282-QFont PanelStyle::font() const
1283-{
1284- return d->m_font;
1285+GtkStyleContext* PanelStyle::styleContext() const
1286+{
1287+ return d->m_styleContext.data();
1288 }
1289
1290 #include "panelstyle.moc"
1291
1292=== modified file 'panel/applets/common/panelstyle.h'
1293--- panel/applets/common/panelstyle.h 2011-06-30 16:43:27 +0000
1294+++ panel/applets/common/panelstyle.h 2011-07-27 15:51:26 +0000
1295@@ -26,12 +26,15 @@
1296 // Qt
1297 #include <QObject>
1298
1299-class QColor;
1300-class QFont;
1301+struct _GtkStyleContext;
1302
1303 class PanelStylePrivate;
1304 /**
1305- * Provides easy access to panel colors
1306+ * Provides easy access to panel style context and track platform theme to
1307+ * ensure we have the correct background brush.
1308+ *
1309+ * FIXME: This class does not have a very clear focus and has side-effects
1310+ * (background brush handling). It should be refactored.
1311 */
1312 class PanelStyle : public QObject
1313 {
1314@@ -42,13 +45,7 @@
1315
1316 static PanelStyle* instance();
1317
1318- QColor textColor() const;
1319- QColor backgroundTopColor() const;
1320- QColor backgroundBottomColor() const;
1321- QColor textShadowColor() const;
1322- QColor lineColor() const;
1323-
1324- QFont font() const;
1325+ struct _GtkStyleContext* styleContext() const;
1326
1327 private:
1328 friend class PanelStylePrivate;
1329
1330=== modified file 'panel/applets/homebutton/homebutton.cpp'
1331--- panel/applets/homebutton/homebutton.cpp 2011-05-26 16:41:04 +0000
1332+++ panel/applets/homebutton/homebutton.cpp 2011-07-27 15:51:26 +0000
1333@@ -40,8 +40,10 @@
1334 setStyleSheet(
1335 "QToolButton { border: none; margin: 0; padding: 0; width: 61 }"
1336 "QToolButton:checked, QToolButton:pressed {"
1337- // Use border-image here, not background-image, because bfb_bg_active.png is 56px wide
1338- " border-image: url(theme:/bfb_bg_active.png);"
1339+ " padding-top: 1px;"
1340+ " padding-left: 1px;"
1341+ " padding-right: -1px;"
1342+ " padding-bottom: -1px;"
1343 "}"
1344 );
1345 }

Subscribers

People subscribed via source and target branches