From 3769719f7e883e5215dbeb5e66f98ddbf6cffda9 Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Sat, 14 Mar 2009 15:01:16 +0000 Subject: [PATCH] Reworked MiniButton as a template class --- src/gui/Makefile.am | 1 - src/gui/widgets/button-bar.cpp | 14 --------- src/gui/widgets/button-bar.hpp | 15 +++++++--- src/gui/widgets/mini-button.cpp | 50 --------------------------------- src/gui/widgets/mini-button.hpp | 32 +++++++++++++++++---- 5 files changed, 37 insertions(+), 75 deletions(-) delete mode 100644 src/gui/widgets/mini-button.cpp diff --git a/src/gui/Makefile.am b/src/gui/Makefile.am index 2cd04544e..d2a58c6bf 100644 --- a/src/gui/Makefile.am +++ b/src/gui/Makefile.am @@ -82,7 +82,6 @@ gtk_gui_la_SOURCES = \ $(lumigui_srcdir)/widgets/button-bar.hpp \ $(lumigui_srcdir)/widgets/menu-button.cpp \ $(lumigui_srcdir)/widgets/menu-button.hpp \ - $(lumigui_srcdir)/widgets/mini-button.cpp \ $(lumigui_srcdir)/widgets/mini-button.hpp \ $(lumigui_srcdir)/widgets/video-display-widget.cpp \ $(lumigui_srcdir)/widgets/video-display-widget.hpp \ diff --git a/src/gui/widgets/button-bar.cpp b/src/gui/widgets/button-bar.cpp index 58abc9f12..63023c04e 100644 --- a/src/gui/widgets/button-bar.cpp +++ b/src/gui/widgets/button-bar.cpp @@ -34,20 +34,6 @@ ButtonBar::ButtonBar() { } -void -ButtonBar::append(MiniButton& button) -{ - pack_start(button, PACK_SHRINK); -} - -void -ButtonBar::append(MiniButton& button, - const sigc::slot& clicked_slot) -{ - button.signal_clicked().connect(clicked_slot); - append(button); -} - void ButtonBar::append(SeparatorToolItem &seperator) { diff --git a/src/gui/widgets/button-bar.hpp b/src/gui/widgets/button-bar.hpp index cdb3bc090..813996cdc 100644 --- a/src/gui/widgets/button-bar.hpp +++ b/src/gui/widgets/button-bar.hpp @@ -46,16 +46,23 @@ public: * Append a button to the button bar. * @param button The button to append. **/ - void append(MiniButton& button); + template void append(MiniWrapper& button) + { + pack_start(button, Gtk::PACK_SHRINK); + } /** * Append a button to the button bar, and connect a click event. * @param button The button to append. * @param clicked_slot The slot to connect. **/ - void append(MiniButton& button, - const sigc::slot& clicked_slot); - + template void append(MiniWrapper& button, + const sigc::slot& clicked_slot) + { + button.signal_clicked().connect(clicked_slot); + append(button); + } + /** * Append a sererator item. * @param seperator The seperator to append. diff --git a/src/gui/widgets/mini-button.cpp b/src/gui/widgets/mini-button.cpp deleted file mode 100644 index 76fda41c6..000000000 --- a/src/gui/widgets/mini-button.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/* - mini-button.cpp - Implementation of the mini button widget - - Copyright (C) Lumiera.org - 2009, Joel Holdsworth - - This program 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 program 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 program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -* *****************************************************/ - -#include "mini-button.hpp" - -#include - -using namespace Gtk; -using namespace sigc; - -namespace gui { -namespace widgets { - -MiniButton::MiniButton(const StockID& stock_id, - const IconSize icon_size) : - image(stock_id, icon_size) -{ - add(image); - set_relief(RELIEF_NONE); - set_focus_on_click(false); -} - -void -MiniButton::set_stock_id(const StockID& stock_id, - const IconSize icon_size) -{ - image.set(stock_id, icon_size); -} - -} // widgets -} // gui diff --git a/src/gui/widgets/mini-button.hpp b/src/gui/widgets/mini-button.hpp index 7805528c5..7edf510ad 100644 --- a/src/gui/widgets/mini-button.hpp +++ b/src/gui/widgets/mini-button.hpp @@ -32,9 +32,10 @@ namespace gui { namespace widgets { /** - * A ToolButton-like widget + * A wrapper for ToolButton-like Button widgets **/ -class MiniButton : public Gtk::Button +template +class MiniWrapper : public T { public: @@ -46,16 +47,25 @@ public: * @remarks Stock ids have identifiers like Gtk::Stock::OK and * Gtk::Stock::APPLY. **/ - MiniButton(const Gtk::StockID& stock_id, - const Gtk::IconSize icon_size = Gtk::ICON_SIZE_LARGE_TOOLBAR); - + MiniWrapper(const Gtk::StockID& stock_id, + const Gtk::IconSize icon_size = Gtk::ICON_SIZE_LARGE_TOOLBAR) : + image(stock_id, icon_size) + { + T::add(image); + T::set_relief(Gtk::RELIEF_NONE); + T::set_focus_on_click(false); + } + /** * Sets a new image from a stock-id for this button. * @param stock_id The stock_id of the image. * @param icon_size The size of the image to show. **/ void set_stock_id(const Gtk::StockID& stock_id, - const Gtk::IconSize icon_size = Gtk::ICON_SIZE_LARGE_TOOLBAR); + const Gtk::IconSize icon_size = Gtk::ICON_SIZE_LARGE_TOOLBAR) + { + image.set(stock_id, icon_size); + } private: @@ -65,6 +75,16 @@ private: Gtk::Image image; }; +/** + * A ToolButton-like widget + **/ +typedef MiniWrapper MiniButton; + +/** + * A ToggleToolButton-like widget + **/ +typedef MiniWrapper MiniToggleButton; + } // gui } // widgets