diff options
| author | Geoff Lankow <geoff@darktrojan.net> | 2018-04-13 03:46:26 +0000 |
|---|---|---|
| committer | Marc Jeanmougin <marcjeanmougin@free.fr> | 2018-05-09 12:23:00 +0000 |
| commit | cca246da00beb707a032340f2b2f36e8da093194 (patch) | |
| tree | bd51357f4c9afddb1e2071ced98e71ab4da7a2ce /src | |
| parent | Add buttons to align grids to page (diff) | |
| download | inkscape-cca246da00beb707a032340f2b2f36e8da093194.tar.gz inkscape-cca246da00beb707a032340f2b2f36e8da093194.zip | |
Create stateless alignment selector and use it instead
Diffstat (limited to 'src')
| -rw-r--r-- | src/display/canvas-grid.cpp | 13 | ||||
| -rw-r--r-- | src/display/canvas-grid.h | 6 | ||||
| -rw-r--r-- | src/ui/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/ui/widget/alignment-selector.cpp | 77 | ||||
| -rw-r--r-- | src/ui/widget/alignment-selector.h | 56 |
5 files changed, 144 insertions, 10 deletions
diff --git a/src/display/canvas-grid.cpp b/src/display/canvas-grid.cpp index a81b06aae..6d646f39d 100644 --- a/src/display/canvas-grid.cpp +++ b/src/display/canvas-grid.cpp @@ -319,13 +319,12 @@ CanvasGrid::newWidget() vbox->pack_start(*_rcb_visible, true, true); vbox->pack_start(*_rcb_snap_visible_only, 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)); + _as_alignment = Gtk::manage( new Inkscape::UI::Widget::AlignmentSelector() ); + _as_alignment->on_alignmentClicked().connect(sigc::mem_fun(*this, &CanvasGrid::align_clicked)); 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); + left->pack_start(*_as_alignment, false, false); Gtk::HBox *outer = new Gtk::HBox(); outer->pack_start(*left, true, true); @@ -386,11 +385,11 @@ void CanvasGrid::setOrigin(Geom::Point const &origin_px) repr->setAttribute("originy", os_y.str().c_str()); } -void CanvasGrid::align_changed() +void CanvasGrid::align_clicked(int align) { Geom::Point dimensions = doc->getDimensions(); - dimensions[Geom::X] *= alignment->getHorizontalAlignment() * 0.5; - dimensions[Geom::Y] *= 1 - (alignment->getVerticalAlignment() * 0.5); + dimensions[Geom::X] *= align % 3 * 0.5; + dimensions[Geom::Y] *= 1 - (align / 3 * 0.5); setOrigin(dimensions); } diff --git a/src/display/canvas-grid.h b/src/display/canvas-grid.h index b815aa305..c15cde656 100644 --- a/src/display/canvas-grid.h +++ b/src/display/canvas-grid.h @@ -9,7 +9,7 @@ #define INKSCAPE_CANVAS_GRID_H #include "sp-canvas-item.h" -#include "ui/widget/anchor-selector.h" +#include "ui/widget/alignment-selector.h" #include "ui/widget/registered-widget.h" #include "ui/widget/registry.h" #include "line-snapper.h" @@ -109,7 +109,7 @@ public: bool isVisible() const { return (isEnabled() &&visible); }; bool isEnabled() const; - void align_changed(); + void align_clicked(int align); protected: CanvasGrid(SPNamedView * nv, Inkscape::XML::Node * in_repr, SPDocument *in_doc, GridType type); @@ -132,7 +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; + Inkscape::UI::Widget::AlignmentSelector *_as_alignment; private: CanvasGrid(const CanvasGrid&); diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index 42ecab427..41c640c68 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -120,6 +120,7 @@ set(ui_SRC dialog/save-template-dialog.cpp widget/addtoicon.cpp + widget/alignment-selector.cpp widget/anchor-selector.cpp widget/button.cpp widget/clipmaskicon.cpp @@ -315,6 +316,7 @@ set(ui_SRC tools/zoom-tool.h widget/addtoicon.h + widget/alignment-selector.h widget/anchor-selector.h widget/attr-widget.h widget/button.h diff --git a/src/ui/widget/alignment-selector.cpp b/src/ui/widget/alignment-selector.cpp new file mode 100644 index 000000000..c6c95f097 --- /dev/null +++ b/src/ui/widget/alignment-selector.cpp @@ -0,0 +1,77 @@ +/* + * anchor-selector.cpp + * + * Released under GNU GPL. Read the file 'COPYING' for more information. + */ + +#include "ui/widget/alignment-selector.h" +#include "ui/icon-names.h" + +#include <gtkmm/image.h> + +namespace Inkscape { +namespace UI { +namespace Widget { + +void AlignmentSelector::setupButton(const Glib::ustring& icon, Gtk::Button& button) { + Gtk::Image* buttonIcon = Gtk::manage(new Gtk::Image()); + buttonIcon->set_from_icon_name(icon, Gtk::ICON_SIZE_SMALL_TOOLBAR); + buttonIcon->show(); + + button.set_relief(Gtk::RELIEF_NONE); + button.show(); + button.add(*buttonIcon); + button.set_can_focus(false); +} + +AlignmentSelector::AlignmentSelector() + : _container() +{ + set_halign(Gtk::ALIGN_CENTER); + setupButton(INKSCAPE_ICON("boundingbox_top_left"), _buttons[0]); + setupButton(INKSCAPE_ICON("boundingbox_top"), _buttons[1]); + setupButton(INKSCAPE_ICON("boundingbox_top_right"), _buttons[2]); + setupButton(INKSCAPE_ICON("boundingbox_left"), _buttons[3]); + setupButton(INKSCAPE_ICON("boundingbox_center"), _buttons[4]); + setupButton(INKSCAPE_ICON("boundingbox_right"), _buttons[5]); + setupButton(INKSCAPE_ICON("boundingbox_bottom_left"), _buttons[6]); + setupButton(INKSCAPE_ICON("boundingbox_bottom"), _buttons[7]); + setupButton(INKSCAPE_ICON("boundingbox_bottom_right"), _buttons[8]); + + _container.set_row_homogeneous(); + _container.set_column_homogeneous(true); + + for(int i = 0; i < 9; ++i) { + _buttons[i].signal_clicked().connect( + sigc::bind(sigc::mem_fun(*this, &AlignmentSelector::btn_activated), i)); + + _container.attach(_buttons[i], i % 3, i / 3, 1, 1); + } + + this->add(_container); +} + +AlignmentSelector::~AlignmentSelector() +{ + // TODO Auto-generated destructor stub +} + +void AlignmentSelector::btn_activated(int index) +{ + _alignmentClicked.emit(index); +} + +} // namespace Widget +} // namespace UI +} // namespace Inkscape + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/ui/widget/alignment-selector.h b/src/ui/widget/alignment-selector.h new file mode 100644 index 000000000..43cd100ef --- /dev/null +++ b/src/ui/widget/alignment-selector.h @@ -0,0 +1,56 @@ +/* + * anchor-selector.h + * + * Released under GNU GPL. Read the file 'COPYING' for more information. + */ + +#ifndef ANCHOR_SELECTOR_H_ +#define ANCHOR_SELECTOR_H_ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include <gtkmm/bin.h> +#include <gtkmm/button.h> +#include <gtkmm/grid.h> + +namespace Inkscape { +namespace UI { +namespace Widget { + +class AlignmentSelector : public Gtk::Bin +{ +private: + Gtk::Button _buttons[9]; + Gtk::Grid _container; + + sigc::signal<void, int> _alignmentClicked; + + void setupButton(const Glib::ustring &icon, Gtk::Button &button); + void btn_activated(int index); + +public: + + sigc::signal<void, int> &on_alignmentClicked() { return _alignmentClicked; } + + AlignmentSelector(); + virtual ~AlignmentSelector(); +}; + +} // namespace Widget +} // namespace UI +} // namespace Inkscape + +#endif /* ANCHOR_SELECTOR_H_ */ + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : |
