1 /* === S Y N F I G ========================================================= */
2 /*!	\file dialog_color.cpp
3 **	\brief Template File
4 **
5 **	$Id$
6 **
7 **	\legal
8 **	Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **
10 **	This package is free software; you can redistribute it and/or
11 **	modify it under the terms of the GNU General Public License as
12 **	published by the Free Software Foundation; either version 2 of
13 **	the License, or (at your option) any later version.
14 **
15 **	This package is distributed in the hope that it will be useful,
16 **	but WITHOUT ANY WARRANTY; without even the implied warranty of
17 **	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 **	General Public License for more details.
19 **	\endlegal
20 */
21 /* ========================================================================= */
22 
23 /* === H E A D E R S ======================================================= */
24 
25 #ifdef USING_PCH
26 #	include "pch.h"
27 #else
28 #ifdef HAVE_CONFIG_H
29 #	include <config.h>
30 #endif
31 
32 #include <synfig/general.h>
33 
34 #include "dialogs/dialog_color.h"
35 #include "widgets/widget_color.h"
36 #include <synfigapp/main.h>
37 #include <gtkmm/button.h>
38 #include "app.h"
39 
40 #include <gui/localization.h>
41 
42 #endif
43 
44 /* === U S I N G =========================================================== */
45 
46 using namespace std;
47 using namespace etl;
48 using namespace synfig;
49 using namespace studio;
50 
51 /* === M A C R O S ========================================================= */
52 
53 /* === G L O B A L S ======================================================= */
54 
55 /* === P R O C E D U R E S ================================================= */
56 
57 /* === M E T H O D S ======================================================= */
58 
Dialog_Color()59 Dialog_Color::Dialog_Color():
60 	Dialog(_("Colors")),
61 	dialog_settings(this, "color"),
62 	busy_(false)
63 {
64 	set_transient_for((Gtk::Window&)(*App::main_window));
65 	set_type_hint(Gdk::WINDOW_TYPE_HINT_UTILITY);
66 
67 	create_color_edit_widget();
68 	create_set_color_button("synfig-set_outline_color", _("Set as Outline"), 0,
69 			sigc::mem_fun(*this, &Dialog_Color::on_set_oc_pressed));
70 	create_set_color_button("synfig-set_fill_color", _("Set as Fill"), 1,
71 			sigc::mem_fun(*this, &Dialog_Color::on_set_fc_pressed));
72 	create_close_button();
73 
74 	add_accel_group(App::ui_manager()->get_accel_group());
75 	show_all_children();
76 }
77 
~Dialog_Color()78 Dialog_Color::~Dialog_Color()
79 {
80 }
81 
82 void
create_color_edit_widget()83 Dialog_Color::create_color_edit_widget()
84 {
85 	color_edit_widget = manage(new Widget_ColorEdit());
86 	color_edit_widget->signal_value_changed().connect(sigc::mem_fun(*this,
87 			&studio::Dialog_Color::on_color_changed));
88 	get_vbox()->pack_start(*color_edit_widget);
89 }
90 
91 void
create_set_color_button(const char * stock_id,const Glib::ustring & tip_text,int index,const sigc::slot0<void> & callback)92 Dialog_Color::create_set_color_button(const char *stock_id,
93 		const Glib::ustring& tip_text, int index,
94 		const sigc::slot0<void>& callback)
95 {
96 	Gtk::Button *set_color_button = manage(new Gtk::Button());
97 	Gtk::Image *set_color_icon = manage(new Gtk::Image(Gtk::StockID(stock_id),
98 			Gtk::IconSize(Gtk::ICON_SIZE_BUTTON)));
99 	set_color_button->add(*set_color_icon);
100 	set_color_icon->show();
101 	set_color_button->set_tooltip_text(tip_text);
102 	set_color_button->show();
103 	add_action_widget(*set_color_button, index);
104 	set_color_button->signal_clicked().connect(callback);
105 }
106 
107 void
create_close_button()108 Dialog_Color::create_close_button()
109 {
110 	Gtk::Button *close_button(manage(new Gtk::Button(Gtk::StockID("gtk-close"))));
111 	close_button->show();
112 	add_action_widget(*close_button, 2);
113 	close_button->signal_clicked().connect(sigc::hide_return(sigc::mem_fun(*this,
114 			&Dialog_Color::on_close_pressed)));
115 	signal_delete_event().connect(sigc::hide(sigc::mem_fun(*this,
116 			&Dialog_Color::on_close_pressed)));
117 }
118 
119 void
on_color_changed()120 Dialog_Color::on_color_changed()
121 {
122 	busy_ = true;
123 	signal_edited_(get_color());
124 	busy_ = false;
125 }
126 
127 void
on_set_oc_pressed()128 Dialog_Color::on_set_oc_pressed()
129 {
130 	busy_ = true;
131 	synfigapp::Main::set_outline_color(get_color());
132 	busy_ = false;
133 }
134 
135 void
on_set_fc_pressed()136 Dialog_Color::on_set_fc_pressed()
137 {
138 	busy_ = true;
139 	synfigapp::Main::set_fill_color(get_color());
140 	busy_ = false;
141 }
142 
143 bool
on_close_pressed()144 Dialog_Color::on_close_pressed()
145 {
146 	busy_ = false;
147 	grab_focus();
148 	reset();
149 	hide();
150 	return true;
151 }
152 
153 void
reset()154 Dialog_Color::reset()
155 {
156 	signal_edited_.clear();
157 }
158