Code

56a1e2ca18c240785abc7bcbaed7b5d6bfbf9490
[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 <gtkmm/adjustment.h>
16 #include <gtkmm/alignment.h>
17 #include <gtkmm/box.h>
18 #include <gtkmm/buttonbox.h>
19 #include <gtkmm/comboboxtext.h>
20 #include <gtkmm/drawingarea.h>
21 #include <gtkmm/frame.h>
22 #include <gtkmm/liststore.h>
23 #include <gtkmm/menu.h>
24 #include <gtkmm/sizegroup.h>
25 #include <gtkmm/treeview.h>
27 #include "attributes.h"
28 #include "dialog.h"
29 #include "sp-filter.h"
30 #include "ui/widget/combo-enums.h"
31 #include "ui/widget/spin-slider.h"
33 using namespace Inkscape::UI::Widget;
35 namespace Inkscape {
36 namespace UI {
37 namespace Dialog {
39 class DualSpinButton;
40 class MultiSpinButton;
41 class FilterEffectsDialog : public Dialog {
42 public:
44     FilterEffectsDialog(Behavior::BehaviorFactory behavior_factory);
45     ~FilterEffectsDialog();
47     static FilterEffectsDialog *create(Behavior::BehaviorFactory behavior_factory)
48     { return new FilterEffectsDialog(behavior_factory); }
50     void set_attrs_locked(const bool);
51 private:
52     class SignalObserver;
54     class FilterModifier : public Gtk::VBox
55     {
56     public:
57         FilterModifier(FilterEffectsDialog&);
58         ~FilterModifier();
60         SPFilter* get_selected_filter();
61         void select_filter(const SPFilter*);
63         sigc::signal<void>& signal_filter_changed()
64         {
65             return _signal_filter_changed;
66         }
67     private:
68         class Columns : public Gtk::TreeModel::ColumnRecord
69         {
70         public:
71             Columns()
72             {
73                 add(filter);
74                 add(label);
75                 add(sel);
76             }
78             Gtk::TreeModelColumn<SPFilter*> filter;
79             Gtk::TreeModelColumn<Glib::ustring> label;
80             Gtk::TreeModelColumn<int> sel;
81         };
83         static void on_activate_desktop(Application*, SPDesktop*, FilterModifier*);
84         void on_document_replaced(SPDesktop*, SPDocument*)
85         {
86             update_filters();
87         }
88        
89         static void on_inkscape_change_selection(Application *, Selection *, FilterModifier*);
90         
91         void update_selection(Selection *);
92         void on_filter_selection_changed();
93         void on_selection_toggled(const Glib::ustring&);
95         void update_filters();
96         void filter_list_button_release(GdkEventButton*);
97         void add_filter();
98         void remove_filter();
99         void duplicate_filter();
100         void rename_filter();
102         sigc::connection _doc_replaced;
103         sigc::connection _resource_changed;
105         FilterEffectsDialog& _dialog;
106         Gtk::TreeView _list;
107         Glib::RefPtr<Gtk::ListStore> _model;
108         Columns _columns;
109         Gtk::CellRendererToggle _cell_toggle;
110         Gtk::Button _add;
111         Glib::RefPtr<Gtk::Menu> _menu;
112         sigc::signal<void> _signal_filter_changed;
113         std::auto_ptr<SignalObserver> _observer;
114     };
116     class PrimitiveColumns : public Gtk::TreeModel::ColumnRecord
117     {
118     public:
119         PrimitiveColumns()
120         {
121             add(primitive);
122             add(type_id);
123             add(type);
124             add(id);
125         }
127         Gtk::TreeModelColumn<SPFilterPrimitive*> primitive;
128         Gtk::TreeModelColumn<NR::FilterPrimitiveType> type_id;
129         Gtk::TreeModelColumn<Glib::ustring> type;
130         Gtk::TreeModelColumn<Glib::ustring> id;
131     };
133     class CellRendererConnection : public Gtk::CellRenderer
134     {
135     public:
136         CellRendererConnection();
137         Glib::PropertyProxy<void*> property_primitive();
139         static const int size = 24;
140         
141         void set_text_width(const int w);
142         int get_text_width() const;
143     protected:
144         virtual void get_size_vfunc(Gtk::Widget& widget, const Gdk::Rectangle* cell_area,
145                                     int* x_offset, int* y_offset, int* width, int* height) const;
146     private:
147         // void* should be SPFilterPrimitive*, some weirdness with properties prevents this
148         Glib::Property<void*> _primitive;
149         int _text_width;
150     };
152     class PrimitiveList : public Gtk::TreeView
153     {
154     public:
155         PrimitiveList(FilterEffectsDialog&);
157         sigc::signal<void>& signal_primitive_changed();
159         void update();
160         void set_menu(Glib::RefPtr<Gtk::Menu>);
162         SPFilterPrimitive* get_selected();
163         void select(SPFilterPrimitive *prim);
165         int primitive_count() const;
166     protected:
167         bool on_expose_signal(GdkEventExpose*);
168         bool on_button_press_event(GdkEventButton*);
169         bool on_motion_notify_event(GdkEventMotion*);
170         bool on_button_release_event(GdkEventButton*);
171         void on_drag_end(const Glib::RefPtr<Gdk::DragContext>&);
172     private:
173         int init_text();
175         bool do_connection_node(const Gtk::TreeIter& row, const int input, std::vector<Gdk::Point>& points,
176                                 const int ix, const int iy);
177         const Gtk::TreeIter find_result(const Gtk::TreeIter& start, const int attr, int& src_id);
178         int find_index(const Gtk::TreeIter& target);
179         void draw_connection(const Gtk::TreeIter&, const int attr, const int text_start_x,
180                              const int x1, const int y1, const int row_count);
181         void sanitize_connections(const Gtk::TreeIter& prim_iter);
182         void on_primitive_selection_changed();
183         bool on_scroll_timeout();
185         FilterEffectsDialog& _dialog;
186         Glib::RefPtr<Gtk::ListStore> _model;
187         PrimitiveColumns _columns;
188         CellRendererConnection _connection_cell;
189         Glib::RefPtr<Gtk::Menu> _primitive_menu;
190         Glib::RefPtr<Pango::Layout> _vertical_layout;
191         int _in_drag;
192         SPFilterPrimitive* _drag_prim;
193         sigc::signal<void> _signal_primitive_changed;
194         sigc::connection _scroll_connection;
195         int _autoscroll;
196         std::auto_ptr<SignalObserver> _observer;
197     };
199     FilterEffectsDialog();
200     void init_settings_widgets();
202     // Handlers
203     void add_primitive();
204     void remove_primitive();
205     void duplicate_primitive();
206     void convolve_order_changed();
208     void set_attr_direct(const AttrWidget*);
209     void set_child_attr_direct(const AttrWidget*);
210     void set_attr(SPObject*, const SPAttributeEnum, const gchar* val);
211     void update_settings_view();
212     void update_settings_sensitivity();
213     void update_color_matrix();
215     // Filter effect selection
216     FilterModifier _filter_modifier;
218     // View/add primitives
219     Gtk::VBox _primitive_box;
220     PrimitiveList _primitive_list;
221     UI::Widget::ComboBoxEnum<NR::FilterPrimitiveType> _add_primitive_type;
222     Gtk::Button _add_primitive;
224     // Bottom pane (filter effect primitive settings)
225     Gtk::VBox _settings_box;
226     Gtk::Label _empty_settings;
228     class Settings;
229     class MatrixAttr;
230     class ColorMatrixValues;
231     class LightSourceControl;
232     Settings* _settings;
233     Glib::RefPtr<Gtk::SizeGroup> _sizegroup;
235     // Color Matrix
236     ColorMatrixValues* _color_matrix_values;
238     // Convolve Matrix
239     MatrixAttr* _convolve_matrix;
240     DualSpinButton* _convolve_order;
241     MultiSpinButton* _convolve_target;
243     // For controlling setting sensitivity
244     Gtk::Widget* _k1, *_k2, *_k3, *_k4;
245     Gtk::Widget* _ct_table, *_ct_slope, *_ct_intercept, *_ct_amplitude, *_ct_exponent, *_ct_offset;
247     // To prevent unwanted signals
248     bool _locked;
249     bool _attr_lock;
251     FilterEffectsDialog(FilterEffectsDialog const &d);
252     FilterEffectsDialog& operator=(FilterEffectsDialog const &d);
253 };
255 } // namespace Dialog
256 } // namespace UI
257 } // namespace Inkscape
259 #endif // INKSCAPE_UI_DIALOG_FILTER_EFFECTS_H
261 /*
262   Local Variables:
263   mode:c++
264   c-file-style:"stroustrup"
265   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
266   indent-tabs-mode:nil
267   fill-column:99
268   End:
269 */
270 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :