From 1b2d22f4dd360e69d25d4cb8df830650b353e9fe Mon Sep 17 00:00:00 2001 From: gballintijn Date: Sat, 14 Feb 2009 11:52:50 +0000 Subject: [PATCH] #2577196: Clean up the color dialog code. This commit cleans up the code of the color dialog, making it easier to understand. Specifically, removal of pointless use of a table widget, some refactoring of the code, some renaming of identifiers, some reordering of code, some removal of useless include and unused methods, and the removal of commented out code. git-svn-id: https://synfig.svn.sourceforge.net/svnroot/synfig@2345 1f10aa63-cdf2-0310-b900-c93c546f37ac --- synfig-studio/trunk/src/gtkmm/dialog_color.cpp | 139 +++++++++++-------------- synfig-studio/trunk/src/gtkmm/dialog_color.h | 56 ++++------ 2 files changed, 77 insertions(+), 118 deletions(-) diff --git a/synfig-studio/trunk/src/gtkmm/dialog_color.cpp b/synfig-studio/trunk/src/gtkmm/dialog_color.cpp index 4d98e83..bc7d5e1 100644 --- a/synfig-studio/trunk/src/gtkmm/dialog_color.cpp +++ b/synfig-studio/trunk/src/gtkmm/dialog_color.cpp @@ -31,18 +31,9 @@ #include "dialog_color.h" #include "widget_color.h" -#include -#include -#include #include -#include -#include -#include "widget_color.h" -#include #include -#include -#include -#include +#include #include "app.h" #include "general.h" @@ -65,60 +56,20 @@ using namespace studio; /* === M E T H O D S ======================================================= */ Dialog_Color::Dialog_Color(): - Dialog(_("Colors"),false,true), - dialog_settings(this,"color"), + Dialog(_("Colors"), false, true), + dialog_settings(this, "color"), busy_(false) -// adjustment_pos(0,0.0,1.0,0.001,0.001,0.001) { set_type_hint(Gdk::WINDOW_TYPE_HINT_UTILITY); - // Setup the buttons - - Gtk::Image *icon; - - Gtk::Button *set_fg_color(manage(new class Gtk::Button())); - icon = manage(new Gtk::Image(Gtk::StockID("synfig-set_fg_color"), Gtk::IconSize::IconSize(Gtk::ICON_SIZE_BUTTON))); - set_fg_color->add(*icon); - icon->show(); - tooltips.set_tip(*set_fg_color, _("Set as Foreground")); - set_fg_color->show(); - add_action_widget(*set_fg_color, 4); - set_fg_color->signal_clicked().connect(sigc::mem_fun(*this, &Dialog_Color::on_set_fg_pressed)); - - Gtk::Button *set_bg_color(manage(new class Gtk::Button())); - icon = manage(new Gtk::Image(Gtk::StockID("synfig-set_bg_color"), Gtk::IconSize::IconSize(Gtk::ICON_SIZE_BUTTON))); - set_bg_color->add(*icon); - icon->show(); - tooltips.set_tip(*set_bg_color, _("Set as Background")); - set_bg_color->show(); - add_action_widget(*set_bg_color, 3); - set_bg_color->signal_clicked().connect(sigc::mem_fun(*this, &Dialog_Color::on_set_bg_pressed)); - - //Gtk::Button *ok_button(manage(new class Gtk::Button(Gtk::StockID("gtk-ok")))); - //ok_button->show(); - //add_action_widget(*ok_button,2); - //ok_button->signal_clicked().connect(sigc::mem_fun(*this, &Dialog_Color::on_ok_pressed)); - - //Gtk::Button *apply_button(manage(new class Gtk::Button(Gtk::StockID("gtk-apply")))); - //apply_button->show(); - //add_action_widget(*apply_button,1); - //apply_button->signal_clicked().connect(sigc::mem_fun(*this, &Dialog_Color::on_apply_pressed)); - - Gtk::Button *cancel_button(manage(new class Gtk::Button(Gtk::StockID("gtk-close")))); - cancel_button->show(); - add_action_widget(*cancel_button,0); - cancel_button->signal_clicked().connect(sigc::hide_return(sigc::mem_fun(*this, &Dialog_Color::on_close_pressed))); - signal_delete_event().connect(sigc::hide(sigc::mem_fun(*this, &Dialog_Color::on_close_pressed))); - - Gtk::Table* table(manage(new Gtk::Table(2,2,false))); - get_vbox()->pack_start(*table); - - widget_color=manage(new Widget_ColorEdit()); - widget_color->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Dialog_Color::on_color_changed)); - //widget_color->signal_activate().connect(sigc::mem_fun(*this,&studio::Dialog_Color::on_color_changed)); - table->attach(*widget_color, 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); - add_accel_group(App::ui_manager()->get_accel_group()); + create_color_edit_widget(); + create_set_color_button("synfig-set_fg_color", _("Set as Foreground"), 0, + sigc::mem_fun(*this, &Dialog_Color::on_set_fg_pressed)); + create_set_color_button("synfig-set_bg_color", _("Set as Background"), 1, + sigc::mem_fun(*this, &Dialog_Color::on_set_bg_pressed)); + create_close_button(); + add_accel_group(App::ui_manager()->get_accel_group()); show_all_children(); } @@ -127,50 +78,78 @@ Dialog_Color::~Dialog_Color() } void -Dialog_Color::reset() +Dialog_Color::create_color_edit_widget() { - signal_edited_.clear(); + color_edit_widget = manage(new Widget_ColorEdit()); + color_edit_widget->signal_value_changed().connect(sigc::mem_fun(*this, + &studio::Dialog_Color::on_color_changed)); + get_vbox()->pack_start(*color_edit_widget); } -bool -Dialog_Color::on_close_pressed() +void +Dialog_Color::create_set_color_button(const char *stock_id, + const Glib::ustring& tip_text, int index, + const sigc::slot0& callback) { -// signal_edited_(get_color()); - busy_=false; - grab_focus(); - reset(); - hide(); - return true; + Gtk::Button *set_color_button = manage(new Gtk::Button()); + Gtk::Image *set_color_icon = manage(new Gtk::Image(Gtk::StockID(stock_id), + Gtk::IconSize::IconSize(Gtk::ICON_SIZE_BUTTON))); + set_color_button->add(*set_color_icon); + set_color_icon->show(); + tooltips.set_tip(*set_color_button, tip_text); + set_color_button->show(); + add_action_widget(*set_color_button, index); + set_color_button->signal_clicked().connect(callback); +} + +void +Dialog_Color::create_close_button() +{ + Gtk::Button *close_button(manage(new Gtk::Button(Gtk::StockID("gtk-close")))); + close_button->show(); + add_action_widget(*close_button, 2); + close_button->signal_clicked().connect(sigc::hide_return(sigc::mem_fun(*this, + &Dialog_Color::on_close_pressed))); + signal_delete_event().connect(sigc::hide(sigc::mem_fun(*this, + &Dialog_Color::on_close_pressed))); } void -Dialog_Color::on_apply_pressed() +Dialog_Color::on_color_changed() { - busy_=true; + busy_ = true; signal_edited_(get_color()); - busy_=false; + busy_ = false; } void Dialog_Color::on_set_fg_pressed() { - busy_=true; + busy_ = true; synfigapp::Main::set_foreground_color(get_color()); - busy_=false; + busy_ = false; } void Dialog_Color::on_set_bg_pressed() { - busy_=true; + busy_ = true; synfigapp::Main::set_background_color(get_color()); - busy_=false; + busy_ = false; +} + +bool +Dialog_Color::on_close_pressed() +{ + busy_ = false; + grab_focus(); + reset(); + hide(); + return true; } void -Dialog_Color::on_color_changed() +Dialog_Color::reset() { - busy_=true; - signal_edited_(get_color()); - busy_=false; + signal_edited_.clear(); } diff --git a/synfig-studio/trunk/src/gtkmm/dialog_color.h b/synfig-studio/trunk/src/gtkmm/dialog_color.h index 960f414..9825a53 100644 --- a/synfig-studio/trunk/src/gtkmm/dialog_color.h +++ b/synfig-studio/trunk/src/gtkmm/dialog_color.h @@ -28,23 +28,11 @@ /* === H E A D E R S ======================================================= */ #include -#include -#include -#include #include -#include -#include -#include #include - -#include -#include +#include #include "widget_coloredit.h" - -#include -#include - #include "dialogsettings.h" /* === M A C R O S ========================================================= */ @@ -53,12 +41,6 @@ /* === C L A S S E S & S T R U C T S ======================================= */ -namespace Gtk { class Menu; class SpinButton; class Adjustment; }; - -namespace synfigapp { -class CanvasInterface; -}; - namespace studio { class Widget_Color; @@ -68,37 +50,35 @@ class Dialog_Color : public Gtk::Dialog DialogSettings dialog_settings; Gtk::Tooltips tooltips; + Widget_ColorEdit* color_edit_widget; + sigc::signal signal_edited_; - //sigc::signal signal_apply_; - bool on_close_pressed(); - void on_apply_pressed(); - void on_set_fg_pressed(); - void on_set_bg_pressed(); - void on_color_changed(); + bool busy_; - Widget_ColorEdit* widget_color; + void create_color_edit_widget(); + void create_set_color_button(const char *stock_id, + const Glib::ustring& tip_text, int index, + const sigc::slot0& callback); + void create_close_button(); - bool busy_; + void on_color_changed(); + void on_set_fg_pressed(); + void on_set_bg_pressed(); + bool on_close_pressed(); public: - bool busy()const { return busy_; } + Dialog_Color(); + ~Dialog_Color(); sigc::signal& signal_edited() { return signal_edited_; } - //sigc::signal& signal_apply() { return signal_apply_; } - - void set_color(const synfig::Color& x) { widget_color->set_value(x); } - - synfig::Color get_color()const { return widget_color->get_value(); } - + void set_color(const synfig::Color& x) { color_edit_widget->set_value(x); } + synfig::Color get_color() const { return color_edit_widget->get_value(); } void reset(); + bool busy() const { return busy_; } - Dialog_Color(); - ~Dialog_Color(); - -// void edit(const synfigapp::ValueDesc &x, etl::handle canvas_interface, synfig::Time x=0); }; // END of Dialog_Color }; // END of namespace studio -- 2.7.4