summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/display/canvas-axonomgrid.cpp84
-rw-r--r--src/display/canvas-grid.cpp110
-rw-r--r--src/display/canvas-grid.h4
3 files changed, 53 insertions, 145 deletions
diff --git a/src/display/canvas-axonomgrid.cpp b/src/display/canvas-axonomgrid.cpp
index 82ef69579..66231b7dd 100644
--- a/src/display/canvas-axonomgrid.cpp
+++ b/src/display/canvas-axonomgrid.cpp
@@ -76,57 +76,6 @@ sp_grid_vline (SPCanvasBuf *buf, gint x, gint ys, gint ye, guint32 rgba)
namespace Inkscape {
-/**
-* A DIRECT COPY-PASTE FROM DOCUMENT-PROPERTIES.CPP TO QUICKLY GET RESULTS
-*
- * Helper function that attachs widgets in a 3xn table. The widgets come in an
- * array that has two entries per table row. The two entries code for four
- * possible cases: (0,0) means insert space in first column; (0, non-0) means
- * widget in columns 2-3; (non-0, 0) means label in columns 1-3; and
- * (non-0, non-0) means two widgets in columns 2 and 3.
-**/
-#define SPACE_SIZE_X 15
-#define SPACE_SIZE_Y 10
-static inline void
-attach_all(Gtk::Grid &table, Gtk::Widget const *const arr[], unsigned size, int start = 0)
-{
- for (unsigned i=0, r=start; i<size/sizeof(Gtk::Widget*); i+=2) {
- if (arr[i] && arr[i+1]) {
- (const_cast<Gtk::Widget&>(*arr[i])).set_hexpand();
- (const_cast<Gtk::Widget&>(*arr[i])).set_valign(Gtk::ALIGN_CENTER);
- table.attach(const_cast<Gtk::Widget&>(*arr[i]), 1, r, 1, 1);
-
- (const_cast<Gtk::Widget&>(*arr[i+1])).set_hexpand();
- (const_cast<Gtk::Widget&>(*arr[i+1])).set_valign(Gtk::ALIGN_CENTER);
- table.attach(const_cast<Gtk::Widget&>(*arr[i+1]), 2, r, 1, 1);
- } else {
- if (arr[i+1]) {
- (const_cast<Gtk::Widget&>(*arr[i+1])).set_hexpand();
- (const_cast<Gtk::Widget&>(*arr[i+1])).set_valign(Gtk::ALIGN_CENTER);
- table.attach(const_cast<Gtk::Widget&>(*arr[i+1]), 1, r, 2, 1);
- } else if (arr[i]) {
- Gtk::Label& label = reinterpret_cast<Gtk::Label&> (const_cast<Gtk::Widget&>(*arr[i]));
-#if GTK_CHECK_VERSION(3,16,0)
- label.set_xalign(0.0);
- label.set_yalign(0.5);
-#else
- label.set_alignment (0.0);
-#endif
- label.set_hexpand();
- label.set_valign(Gtk::ALIGN_CENTER);
- table.attach(label, 0, r, 3, 1);
- } else {
- Gtk::HBox *space = Gtk::manage (new Gtk::HBox);
- space->set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
- space->set_halign(Gtk::ALIGN_CENTER);
- space->set_valign(Gtk::ALIGN_CENTER);
- table.attach(*space, 0, r, 1, 1);
- }
- }
- ++r;
- }
-}
-
CanvasAxonomGrid::CanvasAxonomGrid (SPNamedView * nv, Inkscape::XML::Node * in_repr, SPDocument * in_doc)
: CanvasGrid(nv, in_repr, in_doc, GRID_AXONOMETRIC)
{
@@ -319,7 +268,7 @@ CanvasAxonomGrid::newSpecificWidget()
table->set_row_spacing(2);
table->set_column_spacing(2);
-_wr.setUpdating (true);
+ _wr.setUpdating (true);
_rumg = Gtk::manage( new Inkscape::UI::Widget::RegisteredUnitMenu(
_("Grid _units:"), "units", _wr, repr, doc) );
@@ -340,7 +289,6 @@ _wr.setUpdating (true);
_rcp_gcol = Gtk::manage( new Inkscape::UI::Widget::RegisteredColorPicker(
_("Minor grid line _color:"), _("Minor grid line color"), _("Color of the minor grid lines"),
"color", "opacity", _wr, repr, doc));
-
_rcp_gmcol = Gtk::manage( new Inkscape::UI::Widget::RegisteredColorPicker(
_("Ma_jor grid line color:"), _("Major grid line color"),
_("Color of the major (highlighted) grid lines"),
@@ -358,22 +306,7 @@ _wr.setUpdating (true);
_rsu_sy->setDigits(5);
_rsu_sy->setIncrements(0.1, 1.0);
-_wr.setUpdating (false);
-
- Gtk::Widget const *const widget_array[] = {
- 0, _rumg,
- 0, _rsu_ox,
- 0, _rsu_oy,
- 0, _rsu_sy,
- 0, _rsu_ax,
- 0, _rsu_az,
- _rcp_gcol->_label, _rcp_gcol,
- 0, 0,
- _rcp_gmcol->_label, _rcp_gmcol,
- 0, _rsi,
- };
-
- attach_all (*table, widget_array, sizeof(widget_array));
+ _wr.setUpdating (false);
// set widget values
_rumg->setUnit (gridunit->abbr);
@@ -399,7 +332,18 @@ _wr.setUpdating (false);
_rsu_ox->setProgrammatically = false;
_rsu_oy->setProgrammatically = false;
- return table;
+ Gtk::VBox *right = new Gtk::VBox();
+ right->pack_start(*_rumg);
+ right->pack_start(*_rsu_ox);
+ right->pack_start(*_rsu_oy);
+ right->pack_start(*_rsu_sy);
+ right->pack_start(*_rsu_ax);
+ right->pack_start(*_rsu_az);
+ right->pack_start(*_rcp_gcol);
+ right->pack_start(*_rcp_gmcol);
+ right->pack_start(*_rsi);
+
+ return right;
}
diff --git a/src/display/canvas-grid.cpp b/src/display/canvas-grid.cpp
index a5cbcdf39..a81b06aae 100644
--- a/src/display/canvas-grid.cpp
+++ b/src/display/canvas-grid.cpp
@@ -318,13 +318,24 @@ CanvasGrid::newWidget()
vbox->pack_start(*_rcb_enabled, true, true);
vbox->pack_start(*_rcb_visible, true, true);
vbox->pack_start(*_rcb_snap_visible_only, true, true);
- Gtk::Widget * gridwdg = newSpecificWidget();
- vbox->pack_start(*gridwdg, true, true);
+
+ alignment = Gtk::manage( new Inkscape::UI::Widget::AnchorSelector() );
+ alignment->setAlignment(0, 2);
+ alignment->on_selectionChanged().connect(sigc::mem_fun(*this, &CanvasGrid::align_changed));
+
+ Gtk::VBox *left = new Gtk::VBox();
+ left->pack_start(*Gtk::manage(new Gtk::Label(_("Align to page:"))), false, false);
+ left->pack_start(*alignment, false, false);
+
+ Gtk::HBox *outer = new Gtk::HBox();
+ outer->pack_start(*left, true, true);
+ outer->pack_start(*newSpecificWidget(), false, false);
+ vbox->pack_start(*outer, true, true);
std::list<Gtk::Widget*> slaves;
slaves.push_back(_rcb_visible);
slaves.push_back(_rcb_snap_visible_only);
- slaves.push_back(gridwdg);
+ slaves.push_back(outer);
_rcb_enabled->setSlaveWidgets(slaves);
// set widget values
@@ -375,61 +386,18 @@ void CanvasGrid::setOrigin(Geom::Point const &origin_px)
repr->setAttribute("originy", os_y.str().c_str());
}
+void CanvasGrid::align_changed()
+{
+ Geom::Point dimensions = doc->getDimensions();
+ dimensions[Geom::X] *= alignment->getHorizontalAlignment() * 0.5;
+ dimensions[Geom::Y] *= 1 - (alignment->getVerticalAlignment() * 0.5);
+ setOrigin(dimensions);
+}
-// ##########################################################
-// CanvasXYGrid
-/**
-* "attach_all" function
-* A DIRECT COPY-PASTE FROM DOCUMENT-PROPERTIES.CPP TO QUICKLY GET RESULTS
-*
- * Helper function that attachs widgets in a 3xn table. The widgets come in an
- * array that has two entries per table row. The two entries code for four
- * possible cases: (0,0) means insert space in first column; (0, non-0) means
- * widget in columns 2-3; (non-0, 0) means label in columns 1-3; and
- * (non-0, non-0) means two widgets in columns 2 and 3.
-**/
-#define SPACE_SIZE_X 15
-#define SPACE_SIZE_Y 10
-static inline void attach_all(Gtk::Grid &table, Gtk::Widget const *const arr[], unsigned size, int start = 0)
-{
- for (unsigned i=0, r=start; i<size/sizeof(Gtk::Widget*); i+=2) {
- if (arr[i] && arr[i+1]) {
- (const_cast<Gtk::Widget&>(*arr[i])).set_hexpand();
- (const_cast<Gtk::Widget&>(*arr[i])).set_valign(Gtk::ALIGN_CENTER);
- table.attach(const_cast<Gtk::Widget&>(*arr[i]), 1, r, 1, 1);
-
- (const_cast<Gtk::Widget&>(*arr[i+1])).set_hexpand();
- (const_cast<Gtk::Widget&>(*arr[i+1])).set_valign(Gtk::ALIGN_CENTER);
- table.attach(const_cast<Gtk::Widget&>(*arr[i+1]), 2, r, 1, 1);
- } else {
- if (arr[i+1]) {
- (const_cast<Gtk::Widget&>(*arr[i+1])).set_hexpand();
- (const_cast<Gtk::Widget&>(*arr[i+1])).set_valign(Gtk::ALIGN_CENTER);
- table.attach(const_cast<Gtk::Widget&>(*arr[i+1]), 1, r, 2, 1);
- } else if (arr[i]) {
- Gtk::Label& label = reinterpret_cast<Gtk::Label&> (const_cast<Gtk::Widget&>(*arr[i]));
-#if GTK_CHECK_VERSION(3,16,0)
- label.set_xalign(0.0);
- label.set_yalign(0.5);
-#else
- label.set_alignment (0.0);
-#endif
- label.set_hexpand();
- label.set_valign(Gtk::ALIGN_CENTER);
- table.attach(label, 0, r, 3, 1);
- } else {
- Gtk::HBox *space = Gtk::manage (new Gtk::HBox);
- space->set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
- space->set_halign(Gtk::ALIGN_CENTER);
- space->set_valign(Gtk::ALIGN_CENTER);
- table.attach(*space, 0, r, 1, 1);
- }
- }
- ++r;
- }
-}
+// ##########################################################
+// CanvasXYGrid
CanvasXYGrid::CanvasXYGrid (SPNamedView * nv, Inkscape::XML::Node * in_repr, SPDocument * in_doc)
: CanvasGrid(nv, in_repr, in_doc, GRID_RECTANGULAR)
@@ -667,10 +635,6 @@ CanvasXYGrid::onReprAttrChanged(Inkscape::XML::Node */*repr*/, gchar const */*ke
Gtk::Widget *
CanvasXYGrid::newSpecificWidget()
{
- auto table = Gtk::manage( new Gtk::Grid() );
- table->set_row_spacing(2);
- table->set_column_spacing(2);
-
_rumg = Gtk::manage( new Inkscape::UI::Widget::RegisteredUnitMenu(
_("Grid _units:"), "units", _wr, repr, doc) );
_rsu_ox = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalarUnit(
@@ -716,21 +680,6 @@ CanvasXYGrid::newSpecificWidget()
_("_Show dots instead of lines"), _("If set, displays dots at gridpoints instead of gridlines"),
"dotted", _wr, false, repr, doc) );
- Gtk::Widget const *const widget_array[] = {
- 0, _rumg,
- 0, _rsu_ox,
- 0, _rsu_oy,
- 0, _rsu_sx,
- 0, _rsu_sy,
- _rcp_gcol->_label, _rcp_gcol,
- 0, 0,
- _rcp_gmcol->_label, _rcp_gmcol,
- 0, _rsi,
- 0, _rcb_dotted,
- };
-
- attach_all (*table, widget_array, sizeof(widget_array));
-
// set widget values
_rumg->setUnit (gridunit->abbr);
@@ -761,7 +710,18 @@ CanvasXYGrid::newSpecificWidget()
_rsu_sx->setProgrammatically = false;
_rsu_sy->setProgrammatically = false;
- return table;
+ Gtk::VBox *right = new Gtk::VBox();
+ right->pack_start(*_rumg);
+ right->pack_start(*_rsu_ox);
+ right->pack_start(*_rsu_oy);
+ right->pack_start(*_rsu_sx);
+ right->pack_start(*_rsu_sy);
+ right->pack_start(*_rcp_gcol);
+ right->pack_start(*_rcp_gmcol);
+ right->pack_start(*_rsi);
+ right->pack_start(*_rcb_dotted);
+
+ return right;
}
diff --git a/src/display/canvas-grid.h b/src/display/canvas-grid.h
index 1b21c6984..b815aa305 100644
--- a/src/display/canvas-grid.h
+++ b/src/display/canvas-grid.h
@@ -9,6 +9,7 @@
#define INKSCAPE_CANVAS_GRID_H
#include "sp-canvas-item.h"
+#include "ui/widget/anchor-selector.h"
#include "ui/widget/registered-widget.h"
#include "ui/widget/registry.h"
#include "line-snapper.h"
@@ -108,6 +109,8 @@ public:
bool isVisible() const { return (isEnabled() &&visible); };
bool isEnabled() const;
+ void align_changed();
+
protected:
CanvasGrid(SPNamedView * nv, Inkscape::XML::Node * in_repr, SPDocument *in_doc, GridType type);
@@ -129,6 +132,7 @@ protected:
Inkscape::UI::Widget::RegisteredCheckButton *_rcb_enabled;
Inkscape::UI::Widget::RegisteredCheckButton *_rcb_snap_visible_only;
Inkscape::UI::Widget::RegisteredCheckButton *_rcb_visible;
+ Inkscape::UI::Widget::AnchorSelector *alignment;
private:
CanvasGrid(const CanvasGrid&);