Merge lp:~canonical-dx-team/unity/unity.fix-685830 into lp:unity

Proposed by Mirco Müller
Status: Merged
Merged at revision: 867
Proposed branch: lp:~canonical-dx-team/unity/unity.fix-685830
Merge into: lp:unity
Diff against target: 243 lines (+192/-2)
5 files modified
src/PanelIndicatorObjectEntryView.cpp (+1/-0)
src/PanelStyle.cpp (+122/-0)
src/PanelStyle.h (+47/-0)
src/PanelView.cpp (+20/-2)
tests/CMakeLists.txt (+2/-0)
To merge this branch: bzr merge lp:~canonical-dx-team/unity/unity.fix-685830
Reviewer Review Type Date Requested Status
Neil J. Patel (community) Needs Fixing
Review via email: mp+43054@code.launchpad.net

Description of the change

New style-handling class for the panel implemented as a singleton.

To post a comment you must log in.
Revision history for this message
Neil J. Patel (njpatel) wrote :

It looks like you haven't yet hooked everything up so this merge proposal might be a bit premature. I'll comment on what I see anyway:

 - It should be _panel_style not _panelStyle, same goes for anything else like that

- GetDefault(), if _panelStyle == NULL, then create a new one and return it, but if one is already around: return _panelStyle->Reference(); On the other end, the objects should grab panel style object on construction and then ->UnReference it on destruction.

- To be more C++, you should probably have:

nux::Color& GetBackgroundTop ()

etc, so you can do nux::Color top = style->GetBackgroundTop ();, which is cleaner

- Probably can rid of printfs?

- I think the PanelIndicatorObjectEntryView bits still need to be hooked up

- Missing a "changed" signal so we can react to theme changes?

review: Needs Fixing
Revision history for this message
Mirco Müller (macslow) wrote :

> - It should be _panel_style not _panelStyle, same goes for anything else like
> that

Changed.
>
> - GetDefault(), if _panelStyle == NULL, then create a new one and return it,
> but if one is already around: return _panelStyle->Reference(); On the other
> end, the objects should grab panel style object on construction and then
> ->UnReference it on destruction.

But why should reference-counting be used, when PanelStyle is meant to be a singleton. I think these two concepts are mutual exclusive imo.

> - To be more C++, you should probably have:
>
> nux::Color& GetBackgroundTop ()

Initially you asked me to use ANSI-C-ish call-by-reference for this, but I've changed it now to the C++-reference return-type.

> - Probably can rid of printfs?

Yeah, was just for debugging.

> - I think the PanelIndicatorObjectEntryView bits still need to be hooked up
>
> - Missing a "changed" signal so we can react to theme changes?

