[Xfce4-commits] [panel-plugins/xfce4-whiskermenu-plugin] 84/473: Add choosing icon sizes of launchers and categories. Closes #12.

noreply at xfce.org noreply at xfce.org
Mon Feb 16 23:54:14 CET 2015


This is an automated email from the git hooks/post-receive script.

gottcode pushed a commit to branch master
in repository panel-plugins/xfce4-whiskermenu-plugin.

commit 8408358a98966b5da221ff6f926f7ce42e2b31aa
Author: Graeme Gott <graeme at gottcode.org>
Date:   Thu Jul 11 18:58:55 2013 -0400

    Add choosing icon sizes of launchers and categories. Closes #12.
---
 src/CMakeLists.txt                       |    1 +
 src/configuration_dialog.cpp             |   61 +++++++++++++++++++++++-
 src/configuration_dialog.hpp             |    4 ++
 src/icon_size.cpp                        |   60 ++++++++++++++++++++++++
 src/{launcher_view.hpp => icon_size.hpp} |   53 ++++++++++-----------
 src/launcher_view.cpp                    |   74 ++++++++++++++++++++++--------
 src/launcher_view.hpp                    |   12 +++++
 src/menu.cpp                             |    9 ++++
 src/panel_plugin.cpp                     |   12 +++--
 src/section_button.cpp                   |   29 +++++++++++-
 src/section_button.hpp                   |    6 +++
 11 files changed, 266 insertions(+), 55 deletions(-)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 1951f5f..5eecd3b 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -61,6 +61,7 @@ add_library(whiskermenu SHARED
     configuration_dialog.cpp
     favorites_page.cpp
     filter_page.cpp
+    icon_size.cpp
     launcher.cpp
     launcher_model.cpp
     launcher_view.cpp
diff --git a/src/configuration_dialog.cpp b/src/configuration_dialog.cpp
index 9324fb4..42b2332 100644
--- a/src/configuration_dialog.cpp
+++ b/src/configuration_dialog.cpp
@@ -16,7 +16,9 @@
 
 #include "configuration_dialog.hpp"
 
+#include "icon_size.hpp"
 #include "launcher.hpp"
+#include "launcher_view.hpp"
 #include "panel_plugin.hpp"
 #include "section_button.hpp"
 
@@ -79,6 +81,45 @@ ConfigurationDialog::ConfigurationDialog(PanelPlugin* plugin) :
 	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_show_descriptions), Launcher::get_show_description());
 	g_signal_connect(m_show_descriptions, "toggled", SLOT_CALLBACK(ConfigurationDialog::toggle_show_description), this);
 
