Revision: 2345
http://synfig.svn.sourceforge.net/synfig/?rev=2345&view=rev
Author: gballintijn
Date: 2009-02-14 11:52:50 +0000 (Sat, 14 Feb 2009)
Log Message:
-----------
#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.
Modified Paths:
--------------
synfig-studio/trunk/src/gtkmm/dialog_color.cpp
synfig-studio/trunk/src/gtkmm/dialog_color.h
Modified: synfig-studio/trunk/src/gtkmm/dialog_color.cpp
===================================================================
--- synfig-studio/trunk/src/gtkmm/dialog_color.cpp 2009-02-14 11:33:45 UTC
(rev 2344)
+++ synfig-studio/trunk/src/gtkmm/dialog_color.cpp 2009-02-14 11:52:50 UTC
(rev 2345)
@@ -31,18 +31,9 @@
#include "dialog_color.h"
#include "widget_color.h"
-#include <gtkmm/frame.h>
-#include <gtkmm/table.h>
-#include <gtkmm/label.h>
#include <synfig/general.h>
-#include <synfigapp/canvasinterface.h>
-#include <synfigapp/value_desc.h>
-#include "widget_color.h"
-#include <gtkmm/spinbutton.h>
#include <synfigapp/main.h>
-#include <sigc++/retype_return.h>
-#include <sigc++/retype.h>
-#include <sigc++/hide.h>
+#include <gtkmm/button.h>
#include "app.h"
#include "general.h"
@@ -65,60 +56,20 @@
/* === 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;
+ 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();
- 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());
-
show_all_children();
}
@@ -127,50 +78,78 @@
}
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<void>& 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::on_apply_pressed()
+Dialog_Color::create_close_button()
{
- busy_=true;
+ 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_color_changed()
+{
+ 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();
}
Modified: synfig-studio/trunk/src/gtkmm/dialog_color.h
===================================================================
--- synfig-studio/trunk/src/gtkmm/dialog_color.h 2009-02-14 11:33:45 UTC
(rev 2344)
+++ synfig-studio/trunk/src/gtkmm/dialog_color.h 2009-02-14 11:52:50 UTC
(rev 2345)
@@ -28,23 +28,11 @@
/* === H E A D E R S ======================================================= */
#include <gtk/gtk.h>
-#include <gtkmm/adjustment.h>
-#include <gtkmm/table.h>
-#include <gtkmm/button.h>
#include <gtkmm/dialog.h>
-#include <gtkmm/drawingarea.h>
-#include <gtkmm/optionmenu.h>
-#include <gtkmm/checkbutton.h>
#include <gtkmm/tooltips.h>
+#include <sigc++/functors/slot.h>
-#include <synfig/gamma.h>
-#include <synfig/time.h>
-
#include "widget_coloredit.h"
-
-#include <synfigapp/value_desc.h>
-#include <synfig/time.h>
-
#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 @@
DialogSettings dialog_settings;
Gtk::Tooltips tooltips;
+ Widget_ColorEdit* color_edit_widget;
+
sigc::signal<void,synfig::Color> signal_edited_;
- //sigc::signal<void,synfig::Color> signal_apply_;
- bool on_close_pressed();
- void on_apply_pressed();
+ bool busy_;
+
+ void create_color_edit_widget();
+ void create_set_color_button(const char *stock_id,
+ const Glib::ustring& tip_text, int index,
+ const sigc::slot0<void>& callback);
+ void create_close_button();
+
+ void on_color_changed();
void on_set_fg_pressed();
void on_set_bg_pressed();
- void on_color_changed();
+ bool on_close_pressed();
- Widget_ColorEdit* widget_color;
-
- bool busy_;
-
public:
- bool busy()const { return busy_; }
+ Dialog_Color();
+ ~Dialog_Color();
sigc::signal<void,synfig::Color>& signal_edited() { return
signal_edited_; }
- //sigc::signal<void,synfig::Color>& 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<synfigapp::CanvasInterface> canvas_interface, synfig::Time x=0);
}; // END of Dialog_Color
}; // END of namespace studio
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Synfig-devl mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/synfig-devl