Doing that atm.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/PanelIndicatorObjectEntryView.cpp'
--- src/PanelIndicatorObjectEntryView.cpp 2010-12-07 15:01:07 +0000
+++ src/PanelIndicatorObjectEntryView.cpp 2010-12-09 16:50:42 +0000
@@ -25,6 +25,7 @@
25#include "Nux/WindowCompositor.h"25#include "Nux/WindowCompositor.h"
2626
27#include "PanelIndicatorObjectEntryView.h"27#include "PanelIndicatorObjectEntryView.h"
28#include "PanelStyle.h"
2829
29#include <glib.h>30#include <glib.h>
30#include <pango/pangocairo.h>31#include <pango/pangocairo.h>
3132
=== added file 'src/PanelStyle.cpp'
--- src/PanelStyle.cpp 1970-01-01 00:00:00 +0000
+++ src/PanelStyle.cpp 2010-12-09 16:50:42 +0000
@@ -0,0 +1,122 @@
1/*
2 * Copyright (C) 2010 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Mirco Müller <mirco.mueller@canonical.com>
17 */
18
19#include <gtk/gtk.h>
20
21#include "PanelStyle.h"
22
23PanelStyle* PanelStyle::_panel_style = NULL;
24
25void
26OnStyleChanged (GObject* gobject,
27 GParamSpec* pspec,
28 gpointer data)
29{
30 PanelStyle* self = (PanelStyle*) data;
31
32 self->sigChanged.emit (*self);
33}
34
35PanelStyle*
36PanelStyle::GetDefault ()
37{
38 if (_panel_style == NULL)
39 {
40 _panel_style = new PanelStyle ();
41
42 g_signal_connect (gtk_settings_get_default (),
43 "notify::gtk-theme-name",
44 G_CALLBACK (OnStyleChanged),
45 _panel_style);
46 }
47
48 _panel_style->Reference ();
49 return _panel_style;
50}
51
52nux::Color&
53PanelStyle::GetTextColor ()
54{
55 nux::Color& color = _text;
56
57 return color;
58}
59
60nux::Color&
61PanelStyle::GetBackgroundTop ()
62{
63 nux::Color& color = _bg_top;
64
65 return color;
66}
67
68nux::Color&
69PanelStyle::GetBackgroundBottom ()
70{
71 nux::Color& color = _bg_bottom;
72
73 return color;
74}
75
76nux::Color&
77PanelStyle::GetTextShadow ()
78{
79 nux::Color& color = _text_shadow;
80
81 return color;
82}
83
84PanelStyle::PanelStyle ()
85{
86 GtkWidget* menu_bar = NULL;
87 GtkStyle* style = NULL;
88
89 menu_bar = gtk_menu_bar_new ();
90 style = gtk_widget_get_style (menu_bar);
91
92 _text.SetRed ((float) style->text[4].red / (float) 0xffff);
93 _text.SetGreen ((float) style->text[4].green / (float) 0xffff);
94 _text.SetBlue ((float) style->text[4].blue / (float) 0xffff);
95 _text.SetAlpha (1.0f);
96
97 _bg_top.SetRed ((float) style->bg[4].red / (float) 0xffff);
98 _bg_top.SetGreen ((float) style->bg[4].green / (float) 0xffff);
99 _bg_top.SetBlue ((float) style->bg[4].blue / (float) 0xffff);
100 _bg_top = 0.4f * _bg_top;
101 _bg_top.SetAlpha (1.0f);
102
103 _bg_bottom.SetRed ((float) style->bg[4].red / (float) 0xffff);
104 _bg_bottom.SetGreen ((float) style->bg[4].green / (float) 0xffff);
105 _bg_bottom.SetBlue ((float) style->bg[4].blue / (float) 0xffff);
106 _bg_bottom = 0.22f * _bg_bottom;
107 _bg_bottom.SetAlpha (1.0f);
108
109 _text_shadow.SetRed ((float) style->text[2].red / (float) 0xffff);
110 _text_shadow.SetGreen ((float) style->text[2].green / (float) 0xffff);
111 _text_shadow.SetBlue ((float) style->text[2].blue / (float) 0xffff);
112 _text_shadow.SetAlpha (1.0f);
113
114 g_object_unref (style);
115 g_object_unref (menu_bar);
116}
117
118PanelStyle::~PanelStyle ()
119{
120 if (GetReferenceCount () != 0)
121 g_warning ("PanelStyle::~PanelStyle() - Reference-counter is not 0!");
122}
0123
=== added file 'src/PanelStyle.h'
--- src/PanelStyle.h 1970-01-01 00:00:00 +0000
+++ src/PanelStyle.h 2010-12-09 16:50:42 +0000
@@ -0,0 +1,47 @@
1/*
2 * Copyright (C) 2010 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Mirco Müller <mirco.mueller@canonical.com>
17 */
18
19#ifndef PANEL_STYLE_H
20#define PANEL_STYLE_H
21
22#include "Nux/Nux.h"
23
24class PanelStyle : public nux::Object
25{
26 public:
27 PanelStyle ();
28 ~PanelStyle ();
29
30 static PanelStyle* GetDefault ();
31
32 nux::Color& GetTextColor ();
33 nux::Color& GetBackgroundTop ();
34 nux::Color& GetBackgroundBottom ();
35 nux::Color& GetTextShadow ();
36
37 sigc::signal<void, PanelStyle&> sigChanged;
38
39 private:
40 static PanelStyle* _panel_style;
41 nux::Color _text;
42 nux::Color _bg_top;
43 nux::Color _bg_bottom;
44 nux::Color _text_shadow;
45};
46
47#endif // PANEL_STYLE_H
048
=== modified file 'src/PanelView.cpp'
--- src/PanelView.cpp 2010-12-09 15:52:53 +0000
+++ src/PanelView.cpp 2010-12-09 16:50:42 +0000
@@ -31,6 +31,7 @@
31#include <glib.h>31#include <glib.h>
3232
33#include "PanelView.h"33#include "PanelView.h"
34#include "PanelStyle.h"
3435
35#include "IndicatorObjectFactoryRemote.h"36#include "IndicatorObjectFactoryRemote.h"
36#include "PanelIndicatorObjectView.h"37#include "PanelIndicatorObjectView.h"
@@ -156,8 +157,25 @@
156 cairo_set_line_width (cr, 1);157 cairo_set_line_width (cr, 1);
157158
158 cairo_pattern_t *pat = cairo_pattern_create_linear (0, 0, 0, _last_height);159 cairo_pattern_t *pat = cairo_pattern_create_linear (0, 0, 0, _last_height);
159 cairo_pattern_add_color_stop_rgb (pat, 0.0f, 89/255.0f, 88/255.0f, 83/255.0f);160
160 cairo_pattern_add_color_stop_rgb (pat, 1.0f, 50/255.0f, 50/255.0f, 45/255.0f);161 PanelStyle* style = PanelStyle::GetDefault ();
162 nux::Color start;
163 nux::Color end;
164
165 start = style->GetBackgroundTop ();
166 end = style->GetBackgroundBottom ();
167
168 cairo_pattern_add_color_stop_rgb (pat,
169 0.0f,
170 start.GetRed (),
171 start.GetGreen (),
172 start.GetBlue ());
173 cairo_pattern_add_color_stop_rgb (pat,
174 1.0f,
175 end.GetRed (),
176 end.GetGreen (),
177 end.GetBlue ());
178
161 cairo_set_source (cr, pat);179 cairo_set_source (cr, pat);
162 cairo_rectangle (cr, 0, 0, _last_width, _last_height);180 cairo_rectangle (cr, 0, 0, _last_width, _last_height);
163 cairo_fill (cr);181 cairo_fill (cr);
164182
=== modified file 'tests/CMakeLists.txt'
--- tests/CMakeLists.txt 2010-12-09 11:04:20 +0000
+++ tests/CMakeLists.txt 2010-12-09 16:50:42 +0000
@@ -62,6 +62,8 @@
6262
63add_executable (test-panel63add_executable (test-panel
64 TestPanel.cpp64 TestPanel.cpp
65 ../src/PanelStyle.cpp
66 ../src/PanelStyle.h
65 ../src/PanelView.cpp67 ../src/PanelView.cpp
66 ../src/PanelView.h68 ../src/PanelView.h
67 ../src/PanelIndicatorObjectView.cpp69 ../src/PanelIndicatorObjectView.cpp