[glom] Canvas_PrintLayout: Update position numbers when moving items.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] Canvas_PrintLayout: Update position numbers when moving items.
- Date: Sun, 7 Aug 2011 07:14:39 +0000 (UTC)
commit 4be4471cb0c06b6f9e72f291538aa021da0622d7
Author: Murray Cumming <murrayc murrayc com>
Date: Sat Aug 6 21:05:11 2011 +0200
Canvas_PrintLayout: Update position numbers when moving items.
* glom/mode_design/print_layouts/window_print_layout_edit.[h|cc]:
on_canvas_selection_changed(): Connect to the item's signal_moved,
so we can update the spinbuttons during the move.
on_spinbutton_*(): Ignore the spinbutton signals while we are setting
them programatically, to avoid an endless loop.
* glom/utility_widgets/canvas/canvas_item_movable.cc:
set_selected(): Emit the signal here if it has changed, rather than
always doing it after the call.
on_motion_notify_event(): Mark the item as selected whenever it is
moved, therefore emitting the signal.
ChangeLog | 17 +++++++++-
.../print_layouts/window_print_layout_edit.cc | 33 ++++++++++++++++++++
.../print_layouts/window_print_layout_edit.h | 3 ++
glom/utility_widgets/canvas/canvas_item_movable.cc | 21 ++++++++-----
4 files changed, 65 insertions(+), 9 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 323b365..ceaece2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,8 +1,23 @@
2011-08-06 Murray Cumming <murrayc murrayc com>
+ Canvas_PrintLayout: Update position numbers when moving items.
+
+ * glom/mode_design/print_layouts/window_print_layout_edit.[h|cc]:
+ on_canvas_selection_changed(): Connect to the item's signal_moved,
+ so we can update the spinbuttons during the move.
+ on_spinbutton_*(): Ignore the spinbutton signals while we are setting
+ them programatically, to avoid an endless loop.
+ * glom/utility_widgets/canvas/canvas_item_movable.cc:
+ set_selected(): Emit the signal here if it has changed, rather than
+ always doing it after the call.
+ on_motion_notify_event(): Mark the item as selected whenever it is
+ moved, therefore emitting the signal.
+
+2011-08-06 Murray Cumming <murrayc murrayc com>
+
Canvas_PrintLayout: Fix typo to pass the item by reference.
- * glom/print_layout/canvas_print_layout.[h|cc]:
+ * glom/print_layout/canvas_print_layout.[h|cc]:
add_canvas_layout_item(): Add a missing & to the parameter.
2011-08-06 Murray Cumming <murrayc murrayc com>
diff --git a/glom/mode_design/print_layouts/window_print_layout_edit.cc b/glom/mode_design/print_layouts/window_print_layout_edit.cc
index 9971cd3..082c67b 100644
--- a/glom/mode_design/print_layouts/window_print_layout_edit.cc
+++ b/glom/mode_design/print_layouts/window_print_layout_edit.cc
@@ -49,6 +49,7 @@ Window_PrintLayout_Edit::Window_PrintLayout_Edit(BaseObjectType* cobject, const
m_spinbutton_y(0),
m_spinbutton_width(0),
m_spinbutton_height(0),
+ m_ignore_spinbutton_signals(false),
m_drag_preview_requested(false),
m_vruler(0),
m_hruler(0),
@@ -1043,17 +1044,31 @@ void Window_PrintLayout_Edit::on_canvas_selection_changed()
const bool one_selected = (items.size() == 1);
if(one_selected)
+ {
m_layout_item_selected = Glib::RefPtr<CanvasLayoutItem>::cast_dynamic(items[0]);
+ connection_item_selected_moved.disconnect();
+ connection_item_selected_moved =
+ m_layout_item_selected->signal_moved().connect(
+ sigc::mem_fun(*this, &Window_PrintLayout_Edit::on_selected_item_moved));
+ }
else
+ {
m_layout_item_selected.reset();
+ connection_item_selected_moved.disconnect();
+ }
const double width = x2 - x;
const double height = y2 - y;
+ //Update the SpinButton values,
+ //but don't respond to the SpinButton changes that we cause programatically:
+ const bool old_ignore = m_ignore_spinbutton_signals;
+ m_ignore_spinbutton_signals = true;
m_spinbutton_x->set_value(x);
m_spinbutton_y->set_value(y);
m_spinbutton_width->set_value(width);
m_spinbutton_height->set_value(height);
+ m_ignore_spinbutton_signals = old_ignore;
//Disable the spinbuttons if there are no items selected,
//or if there are more than 1.
@@ -1070,8 +1085,17 @@ void Window_PrintLayout_Edit::on_canvas_selection_changed()
m_action_edit_delete->set_sensitive(one_selected);
}
+void Window_PrintLayout_Edit::on_selected_item_moved()
+{
+ //Show the new positions in the spinbuttons:
+ on_canvas_selection_changed();
+}
+
void Window_PrintLayout_Edit::on_spinbutton_x()
{
+ if(m_ignore_spinbutton_signals)
+ return;
+
if(!m_layout_item_selected)
return;
@@ -1086,6 +1110,9 @@ void Window_PrintLayout_Edit::on_spinbutton_x()
void Window_PrintLayout_Edit::on_spinbutton_y()
{
+ if(m_ignore_spinbutton_signals)
+ return;
+
if(!m_layout_item_selected)
return;
@@ -1100,6 +1127,9 @@ void Window_PrintLayout_Edit::on_spinbutton_y()
void Window_PrintLayout_Edit::on_spinbutton_width()
{
+ if(m_ignore_spinbutton_signals)
+ return;
+
if(!m_layout_item_selected)
return;
@@ -1114,6 +1144,9 @@ void Window_PrintLayout_Edit::on_spinbutton_width()
void Window_PrintLayout_Edit::on_spinbutton_height()
{
+ if(m_ignore_spinbutton_signals)
+ return;
+
if(!m_layout_item_selected)
return;
diff --git a/glom/mode_design/print_layouts/window_print_layout_edit.h b/glom/mode_design/print_layouts/window_print_layout_edit.h
index 21b22dd..245ce0b 100644
--- a/glom/mode_design/print_layouts/window_print_layout_edit.h
+++ b/glom/mode_design/print_layouts/window_print_layout_edit.h
@@ -96,6 +96,7 @@ private:
void on_canvas_drag_leave(const Glib::RefPtr<Gdk::DragContext>& drag_context, guint timestamp);
void on_canvas_selection_changed();
+ void on_selected_item_moved();
void on_spinbutton_x();
void on_spinbutton_y();
@@ -141,6 +142,7 @@ private:
Gtk::SpinButton* m_spinbutton_y;
Gtk::SpinButton* m_spinbutton_width;
Gtk::SpinButton* m_spinbutton_height;
+ bool m_ignore_spinbutton_signals;
//A preview of the item being dragged onto the canvas:
bool m_drag_preview_requested;
@@ -149,6 +151,7 @@ private:
//A cache of the selected item,
//to avoid repeatedly requesting it:
Glib::RefPtr<CanvasLayoutItem> m_layout_item_selected;
+ sigc::connection connection_item_selected_moved;
//A copied item to be pasted later:
sharedptr<LayoutItem> m_layout_item_to_paste;
diff --git a/glom/utility_widgets/canvas/canvas_item_movable.cc b/glom/utility_widgets/canvas/canvas_item_movable.cc
index f288877..2e980ca 100644
--- a/glom/utility_widgets/canvas/canvas_item_movable.cc
+++ b/glom/utility_widgets/canvas/canvas_item_movable.cc
@@ -150,6 +150,11 @@ bool CanvasItemMovable::on_motion_notify_event(const Glib::RefPtr<Goocanvas::Ite
set_xy(new_x, new_y);
+ // A click with a move should always select:
+ // We emit this before signal_moved,
+ // so that its signal handler can know about the selection.
+ set_selected(true);
+
m_signal_moved.emit();
return true; //We handled this event.
@@ -188,15 +193,8 @@ bool CanvasItemMovable::on_button_release_event(const Glib::RefPtr<Goocanvas::It
}
//This will also ask derived classes to indicate it visually:
-
set_selected(selected);
- //Notify of the selection change, if any:
- if(selected != old_selected)
- {
- m_signal_selected.emit();
- }
-
return true;
}
@@ -409,8 +407,15 @@ Glib::RefPtr<const Goocanvas::Item> CanvasItemMovable::cast_const_to_item(const
void CanvasItemMovable::set_selected(bool selected)
{
+ const bool old_selected = m_selected;
m_selected = selected;
- show_selected(); //Let derived classes indicate it visually,
+ show_selected(); //Let derived classes indicate it visually.
+
+ //Notify of the selection change, if any:
+ if(m_selected != old_selected)
+ {
+ m_signal_selected.emit();
+ }
}
bool CanvasItemMovable::get_selected() const
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]