[glom] Print Layout: Allow moving of multiple items via x and y numbers.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] Print Layout: Allow moving of multiple items via x and y numbers.
- Date: Mon, 8 Aug 2011 10:29:33 +0000 (UTC)
commit fc9f12f084b33780a4890d1d5cf87ad02637dfc7
Author: Murray Cumming <murrayc murrayc com>
Date: Mon Aug 8 00:34:55 2011 +0200
Print Layout: Allow moving of multiple items via x and y numbers.
* glom/mode_design/print_layouts/window_print_layout_edit.[h|cc]:
on_canvas_selection_changed(): Move the calculation of the group
dimensions into get_dimensions_of_multiple_selected_items().
on_spinbutton_x(), on_spinbutton_y(): Use the new method to get the
old dimensions, so we can calculate the offset and then apply it to
all items, moving them together.
ChangeLog | 11 ++
.../print_layouts/window_print_layout_edit.cc | 139 ++++++++++++++------
.../print_layouts/window_print_layout_edit.h | 1 +
3 files changed, 110 insertions(+), 41 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 0fa7d0f..345fc3f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
2011-08-08 Murray Cumming <murrayc murrayc com>
+ Print Layout: Allow moving of multiple items via x and y numbers.
+
+ * glom/mode_design/print_layouts/window_print_layout_edit.[h|cc]:
+ on_canvas_selection_changed(): Move the calculation of the group
+ dimensions into get_dimensions_of_multiple_selected_items().
+ on_spinbutton_x(), on_spinbutton_y(): Use the new method to get the
+ old dimensions, so we can calculate the offset and then apply it to
+ all items, moving them together.
+
+2011-08-08 Murray Cumming <murrayc murrayc com>
+
Print Layout: Snap to grid when dragging items from the toolbar.
* glom/utility_widgets/canvas/canvas_group_resizable.h:
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 e8f05a0..4fe934d 100644
--- a/glom/mode_design/print_layouts/window_print_layout_edit.cc
+++ b/glom/mode_design/print_layouts/window_print_layout_edit.cc
@@ -1027,39 +1027,21 @@ bool Window_PrintLayout_Edit::on_configure_event(GdkEventConfigure* event)
return result;
}
-void Window_PrintLayout_Edit::on_canvas_selection_changed()
+void Window_PrintLayout_Edit::get_dimensions_of_multiple_selected_items(double& x, double& y, double& width, double& height)
{
- Canvas_PrintLayout::type_vec_items items = m_canvas.get_selected_items();
-
- //Forget about any previously selected items:
- m_layout_items_selected.clear();
- for(type_vec_connections::iterator iter = m_connections_items_selected_moved.begin();
- iter != m_connections_items_selected_moved.end(); ++iter)
- {
- iter->disconnect();
- }
- m_connections_items_selected_moved.clear();
-
-
- //Get the selected items, and their dimensions as a group:
- double x = 0;
- double y = 0;
+ //Get the selected items, and their dimensions as a group:
+ x = 0;
+ y = 0;
double x2 = 0;
double y2 = 0;
bool first = true;
- for(Canvas_PrintLayout::type_vec_items::const_iterator iter = items.begin();
- iter != items.end(); ++iter)
+ for(type_vec_canvas_items::iterator iter = m_layout_items_selected.begin();
+ iter != m_layout_items_selected.end(); ++iter)
{
Glib::RefPtr<CanvasLayoutItem> item = Glib::RefPtr<CanvasLayoutItem>::cast_dynamic(*iter);
if(!item)
continue;
- //Cache the selected items and handle their signal_moved signals:
- m_layout_items_selected.push_back(item);
- m_connections_items_selected_moved.push_back(
- item->signal_moved().connect(
- sigc::mem_fun(*this, &Window_PrintLayout_Edit::on_selected_item_moved)));
-
//Get the position:
double item_x = 0;
double item_y = 0;
@@ -1086,8 +1068,43 @@ void Window_PrintLayout_Edit::on_canvas_selection_changed()
first = false;
}
- const double width = x2 - x;
- const double height = y2 - y;
+ width = x2 - x;
+ height = y2 - y;
+}
+
+void Window_PrintLayout_Edit::on_canvas_selection_changed()
+{
+ Canvas_PrintLayout::type_vec_items items = m_canvas.get_selected_items();
+
+ //Forget about any previously selected items:
+ m_layout_items_selected.clear();
+ for(type_vec_connections::iterator iter = m_connections_items_selected_moved.begin();
+ iter != m_connections_items_selected_moved.end(); ++iter)
+ {
+ iter->disconnect();
+ }
+ m_connections_items_selected_moved.clear();
+
+
+ for(Canvas_PrintLayout::type_vec_items::const_iterator iter = items.begin();
+ iter != items.end(); ++iter)
+ {
+ Glib::RefPtr<CanvasLayoutItem> item = Glib::RefPtr<CanvasLayoutItem>::cast_dynamic(*iter);
+ if(!item)
+ continue;
+
+ //Cache the selected items and handle their signal_moved signals:
+ m_layout_items_selected.push_back(item);
+ m_connections_items_selected_moved.push_back(
+ item->signal_moved().connect(
+ sigc::mem_fun(*this, &Window_PrintLayout_Edit::on_selected_item_moved)));
+ }
+
+ double x = 0;
+ double y = 0;
+ double width = 0;
+ double height = 0;
+ get_dimensions_of_multiple_selected_items(x, y, width, height);
//Update the SpinButton values,
//but don't respond to the SpinButton changes that we cause programatically:
@@ -1103,9 +1120,17 @@ void Window_PrintLayout_Edit::on_canvas_selection_changed()
//or if there are more than 1.
//TODO: Let the user resize groups of items.
const bool one_selected = (m_layout_items_selected.size() == 1);
- m_box_item_position->set_sensitive(one_selected);
-
const bool some_selected = !m_layout_items_selected.empty();
+
+ //Allow x/y editing via the numbers for multiple items,
+ //but not width/height for multiple items (TODO: Stretch them in that case?)
+ //and only allow any editing when at least one item is selected:
+ m_box_item_position->set_sensitive(some_selected);
+ m_spinbutton_x->set_sensitive(some_selected);
+ m_spinbutton_y->set_sensitive(some_selected);
+ m_spinbutton_width->set_sensitive(one_selected);
+ m_spinbutton_height->set_sensitive(one_selected);
+
if(m_action_edit_cut)
m_action_edit_cut->set_sensitive(some_selected);
@@ -1144,15 +1169,31 @@ void Window_PrintLayout_Edit::on_spinbutton_x()
if(m_layout_items_selected.empty())
return;
- Glib::RefPtr<CanvasLayoutItem> item = m_layout_items_selected[0];
-
double x = 0;
double y = 0;
- item->get_xy(x, y);
+ double width = 0;
+ double height = 0;
+ get_dimensions_of_multiple_selected_items(x, y, width, height);
+
+ //Discover the offset:
+ const double offset_x = m_spinbutton_x->get_value() - x;
+
+ //Apply the offset to all items:
+ for(type_vec_canvas_items::iterator iter = m_layout_items_selected.begin();
+ iter != m_layout_items_selected.end(); ++iter)
+ {
+ Glib::RefPtr<CanvasLayoutItem> item = *iter;
+ if(!item)
+ continue;
+
+ double item_x = 0;
+ double item_y = 0;
+ item->get_xy(item_x, item_y);
- item->set_xy(
- m_spinbutton_x->get_value(),
- y);
+ item->set_xy(
+ item_x + offset_x,
+ item_y);
+ }
}
void Window_PrintLayout_Edit::on_spinbutton_y()
@@ -1163,15 +1204,31 @@ void Window_PrintLayout_Edit::on_spinbutton_y()
if(m_layout_items_selected.empty())
return;
- Glib::RefPtr<CanvasLayoutItem> item = m_layout_items_selected[0];
-
- double x = 0;
+ double x = 0;
double y = 0;
- item->get_xy(x, y);
+ double width = 0;
+ double height = 0;
+ get_dimensions_of_multiple_selected_items(x, y, width, height);
+
+ //Discover the offset:
+ const double offset_y = m_spinbutton_y->get_value() - y;
- item->set_xy(
- x,
- m_spinbutton_y->get_value());
+ //Apply the offset to all items:
+ for(type_vec_canvas_items::iterator iter = m_layout_items_selected.begin();
+ iter != m_layout_items_selected.end(); ++iter)
+ {
+ Glib::RefPtr<CanvasLayoutItem> item = *iter;
+ if(!item)
+ continue;
+
+ double item_x = 0;
+ double item_y = 0;
+ item->get_xy(item_x, item_y);
+
+ item->set_xy(
+ item_x,
+ item_y + offset_y);
+ }
}
void Window_PrintLayout_Edit::on_spinbutton_width()
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 e0fe27a..2c65ea3 100644
--- a/glom/mode_design/print_layouts/window_print_layout_edit.h
+++ b/glom/mode_design/print_layouts/window_print_layout_edit.h
@@ -116,6 +116,7 @@ private:
void set_default_position(const sharedptr<LayoutItem>& item);
void canvas_convert_from_drag_pixels(double& x, double& y) const;
+ void get_dimensions_of_multiple_selected_items(double& x, double& y, double& width, double& height);
//Box_DB_Table_Definition* m_box;
Glib::ustring m_name_original;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]