summaryrefslogtreecommitdiffstats
path: root/src/ui/widget
diff options
context:
space:
mode:
authorMarc Jeanmougin <marc@jeanmougin.fr>2017-07-28 22:05:28 +0000
committerMarc Jeanmougin <marc@jeanmougin.fr>2017-07-28 22:05:28 +0000
commit3eb67b103fe69a3b42ec16d085a2cb3a58a596b7 (patch)
tree986b33696b0a7f229589b85bd13e6fdb2cbd022a /src/ui/widget
parentfix typo, update CI (diff)
parentShow a control point for the center of a spiral (diff)
downloadinkscape-3eb67b103fe69a3b42ec16d085a2cb3a58a596b7.tar.gz
inkscape-3eb67b103fe69a3b42ec16d085a2cb3a58a596b7.zip
Merge gitlab.com:inkscape/inkscape
Diffstat (limited to 'src/ui/widget')
-rw-r--r--src/ui/widget/ink-select-one-action.cpp239
-rw-r--r--src/ui/widget/ink-select-one-action.h131
-rw-r--r--src/ui/widget/page-sizer.cpp6
-rw-r--r--src/ui/widget/page-sizer.h1
4 files changed, 371 insertions, 6 deletions
diff --git a/src/ui/widget/ink-select-one-action.cpp b/src/ui/widget/ink-select-one-action.cpp
new file mode 100644
index 000000000..40bafecc2
--- /dev/null
+++ b/src/ui/widget/ink-select-one-action.cpp
@@ -0,0 +1,239 @@
+/*
+ * Authors:
+ * Tavmjong Bah <tavmjong@free.fr>
+ *
+ * Copyright (C) 2017 Tavmjong Bah
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+
+/** \file
+ An action (menu/toolbar item) that allows selecting one choice out of many.
+
+ The choices may be displayed as:
+
+ 1. A group of items in a toolbar with labels and/or icons.
+ 2. As a drop-down menu with a labels and/or icons.
+*/
+
+#include "ink-select-one-action.h"
+
+#include <iostream>
+#include <gtkmm/toolitem.h>
+#include <gtkmm/menuitem.h>
+#include <gtkmm/radioaction.h>
+#include <gtkmm/radiomenuitem.h>
+#include <gtkmm/combobox.h>
+#include <gtkmm/menu.h>
+#include <gtkmm/box.h>
+#include <gtkmm/label.h>
+#include <gtkmm/image.h>
+
+InkSelectOneAction* InkSelectOneAction::create(const Glib::ustring &name,
+ const Glib::ustring &label,
+ const Glib::ustring &tooltip,
+ const Glib::ustring &stock_id,
+ Glib::RefPtr<Gtk::ListStore> store ) {
+
+ return new InkSelectOneAction(name, label, tooltip, stock_id, store);
+}
+
+InkSelectOneAction::InkSelectOneAction (const Glib::ustring &name,
+ const Glib::ustring &label,
+ const Glib::ustring &tooltip,
+ const Glib::ustring &stock_id,
+ Glib::RefPtr<Gtk::ListStore> store ) :
+ Gtk::Action(name, stock_id, label, tooltip),
+ _name( name ),
+ _label( label ),
+ _tooltip( tooltip ),
+ _stock_id( stock_id ),
+ _store (store),
+ _use_radio (true),
+ _use_label (true),
+ _use_icon (true),
+ _icon_size ( Gtk::ICON_SIZE_LARGE_TOOLBAR ),
+ _combobox (nullptr),
+ _radioaction (nullptr),
+ _menuitem (nullptr)
+{
+}
+
+void InkSelectOneAction::set_active (gint active) {
+
+ if (_active != active) {
+
+ _active = active;
+
+ if (_combobox) {
+ _combobox->set_active (active);
+ }
+
+ if (_radioaction) {
+ _radioaction->set_current_value (active);
+ }
+
+ if (active < _radiomenuitems.size()) {
+ _radiomenuitems[ active ]->set_active();
+ }
+ }
+}
+
+Gtk::Widget* InkSelectOneAction::create_menu_item_vfunc() {
+
+ if (_menuitem == nullptr) {
+
+ _menuitem = Gtk::manage (new Gtk::MenuItem);
+ Gtk::Menu *menu = Gtk::manage (new Gtk::Menu);
+
+ Gtk::RadioButton::Group group;
+ int index = 0;
+ auto children = _store->children();
+ for (auto iter = children.begin(); iter != children.end(); ++iter) {
+ Gtk::TreeModel::Row row = *iter;
+
+ InkSelectOneActionColumns columns;
+ Glib::ustring label = row[columns.col_label ];
+ Glib::ustring icon = row[columns.col_icon ];
+ Glib::ustring tooltip = row[columns.col_tooltip ];
+ bool sensitive = row[columns.col_sensitive ];
+
+ Gtk::RadioMenuItem* button = Gtk::manage(new Gtk::RadioMenuItem(group));
+ button->set_label (label);
+ button->set_tooltip_text( tooltip );
+ button->set_sensitive( sensitive );
+
+ button->signal_toggled().connect( sigc::bind<0>(
+ sigc::mem_fun(*this, &InkSelectOneAction::on_toggled_radiomenu), index++)
+ );
+
+ menu->add (*button);
+
+ _radiomenuitems.push_back( button );
+ }
+
+ if ( _active < _radiomenuitems.size()) {
+ _radiomenuitems[ _active ]->set_active();
+ }
+
+ _menuitem->set_submenu (*menu);
+ _menuitem->show_all();
+ }
+
+ return _menuitem;
+}
+
+
+Gtk::Widget* InkSelectOneAction::create_tool_item_vfunc() {
+ // Either a group of radio actions or a combobox with labels and/or icons.
+
+ Gtk::ToolItem *tool_item = new Gtk::ToolItem;
+
+ if (_use_radio) {
+ // Create radio actions (note: these are not radio buttons).
+
+ Gtk::Box* box = Gtk::manage(new Gtk::Box());
+ tool_item->add (*box);
+
+ Gtk::RadioAction::Group group;
+ int index = 0;
+ auto children = _store->children();
+ for (auto iter = children.begin(); iter != children.end(); ++iter) {
+ Gtk::TreeModel::Row row = *iter;
+
+ InkSelectOneActionColumns columns;
+ Glib::ustring label = row[columns.col_label ];
+ Glib::ustring icon = row[columns.col_icon ];
+ Glib::ustring tooltip = row[columns.col_tooltip ];
+ bool sensitive = row[columns.col_sensitive];
+ Glib::RefPtr<Gtk::RadioAction> action;
+ if (_use_icon) {
+ action =
+ Gtk::RadioAction::create_with_icon_name (group, "Anonymous", icon, label, tooltip);
+ } else {
+ action =
+ Gtk::RadioAction::create (group, "Anonymous", label, tooltip);
+ }
+ action->set_property( "value", index++ ); // To identify uniquely each radioaction.
+ action->set_sensitive( sensitive );
+
+ // Save first action for use in setting/getting active value.
+ if (!_radioaction) {
+ _radioaction = action;
+ }
+
+ Gtk::ToolItem* item = action->create_tool_item();
+ box->add (*item);
+ }
+
+ _radioaction->signal_changed().connect( sigc::mem_fun(*this, &InkSelectOneAction::on_changed_radioaction));
+
+ } else {
+ // Create combobox
+
+ _combobox = Gtk::manage (new Gtk::ComboBox());
+ _combobox->set_model(_store);
+
+ InkSelectOneActionColumns columns;
+ if (_use_icon ) {
+ Gtk::CellRendererPixbuf *renderer = new Gtk::CellRendererPixbuf;
+ renderer->set_property ("stock_size", Gtk::ICON_SIZE_LARGE_TOOLBAR);
+ _combobox->pack_start (*renderer, false);
+ _combobox->add_attribute (*renderer, "icon_name", columns.col_icon );
+ }
+
+ if (_use_label) {
+ _combobox->pack_start(columns.col_label);
+ }
+
+ std::vector<Gtk::CellRenderer*> cells = _combobox->get_cells();
+ for (auto iter = cells.begin(); iter!= cells.end(); ++iter) {
+ _combobox->add_attribute (**iter, "sensitive", columns.col_sensitive);
+ }
+
+ _combobox->set_active (_active);
+
+ _combobox->signal_changed().connect(
+ sigc::mem_fun(*this, &InkSelectOneAction::on_changed_combobox));
+
+ tool_item->add (*_combobox);
+ }
+
+ tool_item->show_all();
+
+ return tool_item;
+}
+
+void InkSelectOneAction::on_changed_combobox() {
+
+ set_active( _combobox->get_active_row_number() );
+ _changed.emit (_active);
+}
+
+void InkSelectOneAction::on_changed_radioaction(const Glib::RefPtr<Gtk::RadioAction>& current) {
+
+ set_active( current->get_current_value() );
+ _changed.emit (_active);
+}
+
+void InkSelectOneAction::on_toggled_radiomenu(int n) {
+
+ // toggled emitted twice, first for button toggled off, second for button toggled on.
+ // We want to react only to the button turned on.
+ if ( n < _radiomenuitems.size() &&_radiomenuitems[ n ]->get_active()) {
+ set_active ( n );
+ _changed.emit (_active);
+ }
+}
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
diff --git a/src/ui/widget/ink-select-one-action.h b/src/ui/widget/ink-select-one-action.h
new file mode 100644
index 000000000..194ca8027
--- /dev/null
+++ b/src/ui/widget/ink-select-one-action.h
@@ -0,0 +1,131 @@
+#ifndef SEEN_INK_SELECT_ONE_ACTION
+#define SEEN_INK_SELECT_ONE_ACTION
+
+/*
+ * Authors:
+ * Tavmjong Bah <tavmjong@free.fr>
+ *
+ * Copyright (C) 2017 Tavmjong Bah
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+/**
+ An action (menu/toolbar item) that allows selecting one choice out of many.
+
+ The choices may be displayed as:
+
+ 1. A group of items in a toolbar with labels and/or icons.
+ 2. As a drop-down menu with a labels and/or icons.
+*/
+
+#include <gtkmm/action.h>
+#include <gtkmm/liststore.h>
+#include <sigc++/sigc++.h>
+#include <vector>
+
+namespace Gtk {
+class ComboBox;
+class RadioAction;
+class MenuItem;
+class RadioMenuItem;
+}
+
+class InkSelectOneActionColumns : public Gtk::TreeModel::ColumnRecord {
+
+public:
+ InkSelectOneActionColumns() {
+ add (col_label);
+ add (col_icon);
+ add (col_tooltip);
+ add (col_sensitive);
+ }
+ Gtk::TreeModelColumn<Glib::ustring> col_label;
+ Gtk::TreeModelColumn<Glib::ustring> col_icon;
+ Gtk::TreeModelColumn<Glib::ustring> col_tooltip;
+ Gtk::TreeModelColumn<bool> col_sensitive;
+};
+
+
+class InkSelectOneAction : public Gtk::Action {
+
+public:
+
+ static InkSelectOneAction* create(const Glib::ustring &name,
+ const Glib::ustring &label,
+ const Glib::ustring &tooltip,
+ const Glib::ustring &stock_id,
+ Glib::RefPtr<Gtk::ListStore> store );
+
+ /* Style of action */
+ void use_radio( bool use_radio ) { _use_radio = use_radio; }
+ void use_label( bool use_label ) { _use_label = use_label; }
+ void use_icon( bool use_icon ) { _use_icon = use_icon; }
+
+ gint get_active() { return _active; }
+ void set_active( gint active );
+ void set_icon_size( Gtk::BuiltinIconSize size ) { _icon_size = size; }
+
+ Glib::RefPtr<Gtk::ListStore> get_store() { return _store; }
+
+ sigc::signal<void, int> signal_changed() { return _changed; }
+
+protected:
+
+ virtual Gtk::Widget* create_menu_item_vfunc();
+ virtual Gtk::Widget* create_tool_item_vfunc();
+
+ /* Signals */
+ sigc::signal<void, int> _changed;
+
+private:
+
+ Glib::ustring _name;
+ Glib::ustring _label;
+ Glib::ustring _tooltip;
+ Glib::ustring _stock_id;
+ Glib::RefPtr<Gtk::ListStore> _store;
+
+ gint _active; /* Active menu item/button */
+
+ /* Style */
+ bool _use_radio; // Applies to tool item only
+ bool _use_label;
+ bool _use_icon; // Applies to menu item only
+ Gtk::BuiltinIconSize _icon_size;
+
+ /* Combobox in tool */
+ Gtk::ComboBox* _combobox;
+
+ /* Need to track one action to get active action. */
+ Glib::RefPtr<Gtk::RadioAction> _radioaction;
+
+ Gtk::MenuItem* _menuitem;
+ std::vector<Gtk::RadioMenuItem*> _radiomenuitems;
+
+ /* Internal Callbacks */
+ void on_changed_combobox();
+ void on_changed_radioaction(const Glib::RefPtr<Gtk::RadioAction>& current);
+ void on_toggled_radiomenu(int n);
+
+ InkSelectOneAction (const Glib::ustring &name,
+ const Glib::ustring &label,
+ const Glib::ustring &tooltip,
+ const Glib::ustring &stock_id,
+ Glib::RefPtr<Gtk::ListStore> store );
+
+};
+
+
+#endif /* SEEN_INK_SELECT_ONE_ACTION */
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
diff --git a/src/ui/widget/page-sizer.cpp b/src/ui/widget/page-sizer.cpp
index bb88536d5..3ec6a2b9f 100644
--- a/src/ui/widget/page-sizer.cpp
+++ b/src/ui/widget/page-sizer.cpp
@@ -225,7 +225,7 @@ PageSizer::PageSizer(Registry & _wr)
_marginBottom( _("Botto_m:"), _("Bottom margin"), "fit-margin-bottom", _wr),
_lockMarginUpdate(false),
_scaleX(_("Scale _x:"), _("Scale X"), "scale-x", _wr),
- _scaleY(_("Scale _y:"), _("Scale Y"), "scale-y", _wr),
+ _scaleY(_("Scale _y:"), _("While SVG allows non-uniform scaling it is recommended to use only uniform scaling in Inkscape. To set a non-uniform scaling, set the 'viewBox' directly."), "scale-y", _wr),
_lockScaleUpdate(false),
_viewboxX(_("X:"), _("X"), "viewbox-x", _wr),
_viewboxY(_("Y:"), _("Y"), "viewbox-y", _wr),
@@ -416,13 +416,9 @@ PageSizer::PageSizer(Registry & _wr)
_scaleTable.attach(_scaleY, 1, 0, 1, 1);
_scaleTable.attach(_scaleLabel, 2, 0, 1, 1);
- _scaleTable.attach(_scaleWarning, 0, 1, 2, 1);
_viewboxExpander.set_hexpand();
_viewboxExpander.set_vexpand();
_scaleTable.attach(_viewboxExpander, 0, 2, 2, 1);
-
- _scaleWarning.set_label(_("While SVG allows non-uniform scaling it is recommended to use only uniform scaling in Inkscape. To set a non-uniform scaling, set the 'viewBox' directly."));
- _scaleWarning.set_line_wrap( true );
_viewboxExpander.set_use_underline();
_viewboxExpander.set_label(_("_Viewbox..."));
diff --git a/src/ui/widget/page-sizer.h b/src/ui/widget/page-sizer.h
index d0655fb0e..f84f96782 100644
--- a/src/ui/widget/page-sizer.h
+++ b/src/ui/widget/page-sizer.h
@@ -238,7 +238,6 @@ protected:
Gtk::Grid _scaleTable;
Gtk::Label _scaleLabel;
- Gtk::Label _scaleWarning;
RegisteredScalar _scaleX;
RegisteredScalar _scaleY;
bool _lockScaleUpdate;