Change Gtk::IconSize::IconSize to Gtk::IconSize
[synfig.git] / synfig-studio / src / gui / dialogs / dialog_color.cpp
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 "dialogs/dialog_color.h"
33 #include "widgets/widget_color.h"
34 #include <synfig/general.h>
35 #include <synfigapp/main.h>
36 #include <gtkmm/button.h>
37 #include "app.h"
38
39 #include "general.h"
40
41 #endif
42
43 /* === U S I N G =========================================================== */
44
45 using namespace std;
46 using namespace etl;
47 using namespace synfig;
48 using namespace studio;
49
50 /* === M A C R O S ========================================================= */
51
52 /* === G L O B A L S ======================================================= */
53
54 /* === P R O C E D U R E S ================================================= */
55
56 /* === M E T H O D S ======================================================= */
57
58 Dialog_Color::Dialog_Color():
59         Dialog(_("Colors"), false, true),
60         dialog_settings(this, "color"),
61         busy_(false)
62 {
63         set_type_hint(Gdk::WINDOW_TYPE_HINT_UTILITY);
64
65         create_color_edit_widget();
66         create_set_color_button("synfig-set_outline_color", _("Set as Outline"), 0,
67                         sigc::mem_fun(*this, &Dialog_Color::on_set_oc_pressed));
68         create_set_color_button("synfig-set_fill_color", _("Set as Fill"), 1,
69                         sigc::mem_fun(*this, &Dialog_Color::on_set_fc_pressed));
70         create_close_button();
71
72         add_accel_group(App::ui_manager()->get_accel_group());
73         show_all_children();
74 }
75
76 Dialog_Color::~Dialog_Color()
77 {
78 }
79
80 void
81 Dialog_Color::create_color_edit_widget()
82 {
83         color_edit_widget = manage(new Widget_ColorEdit());
84         color_edit_widget->signal_value_changed().connect(sigc::mem_fun(*this,
85                         &studio::Dialog_Color::on_color_changed));
86         get_vbox()->pack_start(*color_edit_widget);
87 }
88
89 void
90 Dialog_Color::create_set_color_button(const char *stock_id,
91                 const Glib::ustring& tip_text, int index,
92                 const sigc::slot0<void>& callback)
93 {
94         Gtk::Button *set_color_button = manage(new Gtk::Button());
95         Gtk::Image *set_color_icon = manage(new Gtk::Image(Gtk::StockID(stock_id),
96                         Gtk::IconSize(Gtk::ICON_SIZE_BUTTON)));
97         set_color_button->add(*set_color_icon);
98         set_color_icon->show();
99         tooltips.set_tip(*set_color_button, tip_text);
100         set_color_button->show();
101         add_action_widget(*set_color_button, index);
102         set_color_button->signal_clicked().connect(callback);
103 }
104
105 void
106 Dialog_Color::create_close_button()
107 {
108         Gtk::Button *close_button(manage(new Gtk::Button(Gtk::StockID("gtk-close"))));
109         close_button->show();
110         add_action_widget(*close_button, 2);
111         close_button->signal_clicked().connect(sigc::hide_return(sigc::mem_fun(*this,
112                         &Dialog_Color::on_close_pressed)));
113         signal_delete_event().connect(sigc::hide(sigc::mem_fun(*this,
114                         &Dialog_Color::on_close_pressed)));
115 }
116
117 void
118 Dialog_Color::on_color_changed()
119 {
120         busy_ = true;
121         signal_edited_(get_color());
122         busy_ = false;
123 }
124
125 void
126 Dialog_Color::on_set_oc_pressed()
127 {
128         busy_ = true;
129         synfigapp::Main::set_outline_color(get_color());
130         busy_ = false;
131 }
132
133 void
134 Dialog_Color::on_set_fc_pressed()
135 {
136         busy_ = true;
137         synfigapp::Main::set_fill_color(get_color());
138         busy_ = false;
139 }
140
141 bool
142 Dialog_Color::on_close_pressed()
143 {
144         busy_ = false;
145         grab_focus();
146         reset();
147         hide();
148         return true;
149 }
150
151 void
152 Dialog_Color::reset()
153 {
154         signal_edited_.clear();
155 }