[glom] Canvas_PrintLayout: Selecting unselects others. Allow shift-clicking.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] Canvas_PrintLayout: Selecting unselects others. Allow shift-clicking.
- Date: Sun, 7 Aug 2011 08:49:06 +0000 (UTC)
commit e6a8d485ca46e05753201b13372d2ab5a263c02b
Author: Murray Cumming <murrayc murrayc com>
Date: Sun Aug 7 10:48:55 2011 +0200
Canvas_PrintLayout: Selecting unselects others. Allow shift-clicking.
* glom/utility_widgets/canvas/canvas_item_movable.[h|cc]:
signal_selected(): Also send the item (this), to avoid the need for
awkward (due to keeping a reference) sigc::bind()ing of RefPtr<>s.
Send a bool group_select parameter too, so we know if the button
press (corresponding to the button release) was with the shift key
held down.
* glom/utility_widgets/canvas/canvas_editable.[h|cc]:
on_item_selected(): Deselect other already-selected items if
the select was not with shift held down.
ChangeLog | 14 +++++++++++
glom/utility_widgets/canvas/canvas_editable.cc | 19 ++++++++++++++-
glom/utility_widgets/canvas/canvas_editable.h | 2 +-
glom/utility_widgets/canvas/canvas_item_movable.cc | 25 +++++++++++++++++--
glom/utility_widgets/canvas/canvas_item_movable.h | 9 +++++-
5 files changed, 62 insertions(+), 7 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index ebe0a01..a627597 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2011-08-07 Murray Cumming <murrayc murrayc com>
+
+ Canvas_PrintLayout: Selecting unselects others. Allow shift-clicking.
+
+ * glom/utility_widgets/canvas/canvas_item_movable.[h|cc]:
+ signal_selected(): Also send the item (this), to avoid the need for
+ awkward (due to keeping a reference) sigc::bind()ing of RefPtr<>s.
+ Send a bool group_select parameter too, so we know if the button
+ press (corresponding to the button release) was with the shift key
+ held down.
+ * glom/utility_widgets/canvas/canvas_editable.[h|cc]:
+ on_item_selected(): Deselect other already-selected items if
+ the select was not with shift held down.
+
2011-08-06 Murray Cumming <murrayc murrayc com>
CanvasItemMovable: set_selected(): Do not emit the signal here.
diff --git a/glom/utility_widgets/canvas/canvas_editable.cc b/glom/utility_widgets/canvas/canvas_editable.cc
index 465facb..7e2f6dd 100644
--- a/glom/utility_widgets/canvas/canvas_editable.cc
+++ b/glom/utility_widgets/canvas/canvas_editable.cc
@@ -182,8 +182,25 @@ CanvasEditable::type_signal_selection_changed CanvasEditable::signal_selection_c
return m_signal_selection_changed;
}
-void CanvasEditable::on_item_selected()
+void CanvasEditable::on_item_selected(const Glib::RefPtr<CanvasItemMovable>& item, bool group_select)
{
+ const bool selected = !item->get_selected();
+
+ if(!group_select)
+ {
+ //Make sure that all other items are deselected first:
+ const type_vec_items items = get_selected_items();
+ for(type_vec_items::const_iterator iter = items.begin();
+ iter != items.end(); ++iter)
+ {
+ Glib::RefPtr<CanvasItemMovable> selected_item = *iter;
+ if(selected_item)
+ selected_item->set_selected(false);
+ }
+ }
+
+ item->set_selected(!selected);
+
m_signal_selection_changed.emit();
}
diff --git a/glom/utility_widgets/canvas/canvas_editable.h b/glom/utility_widgets/canvas/canvas_editable.h
index 65e5b30..03a7582 100644
--- a/glom/utility_widgets/canvas/canvas_editable.h
+++ b/glom/utility_widgets/canvas/canvas_editable.h
@@ -85,7 +85,7 @@ public:
private:
- void on_item_selected();
+ void on_item_selected(const Glib::RefPtr<CanvasItemMovable>& item, bool group_select);
static Glib::RefPtr<Goocanvas::Item> get_parent_container_or_self(const Glib::RefPtr<Goocanvas::Item>& item);
diff --git a/glom/utility_widgets/canvas/canvas_item_movable.cc b/glom/utility_widgets/canvas/canvas_item_movable.cc
index 334370b..f8eb588 100644
--- a/glom/utility_widgets/canvas/canvas_item_movable.cc
+++ b/glom/utility_widgets/canvas/canvas_item_movable.cc
@@ -43,7 +43,8 @@ CanvasItemMovable::CanvasItemMovable()
m_drag_start_position_x(0.0), m_drag_start_position_y(0.0),
m_grid(0),
m_allow_vertical_movement(true), m_allow_horizontal_movement(true),
- m_selected(false)
+ m_selected(false),
+ m_shift_click(false)
{
//TODO: Remove this when goocanvas is fixed, so the goocanvasmm constructor can connect default signal handlers:
/*
@@ -63,6 +64,10 @@ CanvasItemMovable::~CanvasItemMovable()
bool CanvasItemMovable::on_button_press_event(const Glib::RefPtr<Goocanvas::Item>& target, GdkEventButton* event)
{
+ //std::cout << G_STRFUNC << ": DEBUG" << std::endl;
+
+ m_shift_click = false;
+
switch(event->button)
{
case 1:
@@ -84,6 +89,12 @@ bool CanvasItemMovable::on_button_press_event(const Glib::RefPtr<Goocanvas::Item
}
m_dragging = true;
+
+ //Holding down shift when pressing the mouse down
+ //means that any selection (decided later) will be a multiple selection.
+ if(event->state & GDK_SHIFT_MASK)
+ m_shift_click = true;
+
return true; // Handled.
break;
}
@@ -156,7 +167,11 @@ bool CanvasItemMovable::on_motion_notify_event(const Glib::RefPtr<Goocanvas::Ite
const bool old_selected = get_selected();
set_selected(true);
if(!old_selected)
- m_signal_selected.emit();
+ {
+ Glib::RefPtr<CanvasItemMovable> refThis(this);
+ refThis->reference();
+ m_signal_selected.emit(refThis, m_shift_click);
+ }
m_signal_moved.emit();
@@ -168,6 +183,8 @@ bool CanvasItemMovable::on_motion_notify_event(const Glib::RefPtr<Goocanvas::Ite
bool CanvasItemMovable::on_button_release_event(const Glib::RefPtr<Goocanvas::Item>& target, GdkEventButton* event)
{
+ //std::cout << G_STRFUNC << ": DEBUG" << std::endl;
+
if(!m_allow_vertical_movement && !m_allow_horizontal_movement)
return false; // Not handled. Let it be handled by an item lower in the z order, or a parent group, if any.
@@ -202,7 +219,9 @@ bool CanvasItemMovable::on_button_release_event(const Glib::RefPtr<Goocanvas::It
//Notify of the selection change, if any:
if(selected != old_selected)
{
- m_signal_selected.emit();
+ Glib::RefPtr<CanvasItemMovable> refThis(this);
+ refThis->reference();
+ m_signal_selected.emit(refThis, m_shift_click);
}
return true;
diff --git a/glom/utility_widgets/canvas/canvas_item_movable.h b/glom/utility_widgets/canvas/canvas_item_movable.h
index 152b0b4..4e7b168 100644
--- a/glom/utility_widgets/canvas/canvas_item_movable.h
+++ b/glom/utility_widgets/canvas/canvas_item_movable.h
@@ -71,9 +71,13 @@ public:
type_signal_show_context signal_show_context();
/** For instance,
- * void on_selected();
+ *
+ * @param item The item (this item) that was selected/deseleted, for convenience.
+ * @param group_select Whether the user selected this while pressing Shift to select multiple items.
+ *
+ * void on_selected(bool group_select);
*/
- typedef sigc::signal<void> type_signal_selected;
+ typedef sigc::signal<void, const Glib::RefPtr<CanvasItemMovable>&, bool> type_signal_selected;
/** This signal is emitted if the user causes the item
* to be selected or deselected. See get_selected().
@@ -144,6 +148,7 @@ protected:
private:
bool m_allow_vertical_movement, m_allow_horizontal_movement;
bool m_selected;
+ bool m_shift_click;
type_signal_moved m_signal_moved;
type_signal_show_context m_signal_show_context;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]