+	// Add item icon size selector
+	GtkBox* hbox = GTK_BOX(gtk_hbox_new(false, 12));
+	gtk_box_pack_start(appearance_vbox, GTK_WIDGET(hbox), false, false, 0);
+
+	GtkWidget* label = gtk_label_new_with_mnemonic(_("Ite_m icon size:"));
+	gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
+	gtk_box_pack_start(hbox, label, false, false, 0);
+	gtk_size_group_add_widget(label_size_group, label);
+
+	m_item_icon_size = gtk_combo_box_text_new();
+	std::vector<std::string> icon_sizes = IconSize::get_strings();
+	for (std::vector<std::string>::const_iterator i = icon_sizes.begin(), end = icon_sizes.end(); i != end; ++i)
+	{
+		gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(m_item_icon_size), i->c_str());
+	}
+	gtk_combo_box_set_active(GTK_COMBO_BOX(m_item_icon_size), LauncherView::get_icon_size());
+	gtk_box_pack_start(hbox, m_item_icon_size, false, false, 0);
+	gtk_label_set_mnemonic_widget(GTK_LABEL(label), m_item_icon_size);
+	g_signal_connect(m_item_icon_size, "changed", SLOT_CALLBACK(ConfigurationDialog::item_icon_size_changed), this);
+
+	// Add category icon size selector
+	hbox = GTK_BOX(gtk_hbox_new(false, 12));
+	gtk_box_pack_start(appearance_vbox, GTK_WIDGET(hbox), false, false, 0);
+
+	label = gtk_label_new_with_mnemonic(_("Categ_ory icon size:"));
+	gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
+	gtk_box_pack_start(hbox, label, false, false, 0);
+	gtk_size_group_add_widget(label_size_group, label);
+
+	m_category_icon_size = gtk_combo_box_text_new();
+	for (std::vector<std::string>::const_iterator i = icon_sizes.begin(), end = icon_sizes.end(); i != end; ++i)
+	{
+		gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(m_category_icon_size), i->c_str());
+	}
+	gtk_combo_box_set_active(GTK_COMBO_BOX(m_category_icon_size), SectionButton::get_icon_size());
+	gtk_box_pack_start(hbox, m_category_icon_size, false, false, 0);
+	gtk_label_set_mnemonic_widget(GTK_LABEL(label), m_category_icon_size);
+	g_signal_connect(m_category_icon_size, "changed", SLOT_CALLBACK(ConfigurationDialog::category_icon_size_changed), this);
+
 	// Create panel button section
 	GtkBox* panel_vbox = GTK_BOX(gtk_vbox_new(false, 8));
 	GtkWidget* panel_frame = xfce_gtk_frame_box_new_with_content(_("Panel Button"), GTK_WIDGET(panel_vbox));
@@ -86,10 +127,10 @@ ConfigurationDialog::ConfigurationDialog(PanelPlugin* plugin) :
 	gtk_container_set_border_width(GTK_CONTAINER(panel_frame), 6);
 
 	// Add button style selector
-	GtkBox* hbox = GTK_BOX(gtk_hbox_new(false, 12));
+	hbox = GTK_BOX(gtk_hbox_new(false, 12));
 	gtk_box_pack_start(panel_vbox, GTK_WIDGET(hbox), false, false, 0);
 
-	GtkWidget* label = gtk_label_new_with_mnemonic(_("Di_splay:"));
+	label = gtk_label_new_with_mnemonic(_("Di_splay:"));
 	gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
 	gtk_box_pack_start(hbox, label, false, false, 0);
 	gtk_size_group_add_widget(label_size_group, label);
@@ -190,6 +231,22 @@ void ConfigurationDialog::choose_icon()
 
 //-----------------------------------------------------------------------------
 
