Merge lp:~canonical-dx-team/unity/unity.quicklist-event-handling into lp:unity

Proposed by Jay Taoko
Status: Merged
Merged at revision: 640
Proposed branch: lp:~canonical-dx-team/unity/unity.quicklist-event-handling
Merge into: lp:unity
Diff against target: 293 lines (+115/-16)
4 files modified
src/QuicklistMenuItem.cpp (+3/-3)
src/QuicklistMenuItem.h (+2/-1)
src/QuicklistView.cpp (+101/-9)
src/QuicklistView.h (+9/-3)
To merge this branch: bzr merge lp:~canonical-dx-team/unity/unity.quicklist-event-handling
Reviewer Review Type Date Requested Status
Jason Smith (community) Approve
Review via email: mp+42206@code.launchpad.net

Description of the change

Improved mouse event handling. Interpret mouse events on the quicklist and get ready to send the clicked signal.

To post a comment you must log in.
Revision history for this message
Jason Smith (jassmith) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/QuicklistMenuItem.cpp'
2--- src/QuicklistMenuItem.cpp 2010-11-29 17:18:55 +0000
3+++ src/QuicklistMenuItem.cpp 2010-11-30 05:21:18 +0000
4@@ -301,7 +301,7 @@
5
6 void QuicklistMenuItem::RecvMouseUp (int x, int y, unsigned long button_flags, unsigned long key_flags)
7 {
8- sigMouseReleased.emit (this);
9+ sigMouseReleased.emit (this, x, y);
10 }
11
12 void QuicklistMenuItem::RecvMouseClick (int x, int y, unsigned long button_flags, unsigned long key_flags)
13@@ -316,12 +316,12 @@
14
15 void QuicklistMenuItem::RecvMouseMove (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags)
16 {
17-
18+ //printf ("[QuicklistMenuItem::RecvMouseMove]\n");
19 }
20
21 void QuicklistMenuItem::RecvMouseDrag (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags)
22 {
23-
24+ sigMouseDrag.emit (this, x, y);
25 }
26
27 void QuicklistMenuItem::RecvMouseEnter (int x, int y, unsigned long button_flags, unsigned long key_flags)
28
29=== modified file 'src/QuicklistMenuItem.h'
30--- src/QuicklistMenuItem.h 2010-11-25 13:01:34 +0000
31+++ src/QuicklistMenuItem.h 2010-11-30 05:21:18 +0000
32@@ -109,8 +109,9 @@
33
34 sigc::signal<void, QuicklistMenuItem*> sigMouseEnter;
35 sigc::signal<void, QuicklistMenuItem*> sigMouseLeave;
36- sigc::signal<void, QuicklistMenuItem*> sigMouseReleased;
37+ sigc::signal<void, QuicklistMenuItem*, int, int> sigMouseReleased;
38 sigc::signal<void, QuicklistMenuItem*> sigMouseClick;
39+ sigc::signal<void, QuicklistMenuItem*, int, int> sigMouseDrag;
40
41 DbusmenuMenuitem* _menuItem;
42 QuicklistMenuItemType _item_type;
43
44=== modified file 'src/QuicklistView.cpp'
45--- src/QuicklistView.cpp 2010-11-24 18:25:38 +0000
46+++ src/QuicklistView.cpp 2010-11-30 05:21:18 +0000
47@@ -139,6 +139,7 @@
48 item->sigMouseReleased.connect (sigc::mem_fun (this, &QuicklistView::RecvItemMouseRelease));
49 item->sigMouseEnter.connect (sigc::mem_fun (this, &QuicklistView::RecvItemMouseEnter));
50 item->sigMouseLeave.connect (sigc::mem_fun (this, &QuicklistView::RecvItemMouseLeave));
51+ item->sigMouseDrag.connect (sigc::mem_fun (this, &QuicklistView::RecvItemMouseDrag));
52
53 _default_item_layout->AddView(item, 1, nux::eCenter, nux::eFull);
54 _default_item_list.push_back (item);
55@@ -159,6 +160,7 @@
56 item->sigMouseReleased.connect (sigc::mem_fun (this, &QuicklistView::RecvItemMouseRelease));
57 item->sigMouseEnter.connect (sigc::mem_fun (this, &QuicklistView::RecvItemMouseEnter));
58 item->sigMouseLeave.connect (sigc::mem_fun (this, &QuicklistView::RecvItemMouseLeave));
59+ item->sigMouseDrag.connect (sigc::mem_fun (this, &QuicklistView::RecvItemMouseDrag));
60
61 _default_item_layout->AddView(item, 1, nux::eCenter, nux::eFull);
62 _default_item_list.push_back (item);
63@@ -214,8 +216,12 @@
64 // We choose to test the quicklist items ourselves instead of processing them as it is usual in nux.
65 // This is meant to be easier since the quicklist has a atypical way of working.
66 if (m_layout)
67+ {
68 ret = m_layout->ProcessEvent (window_event, ret, ProcEvInfo);
69-
70+ }
71+
72+ // The quicklist itself does not process the evvent. Instead we do some analysis of the event
73+ // to detect the user action and perform the correct operation.
74 if (ievent.e_event == nux::NUX_MOUSE_PRESSED)
75 {
76 if (GetGeometry ().IsPointInside (ievent.e_x, ievent.e_y))
77@@ -227,6 +233,7 @@
78 _mouse_down = false;
79 if (IsVisible ())
80 {
81+ CancelItemsPrelightStatus ();
82 CaptureMouseDownAnyWhereElse (false);
83 ForceStopFocus (1, 1);
84 UnGrabPointer ();
85@@ -238,10 +245,10 @@
86 }
87 else if ((ievent.e_event == nux::NUX_MOUSE_RELEASED) && _mouse_down)
88 {
89-
90 _mouse_down = false;
91 if (IsVisible ())
92 {
93+ CancelItemsPrelightStatus ();
94 CaptureMouseDownAnyWhereElse (false);
95 ForceStopFocus (1, 1);
96 UnGrabPointer ();
97@@ -251,11 +258,7 @@
98 return nux::eMouseEventSolved;
99 }
100
101- // PostProcessEvent2 must always have its last parameter set to 0
102- // because the m_BackgroundArea is the real physical limit of the window.
103- // So the previous test about IsPointInside do not prevail over m_BackgroundArea
104- // testing the event by itself.
105- //ret = PostProcessEvent2 (ievent, ret, 0);
106+
107 return ret;
108 }
109
110@@ -440,6 +443,7 @@
111 _mouse_down = false;
112 if (IsVisible ())
113 {
114+ CancelItemsPrelightStatus ();
115 CaptureMouseDownAnyWhereElse (false);
116 ForceStopFocus (1, 1);
117 UnGrabPointer ();
118@@ -448,11 +452,44 @@
119 }
120 }
121
122-void QuicklistView::RecvItemMouseRelease (QuicklistMenuItem* item)
123+void QuicklistView::CheckAndEmitItemSignal (int x, int y)
124+{
125+ nux::Geometry geo;
126+ std::list<QuicklistMenuItem*>::iterator it;
127+ for (it = _item_list.begin(); it != _item_list.end(); it++)
128+ {
129+ geo = (*it)->GetGeometry ();
130+ geo.width = _item_layout->GetBaseWidth ();
131+
132+ if (geo.IsPointInside (x, y))
133+ {
134+ // An action is performed: send the signal back to the application
135+ }
136+ }
137+
138+ for (it = _default_item_list.begin(); it != _default_item_list.end(); it++)
139+ {
140+ geo = (*it)->GetGeometry ();
141+ geo.width = _default_item_layout->GetBaseWidth ();
142+
143+ if (geo.IsPointInside (x, y))
144+ {
145+ // An action is performed: send the signal back to the application
146+ }
147+ }
148+}
149+
150+void QuicklistView::RecvItemMouseRelease (QuicklistMenuItem* item, int x, int y)
151 {
152 _mouse_down = false;
153+
154+
155 if (IsVisible ())
156 {
157+ // Check if the mouse was released over an item and emit the signal
158+ CheckAndEmitItemSignal (x + item->GetBaseX (), y + item->GetBaseY ());
159+
160+ CancelItemsPrelightStatus ();
161 CaptureMouseDownAnyWhereElse (false);
162 ForceStopFocus (1, 1);
163 UnGrabPointer ();
164@@ -461,6 +498,57 @@
165 }
166 }
167
168+void QuicklistView::CancelItemsPrelightStatus ()
169+{
170+ std::list<QuicklistMenuItem*>::iterator it;
171+ for (it = _item_list.begin(); it != _item_list.end(); it++)
172+ {
173+ (*it)->_prelight = false;
174+ }
175+
176+ for (it = _default_item_list.begin(); it != _default_item_list.end(); it++)
177+ {
178+ (*it)->_prelight = false;
179+ }
180+}
181+
182+void QuicklistView::RecvItemMouseDrag (QuicklistMenuItem* item, int x, int y)
183+{
184+ nux::Geometry geo;
185+ std::list<QuicklistMenuItem*>::iterator it;
186+ for (it = _item_list.begin(); it != _item_list.end(); it++)
187+ {
188+ geo = (*it)->GetGeometry ();
189+ geo.width = _item_layout->GetBaseWidth ();
190+
191+ if (geo.IsPointInside (x + item->GetBaseX (), y + item->GetBaseY ()))
192+ {
193+ (*it)->_prelight = true;
194+ }
195+ else
196+ {
197+ (*it)->_prelight = false;
198+ }
199+ }
200+
201+ for (it = _default_item_list.begin(); it != _default_item_list.end(); it++)
202+ {
203+ geo = (*it)->GetGeometry ();
204+ geo.width = _default_item_layout->GetBaseWidth ();
205+
206+ if (geo.IsPointInside (x + item->GetBaseX (), y + item->GetBaseY ()))
207+ {
208+ (*it)->_prelight = true;
209+ }
210+ else
211+ {
212+ (*it)->_prelight = false;
213+ }
214+ }
215+
216+ NeedRedraw ();
217+}
218+
219 void QuicklistView::RecvItemMouseEnter (QuicklistMenuItem* item)
220 {
221 NeedRedraw ();
222@@ -485,13 +573,15 @@
223
224 void QuicklistView::RecvMouseUp (int x, int y, unsigned long button_flags, unsigned long key_flags)
225 {
226-
227+ // Check if the mouse was released over an item and emit the signal
228+ CheckAndEmitItemSignal (x, y);
229 }
230
231 void QuicklistView::RecvMouseClick (int x, int y, unsigned long button_flags, unsigned long key_flags)
232 {
233 if (IsVisible ())
234 {
235+ CancelItemsPrelightStatus ();
236 CaptureMouseDownAnyWhereElse (false);
237 ForceStopFocus (1, 1);
238 UnGrabPointer ();
239@@ -514,6 +604,7 @@
240 {
241 if (IsVisible ())
242 {
243+ CancelItemsPrelightStatus ();
244 CaptureMouseDownAnyWhereElse (false);
245 ForceStopFocus (1, 1);
246 UnGrabPointer ();
247@@ -544,6 +635,7 @@
248 item->sigMouseReleased.connect (sigc::mem_fun (this, &QuicklistView::RecvItemMouseRelease));
249 item->sigMouseEnter.connect (sigc::mem_fun (this, &QuicklistView::RecvItemMouseEnter));
250 item->sigMouseLeave.connect (sigc::mem_fun (this, &QuicklistView::RecvItemMouseLeave));
251+ item->sigMouseDrag.connect (sigc::mem_fun (this, &QuicklistView::RecvItemMouseDrag));
252
253 _item_layout->AddView(item, 1, nux::eCenter, nux::eFull);
254 _item_list.push_back (item);
255
256=== modified file 'src/QuicklistView.h'
257--- src/QuicklistView.h 2010-11-24 00:03:08 +0000
258+++ src/QuicklistView.h 2010-11-30 05:21:18 +0000
259@@ -81,7 +81,7 @@
260
261 int GetNumItems ();
262 QuicklistMenuItem* GetNthItems (int index);
263- QuicklistMenuItemType GetNthType (int index);
264+ QuicklistMenuItemType GetNthType (int index);
265 std::list<QuicklistMenuItem*> GetChildren ();
266
267 void TestMenuItems (DbusmenuMenuitem* root);
268@@ -90,10 +90,11 @@
269 void RecvCairoTextChanged (QuicklistMenuItem* item);
270 void RecvCairoTextColorChanged (QuicklistMenuItem* item);
271 void RecvItemMouseClick (QuicklistMenuItem* item);
272- void RecvItemMouseRelease (QuicklistMenuItem* item);
273+ void RecvItemMouseRelease (QuicklistMenuItem* item, int x, int y);
274 void RecvItemMouseEnter (QuicklistMenuItem* item);
275 void RecvItemMouseLeave (QuicklistMenuItem* item);
276-
277+ void RecvItemMouseDrag (QuicklistMenuItem* item, int x, int y);
278+
279 void RecvMouseDown (int x, int y, unsigned long button_flags, unsigned long key_flags);
280 void RecvMouseUp (int x, int y, unsigned long button_flags, unsigned long key_flags);
281 void RecvMouseClick (int x, int y, unsigned long button_flags, unsigned long key_flags);
282@@ -114,6 +115,11 @@
283 //! A convenience function to fill in the default quicklist with some random items.
284 void FillInDefaultItems ();
285
286+ void CancelItemsPrelightStatus ();
287+
288+ //! Check the mouse up event sent by an item. Detect the item where the mous is and emit the appropriate signal.
289+ void CheckAndEmitItemSignal (int x, int y);
290+
291 //nux::CairoGraphics* _cairo_graphics;
292 int _anchorX;
293 int _anchorY;