summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMartin Owens <doctormo@gmail.com>2018-09-27 02:44:51 +0000
committerMartin Owens <doctormo@gmail.com>2018-09-27 02:44:51 +0000
commit42969f6dc9924dc1b604ac163fbf29ad60e12fdd (patch)
treef3a81142978739026441112bf926aea922bd6c00 /src
parentFix crash in fill and stroke dialog (diff)
downloadinkscape-42969f6dc9924dc1b604ac163fbf29ad60e12fdd.tar.gz
inkscape-42969f6dc9924dc1b604ac163fbf29ad60e12fdd.zip
Refactor addtoicon and turn into more generic iconrenderer CellRenderer
Diffstat (limited to 'src')
-rw-r--r--src/ui/CMakeLists.txt4
-rw-r--r--src/ui/dialog/attrdialog.cpp7
-rw-r--r--src/ui/dialog/attrdialog.h2
-rw-r--r--src/ui/dialog/cssdialog.cpp9
-rw-r--r--src/ui/dialog/styledialog.cpp10
-rw-r--r--src/ui/dialog/tags.cpp17
-rw-r--r--src/ui/widget/iconrenderer.cpp (renamed from src/ui/widget/addtoicon.cpp)47
-rw-r--r--src/ui/widget/iconrenderer.h (renamed from src/ui/widget/addtoicon.h)19
8 files changed, 55 insertions, 60 deletions
diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt
index 6d1ebb785..458125c59 100644
--- a/src/ui/CMakeLists.txt
+++ b/src/ui/CMakeLists.txt
@@ -142,7 +142,7 @@ set(ui_SRC
dialog/xml-tree.cpp
dialog/save-template-dialog.cpp
- widget/addtoicon.cpp
+ widget/iconrenderer.cpp
widget/alignment-selector.cpp
widget/anchor-selector.cpp
widget/button.cpp
@@ -361,7 +361,7 @@ set(ui_SRC
tools/tweak-tool.h
tools/zoom-tool.h
- widget/addtoicon.h
+ widget/iconrenderer.h
widget/alignment-selector.h
widget/anchor-selector.h
widget/attr-widget.h
diff --git a/src/ui/dialog/attrdialog.cpp b/src/ui/dialog/attrdialog.cpp
index 3133ff279..0c00a6b76 100644
--- a/src/ui/dialog/attrdialog.cpp
+++ b/src/ui/dialog/attrdialog.cpp
@@ -16,7 +16,7 @@
#include "document-undo.h"
#include "helper/icon-loader.h"
-#include "ui/widget/addtoicon.h"
+#include "ui/widget/iconrenderer.h"
#include "xml/node-event-vector.h"
#include "xml/attribute-record.h"
@@ -65,14 +65,13 @@ AttrDialog::AttrDialog():
_store = Gtk::ListStore::create(_attrColumns);
_treeView.set_model(_store);
- Inkscape::UI::Widget::AddToIcon * addRenderer = manage(new Inkscape::UI::Widget::AddToIcon());
- addRenderer->property_active() = false;
+ Inkscape::UI::Widget::IconRenderer * addRenderer = manage(new Inkscape::UI::Widget::IconRenderer());
+ addRenderer->add_icon("edit-delete");
_treeView.append_column("", *addRenderer);
Gtk::TreeViewColumn *col = _treeView.get_column(0);
if (col) {
auto add_icon = Gtk::manage(sp_get_icon_image("list-add", GTK_ICON_SIZE_SMALL_TOOLBAR));
- col->add_attribute(addRenderer->property_active(), _attrColumns._colUnsetAttr);
col->set_clickable(true);
col->set_widget(*add_icon);
add_icon->set_tooltip_text(_("Add a new attribute"));
diff --git a/src/ui/dialog/attrdialog.h b/src/ui/dialog/attrdialog.h
index 448d8a804..c2efb66fc 100644
--- a/src/ui/dialog/attrdialog.h
+++ b/src/ui/dialog/attrdialog.h
@@ -43,11 +43,9 @@ public:
class AttrColumns : public Gtk::TreeModel::ColumnRecord {
public:
AttrColumns() {
- add(_colUnsetAttr);
add(_attributeName);
add(_attributeValue);
}
- Gtk::TreeModelColumn<bool> _colUnsetAttr;
Gtk::TreeModelColumn<Glib::ustring> _attributeName;
Gtk::TreeModelColumn<Glib::ustring> _attributeValue;
};
diff --git a/src/ui/dialog/cssdialog.cpp b/src/ui/dialog/cssdialog.cpp
index 47922fc64..13903af70 100644
--- a/src/ui/dialog/cssdialog.cpp
+++ b/src/ui/dialog/cssdialog.cpp
@@ -17,7 +17,7 @@
#include "selection.h"
#include "helper/icon-loader.h"
-#include "ui/widget/addtoicon.h"
+#include "ui/widget/iconrenderer.h"
#include "xml/attribute-record.h"
@@ -47,14 +47,11 @@ CssDialog::CssDialog():
_store = Gtk::ListStore::create(_cssColumns);
_treeView.set_model(_store);
- Inkscape::UI::Widget::AddToIcon * addRenderer = manage(new Inkscape::UI::Widget::AddToIcon());
- addRenderer->property_active() = false;
+ Inkscape::UI::Widget::IconRenderer * addRenderer = manage(new Inkscape::UI::Widget::IconRenderer());
+ addRenderer->add_icon("edit-delete");
int addCol = _treeView.append_column("", *addRenderer) - 1;
Gtk::TreeViewColumn *col = _treeView.get_column(addCol);
- if (col) {
- col->add_attribute(addRenderer->property_active(), _cssColumns._colUnsetProp);
- }
_propRenderer = Gtk::manage(new Gtk::CellRendererText());
_propRenderer->property_editable() = true;
diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp
index e978667ef..2984ae11a 100644
--- a/src/ui/dialog/styledialog.cpp
+++ b/src/ui/dialog/styledialog.cpp
@@ -19,7 +19,7 @@
#include "document-undo.h"
#include "helper/icon-loader.h"
-#include "ui/widget/addtoicon.h"
+#include "ui/widget/iconrenderer.h"
#include "xml/attribute-record.h"
#include "xml/node-observer.h"
@@ -248,8 +248,10 @@ StyleDialog::StyleDialog() :
#endif
// Tree
- Inkscape::UI::Widget::AddToIcon * addRenderer = manage(
- new Inkscape::UI::Widget::AddToIcon() );
+ Inkscape::UI::Widget::IconRenderer * addRenderer = manage(
+ new Inkscape::UI::Widget::IconRenderer() );
+ addRenderer->add_icon("edit-delete");
+ addRenderer->add_icon("list-add");
_store = TreeStore::create(this);
_treeView.set_model(_store);
@@ -260,7 +262,7 @@ StyleDialog::StyleDialog() :
int addCol = _treeView.append_column("", *addRenderer) - 1;
Gtk::TreeViewColumn *col = _treeView.get_column(addCol);
if ( col ) {
- col->add_attribute( addRenderer->property_active(), _mColumns._colIsSelector );
+ col->add_attribute( addRenderer->property_icon(), _mColumns._colIsSelector );
}
_treeView.append_column("CSS Selector", _mColumns._colSelector);
_treeView.set_expander_column(*(_treeView.get_column(1)));
diff --git a/src/ui/dialog/tags.cpp b/src/ui/dialog/tags.cpp
index d27a320a7..bf191fd3e 100644
--- a/src/ui/dialog/tags.cpp
+++ b/src/ui/dialog/tags.cpp
@@ -31,7 +31,7 @@
#include "helper/icon-loader.h"
#include "svg/css-ostringstream.h"
#include "ui/tools/tool-base.h" //"event-context.h"
-#include "ui/widget/addtoicon.h"
+#include "ui/widget/iconrenderer.h"
#include "ui/widget/layertypeicon.h"
#include "verbs.h"
#include "xml/node-observer.h"
@@ -286,7 +286,7 @@ public:
Gtk::TreeModelColumn<SPObject*> _colParentObject;
Gtk::TreeModelColumn<SPObject*> _colObject;
Gtk::TreeModelColumn<Glib::ustring> _colLabel;
- Gtk::TreeModelColumn<bool> _colAddRemove;
+ Gtk::TreeModelColumn<int> _colAddRemove;
Gtk::TreeModelColumn<bool> _colAllowAddRemove;
};
@@ -391,7 +391,7 @@ void TagsPanel::_addObject( SPDocument* doc, SPObject* obj, Gtk::TreeModel::Row*
row[_model->_colObject] = &child;
row[_model->_colParentObject] = NULL;
row[_model->_colLabel] = child.label() ? child.label() : child.getId();
- row[_model->_colAddRemove] = true;
+ row[_model->_colAddRemove] = 1;
row[_model->_colAllowAddRemove] = true;
_tree.expand_to_path( _store->get_path(iter) );
@@ -409,7 +409,7 @@ void TagsPanel::_addObject( SPDocument* doc, SPObject* obj, Gtk::TreeModel::Row*
rowitems[_model->_colObject] = NULL;
rowitems[_model->_colParentObject] = obj;
rowitems[_model->_colLabel] = _("Items");
- rowitems[_model->_colAddRemove] = false;
+ rowitems[_model->_colAddRemove] = 0;
rowitems[_model->_colAllowAddRemove] = false;
_tree.expand_to_path( _store->get_path(iteritems) );
@@ -423,7 +423,7 @@ void TagsPanel::_addObject( SPDocument* doc, SPObject* obj, Gtk::TreeModel::Row*
row[_model->_colObject] = &child;
row[_model->_colParentObject] = NULL;
row[_model->_colLabel] = item ? (item->label() ? item->label() : item->getId()) : SP_TAG_USE(&child)->href;
- row[_model->_colAddRemove] = false;
+ row[_model->_colAddRemove] = 0;
row[_model->_colAllowAddRemove] = true;
if (SP_TAG(obj)->expanded()) {
@@ -933,11 +933,14 @@ TagsPanel::TagsPanel() :
tooltip_string += (_("Remove from selection set"));
_tree.set_tooltip_text( tooltip_string );
- Inkscape::UI::Widget::AddToIcon * addRenderer = manage( new Inkscape::UI::Widget::AddToIcon());
+ Inkscape::UI::Widget::IconRenderer * addRenderer = manage( new Inkscape::UI::Widget::IconRenderer());
+ addRenderer->add_icon("edit-delete");
+ addRenderer->add_icon("list-add");
+
int addColNum = _tree.append_column("type", *addRenderer) - 1;
Gtk::TreeViewColumn *col = _tree.get_column(addColNum);
if ( col ) {
- col->add_attribute( addRenderer->property_active(), _model->_colAddRemove );
+ col->add_attribute( addRenderer->property_icon(), _model->_colAddRemove );
col->add_attribute( addRenderer->property_visible(), _model->_colAllowAddRemove );
}
diff --git a/src/ui/widget/addtoicon.cpp b/src/ui/widget/iconrenderer.cpp
index 4542333b5..9826d0bd3 100644
--- a/src/ui/widget/addtoicon.cpp
+++ b/src/ui/widget/iconrenderer.cpp
@@ -3,8 +3,9 @@
* Theodore Janeczko
*
* Copyright (C) Theodore Janeczko 2012 <flutterguy317@gmail.com>
+ * Martin Owens 2018 <doctormo@gmail.com>
*
- * Released under GNU GPL, read the file 'COPYING' for more information
+ * Released under GNU GPLv2+, read the file 'COPYING' for more information
*/
@@ -12,7 +13,7 @@
#include <config.h>
#endif
-#include "ui/widget/addtoicon.h"
+#include "ui/widget/iconrenderer.h"
#include "helper/icon-loader.h"
#include "layertypeicon.h"
@@ -23,29 +24,16 @@ namespace Inkscape {
namespace UI {
namespace Widget {
-AddToIcon::AddToIcon() :
- Glib::ObjectBase(typeid(AddToIcon)),
+IconRenderer::IconRenderer() :
+ Glib::ObjectBase(typeid(IconRenderer)),
Gtk::CellRendererPixbuf(),
-// _pixAddName(INKSCAPE_ICON("layer-new")),
- _property_active(*this, "active", false)
-// _property_pixbuf_add(*this, "pixbuf_on", Glib::RefPtr<Gdk::Pixbuf>(0))
+ _property_icon(*this, "icon", 0)
{
property_mode() = Gtk::CELL_RENDERER_MODE_ACTIVATABLE;
-
-
-// Glib::RefPtr<Gtk::IconTheme> icon_theme = Gtk::IconTheme::get_default();
-//
-// if (!icon_theme->has_icon(_pixAddName)) {
-// Inkscape::queueIconPrerender( INKSCAPE_ICON(_pixAddName.data()), Inkscape::ICON_SIZE_DECORATION );
-// }
-// if (icon_theme->has_icon(_pixAddName)) {
-// _property_pixbuf_add = icon_theme->load_icon(_pixAddName, phys, (Gtk::IconLookupFlags)0);
-// }
-
set_pixbuf();
}
-void AddToIcon::get_preferred_height_vfunc(Gtk::Widget& widget,
+void IconRenderer::get_preferred_height_vfunc(Gtk::Widget& widget,
int& min_h,
int& nat_h) const
{
@@ -60,7 +48,7 @@ void AddToIcon::get_preferred_height_vfunc(Gtk::Widget& widget,
}
}
-void AddToIcon::get_preferred_width_vfunc(Gtk::Widget& widget,
+void IconRenderer::get_preferred_width_vfunc(Gtk::Widget& widget,
int& min_w,
int& nat_w) const
{
@@ -75,7 +63,7 @@ void AddToIcon::get_preferred_width_vfunc(Gtk::Widget& widget,
}
}
-void AddToIcon::render_vfunc( const Cairo::RefPtr<Cairo::Context>& cr,
+void IconRenderer::render_vfunc( const Cairo::RefPtr<Cairo::Context>& cr,
Gtk::Widget& widget,
const Gdk::Rectangle& background_area,
const Gdk::Rectangle& cell_area,
@@ -86,7 +74,7 @@ void AddToIcon::render_vfunc( const Cairo::RefPtr<Cairo::Context>& cr,
Gtk::CellRendererPixbuf::render_vfunc( cr, widget, background_area, cell_area, flags );
}
-bool AddToIcon::activate_vfunc(GdkEvent* /*event*/,
+bool IconRenderer::activate_vfunc(GdkEvent* /*event*/,
Gtk::Widget& /*widget*/,
const Glib::ustring& /*path*/,
const Gdk::Rectangle& /*background_area*/,
@@ -96,10 +84,19 @@ bool AddToIcon::activate_vfunc(GdkEvent* /*event*/,
return false;
}
-void AddToIcon::set_pixbuf()
+void IconRenderer::add_icon(Glib::ustring name)
{
- bool active = property_active().get_value();
- property_pixbuf() = sp_get_icon_pixbuf((active ? "list-add" : "edit-delete"), GTK_ICON_SIZE_BUTTON);
+ _icons.push_back(name);
+}
+
+void IconRenderer::set_pixbuf()
+{
+ int icon_index = property_icon().get_value();
+ auto icon_name = Glib::ustring("image-missing");
+ if(icon_index >= 0 && icon_index < _icons.size()) {
+ icon_name = _icons[icon_index];
+ }
+ property_pixbuf() = sp_get_icon_pixbuf(icon_name.c_str(), GTK_ICON_SIZE_BUTTON);
}
diff --git a/src/ui/widget/addtoicon.h b/src/ui/widget/iconrenderer.h
index 2cfcda958..1f5aafde9 100644
--- a/src/ui/widget/addtoicon.h
+++ b/src/ui/widget/iconrenderer.h
@@ -5,8 +5,9 @@
* Theodore Janeczko
*
* Copyright (C) Theodore Janeczko 2012 <flutterguy317@gmail.com>
+ * Martin Owens 2018 <doctormo@gmail.com>
*
- * Released under GNU GPL, read the file 'COPYING' for more information
+ * Released under GNU GPLv2+, read the file 'COPYING' for more information
*/
#include <gtkmm/cellrendererpixbuf.h>
@@ -17,15 +18,16 @@ namespace Inkscape {
namespace UI {
namespace Widget {
-class AddToIcon : public Gtk::CellRendererPixbuf {
+class IconRenderer : public Gtk::CellRendererPixbuf {
public:
- AddToIcon();
- ~AddToIcon() override = default;;
+ IconRenderer();
+ ~IconRenderer() override = default;;
- Glib::PropertyProxy<bool> property_active() { return _property_active.get_proxy(); }
+ Glib::PropertyProxy<int> property_icon() { return _property_icon.get_proxy(); }
Glib::PropertyProxy< Glib::RefPtr<Gdk::Pixbuf> > property_pixbuf_on();
Glib::PropertyProxy< Glib::RefPtr<Gdk::Pixbuf> > property_pixbuf_off();
+ void add_icon(Glib::ustring name);
protected:
void render_vfunc( const Cairo::RefPtr<Cairo::Context>& cr,
Gtk::Widget& widget,
@@ -48,13 +50,10 @@ protected:
const Gdk::Rectangle &cell_area,
Gtk::CellRendererState flags) override;
-
private:
-// Glib::ustring _pixAddName;
-
- Glib::Property<bool> _property_active;
-// Glib::Property< Glib::RefPtr<Gdk::Pixbuf> > _property_pixbuf_add;
+ Glib::Property<int> _property_icon;
+ std::vector<Glib::ustring> _icons;
void set_pixbuf();
};