4d98e8330db0c3eae0fe1d072ff2e04aaa5a2e37
[synfig.git] / synfig-studio / trunk / src / gtkmm / 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 "dialog_color.h"
33 #include "widget_color.h"
34 #include <gtkmm/frame.h>
35 #include <gtkmm/table.h>
36 #include <gtkmm/label.h>
37 #include <synfig/general.h>
38 #include <synfigapp/canvasinterface.h>
39 #include <synfigapp/value_desc.h>
40 #include "widget_color.h"
41 #include <gtkmm/spinbutton.h>
42 #include <synfigapp/main.h>
43 #include <sigc++/retype_return.h>
44 #include <sigc++/retype.h>
45 #include <sigc++/hide.h>
46 #include "app.h"
47
48 #include "general.h"
49
50 #endif
51
52 /* === U S I N G =========================================================== */
53
54 using namespace std;
55 using namespace etl;
56 using namespace synfig;
57 using namespace studio;
58
59 /* === M A C R O S ========================================================= */
60
61 /* === G L O B A L S ======================================================= */
62
63 /* === P R O C E D U R E S ================================================= */
64
65 /* === M E T H O D S ======================================================= */
66
67 Dialog_Color::Dialog_Color():
68         Dialog(_("Colors"),false,true),
69         dialog_settings(this,"color"),
70         busy_(false)
71 //      adjustment_pos(0,0.0,1.0,0.001,0.001,0.001)
72 {
73         set_type_hint(Gdk::WINDOW_TYPE_HINT_UTILITY);
74         // Setup the buttons
75
76         Gtk::Image *icon;
77
78         Gtk::Button *set_fg_color(manage(new class Gtk::Button()));
79         icon = manage(new Gtk::Image(Gtk::StockID("synfig-set_fg_color"), Gtk::IconSize::IconSize(Gtk::ICON_SIZE_BUTTON)));
80         set_fg_color->add(*icon);
81         icon->show();
82         tooltips.set_tip(*set_fg_color, _("Set as Foreground"));
83         set_fg_color->show();
84         add_action_widget(*set_fg_color, 4);
85         set_fg_color->signal_clicked().connect(sigc::mem_fun(*this, &Dialog_Color::on_set_fg_pressed));
86
87         Gtk::Button *set_bg_color(manage(new class Gtk::Button()));
88         icon = manage(new Gtk::Image(Gtk::StockID("synfig-set_bg_color"), Gtk::IconSize::IconSize(Gtk::ICON_SIZE_BUTTON)));
89         set_bg_color->add(*icon);
90         icon->show();
91         tooltips.set_tip(*set_bg_color, _("Set as Background"));
92         set_bg_color->show();
93         add_action_widget(*set_bg_color, 3);
94         set_bg_color->signal_clicked().connect(sigc::mem_fun(*this, &Dialog_Color::on_set_bg_pressed));
95
96         //Gtk::Button *ok_button(manage(new class Gtk::Button(Gtk::StockID("gtk-ok"))));
97         //ok_button->show();
98         //add_action_widget(*ok_button,2);
99         //ok_button->signal_clicked().connect(sigc::mem_fun(*this, &Dialog_Color::on_ok_pressed));
100
101         //Gtk::Button *apply_button(manage(new class Gtk::Button(Gtk::StockID("gtk-apply"))));
102         //apply_button->show();
103         //add_action_widget(*apply_button,1);
104         //apply_button->signal_clicked().connect(sigc::mem_fun(*this, &Dialog_Color::on_apply_pressed));
105
106         Gtk::Button *cancel_button(manage(new class Gtk::Button(Gtk::StockID("gtk-close"))));
107         cancel_button->show();
108         add_action_widget(*cancel_button,0);
109         cancel_button->signal_clicked().connect(sigc::hide_return(sigc::mem_fun(*this, &Dialog_Color::on_close_pressed)));
110         signal_delete_event().connect(sigc::hide(sigc::mem_fun(*this, &Dialog_Color::on_close_pressed)));
111
112         Gtk::Table* table(manage(new Gtk::Table(2,2,false)));
113         get_vbox()->pack_start(*table);
114
115         widget_color=manage(new Widget_ColorEdit());
116         widget_color->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Dialog_Color::on_color_changed));
117         //widget_color->signal_activate().connect(sigc::mem_fun(*this,&studio::Dialog_Color::on_color_changed));
118         table->attach(*widget_color, 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
119
120         add_accel_group(App::ui_manager()->get_accel_group());
121
122         show_all_children();
123 }
124
125 Dialog_Color::~Dialog_Color()
126 {
127 }
128
129 void
130 Dialog_Color::reset()
131 {
132         signal_edited_.clear();
133 }
134
135 bool
136 Dialog_Color::on_close_pressed()
137 {
138 //      signal_edited_(get_color());
139         busy_=false;
140         grab_focus();
141         reset();
142         hide();
143         return true;
144 }
145
146 void
147 Dialog_Color::on_apply_pressed()
148 {
149         busy_=true;
150         signal_edited_(get_color());
151         busy_=false;
152 }
153
154 void
155 Dialog_Color::on_set_fg_pressed()
156 {
157         busy_=true;
158         synfigapp::Main::set_foreground_color(get_color());
159         busy_=false;
160 }
161
162 void
163 Dialog_Color::on_set_bg_pressed()
164 {
165         busy_=true;
166         synfigapp::Main::set_background_color(get_color());
167         busy_=false;
168 }
169
170 void
171 Dialog_Color::on_color_changed()
172 {
173         busy_=true;
174         signal_edited_(get_color());
175         busy_=false;
176 }