Code

c2fc7ff4202c49892b5253fc58335e26b04ef1f4
[inkscape.git] / src / ui / dialog / filter-effects-dialog.h
1 /**
2  * \brief Filter Effects dialog
3  *
4  * Authors:
5  *   Nicholas Bishop <nicholasbishop@gmail.com>
6  *
7  * Copyright (C) 2007 Authors
8  *
9  * Released under GNU GPL.  Read the file 'COPYING' for more information.
10  */
12 #ifndef INKSCAPE_UI_DIALOG_FILTER_EFFECTS_H
13 #define INKSCAPE_UI_DIALOG_FILTER_EFFECTS_H
15 #include <memory>
17 #include <gtkmm/adjustment.h>
18 #include <gtkmm/alignment.h>
19 #include <gtkmm/box.h>
20 #include <gtkmm/buttonbox.h>
21 #include <gtkmm/comboboxtext.h>
22 #include <gtkmm/drawingarea.h>
23 #include <gtkmm/frame.h>
24 #include <gtkmm/liststore.h>
25 #include <gtkmm/menu.h>
26 #include <gtkmm/sizegroup.h>
27 #include <gtkmm/treeview.h>
29 #include "attributes.h"
30 #include "ui/widget/panel.h"
31 #include "sp-filter.h"
32 #include "ui/widget/combo-enums.h"
33 #include "ui/widget/spin-slider.h"
35 using namespace Inkscape::UI::Widget;
37 namespace Inkscape {
38 namespace UI {
39 namespace Dialog {
41 class DualSpinButton;
42 class MultiSpinButton;
43 class FilterEffectsDialog : public UI::Widget::Panel {
44 public:
46     FilterEffectsDialog();
47     ~FilterEffectsDialog();
49     static FilterEffectsDialog &getInstance()
50     { return *new FilterEffectsDialog(); }
52     void set_attrs_locked(const bool);
53 protected:
54     virtual void show_all_vfunc();
55 private:
56     class SignalObserver;
58     class FilterModifier : public Gtk::VBox
59     {
60     public:
61         FilterModifier(FilterEffectsDialog&);
62         ~FilterModifier();
64         SPFilter* get_selected_filter();
65         void select_filter(const SPFilter*);
67         sigc::signal<void>& signal_filter_changed()
68         {
69             return _signal_filter_changed;
70         }
71     private:
72         class Columns : public Gtk::TreeModel::ColumnRecord
73         {
74         public:
75             Columns()
76             {
77                 add(filter);
78                 add(label);
79                 add(sel);
80             }
82             Gtk::TreeModelColumn<SPFilter*> filter;
83             Gtk::TreeModelColumn<Glib::ustring> label;
84             Gtk::TreeModelColumn<int> sel;
85         };
87         static void on_activate_desktop(Application*, SPDesktop*, FilterModifier*);
88         void on_document_replaced(SPDesktop*, SPDocument*)
89         {
90             update_filters();
91         }
92        
93         static void on_inkscape_change_selection(Application *, Selection *, FilterModifier*);
94         
95         void update_selection(Selection *);
96         void on_filter_selection_changed();
98         void on_name_edited(const Glib::ustring&, const Glib::ustring&);
99         void on_selection_toggled(const Glib::ustring&);
101         void update_filters();
102         void filter_list_button_release(GdkEventButton*);
103         void add_filter();
104         void remove_filter();
105         void duplicate_filter();
106         void rename_filter();
108         sigc::connection _doc_replaced;
109         sigc::connection _resource_changed;
111         FilterEffectsDialog& _dialog;
112         Gtk::TreeView _list;
113         Glib::RefPtr<Gtk::ListStore> _model;
114         Columns _columns;
115         Gtk::CellRendererToggle _cell_toggle;
116         Gtk::Button _add;
117         Glib::RefPtr<Gtk::Menu> _menu;
118         sigc::signal<void> _signal_filter_changed;
119         std::auto_ptr<SignalObserver> _observer;
120     };
122     class PrimitiveColumns : public Gtk::TreeModel::ColumnRecord
123     {
124     public:
125         PrimitiveColumns()
126         {
127             add(primitive);
128             add(type_id);
129             add(type);
130             add(id);
131         }
133         Gtk::TreeModelColumn<SPFilterPrimitive*> primitive;
134         Gtk::TreeModelColumn<NR::FilterPrimitiveType> type_id;
135         Gtk::TreeModelColumn<Glib::ustring> type;
136         Gtk::TreeModelColumn<Glib::ustring> id;
137     };
139     class CellRendererConnection : public Gtk::CellRenderer
140     {
141     public:
142         CellRendererConnection();
143         Glib::PropertyProxy<void*> property_primitive();
145         static const int size = 24;
146         
147         void set_text_width(const int w);
148         int get_text_width() const;
149     protected:
150         virtual void get_size_vfunc(Gtk::Widget& widget, const Gdk::Rectangle* cell_area,
151                                     int* x_offset, int* y_offset, int* width, int* height) const;
152     private:
153         // void* should be SPFilterPrimitive*, some weirdness with properties prevents this
154         Glib::Property<void*> _primitive;
155         int _text_width;
156     };
158     class PrimitiveList : public Gtk::TreeView
159     {
160     public:
161         PrimitiveList(FilterEffectsDialog&);
163         sigc::signal<void>& signal_primitive_changed();
165         void update();
166         void set_menu(Glib::RefPtr<Gtk::Menu>);
168         SPFilterPrimitive* get_selected();
169         void select(SPFilterPrimitive *prim);
170         void remove_selected();
172         int primitive_count() const;
173     protected:
174         bool on_expose_signal(GdkEventExpose*);
175         bool on_button_press_event(GdkEventButton*);
176         bool on_motion_notify_event(GdkEventMotion*);
177         bool on_button_release_event(GdkEventButton*);
178         void on_drag_end(const Glib::RefPtr<Gdk::DragContext>&);
179     private:
180         int init_text();
182         bool do_connection_node(const Gtk::TreeIter& row, const int input, std::vector<Gdk::Point>& points,
183                                 const int ix, const int iy);
184         const Gtk::TreeIter find_result(const Gtk::TreeIter& start, const int attr, int& src_id);
185         int find_index(const Gtk::TreeIter& target);
186         void draw_connection(const Gtk::TreeIter&, const int attr, const int text_start_x,
187                              const int x1, const int y1, const int row_count);
188         void sanitize_connections(const Gtk::TreeIter& prim_iter);
189         void on_primitive_selection_changed();
190         bool on_scroll_timeout();
192         FilterEffectsDialog& _dialog;
193         Glib::RefPtr<Gtk::ListStore> _model;
194         PrimitiveColumns _columns;
195         CellRendererConnection _connection_cell;
196         Glib::RefPtr<Gtk::Menu> _primitive_menu;
197         Glib::RefPtr<Pango::Layout> _vertical_layout;
198         int _in_drag;
199         SPFilterPrimitive* _drag_prim;
200         sigc::signal<void> _signal_primitive_changed;
201         sigc::connection _scroll_connection;
202         int _autoscroll;
203         std::auto_ptr<SignalObserver> _observer;
204     };
206     void init_settings_widgets();
208     // Handlers
209     void add_primitive();
210     void remove_primitive();
211     void duplicate_primitive();
212     void convolve_order_changed();
214     void set_attr_direct(const AttrWidget*);
215     void set_child_attr_direct(const AttrWidget*);
216     void set_attr(SPObject*, const SPAttributeEnum, const gchar* val);
217     void update_settings_view();
218     void update_settings_sensitivity();
219     void update_color_matrix();
220     void update_primitive_infobox();
222     // Filter effect selection
223     FilterModifier _filter_modifier;
225     // Primitives Info Box  
226     Gtk::Label _infobox_desc;
227     Gtk::Image _infobox_icon;
229     // View/add primitives
230     Gtk::VBox _primitive_box;
231     PrimitiveList _primitive_list;
232     UI::Widget::ComboBoxEnum<NR::FilterPrimitiveType> _add_primitive_type;
233     Gtk::Button _add_primitive;
235     // Bottom pane (filter effect primitive settings)
236     Gtk::VBox _settings_box;
237     Gtk::Label _empty_settings;
239     class Settings;
240     class MatrixAttr;
241     class ColorMatrixValues;
242     class LightSourceControl;
243     Settings* _settings;
244     Glib::RefPtr<Gtk::SizeGroup> _sizegroup;
246     // Color Matrix
247     ColorMatrixValues* _color_matrix_values;
249     // Convolve Matrix
250     MatrixAttr* _convolve_matrix;
251     DualSpinButton* _convolve_order;
252     MultiSpinButton* _convolve_target;
254     // For controlling setting sensitivity
255     Gtk::Widget* _k1, *_k2, *_k3, *_k4;
256     Gtk::Widget* _ct_table, *_ct_slope, *_ct_intercept, *_ct_amplitude, *_ct_exponent, *_ct_offset;
258     // To prevent unwanted signals
259     bool _locked;
260     bool _attr_lock;
262     FilterEffectsDialog(FilterEffectsDialog const &d);
263     FilterEffectsDialog& operator=(FilterEffectsDialog const &d);
264 };
266 } // namespace Dialog
267 } // namespace UI
268 } // namespace Inkscape
270 #endif // INKSCAPE_UI_DIALOG_FILTER_EFFECTS_H
272 /*
273   Local Variables:
274   mode:c++
275   c-file-style:"stroustrup"
276   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
277   indent-tabs-mode:nil
278   fill-column:99
279   End:
280 */
281 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :