diff --git a/rtgui/externaleditorpreferences.cc b/rtgui/externaleditorpreferences.cc index 79dac52d2..a1f6a2846 100644 --- a/rtgui/externaleditorpreferences.cc +++ b/rtgui/externaleditorpreferences.cc @@ -25,7 +25,6 @@ #include "externaleditorpreferences.h" #include "multilangmgr.h" -#include "rtimage.h" ExternalEditorPreferences::ExternalEditorPreferences(): @@ -52,12 +51,10 @@ ExternalEditorPreferences::ExternalEditorPreferences(): list_scroll_area.add(*list_view); // Toolbar buttons. - auto add_image = Gtk::manage(new RTImage("add-small.png")); - auto remove_image = Gtk::manage(new RTImage("remove-small.png")); button_add = Gtk::manage(new Gtk::Button()); button_remove = Gtk::manage(new Gtk::Button()); - button_add->set_image(*add_image); - button_remove->set_image(*remove_image); + button_add->set_image_from_icon_name("add-small"); + button_remove->set_image_from_icon_name("remove-small"); button_app_chooser = Gtk::manage(new Gtk::Button(M("PREFERENCES_EXTERNALEDITOR_CHANGE"))); button_file_chooser = Gtk::manage(new Gtk::Button(M("PREFERENCES_EXTERNALEDITOR_CHANGE_FILE"))); diff --git a/rtgui/popupcommon.h b/rtgui/popupcommon.h index 9ca6b2030..cc83c4998 100644 --- a/rtgui/popupcommon.h +++ b/rtgui/popupcommon.h @@ -61,8 +61,8 @@ public: explicit PopUpCommon (Gtk::Button* button, const Glib::ustring& label = ""); virtual ~PopUpCommon (); - bool addEntry (const Glib::ustring& fileName, const Glib::ustring& label, Gtk::RadioButtonGroup* radioGroup = nullptr); - bool insertEntry(int position, const Glib::ustring& fileName, const Glib::ustring& label, Gtk::RadioButtonGroup* radioGroup = nullptr); + bool addEntry (const Glib::ustring& iconName, const Glib::ustring& label, Gtk::RadioButtonGroup* radioGroup = nullptr); + bool insertEntry(int position, const Glib::ustring& iconName, const Glib::ustring& label, Gtk::RadioButtonGroup* radioGroup = nullptr); bool insertEntry(int position, const Glib::RefPtr& gIcon, const Glib::ustring& label, Gtk::RadioButtonGroup* radioGroup = nullptr); int getEntryCount () const; bool setSelected (int entryNum); @@ -78,7 +78,7 @@ private: type_signal_item_selected messageItemSelected; std::vector> imageIcons; - std::vector imageFilenames; + std::vector imageIconNames; std::vector images; Glib::ustring buttonHint; RTImage* buttonImage; @@ -90,15 +90,15 @@ private: bool hasMenu; void changeImage(int position); - void changeImage(const Glib::ustring& fileName, const Glib::RefPtr& gIcon); + void changeImage(const Glib::ustring& iconName, const Glib::RefPtr& gIcon); void entrySelected(Gtk::Widget* menuItem); - bool insertEntryImpl(int position, const Glib::ustring& fileName, const Glib::RefPtr& gIcon, RTImage* image, const Glib::ustring& label, Gtk::RadioButtonGroup* radioGroup); + bool insertEntryImpl(int position, const Glib::ustring& iconName, const Glib::RefPtr& gIcon, RTImage* image, const Glib::ustring& label, Gtk::RadioButtonGroup* radioGroup); void showMenu(GdkEventButton* event); protected: virtual int posToIndex(int p) const { return p; } virtual int indexToPos(int i) const { return i; } - + void entrySelected (int i); }; diff --git a/rtgui/rtimage.cc b/rtgui/rtimage.cc index 6096b9251..37044d1e6 100644 --- a/rtgui/rtimage.cc +++ b/rtgui/rtimage.cc @@ -58,7 +58,8 @@ RTImage::RTImage () {} RTImage::RTImage (const Glib::ustring& iconName, const Gtk::IconSize iconSize) : Gtk::Image(), size(iconSize), - icon_name(iconName) + icon_name(iconName), + g_icon(Glib::RefPtr()) { // Set surface from icon cache surface = RTImageCache::getCachedSurface(this->icon_name, this->size); @@ -69,6 +70,16 @@ RTImage::RTImage (const Glib::ustring& iconName, const Gtk::IconSize iconSize) : } } +RTImage::RTImage (const Glib::RefPtr& gIcon, const Gtk::IconSize iconSize) : + Gtk::Image(), + size(iconSize), + icon_name(""), + g_icon(Glib::RefPtr()) +{ + // Configure RTImage based on g_icon + set(this->g_icon, this->size); +} + void RTImage::set_from_icon_name(const Glib::ustring& iconName) { this->icon_name = iconName; @@ -80,6 +91,11 @@ void RTImage::set_from_icon_name(const Glib::ustring& iconName) if (surface) { set(surface->get()); } + + // Unset Gio::Icon if firstly exists + if (this->g_icon) { + g_icon = Glib::RefPtr(); + } } void RTImage::set_from_icon_name(const Glib::ustring& iconName, const Gtk::IconSize iconSize) @@ -90,16 +106,54 @@ void RTImage::set_from_icon_name(const Glib::ustring& iconName, const Gtk::IconS // Set surface from icon cache surface = RTImageCache::getCachedSurface(this->icon_name, this->size); - // Add it to the RTImage if surface exists + // Add it to the RTImage if previously chosen if (surface) { set(surface->get()); } + + // Unset Gio::Icon if previously chosen + if (this->g_icon) { + g_icon = Glib::RefPtr(); + } +} + +void RTImage::set_from_gicon(const Glib::RefPtr& gIcon) +{ + this->g_icon = gIcon; + + // Set image from Gio::Icon + set(this->g_icon, this->size); + + // Unset surface if previously chosen + this->icon_name = ""; + + if (surface) { + surface = std::shared_ptr(); + } +} + +void RTImage::set_from_gicon(const Glib::RefPtr& gIcon, const Gtk::IconSize iconSize) +{ + this->g_icon = gIcon; + this->size = iconSize; + + // Set image from Gio::Icon + set(this->g_icon, this->size); + + // Unset surface if previously chosen + this->icon_name = ""; + + if (surface) { + surface = std::shared_ptr(); + } } int RTImage::get_width() { if (surface) { return surface->getWidth(); + } else if (g_icon) { + Gtk::Image::get_width(); } return -1; @@ -109,6 +163,8 @@ int RTImage::get_height() { if (surface) { return surface->getHeight(); + } else if (g_icon) { + Gtk::Image::get_height(); } return -1; diff --git a/rtgui/rtimage.h b/rtgui/rtimage.h index 0908683c8..3fe67eb8d 100644 --- a/rtgui/rtimage.h +++ b/rtgui/rtimage.h @@ -42,13 +42,17 @@ private: Gtk::IconSize size; Glib::ustring icon_name; std::shared_ptr surface; + Glib::RefPtr g_icon; public: RTImage (); explicit RTImage (const Glib::ustring& iconName, const Gtk::IconSize iconSize = Gtk::ICON_SIZE_SMALL_TOOLBAR); + explicit RTImage (const Glib::RefPtr& gIcon, const Gtk::IconSize iconSize = Gtk::ICON_SIZE_SMALL_TOOLBAR); void set_from_icon_name(const Glib::ustring& iconName); void set_from_icon_name(const Glib::ustring& iconName, const Gtk::IconSize iconSize); + void set_from_gicon(const Glib::RefPtr& gIcon); + void set_from_gicon(const Glib::RefPtr& gIcon, const Gtk::IconSize iconSize); int get_width(); int get_height(); diff --git a/rtgui/toollocationpref.cc b/rtgui/toollocationpref.cc index cf25dbc34..f6719e918 100644 --- a/rtgui/toollocationpref.cc +++ b/rtgui/toollocationpref.cc @@ -21,7 +21,6 @@ #include "guiutils.h" #include "options.h" -#include "rtimage.h" #include "rtscalable.h" #include "toollocationpref.h" #include "toolpanelcoord.h" @@ -277,12 +276,9 @@ ListEditButtons::ListEditButtons(Gtk::TreeView &list, Glib::RefPtrset_min_content_width( - 400 * (RTScalable::getTweakedDPI() / RTScalable::baseDPI)); + tool_list_scrolled_window->set_min_content_width(RTScalable::scalePixelSize(400)); layout_grid->attach_next_to(*tool_list_frame, Gtk::PositionType::POS_RIGHT, 1, 1); tool_list_frame->add(*tool_list_scrolled_window); tool_list_scrolled_window->add(*impl->toolListViewPtr); @@ -739,8 +734,7 @@ ToolLocationPreference::ToolLocationPreference(Options &options) : Gtk::Box *favorites_box = Gtk::manage(new Gtk::Box()); Gtk::ScrolledWindow *favorites_list_scrolled_window = Gtk::manage(new Gtk::ScrolledWindow()); - favorites_list_scrolled_window->set_min_content_width( - 300 * (RTScalable::getTweakedDPI() / RTScalable::baseDPI)); + favorites_list_scrolled_window->set_min_content_width(RTScalable::scalePixelSize(300)); layout_grid->attach_next_to(*favorites_frame, Gtk::PositionType::POS_RIGHT, 1, 1); favorites_box->pack_start(impl->favoritesListEditButtons, false, false); favorites_box->pack_start(*favorites_list_scrolled_window, false, false);