+void ConfigurationDialog::category_icon_size_changed(GtkComboBox* combo)
+{
+	SectionButton::set_icon_size(gtk_combo_box_get_active(combo));
+	m_plugin->reload();
+}
+
+//-----------------------------------------------------------------------------
+
+void ConfigurationDialog::item_icon_size_changed(GtkComboBox* combo)
+{
+	LauncherView::set_icon_size(gtk_combo_box_get_active(combo));
+	m_plugin->reload();
+}
+
+//-----------------------------------------------------------------------------
+
 void ConfigurationDialog::style_changed(GtkComboBox* combo)
 {
 	m_plugin->set_button_style(PanelPlugin::ButtonStyle(gtk_combo_box_get_active(combo) + 1));
diff --git a/src/configuration_dialog.hpp b/src/configuration_dialog.hpp
index 93a80cb..1838a9d 100644
--- a/src/configuration_dialog.hpp
+++ b/src/configuration_dialog.hpp
@@ -42,6 +42,8 @@ public:
 
 private:
 	SLOT_0(void, ConfigurationDialog, choose_icon);
+	SLOT_1(void, ConfigurationDialog, category_icon_size_changed, GtkComboBox*);
+	SLOT_1(void, ConfigurationDialog, item_icon_size_changed, GtkComboBox*);
 	SLOT_1(void, ConfigurationDialog, style_changed, GtkComboBox*);
 	SLOT_1(void, ConfigurationDialog, title_changed, GtkEditable*);
 	SLOT_1(void, ConfigurationDialog, toggle_hover_switch_category, GtkToggleButton*);
@@ -57,6 +59,8 @@ private:
 	GtkWidget* m_title;
 	GtkWidget* m_icon;
 	GtkWidget* m_icon_button;
+	GtkWidget* m_category_icon_size;
+	GtkWidget* m_item_icon_size;
 	GtkWidget* m_show_names;
 	GtkWidget* m_show_descriptions;
 	GtkWidget* m_hover_switch_category;
diff --git a/src/icon_size.cpp b/src/icon_size.cpp
new file mode 100644
index 0000000..8e1a4f0
--- /dev/null
+++ b/src/icon_size.cpp
@@ -0,0 +1,60 @@
+// Copyright (C) 2013 Graeme Gott <graeme at gottcode.org>
+//
+// This library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library.  If not, see <http://www.gnu.org/licenses/>.
+
+
+#include "icon_size.hpp"
+
+extern "C"
+{
+#include <glib/gi18n.h>
+}
+
+using namespace WhiskerMenu;
+
+//-----------------------------------------------------------------------------
+
+int IconSize::get_size() const
+{
+	int size = 0;
+	switch (m_size)
+	{
+		case Smallest: size =  16; break;
+		case Smaller:  size =  24; break;
+		case Small:    size =  32; break;
+		case Normal:   size =  48; break;
+		case Large:    size =  64; break;
+		case Larger:   size =  96; break;
+		case Largest:  size = 128; break;
+		default:       size =   0; break;
+	}
+	return size;
+}
+
+//-----------------------------------------------------------------------------
+
+std::vector<std::string> IconSize::get_strings()
+{
+	std::vector<std::string> strings;
+	strings.push_back(_("Very Small"));
+	strings.push_back(_("Smaller"));
+	strings.push_back(_("Small"));
+	strings.push_back(_("Normal"));
+	strings.push_back(_("Large"));
+	strings.push_back(_("Larger"));
+	strings.push_back(_("Very Large"));
+	return strings;
+}
+
+//-----------------------------------------------------------------------------
diff --git a/src/launcher_view.hpp b/src/icon_size.hpp
similarity index 52%
copy from src/launcher_view.hpp
copy to src/icon_size.hpp
index f2c395c..72af550 100644
--- a/src/launcher_view.hpp
+++ b/src/icon_size.hpp
@@ -14,52 +14,47 @@
 // along with this library.  If not, see <http://www.gnu.org/licenses/>.
 
 
-#ifndef WHISKERMENU_LAUNCHER_VIEW_HPP
-#define WHISKERMENU_LAUNCHER_VIEW_HPP
+#ifndef WHISKERMENU_ICON_SIZE_HPP
+#define WHISKERMENU_ICON_SIZE_HPP
 
-extern "C"
-{
-#include <gtk/gtk.h>
-}
+#include <string>
+#include <vector>
 
 namespace WhiskerMenu
 {
 
-class LauncherView
+class IconSize
 {
 public:
-	LauncherView();
-	~LauncherView();
-
-	GtkWidget* get_widget() const
+	enum Size
+	{
+		Smallest = 0,
+		Smaller,
+		Small,
+		Normal,
+		Large,
+		Larger,
+		Largest
+	};
+
+	IconSize(const int size) :
+		m_size(size > int(Smallest) ? (size < int(Largest) ? size : int(Largest)) : int(Smallest))
 	{
-		return GTK_WIDGET(m_view);
 	}
 
-	GtkTreePath* get_selected_path() const;
-	void activate_path(GtkTreePath* path);
-
-	void scroll_to_path(GtkTreePath* path);
-	void select_path(GtkTreePath* path);
-
-	void set_reorderable(bool reorderable);
-	void set_selection_mode(GtkSelectionMode mode);
-
-	void unselect_all();
+	int get_size() const;
 
-	GtkTreeModel* get_model() const
+	operator int() const
 	{
-		return m_model;
+		return m_size;
 	}
 
-	void set_model(GtkTreeModel* model);
-	void unset_model();
+	static std::vector<std::string> get_strings();
 
 private:
-	GtkTreeModel* m_model;
-	GtkTreeView* m_view;
+	int m_size;
 };
 
 }
 
-#endif // WHISKERMENU_LAUNCHER_VIEW_HPP
+#endif // WHISKERMENU_ICON_SIZE_HPP
diff --git a/src/launcher_view.cpp b/src/launcher_view.cpp
index 3a57ae3..ac01fed 100644
--- a/src/launcher_view.cpp
+++ b/src/launcher_view.cpp
@@ -16,6 +16,7 @@
 
 #include "launcher_view.hpp"
 
+#include "icon_size.hpp"
 #include "launcher_model.hpp"
 
 #include <algorithm>
@@ -29,6 +30,10 @@ using namespace WhiskerMenu;
 
 //-----------------------------------------------------------------------------
 
+static IconSize f_icon_size(IconSize::Small);
+
+//-----------------------------------------------------------------------------
+
 LauncherView::LauncherView() :
 	m_model(NULL)
 {
@@ -39,25 +44,7 @@ LauncherView::LauncherView() :
 	gtk_tree_view_set_rules_hint(m_view, false);
 	gtk_tree_view_set_hover_selection(m_view, true);
 	gtk_tree_view_set_enable_search(m_view, false);
-
-	// Add a column for the icon and text
-	GtkTreeViewColumn* column = gtk_tree_view_column_new();
-	gtk_tree_view_column_set_expand(column, true);
-	gtk_tree_view_column_set_visible(column, true);
-
-	int width = 0, height = 0;
-	gtk_icon_size_lookup(GTK_ICON_SIZE_DND, &width, &height);
-	GtkCellRenderer* icon_renderer = exo_cell_renderer_icon_new();
-	g_object_set(icon_renderer, "size", std::max(width, height), NULL);
-	gtk_tree_view_column_pack_start(column, icon_renderer, false);
-	gtk_tree_view_column_add_attribute(column, icon_renderer, "icon", LauncherModel::COLUMN_ICON);
-
-	GtkCellRenderer* text_renderer = gtk_cell_renderer_text_new();
-	g_object_set(text_renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
-	gtk_tree_view_column_pack_start(column, text_renderer, true);
-	gtk_tree_view_column_add_attribute(column, text_renderer, "markup", LauncherModel::COLUMN_TEXT);
-
-	gtk_tree_view_append_column(m_view, column);
+	create_column();
 
 	// Use single clicks to activate items
 	exo_tree_view_set_single_click(EXO_TREE_VIEW(m_view), true);
@@ -155,3 +142,52 @@ void LauncherView::unset_model()
 }
 
 //-----------------------------------------------------------------------------
+
+void LauncherView::reload_icon_size()
+{
+	// Force exo to reload SVG icons
+	int size = 0;
+	g_object_get(m_icon_renderer, "size", &size, NULL);
+	if (size != f_icon_size)
+	{
+		gtk_tree_view_remove_column(m_view, m_column);
+		create_column();
+	}
+}
+
+//-----------------------------------------------------------------------------
+
+int LauncherView::get_icon_size()
+{
+	return f_icon_size;
+}
+
+//-----------------------------------------------------------------------------
+
+void LauncherView::set_icon_size(const int size)
+{
+	f_icon_size = size;
+}
+
+//-----------------------------------------------------------------------------
+
+void LauncherView::create_column()
+{
+	m_column = gtk_tree_view_column_new();
+	gtk_tree_view_column_set_expand(m_column, true);
+	gtk_tree_view_column_set_visible(m_column, true);
+
+	m_icon_renderer = exo_cell_renderer_icon_new();
+	g_object_set(m_icon_renderer, "size", f_icon_size.get_size(), NULL);
+	gtk_tree_view_column_pack_start(m_column, m_icon_renderer, false);
+	gtk_tree_view_column_add_attribute(m_column, m_icon_renderer, "icon", LauncherModel::COLUMN_ICON);
+
+	GtkCellRenderer* text_renderer = gtk_cell_renderer_text_new();
+	g_object_set(text_renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
+	gtk_tree_view_column_pack_start(m_column, text_renderer, true);
+	gtk_tree_view_column_add_attribute(m_column, text_renderer, "markup", LauncherModel::COLUMN_TEXT);
+
+	gtk_tree_view_append_column(m_view, m_column);
+}
+
+//-----------------------------------------------------------------------------
diff --git a/src/launcher_view.hpp b/src/launcher_view.hpp
index f2c395c..40afe6b 100644
--- a/src/launcher_view.hpp
+++ b/src/launcher_view.hpp
@@ -25,6 +25,8 @@ extern "C"
 namespace WhiskerMenu
 {
 
+class IconSize;
+
 class LauncherView
 {
 public:
@@ -55,9 +57,19 @@ public:
 	void set_model(GtkTreeModel* model);
 	void unset_model();
 
+	void reload_icon_size();
+
+	static int get_icon_size();
+	static void set_icon_size(const int size);
+
+private:
+	void create_column();
+
 private:
 	GtkTreeModel* m_model;
 	GtkTreeView* m_view;
+	GtkTreeViewColumn* m_column;
+	GtkCellRenderer* m_icon_renderer;
 };
 
 }
diff --git a/src/menu.cpp b/src/menu.cpp
index f319bdb..0be2210 100644
--- a/src/menu.cpp
+++ b/src/menu.cpp
@@ -223,6 +223,15 @@ void Menu::hide()
 
 void Menu::show(GtkWidget* parent, bool horizontal)
 {
+	// Make sure icon sizes are correct
+	m_favorites_button->reload_icon_size();
+	m_recent_button->reload_icon_size();
+
+	m_search_results->get_view()->reload_icon_size();
+	m_favorites->get_view()->reload_icon_size();
+	m_recent->get_view()->reload_icon_size();
+	m_applications->get_view()->reload_icon_size();
+
 	// Make sure applications list is current; does nothing unless list has changed
 	m_applications->load_applications();
 
diff --git a/src/panel_plugin.cpp b/src/panel_plugin.cpp
index c9fc00e..add8f70 100644
--- a/src/panel_plugin.cpp
+++ b/src/panel_plugin.cpp
@@ -18,7 +18,9 @@
 
 #include "applications_page.hpp"
 #include "configuration_dialog.hpp"
+#include "icon_size.hpp"
 #include "launcher.hpp"
+#include "launcher_view.hpp"
 #include "menu.hpp"
 #include "section_button.hpp"
 
@@ -59,9 +61,11 @@ PanelPlugin::PanelPlugin(XfcePanelPlugin* plugin) :
 		m_button_icon_name = xfce_rc_read_entry(settings, "button-icon", m_button_icon_name.c_str());
 		m_button_title_visible = xfce_rc_read_bool_entry(settings, "show-button-title", m_button_title_visible);
 		m_button_icon_visible = xfce_rc_read_bool_entry(settings, "show-button-icon", m_button_icon_visible);
-		Launcher::set_show_name(xfce_rc_read_bool_entry(settings, "launcher-show-name", true));
-		Launcher::set_show_description(xfce_rc_read_bool_entry(settings, "launcher-show-description", true));
-		SectionButton::set_hover_activate(xfce_rc_read_bool_entry(settings, "hover-switch-category", false));
+		Launcher::set_show_name(xfce_rc_read_bool_entry(settings, "launcher-show-name", Launcher::get_show_name()));
+		Launcher::set_show_description(xfce_rc_read_bool_entry(settings, "launcher-show-description", Launcher::get_show_description()));
+		SectionButton::set_hover_activate(xfce_rc_read_bool_entry(settings, "hover-switch-category", SectionButton::get_hover_activate()));
+		SectionButton::set_icon_size(xfce_rc_read_int_entry(settings, "category-icon-size", SectionButton::get_icon_size()));
+		LauncherView::set_icon_size(xfce_rc_read_int_entry(settings, "item-icon-size", LauncherView::get_icon_size()));
 		m_menu = new Menu(settings);
 
 		xfce_rc_close(settings);
@@ -303,6 +307,8 @@ void PanelPlugin::save()
 	xfce_rc_write_bool_entry(settings, "launcher-show-name", Launcher::get_show_name());
 	xfce_rc_write_bool_entry(settings, "launcher-show-description", Launcher::get_show_description());
 	xfce_rc_write_bool_entry(settings, "hover-switch-category", SectionButton::get_hover_activate());
+	xfce_rc_write_int_entry(settings, "category-icon-size", SectionButton::get_icon_size());
+	xfce_rc_write_int_entry(settings, "item-icon-size", LauncherView::get_icon_size());
 	m_menu->save(settings);
 
 	xfce_rc_close(settings);
diff --git a/src/section_button.cpp b/src/section_button.cpp
index cdd3e69..844f9fc 100644
--- a/src/section_button.cpp
+++ b/src/section_button.cpp
@@ -16,11 +16,14 @@
 
 #include "section_button.hpp"
 
+#include "icon_size.hpp"
+
 using namespace WhiskerMenu;
 
 //-----------------------------------------------------------------------------
 
 static bool f_hover_activate = false;
+static WhiskerMenu::IconSize f_icon_size(WhiskerMenu::IconSize::Smaller);
 
 static gboolean hover_timeout(GtkToggleButton* button)
 {
@@ -53,8 +56,9 @@ SectionButton::SectionButton(const gchar* icon, const gchar* text)
 	GtkBox* box = GTK_BOX(gtk_hbox_new(false, 4));
 	gtk_container_add(GTK_CONTAINER(m_button), GTK_WIDGET(box));
 
-	GtkWidget* image = gtk_image_new_from_icon_name(icon, GTK_ICON_SIZE_LARGE_TOOLBAR);
-	gtk_box_pack_start(box, image, false, false, 0);
+	m_icon = XFCE_PANEL_IMAGE(xfce_panel_image_new_from_source(icon));
+	reload_icon_size();
+	gtk_box_pack_start(box, GTK_WIDGET(m_icon), false, false, 0);
 
 	GtkWidget* label = gtk_label_new(text);
 	gtk_box_pack_start(box, label, false, true, 0);
@@ -69,6 +73,13 @@ SectionButton::~SectionButton()
 
 //-----------------------------------------------------------------------------
 
+void SectionButton::reload_icon_size()
+{
+	xfce_panel_image_set_size(m_icon, f_icon_size.get_size());
+}
+
+//-----------------------------------------------------------------------------
+
 bool SectionButton::get_hover_activate()
 {
 	return f_hover_activate;
@@ -82,3 +93,17 @@ void SectionButton::set_hover_activate(bool hover_activate)
 }
 
 //-----------------------------------------------------------------------------
+
+int SectionButton::get_icon_size()
+{
+	return f_icon_size;
+}
+
+//-----------------------------------------------------------------------------
+
+void SectionButton::set_icon_size(const int size)
+{
+	f_icon_size = size;
+}
+
+//-----------------------------------------------------------------------------
diff --git a/src/section_button.hpp b/src/section_button.hpp
index bb320f4..daa06c3 100644
--- a/src/section_button.hpp
+++ b/src/section_button.hpp
@@ -20,6 +20,7 @@
 extern "C"
 {
 #include <gtk/gtk.h>
+#include <libxfce4panel/libxfce4panel.h>
 }
 
 namespace WhiskerMenu
@@ -56,11 +57,16 @@ public:
 		gtk_radio_button_set_group(m_button, group);
 	}
 
+	void reload_icon_size();
+
 	static bool get_hover_activate();
 	static void set_hover_activate(bool hover_activate);
+	static int get_icon_size();
+	static void set_icon_size(const int size);
 
 private:
 	GtkRadioButton* m_button;
+	XfcePanelImage* m_icon;
 };
 
 }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list