Code

merge
[inkscape.git] / src / ui / dialog / spray-option.cpp
1 /*Julien LERAY (julien.leray@ecl2010.ec-lyon.fr), interface for the spray tool*/
4 #ifdef HAVE_CONFIG_H
5 # include <config.h>
6 #endif
8 #include <gtkmm/spinbutton.h>
10 #include "desktop-handles.h"
11 #include "unclump.h"
12 #include "document.h"
13 #include "enums.h"
14 #include "graphlayout/graphlayout.h"
15 #include "inkscape.h"
16 #include "macros.h"
17 #include "node-context.h" 
18 #include "preferences.h"
19 #include "removeoverlap/removeoverlap.h"
20 #include "selection.h"
21 #include "shape-editor.h" 
22 #include "sp-flowtext.h"
23 #include "sp-item-transform.h"
24 #include "sp-text.h"
25 #include "text-editing.h"
26 #include "tools-switch.h"
27 #include "ui/icon-names.h"
28 #include "util/glib-list-iterators.h"
29 #include "verbs.h"
30 #include "widgets/icon.h"
32 #include "spray-option.h"
34 namespace Inkscape {
35 namespace UI {
36 namespace Dialog {
39 //Classes qui permettent de créer les environnements Gaussienne, Witdh...
43 class Action {
44 public:
45     Action(const Glib::ustring &id,
46            const Glib::ustring &tiptext,
47            guint row, guint column,
48            Gtk::Table &parent,
49            Gtk::Tooltips &tooltips,
50            SprayOptionClass &dialog):
51         _dialog(dialog),
52         _id(id),
53         _parent(parent) {}
54     
55     virtual ~Action(){}
56     virtual void on_button_click(){}
57     SprayOptionClass &_dialog;
58     
59 private :
60     
61     Glib::ustring _id;
62     Gtk::Table &_parent;
63 };
65 class ActionE : public Action {
66 private:
67     Gtk::Label _Label;
68     Gtk::SpinButton _Gap;
69     guint _min, _max;
70     Glib::ustring _pref_path;
72 public:
73     ActionE(const Glib::ustring &id,
74                 const Glib::ustring &tiptext,
75                 guint row, guint column,
76                 SprayOptionClass &dialog,
77                 guint min, guint max,
78                 Glib::ustring const &pref_path ):
79         Action(id, tiptext, row, column,
80                dialog._Table(), dialog.tooltips(), dialog),
81         _min(min),
82         _max(max),
83         _pref_path(pref_path)
84         {
85             dialog._Table().set_col_spacings(3);
87             double increm = ((double)_max - (double)_min)/10;
88             double val_ini = ((double)_max + (double)_min)/2;            
89             _Gap.set_digits(1);
90             _Gap.set_size_request(60, -1);
91             _Gap.set_increments(increm , 0);
92             _Gap.set_range(_min, _max);
93             _Gap.set_value(val_ini);
94             dialog.tooltips().set_tip(_Gap,
95                                   tiptext);
96             _Gap.signal_changed().connect(sigc::mem_fun(*this, &ActionE::on_button_click));  //rajout douteux
97             _Label.set_label(id);
99             dialog._Table().attach(_Label, column, column+1, row, row+1, Gtk::FILL, Gtk::FILL);
100             dialog._Table().attach(_Gap, column+1, column+2, row, row+1, Gtk::EXPAND, Gtk::EXPAND);
101         }
103     virtual void on_button_click(){
104         if (!_dialog.getDesktop()) return;
105               
106         Inkscape::Preferences *prefs = Inkscape::Preferences::get();
107         
108         prefs->setDouble(_pref_path, SP_VERB_CONTEXT_SPRAY);
109        
110         double const Gap = _Gap.get_value();
111         
112          
113         prefs->setDouble(_pref_path, Gap);
115         sp_document_done(sp_desktop_document(_dialog.getDesktop()), SP_VERB_CONTEXT_SPRAY,
116                          _("Remove overlaps"));
117     }
120 };    
122 class ActionF : public Action {
123 private:
124     Gtk::Label _Label;
125     Gtk::Label _Label1;
126     Gtk::Label _Label2;
127     Gtk::SpinButton _Gap1;
128     Gtk::SpinButton _Gap2;
129     Glib::ustring _pref1_path;
130     Glib::ustring _pref2_path;
132 public:
133     ActionF(const Glib::ustring &id,
134                 const Glib::ustring &tiptext,
135                 guint row, guint column,
136                 SprayOptionClass &dialog,
137                 Glib::ustring const &pref1_path,
138                 Glib::ustring const &pref2_path ):
139         Action(id, tiptext, row, column,
140                dialog._Table(), dialog.tooltips(), dialog),
141         _pref1_path(pref1_path),
142         _pref2_path(pref2_path)
143         {
144             dialog.F_Table().set_col_spacings(3);
146             _Label.set_label(id);            
148             _Gap1.set_digits(1);
149             _Gap1.set_size_request(60, -1);
150             _Gap1.set_increments(0.1, 0);
151             _Gap1.set_range(0, 10);
152             _Gap1.set_value(1);
153             dialog.tooltips().set_tip(_Gap1,
154                                   _("Minimum"));
155         
156             _Label1.set_label(Q_("Min"));
158             _Gap2.set_digits(1);
159             _Gap2.set_size_request(60, -1);
160             _Gap2.set_increments(0.1, 0);
161             _Gap2.set_range(0, 10);
162             _Gap2.set_value(1);
163             dialog.tooltips().set_tip(_Gap2,
164                                   _("Maximum"));
165         
166             _Label2.set_label(_("Max:"));
167             
168             _Gap1.signal_changed().connect(sigc::mem_fun(*this, &ActionF::on_button_click));
169             _Gap2.signal_changed().connect(sigc::mem_fun(*this, &ActionF::on_button_click)); 
171             dialog.F_Table().attach(_Label, column, column+1, row, row+1, Gtk::FILL, Gtk::FILL);
172             dialog.F_Table().attach(_Label1, column+1, column+2, row, row+1, Gtk::FILL, Gtk::FILL);
173             dialog.F_Table().attach(_Gap1, column+2, column+3, row, row+1, Gtk::EXPAND, Gtk::EXPAND);
174             dialog.F_Table().attach(_Label2, column+3, column+4, row, row+1, Gtk::FILL, Gtk::FILL);
175             dialog.F_Table().attach(_Gap2, column+4, column+5, row, row+1, Gtk::EXPAND, Gtk::EXPAND);
177         }
179     virtual void on_button_click(){
180         if (!_dialog.getDesktop()) return;
181               
182         Inkscape::Preferences *prefs = Inkscape::Preferences::get();
183         
184         prefs->setDouble(_pref1_path, SP_VERB_CONTEXT_SPRAY);
185         prefs->setDouble(_pref2_path, SP_VERB_CONTEXT_SPRAY);
186        
187         double const Gap1 = _Gap1.get_value();
188         double const Gap2 = _Gap2.get_value();
189                  
190         prefs->setDouble(_pref1_path, Gap1);
191         prefs->setDouble(_pref2_path, Gap2);
193         sp_document_done(sp_desktop_document(_dialog.getDesktop()), SP_VERB_CONTEXT_SPRAY,
194                          _("Remove overlaps"));
195     }
198 };    
202 void SprayOptionClass::combo_action() {
203     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
204     cout<<"combo.get_active_row_number = "<<_combo.get_active_row_number()<<endl;
205         
206     int const distrib = _combo.get_active_row_number();
207                  
208     prefs->setInt("/tools/spray/distribution", distrib);
209        
211     sp_document_done(sp_desktop_document(this->getDesktop()), SP_VERB_CONTEXT_SPRAY,
212                          _("Remove overlaps"));    
219 void SprayOptionClass::action() {
220     int r=1;    
221     for (list<Action *>::iterator it = _actionList.begin();
222          it != _actionList.end();
223          it ++)
224         (*it)->on_button_click();
225     combo_action();
233 void on_selection_changed(Inkscape::Application */*inkscape*/, Inkscape::Selection */*selection*/, SprayOptionClass *daad)
235     daad->randomize_bbox = Geom::OptRect();
238 /////////////////////////////////////////////////////////
239 //Construction de l'interface
240 /////////////////////////////////////////////////////////
243 SprayOptionClass::SprayOptionClass()
244     : UI::Widget::Panel ("", "/dialogs/spray", SP_VERB_DIALOG_SPRAY_OPTION),
245       _distributionFrame(_("Distribution")),
246       _Frame(_("Cursor Options")),
247       _FFrame(_("Random Options")),
248       _gaussianTable(1, 5, false),
249       _ETable(3,2,false),
250       _FTable(2,5,false),
251       _unifLabel(_("Uniform")),
252       _gaussLabel(_("Gaussian   ")),
253       _anchorLabel(_("Distribution : "))
254       
256     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
258     //ComboBoxText
260     _combo.append_text(_("Uniforme"));
261     _combo.append_text(_("Gaussienne"));
262     
263     _combo.set_active(prefs->getInt("/tools/spray/distribution", 1));
264     _combo.signal_changed().connect(sigc::mem_fun(*this, &SprayOptionClass::combo_action));
266     _anchorBox.pack_start(_anchorLabel);
267     _anchorBox.pack_start(_combo);
269     _gaussianBox.pack_start(_anchorBox);
272     _distributionBox.pack_start(_gaussianBox);
273     _distributionFrame.add(_distributionBox);
276     //Hbox Random
277     addFButton(_("Scale : ") ,_("Applique un facteur d'échelle"), 0, 0, "/tools/spray/scale_min","/tools/spray/scale_max");
278     addFButton(_("Rotation : ") ,_("Fait tourner"), 1, 0, "/tools/spray/rot_min","/tools/spray/rot_max");
279     _FHBox.pack_start(_FLabel);
280     _FHBox.pack_start(_FTable);
282     //Implementation dans la Vbox Cursor
283     _FVBox.pack_start(_FHBox);
284     _FFrame.add(_FVBox);    
286     //Hbox Cursor
287     addEButton(_("Ratio : ") ,_("Excentricité de l'ellipse"), 0, 0, 0, 1,"/tools/spray/ratio");
288     addEButton(_("Angle : ") ,_("Angle de l'ellipse"), 1, 0, 0, 5,"/tools/spray/tilt");
289     addEButton(_("Width : ") ,_("Taille de l'ellipse"), 2, 0, 0, 1,"/tools/spray/width");
290     _HBox.pack_start(_Label);
291     _HBox.pack_start(_ETable);
293     //Implementation dans la Vbox Cursor
294     _VBox.pack_start(_HBox);
295     _Frame.add(_VBox);
297     Gtk::Box *contents = _getContents();
298     contents->set_spacing(4);
300     
301     
303     
305     // Crée dans l'ordre suivant les différentes Frames (cadres de réglages)
307     contents->pack_start(_distributionFrame, true, true);
308     contents->pack_start(_FFrame, true, true);    
309     contents->pack_start(_Frame, true, true);
310     
311     
313     // Connect to the global selection change, to invalidate cached randomize_bbox
314     g_signal_connect (G_OBJECT (INKSCAPE), "change_selection", G_CALLBACK (on_selection_changed), this);
315     randomize_bbox = Geom::OptRect();
317     show_all_children();
318     
319     
323 SprayOptionClass::~SprayOptionClass()
325     sp_signal_disconnect_by_data (G_OBJECT (INKSCAPE), this);
327     for (std::list<Action *>::iterator it = _actionList.begin();
328          it != _actionList.end();
329          it ++)
330         delete *it;
339 //Fonctions qui lient la demande d'ajout d'une interface graphique à l'action correspondante
341 void SprayOptionClass::addEButton(const Glib::ustring &id,
342                 const Glib::ustring &tiptext,
343                 guint row, guint column,
344                 guint min, guint max,
345                 Glib::ustring const &pref_path) 
347         _actionList.push_back( new ActionE(id, tiptext,row, column,*this,min ,max, pref_path ));
350 void SprayOptionClass::addFButton(const Glib::ustring &id,
351                 const Glib::ustring &tiptext,
352                 guint row, guint column,
353                 Glib::ustring const &pref1_path,
354                 Glib::ustring const &pref2_path) 
356         _actionList.push_back( new ActionF(id, tiptext,row, column,*this,pref1_path, pref2_path ));
363 SprayOptionClass &SprayOptionClass::get_SprayOptionClass()
365     return *this;
368 } // namespace Dialog
369 } // namespace UI
370 } // namespace Inkscape
372 /*
373   Local Variables:
374   mode:c++
375   c-file-style:"stroustrup"
376   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
377   indent-tabs-mode:nil
378   fill-column:99
379   End:
380 */
381 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :