Merge lp:~azzar1/unity/fix-1008656 into lp:unity

Proposed by Andrea Azzarone
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: no longer in the source branch.
Merged at revision: 2385
Proposed branch: lp:~azzar1/unity/fix-1008656
Merge into: lp:unity
Diff against target: 249 lines (+120/-25)
5 files modified
hud/HudView.cpp (+17/-9)
hud/HudView.h (+1/-0)
tests/CMakeLists.txt (+9/-0)
tests/test_hud_view.cpp (+75/-0)
unity-shared/SearchBar.cpp (+18/-16)
To merge this branch: bzr merge lp:~azzar1/unity/fix-1008656
Reviewer Review Type Date Requested Status
Marco Trevisan (Treviño) Approve
Review via email: mp+108655@code.launchpad.net

Commit message

Makes rounded the last hud button,

Description of the change

== Problem ==
[hud] the last button is not rounded.

== Test ==
Unit test added for unity::hud::View::SetQueries

To post a comment you must log in.
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Everything's fine ;)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hud/HudView.cpp'
2--- hud/HudView.cpp 2012-05-07 00:49:31 +0000
3+++ hud/HudView.cpp 2012-06-04 23:06:19 +0000
4@@ -213,6 +213,12 @@
5 return search_bar_->text_entry();
6 }
7
8+std::list<HudButton::Ptr> const& View::buttons() const
9+{
10+ return buttons_;
11+}
12+
13+
14 void View::SetQueries(Hud::Queries queries)
15 {
16 // early exit, if the user is key navigating on the hud, we don't want to set new
17@@ -231,14 +237,14 @@
18 buttons_.clear();
19 button_views_->Clear();
20 int found_items = 0;
21- for (auto query = queries.begin(); query != queries.end(); query++)
22+ for (auto query : queries)
23 {
24 if (found_items >= 5)
25 break;
26
27 HudButton::Ptr button(new HudButton());
28 buttons_.push_front(button);
29- button->SetQuery(*query);
30+ button->SetQuery(query);
31
32 button_views_->AddView(button.GetPointer(), 0, nux::MINOR_POSITION_LEFT);
33
34@@ -246,24 +252,26 @@
35 query_activated.emit(dynamic_cast<HudButton*>(view)->GetQuery());
36 });
37
38- button->key_nav_focus_activate.connect([&](nux::Area *area) {
39+ button->key_nav_focus_activate.connect([&](nux::Area* area) {
40 query_activated.emit(dynamic_cast<HudButton*>(area)->GetQuery());
41 });
42
43- button->key_nav_focus_change.connect([&](nux::Area *area, bool recieving, KeyNavDirection direction){
44+ button->key_nav_focus_change.connect([&](nux::Area* area, bool recieving, KeyNavDirection direction){
45 if (recieving)
46 query_selected.emit(dynamic_cast<HudButton*>(area)->GetQuery());
47 });
48
49- // You should never decrement end(). We should fix this loop.
50- button->is_rounded = (query == --(queries.end())) ? true : false;
51- button->fake_focused = (query == (queries.begin())) ? true : false;
52-
53 button->SetMinimumWidth(content_width);
54- found_items++;
55+ ++found_items;
56 }
57+
58 if (found_items)
59+ {
60+ buttons_.front()->is_rounded = true;
61+ buttons_.back()->fake_focused = true;
62 selected_button_ = 1;
63+ }
64+
65
66 QueueRelayout();
67 QueueDraw();
68
69=== modified file 'hud/HudView.h'
70--- hud/HudView.h 2012-05-07 00:49:31 +0000
71+++ hud/HudView.h 2012-06-04 23:06:19 +0000
72@@ -51,6 +51,7 @@
73
74 void Relayout();
75 nux::View* default_focus() const;
76+ std::list<HudButton::Ptr> const& buttons() const;
77
78 void SetQueries(Hud::Queries queries);
79 void SetIcon(std::string icon_name, unsigned int tile_size, unsigned int size, unsigned int padding);
80
81=== modified file 'tests/CMakeLists.txt'
82--- tests/CMakeLists.txt 2012-05-30 14:33:07 +0000
83+++ tests/CMakeLists.txt 2012-06-04 23:06:19 +0000
84@@ -204,6 +204,7 @@
85 test_main.cpp
86 test_lensview_impl.cpp
87 test_icon_loader.cpp
88+ test_hud_view.cpp
89 test_resultviewgrid.cpp
90 test_single_monitor_launcher_icon.cpp
91 test_switcher_controller.cpp
92@@ -215,7 +216,10 @@
93 ${CMAKE_SOURCE_DIR}/dash/ResultView.cpp
94 ${CMAKE_SOURCE_DIR}/dash/ResultViewGrid.cpp
95 ${CMAKE_SOURCE_DIR}/hud/HudButton.cpp
96+ ${CMAKE_SOURCE_DIR}/hud/HudIcon.cpp
97+ ${CMAKE_SOURCE_DIR}/hud/HudIconTextureSource.cpp
98 ${CMAKE_SOURCE_DIR}/hud/HudPrivate.cpp
99+ ${CMAKE_SOURCE_DIR}/hud/HudView.cpp
100 ${CMAKE_SOURCE_DIR}/launcher/AbstractLauncherIcon.cpp
101 ${CMAKE_SOURCE_DIR}/launcher/CairoBaseWindow.cpp
102 ${CMAKE_SOURCE_DIR}/launcher/DNDCollectionWindow.cpp
103@@ -249,11 +253,16 @@
104 ${CMAKE_SOURCE_DIR}/unity-shared/DashStyle.cpp
105 ${CMAKE_SOURCE_DIR}/unity-shared/IconLoader.cpp
106 ${CMAKE_SOURCE_DIR}/unity-shared/IconRenderer.cpp
107+ ${CMAKE_SOURCE_DIR}/unity-shared/IconTexture.cpp
108 ${CMAKE_SOURCE_DIR}/unity-shared/IconTextureSource.cpp
109+ ${CMAKE_SOURCE_DIR}/unity-shared/IMTextEntry.cpp
110 ${CMAKE_SOURCE_DIR}/unity-shared/Introspectable.cpp
111 ${CMAKE_SOURCE_DIR}/unity-shared/IntrospectableWrappers.cpp
112 ${CMAKE_SOURCE_DIR}/unity-shared/JSONParser.cpp
113+ ${CMAKE_SOURCE_DIR}/unity-shared/OverlayRenderer.cpp
114 ${CMAKE_SOURCE_DIR}/unity-shared/PanelStyle.cpp
115+ ${CMAKE_SOURCE_DIR}/unity-shared/SearchBar.cpp
116+ ${CMAKE_SOURCE_DIR}/unity-shared/SearchBarSpinner.cpp
117 ${CMAKE_SOURCE_DIR}/unity-shared/StaticCairoText.cpp
118 ${CMAKE_SOURCE_DIR}/unity-shared/TextureCache.cpp
119 ${CMAKE_SOURCE_DIR}/unity-shared/Timer.cpp
120
121=== added file 'tests/test_hud_view.cpp'
122--- tests/test_hud_view.cpp 1970-01-01 00:00:00 +0000
123+++ tests/test_hud_view.cpp 2012-06-04 23:06:19 +0000
124@@ -0,0 +1,75 @@
125+/*
126+ * Copyright 2012 Canonical Ltd.
127+ *
128+ * This program is free software: you can redistribute it and/or modify it
129+ * under the terms of the GNU Lesser General Public License version 3, as
130+ * published by the Free Software Foundation.
131+ *
132+ * This program is distributed in the hope that it will be useful, but
133+ * WITHOUT ANY WARRANTY; without even the implied warranties of
134+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
135+ * PURPOSE. See the applicable version of the GNU Lesser General Public
136+ * License for more details.
137+ *
138+ * You should have received a copy of both the GNU Lesser General Public
139+ * License version 3 along with this program. If not, see
140+ * <http://www.gnu.org/licenses/>
141+ *
142+ * Authored by: Andrea Azzarone <azzaronea@gmail.com>
143+ *
144+ */
145+
146+#include <list>
147+
148+#include <gtest/gtest.h>
149+
150+#include <Nux/Nux.h>
151+#include <NuxCore/ObjectPtr.h>
152+
153+#include "UnityCore/Hud.h"
154+
155+#include "hud/HudView.h"
156+#include "unity-shared/DashStyle.h"
157+#include "unity-shared/UnitySettings.h"
158+using namespace unity;
159+
160+namespace
161+{
162+
163+TEST(TestHudView, TestSetQueries)
164+{
165+ Settings unity_settings;
166+ dash::Style dash_style;
167+ nux::ObjectPtr<hud::View> view(new hud::View());
168+
169+ hud::Hud::Queries queries;
170+ queries.push_back(hud::Query::Ptr(new hud::Query("1", "","", "", "", NULL)));
171+ queries.push_back(hud::Query::Ptr(new hud::Query("2", "","", "", "", NULL)));
172+ queries.push_back(hud::Query::Ptr(new hud::Query("3", "","", "", "", NULL)));
173+ queries.push_back(hud::Query::Ptr(new hud::Query("4", "","", "", "", NULL)));
174+ view->SetQueries(queries);
175+
176+ ASSERT_EQ(view->buttons().size(), 4);
177+
178+ auto it = view->buttons().begin();
179+ EXPECT_EQ((*it)->label, "4");
180+ EXPECT_TRUE((*it)->is_rounded);
181+ EXPECT_FALSE((*it)->fake_focused);
182+
183+ it++;
184+ EXPECT_EQ((*it)->label, "3");
185+ EXPECT_FALSE((*it)->is_rounded);
186+ EXPECT_FALSE((*it)->fake_focused);
187+
188+ it++;
189+ EXPECT_EQ((*it)->label, "2");
190+ EXPECT_FALSE((*it)->is_rounded);
191+ EXPECT_FALSE((*it)->fake_focused);
192+
193+ it++;
194+ EXPECT_EQ((*it)->label, "1");
195+ EXPECT_FALSE((*it)->is_rounded);
196+ EXPECT_TRUE((*it)->fake_focused);
197+}
198+
199+}
200
201=== modified file 'unity-shared/SearchBar.cpp'
202--- unity-shared/SearchBar.cpp 2012-05-07 00:49:31 +0000
203+++ unity-shared/SearchBar.cpp 2012-06-04 23:06:19 +0000
204@@ -302,27 +302,29 @@
205
206 void SearchBar::OnFontChanged(GtkSettings* settings, GParamSpec* pspec)
207 {
208- gchar* font_name = NULL;
209+ glib::String font_name;
210 PangoFontDescription* desc;
211 std::ostringstream font_desc;
212
213 g_object_get(settings, "gtk-font-name", &font_name, NULL);
214
215- desc = pango_font_description_from_string(font_name);
216- pango_entry_->SetFontFamily(pango_font_description_get_family(desc));
217- pango_entry_->SetFontSize(PANGO_ENTRY_FONT_SIZE);
218- pango_entry_->SetFontOptions(gdk_screen_get_font_options(gdk_screen_get_default()));
219-
220- font_desc << pango_font_description_get_family(desc) << " " << HINT_LABEL_FONT_STYLE << " " << HINT_LABEL_FONT_SIZE;
221- hint_->SetFont(font_desc.str().c_str());
222-
223- font_desc.str("");
224- font_desc.clear();
225- font_desc << pango_font_description_get_family(desc) << " " << SHOW_FILTERS_LABEL_FONT_STYLE << " " << SHOW_FILTERS_LABEL_FONT_SIZE;
226- show_filters_->SetFont(font_desc.str().c_str());
227-
228- pango_font_description_free(desc);
229- g_free(font_name);
230+ desc = pango_font_description_from_string(font_name.Value());
231+ if (desc)
232+ {
233+ pango_entry_->SetFontFamily(pango_font_description_get_family(desc));
234+ pango_entry_->SetFontSize(PANGO_ENTRY_FONT_SIZE);
235+ pango_entry_->SetFontOptions(gdk_screen_get_font_options(gdk_screen_get_default()));
236+
237+ font_desc << pango_font_description_get_family(desc) << " " << HINT_LABEL_FONT_STYLE << " " << HINT_LABEL_FONT_SIZE;
238+ hint_->SetFont(font_desc.str().c_str());
239+
240+ font_desc.str("");
241+ font_desc.clear();
242+ font_desc << pango_font_description_get_family(desc) << " " << SHOW_FILTERS_LABEL_FONT_STYLE << " " << SHOW_FILTERS_LABEL_FONT_SIZE;
243+ show_filters_->SetFont(font_desc.str().c_str());
244+
245+ pango_font_description_free(desc);
246+ }
247 }
248
249 void SearchBar::OnSearchHintChanged()