diff options
| author | Alexander Valavanis <valavanisalex@gmail.com> | 2019-05-28 14:08:01 +0000 |
|---|---|---|
| committer | Alexander Valavanis <valavanisalex@gmail.com> | 2019-05-28 14:08:01 +0000 |
| commit | c36a1de9d1b762355bbed31ab9b6672dc90aec43 (patch) | |
| tree | 0e5b3320f9d6999b682bdd330f3a4df8ac627bed /src/ui/widget | |
| parent | Hackfest2019: Drop unused EgeAdjustmentAction (diff) | |
| download | inkscape-c36a1de9d1b762355bbed31ab9b6672dc90aec43.tar.gz inkscape-c36a1de9d1b762355bbed31ab9b6672dc90aec43.zip | |
Hackfest2019: Get rid of deprecated InkSelectOneAction
Diffstat (limited to 'src/ui/widget')
| -rw-r--r-- | src/ui/widget/ink-select-one-action.cpp | 269 | ||||
| -rw-r--r-- | src/ui/widget/ink-select-one-action.h | 143 | ||||
| -rw-r--r-- | src/ui/widget/unit-tracker.cpp | 57 | ||||
| -rw-r--r-- | src/ui/widget/unit-tracker.h | 11 |
4 files changed, 5 insertions, 475 deletions
diff --git a/src/ui/widget/ink-select-one-action.cpp b/src/ui/widget/ink-select-one-action.cpp deleted file mode 100644 index 95f38b511..000000000 --- a/src/ui/widget/ink-select-one-action.cpp +++ /dev/null @@ -1,269 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* - * Authors: - * Tavmjong Bah <tavmjong@free.fr> - * - * Copyright (C) 2017 Tavmjong Bah - * - * Released under GNU GPL v2+, 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 <utility> -#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 &group_label, - const Glib::ustring &tooltip, - const Glib::ustring &stock_id, - Glib::RefPtr<Gtk::ListStore> store ) { - - return new InkSelectOneAction(name, group_label, tooltip, stock_id, store); -} - -InkSelectOneAction::InkSelectOneAction (const Glib::ustring &name, - const Glib::ustring &group_label, - const Glib::ustring &tooltip, - const Glib::ustring &stock_id, - Glib::RefPtr<Gtk::ListStore> store ) : - Gtk::Action(name, stock_id, group_label, tooltip), - _name( name ), - _group_label( group_label ), - _tooltip( tooltip ), - _stock_id( stock_id ), - _store (std::move(store)), - _use_radio (true), - _use_label (true), - _use_icon (true), - _use_pixbuf (false), - _icon_size ( Gtk::ICON_SIZE_LARGE_TOOLBAR ), - _combobox (nullptr), - _radioaction (nullptr), - _menuitem (nullptr) -{ -} - -void InkSelectOneAction::set_active (gint active) { - - if (active < 0) { - std::cerr << "InkSelectOneAction::set_active: active < 0: " << active << std::endl; - return; - } - - 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(); - } - } -} - -Glib::ustring InkSelectOneAction::get_active_text () { - Gtk::TreeModel::Row row = _store->children()[_active]; - InkSelectOneActionColumns columns; - Glib::ustring label = row[columns.col_label]; - return label; -} - -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 row : children) { - 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; - - Gtk::Box* box = Gtk::manage(new Gtk::Box()); - tool_item->add (*box); - - if (_use_group_label) { - Gtk::Label *group_label = Gtk::manage (new Gtk::Label( _group_label + ": " )); - box->add( *group_label ); - } - - if (_use_radio) { - // Create radio actions (note: these are not radio buttons). - - Gtk::RadioAction::Group group; - int index = 0; - auto children = _store->children(); - for (auto row : children) { - 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); - } - - if (_radioaction) { - _radioaction->set_current_value (_active); - } - - _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 ); - } else if (_use_pixbuf) { - 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, "pixbuf", columns.col_pixbuf ); - } - - if (_use_label) { - _combobox->pack_start(columns.col_label); - } - - std::vector<Gtk::CellRenderer*> cells = _combobox->get_cells(); - for (auto & cell : cells) { - _combobox->add_attribute (*cell, "sensitive", columns.col_sensitive); - } - - _combobox->set_active (_active); - - _combobox->signal_changed().connect( - sigc::mem_fun(*this, &InkSelectOneAction::on_changed_combobox)); - - box->add (*_combobox); - } - - tool_item->show_all(); - - return tool_item; -} - -void InkSelectOneAction::on_changed_combobox() { - - int row = _combobox->get_active_row_number(); - if (row < 0) row = 0; // Happens when Gtk::ListStore reconstructed - set_active( row ); - _changed.emit (_active); - _changed_after.emit (_active); -} - -void InkSelectOneAction::on_changed_radioaction(const Glib::RefPtr<Gtk::RadioAction>& current) { - - set_active( current->get_current_value() ); - _changed.emit (_active); - _changed_after.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); - _changed_after.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 deleted file mode 100644 index efe249da8..000000000 --- a/src/ui/widget/ink-select-one-action.h +++ /dev/null @@ -1,143 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -#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 v2+, 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_pixbuf); - add (col_data); // Used to store a pointer - add (col_tooltip); - add (col_sensitive); - } - Gtk::TreeModelColumn<Glib::ustring> col_label; - Gtk::TreeModelColumn<Glib::ustring> col_icon; - Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf> > col_pixbuf; - Gtk::TreeModelColumn<void *> col_data; - 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; } - void use_pixbuf( bool use_pixbuf ) { _use_pixbuf = use_pixbuf; } - void use_group_label( bool use_group_label ) { _use_group_label = use_group_label; } - - gint get_active() { return _active; } - Glib::ustring get_active_text(); - 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; } - sigc::signal<void, int> signal_changed_after() { return _changed_after; } - -protected: - - Gtk::Widget* create_menu_item_vfunc() override; - Gtk::Widget* create_tool_item_vfunc() override; - - /* Signals */ - sigc::signal<void, int> _changed; - sigc::signal<void, int> _changed_after; // Needed for unit tracker which eats _changed. - -private: - - Glib::ustring _name; - Glib::ustring _group_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 - bool _use_pixbuf; - bool _use_group_label; // Applies to tool 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 &group_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/unit-tracker.cpp b/src/ui/widget/unit-tracker.cpp index 4abfaa9c8..0bdd3210a 100644 --- a/src/ui/widget/unit-tracker.cpp +++ b/src/ui/widget/unit-tracker.cpp @@ -19,7 +19,6 @@ #include "unit-tracker.h" -#include "ink-select-one-action.h" #include "combo-tool-item.h" #define COLUMN_STRING 0 @@ -41,7 +40,7 @@ UnitTracker::UnitTracker(UnitType unit_type) : { UnitTable::UnitMap m = unit_table.units(unit_type); - InkSelectOneActionColumns columns; + ComboToolItemColumns columns; _store = Gtk::ListStore::create(columns); Gtk::TreeModel::Row row; @@ -67,7 +66,6 @@ UnitTracker::UnitTracker(UnitType unit_type) : UnitTracker::~UnitTracker() { - _actionList.clear(); _combo_list.clear(); // Unhook weak references to GtkAdjustments @@ -91,7 +89,7 @@ void UnitTracker::setActiveUnit(Inkscape::Util::Unit const *unit) { if (unit) { - InkSelectOneActionColumns columns; + ComboToolItemColumns columns; int index = 0; for (auto& row: _store->children() ) { Glib::ustring storedUnit = row[columns.col_label]; @@ -122,7 +120,7 @@ void UnitTracker::addAdjustment(GtkAdjustment *adj) void UnitTracker::addUnit(Inkscape::Util::Unit const *u) { - InkSelectOneActionColumns columns; + ComboToolItemColumns columns; Gtk::TreeModel::Row row; row = *(_store->append()); @@ -134,7 +132,7 @@ void UnitTracker::addUnit(Inkscape::Util::Unit const *u) void UnitTracker::prependUnit(Inkscape::Util::Unit const *u) { - InkSelectOneActionColumns columns; + ComboToolItemColumns columns; Gtk::TreeModel::Row row; row = *(_store->prepend()); @@ -153,28 +151,6 @@ void UnitTracker::setFullVal(GtkAdjustment *adj, gdouble val) _priorValues[adj] = val; } -/** - * \deprecated Use create_tool_item instead - */ -InkSelectOneAction *UnitTracker::createAction(Glib::ustring const &name, - Glib::ustring const &label, - Glib::ustring const &tooltip) -{ - InkSelectOneAction* act = - InkSelectOneAction::create( name, label, tooltip, "NotUsed", _store); - - act->use_radio( false ); - act->use_label( true ); - act->use_icon( false ); - act->use_group_label( false ); - act->set_active( _active ); - - act->signal_changed().connect(sigc::mem_fun(*this, &UnitTracker::_unitChangedCB)); - _actionList.push_back(act); - - return act; -} - ComboToolItem * UnitTracker::create_tool_item(Glib::ustring const &label, Glib::ustring const &tooltip) @@ -192,14 +168,6 @@ void UnitTracker::_unitChangedCB(int active) _setActive(active); } -void UnitTracker::_actionFinalizedCB(gpointer data, GObject *where_the_object_was) -{ - if (data && where_the_object_was) { - UnitTracker *self = reinterpret_cast<UnitTracker *>(data); - self->_actionFinalized(where_the_object_was); - } -} - void UnitTracker::_adjustmentFinalizedCB(gpointer data, GObject *where_the_object_was) { if (data && where_the_object_was) { @@ -208,17 +176,6 @@ void UnitTracker::_adjustmentFinalizedCB(gpointer data, GObject *where_the_objec } } -void UnitTracker::_actionFinalized(GObject *where_the_object_was) -{ - InkSelectOneAction* act = (InkSelectOneAction*)(where_the_object_was); - auto it = std::find(_actionList.begin(),_actionList.end(), act); - if (it != _actionList.end()) { - _actionList.erase(it); - } else { - g_warning("Received a finalization callback for unknown object %p", where_the_object_was); - } -} - void UnitTracker::_adjustmentFinalized(GObject *where_the_object_was) { GtkAdjustment* adj = (GtkAdjustment*)(where_the_object_was); @@ -238,7 +195,7 @@ void UnitTracker::_setActive(gint active) if (_store) { // Find old and new units - InkSelectOneActionColumns columns; + ComboToolItemColumns columns; int index = 0; Glib::ustring oldAbbr( "NotFound" ); Glib::ustring newAbbr( "NotFound" ); @@ -274,10 +231,6 @@ void UnitTracker::_setActive(gint active) } _active = active; - for (auto act: _actionList) { - act->set_active (active); - } - for (auto combo : _combo_list) { if(combo) combo->set_active(active); } diff --git a/src/ui/widget/unit-tracker.h b/src/ui/widget/unit-tracker.h index c876d8224..1f16292ff 100644 --- a/src/ui/widget/unit-tracker.h +++ b/src/ui/widget/unit-tracker.h @@ -20,17 +20,13 @@ #include <vector> #include <gtkmm/liststore.h> -#include <gtkmm/action.h> #include "util/units.h" -class InkSelectOneAction; - using Inkscape::Util::Unit; using Inkscape::Util::UnitType; typedef struct _GObject GObject; -typedef struct _GtkAction GtkAction; typedef struct _GtkAdjustment GtkAdjustment; typedef struct _GtkListStore GtkListStore; @@ -55,10 +51,6 @@ public: void prependUnit(Inkscape::Util::Unit const *u); void setFullVal(GtkAdjustment *adj, gdouble val); - InkSelectOneAction *createAction(Glib::ustring const &name, - Glib::ustring const &label, - Glib::ustring const &tooltip); - ComboToolItem *create_tool_item(Glib::ustring const &label, Glib::ustring const &tooltip); @@ -68,14 +60,12 @@ protected: private: // Callbacks void _unitChangedCB(int active); - static void _actionFinalizedCB(gpointer data, GObject *where_the_object_was); static void _adjustmentFinalizedCB(gpointer data, GObject *where_the_object_was); void _setActive(gint index); void _fixupAdjustments(Inkscape::Util::Unit const *oldUnit, Inkscape::Util::Unit const *newUnit); // Cleanup - void _actionFinalized(GObject *where_the_object_was); void _adjustmentFinalized(GObject *where_the_object_was); gint _active; @@ -84,7 +74,6 @@ private: bool _activeUnitInitialized; Glib::RefPtr<Gtk::ListStore> _store; - std::vector<InkSelectOneAction*> _actionList; std::vector<ComboToolItem *> _combo_list; std::vector<GtkAdjustment*> _adjList; std::map <GtkAdjustment *, gdouble> _priorValues; |
