diff options
| author | Jabier Arraiza <jabier.arraiza@marker.es> | 2018-07-21 02:55:31 +0000 |
|---|---|---|
| committer | Jabier Arraiza <jabier.arraiza@marker.es> | 2018-07-21 02:55:31 +0000 |
| commit | 75d662f71d8eeb4b1c83e9bb61c1bd56f9b0e959 (patch) | |
| tree | e31f9e32ffa511bb495fc75eac6484681798e0d2 /src/helper | |
| parent | CMake/MSYS2: Update for enchant-2 (diff) | |
| download | inkscape-75d662f71d8eeb4b1c83e9bb61c1bd56f9b0e959.tar.gz inkscape-75d662f71d8eeb4b1c83e9bb61c1bd56f9b0e959.zip | |
adding gtk-theme
Diffstat (limited to 'src/helper')
| -rw-r--r-- | src/helper/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/helper/action.cpp | 6 | ||||
| -rw-r--r-- | src/helper/icon-loader.cpp | 131 | ||||
| -rw-r--r-- | src/helper/icon-loader.h | 25 |
4 files changed, 162 insertions, 2 deletions
diff --git a/src/helper/CMakeLists.txt b/src/helper/CMakeLists.txt index bcd9f7c58..7b6b548b9 100644 --- a/src/helper/CMakeLists.txt +++ b/src/helper/CMakeLists.txt @@ -17,6 +17,7 @@ set(helper_SRC geom-pathvectorsatellites.cpp geom-satellite.cpp gettext.cpp + icon-loader.cpp pixbuf-ops.cpp png-write.cpp stock-items.cpp @@ -38,6 +39,7 @@ set(helper_SRC geom-satellite.h geom.h gettext.h + icon-loader.h mathfns.h pixbuf-ops.h png-write.h diff --git a/src/helper/action.cpp b/src/helper/action.cpp index 6e44487f9..6d14037f0 100644 --- a/src/helper/action.cpp +++ b/src/helper/action.cpp @@ -10,6 +10,7 @@ */ #include "helper/action.h" +#include "helper/icon-loader.h" #include <gtkmm/toolbutton.h> @@ -236,8 +237,9 @@ SPAction::create_toolbutton_for_verb(unsigned int verb_code, auto icon_name = verb->get_image(); // Create a button with the required display properties - auto button = Gtk::manage(new Gtk::ToolButton(verb->get_name())); - button->set_icon_name(icon_name); + auto button = Gtk::manage(new Gtk::ToolButton(verb->get_tip())); + auto icon_widget = sp_get_icon_image(icon_name, "/toolbox/small"); + button->set_icon_widget(*icon_widget); button->set_tooltip_text(verb->get_tip()); // Hook up signal handler diff --git a/src/helper/icon-loader.cpp b/src/helper/icon-loader.cpp new file mode 100644 index 000000000..b19b19582 --- /dev/null +++ b/src/helper/icon-loader.cpp @@ -0,0 +1,131 @@ +/* + * Icon Loader + * + * Icon Loader management code + * + * Authors: + * Jabiertxo Arraiza <jabier.arraiza@marker.es> + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "icon-loader.h" +#include "inkscape.h" +#include "io/resource.h" +#include "preferences.h" +#include "svg/svg-color.h" +#include "widgets/toolbox.h" +#include <gtkmm/iconinfo.h> +#include <gtkmm/icontheme.h> + +Glib::RefPtr<Gdk::Pixbuf> sp_get_icon_pixbuf(Glib::ustring icon_name, gint size) +{ + using namespace Inkscape::IO::Resource; + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + if (prefs->getString("/theme/iconTheme") == "") { + prefs->setString("/theme/iconTheme", "hicolor"); + } + auto iconTheme = Gtk::IconTheme::create(); + iconTheme->set_custom_theme(prefs->getString("/theme/iconTheme")); + iconTheme->append_search_path(get_path_ustring(SYSTEM, ICONS)); + iconTheme->append_search_path(get_path_ustring(USER, ICONS)); +#ifdef INKSCAPE_THEMEDIR + iconTheme->append_search_path(get_path_ustring(SYSTEM, THEMES)); + iconTheme->append_search_path(get_path_ustring(USER, THEMES)); +#endif + Glib::RefPtr<Gdk::Pixbuf> _icon_pixbuf; + try { + if (prefs->getBool("/theme/symbolicIcons", false)) { + gchar colornamed[64]; + if (icon_name == "gtk-preferences") { + icon_name = "preferences-system"; + } + sp_svg_write_color(colornamed, sizeof(colornamed), prefs->getInt("/theme/symbolicColor", + 0x000000ff)); Gdk::RGBA color; color.set(colornamed); Gtk::IconInfo iconinfo = + iconTheme->lookup_icon(icon_name + Glib::ustring("-symbolic"), size, + Gtk::ICON_LOOKUP_FORCE_SIZE); + if (bool(iconinfo)) { + // TODO: view if we need parametrice other colors + bool was_symbolic = false; + _icon_pixbuf = iconinfo.load_symbolic(color, color, color, color, was_symbolic); + } + else { + _icon_pixbuf = iconTheme->load_icon(icon_name, size, Gtk::ICON_LOOKUP_FORCE_SIZE); + } + } + else { + _icon_pixbuf = iconTheme->load_icon(icon_name, size, Gtk::ICON_LOOKUP_FORCE_SIZE); + } + } + catch (const Gtk::IconThemeError &e) { + std::cout << "Icon Loader: " << e.what() << std::endl; + } + return _icon_pixbuf; +} + +Glib::RefPtr<Gdk::Pixbuf> sp_get_icon_pixbuf(Glib::ustring icon_name, Gtk::BuiltinIconSize icon_size) +{ + int width, height; + Gtk::IconSize::lookup(Gtk::IconSize(icon_size), width, height); + return sp_get_icon_pixbuf(icon_name, width); +} + +Glib::RefPtr<Gdk::Pixbuf> sp_get_icon_pixbuf(Glib::ustring icon_name, GtkIconSize icon_size) +{ + gint width, height; + gtk_icon_size_lookup(icon_size, &width, &height); + return sp_get_icon_pixbuf(icon_name, width); +} + +Glib::RefPtr<Gdk::Pixbuf> sp_get_icon_pixbuf(Glib::ustring icon_name, gchar const *prefs_size) +{ + // Load icon based in preference size defined allowed values are: + //"/toolbox/tools/small" Toolbox icon size + //"/toolbox/small" Control bar icon size + //"/toolbox/secondary" Secondary toolbar icon size + GtkIconSize icon_size = Inkscape::UI::ToolboxFactory::prefToSize(prefs_size); + return sp_get_icon_pixbuf(icon_name, icon_size); +} + +Gtk::Image *sp_get_icon_image(Glib::ustring icon_name, gint size) +{ + auto icon = sp_get_icon_pixbuf(icon_name, size); + Gtk::Image *image = new Gtk::Image(icon); + return image; +} + +Gtk::Image *sp_get_icon_image(Glib::ustring icon_name, Gtk::BuiltinIconSize icon_size) +{ + auto icon = sp_get_icon_pixbuf(icon_name, icon_size); + Gtk::Image *image = new Gtk::Image(icon); + return image; +} + +Gtk::Image *sp_get_icon_image(Glib::ustring icon_name, GtkIconSize icon_size) +{ + auto icon = sp_get_icon_pixbuf(icon_name, icon_size); + Gtk::Image *image = new Gtk::Image(icon); + return image; +} + +Gtk::Image *sp_get_icon_image(Glib::ustring icon_name, gchar const *prefs_size) +{ + auto icon = sp_get_icon_pixbuf(icon_name, prefs_size); + Gtk::Image *image = new Gtk::Image(icon); + return image; +} + +/* + 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 : diff --git a/src/helper/icon-loader.h b/src/helper/icon-loader.h new file mode 100644 index 000000000..5b6af546f --- /dev/null +++ b/src/helper/icon-loader.h @@ -0,0 +1,25 @@ +#ifndef SEEN_INK_ICON_LOADER_H +#define SEEN_INK_ICON_LOADER_H + +/* + * Icon Loader + * + * + * Authors: + * Jabiertxo Arraiza <jabier.arraiza@marker.es> + * + * + */ +#include <gdkmm/pixbuf.h> +#include <gtkmm/image.h> + +Glib::RefPtr<Gdk::Pixbuf> sp_get_icon_pixbuf(Glib::ustring icon_name, gint size); +Glib::RefPtr<Gdk::Pixbuf> sp_get_icon_pixbuf(Glib::ustring icon_name, Gtk::BuiltinIconSize icon_size); +Glib::RefPtr<Gdk::Pixbuf> sp_get_icon_pixbuf(Glib::ustring icon_name, GtkIconSize icon_size); +Glib::RefPtr<Gdk::Pixbuf> sp_get_icon_pixbuf(Glib::ustring icon_name, gchar const *prefs_sice); +Gtk::Image *sp_get_icon_image(Glib::ustring icon_name, gint size); +Gtk::Image *sp_get_icon_image(Glib::ustring icon_name, Gtk::BuiltinIconSize icon_sice); +Gtk::Image *sp_get_icon_image(Glib::ustring icon_name, GtkIconSize icon_sice); +Gtk::Image *sp_get_icon_image(Glib::ustring icon_name, gchar const *prefs_sice); + +#endif // SEEN_INK_STOCK_ITEMS_H |
