Code

3d834c4b2cb47f6268b28c2d7dca83d8d1ef803b
[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/cellrendererspin.h>
20 #include <gtkmm/comboboxtext.h>
21 #include <gtkmm/drawingarea.h>
22 #include <gtkmm/frame.h>
23 #include <gtkmm/liststore.h>
24 #include <gtkmm/menu.h>
25 #include <gtkmm/sizegroup.h>
26 #include <gtkmm/treeview.h>
28 #include "attributes.h"
29 #include "dialog.h"
30 #include "sp-filter.h"
31 #include "sp-feconvolvematrix.h"
32 #include "ui/widget/filter-effect-chooser.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 Dialog {
44 public:
45     ~FilterEffectsDialog();
47     void set_attrs_locked(const bool);
49     static FilterEffectsDialog *create() { return new FilterEffectsDialog(); }
50 private:
51     class FilterModifier : public Gtk::VBox, public FilterEffectChooser
52     {
53     public:
54         FilterModifier();
56         virtual SPFilter* get_selected_filter();
57         virtual void select_filter(const SPFilter*);
58         virtual Glib::SignalProxy0<void> signal_selection_changed();
59     private:
60         class CellRendererSel : public Gtk::CellRenderer
61         {
62         public:
63             CellRendererSel();
64             Glib::PropertyProxy<int> property_sel();
65         protected:
66             virtual void get_size_vfunc(Gtk::Widget&, const Gdk::Rectangle*,
67                                     int*, int*, int*, int*) const;
68             virtual void render_vfunc(const Glib::RefPtr<Gdk::Drawable>& win, Gtk::Widget& w,
69                                       const Gdk::Rectangle& bg_area, const Gdk::Rectangle& cell_area,
70                                       const Gdk::Rectangle& expose_area, Gtk::CellRendererState flags);
71         private:
72             const int _size;
73             Glib::Property<int> _sel;
74         };
75         
76         static void on_inkscape_change_selection(Application *, Selection *, FilterModifier*);
77         void update_selection(Selection *);
79         void filter_list_button_press(GdkEventButton*);
80         void filter_list_button_release(GdkEventButton*);
81         void add_filter();
82         void remove_filter();
83         void duplicate_filter();
84         void filter_name_edited(const Glib::ustring& path, const Glib::ustring& text);
86         Gtk::TreeView _list;
87         CellRendererSel _cell_sel;
88         Gtk::Button _add;
89         Glib::RefPtr<Gtk::Menu> _menu;
90     };
92     class PrimitiveColumns : public Gtk::TreeModel::ColumnRecord
93     {
94     public:
95         PrimitiveColumns()
96         {
97             add(primitive);
98             add(type_id);
99             add(type);
100             add(id);
101         }
103         Gtk::TreeModelColumn<SPFilterPrimitive*> primitive;
104         Gtk::TreeModelColumn<NR::FilterPrimitiveType> type_id;
105         Gtk::TreeModelColumn<Glib::ustring> type;
106         Gtk::TreeModelColumn<Glib::ustring> id;
107     };
109     class CellRendererConnection : public Gtk::CellRenderer
110     {
111     public:
112         CellRendererConnection();
113         Glib::PropertyProxy<void*> property_primitive();
115         static const int size = 24;
116         
117         void set_text_width(const int w);
118         int get_text_width() const;
119     protected:
120         virtual void get_size_vfunc(Gtk::Widget& widget, const Gdk::Rectangle* cell_area,
121                                     int* x_offset, int* y_offset, int* width, int* height) const;
122     private:
123         // void* should be SPFilterPrimitive*, some weirdness with properties prevents this
124         Glib::Property<void*> _primitive;
125         int _text_width;
126     };
128     class PrimitiveList : public Gtk::TreeView
129     {
130     public:
131         PrimitiveList(FilterEffectsDialog&);
133         Glib::SignalProxy0<void> signal_selection_changed();
135         void update();
136         void set_menu(Glib::RefPtr<Gtk::Menu>);
138         SPFilterPrimitive* get_selected();
139         void select(SPFilterPrimitive *prim);
141         int primitive_count() const;
142     protected:
143         bool on_expose_signal(GdkEventExpose*);
144         bool on_button_press_event(GdkEventButton*);
145         bool on_motion_notify_event(GdkEventMotion*);
146         bool on_button_release_event(GdkEventButton*);
147         void on_drag_end(const Glib::RefPtr<Gdk::DragContext>&);
148     private:
149         int init_text();
151         bool do_connection_node(const Gtk::TreeIter& row, const int input, std::vector<Gdk::Point>& points,
152                                 const int ix, const int iy);
153         const Gtk::TreeIter find_result(const Gtk::TreeIter& start, const int attr, int& src_id);
154         int find_index(const Gtk::TreeIter& target);
155         void draw_connection(const Gtk::TreeIter&, const int attr, const int text_start_x,
156                              const int x1, const int y1, const int row_count);
157         void sanitize_connections(const Gtk::TreeIter& prim_iter);
159         FilterEffectsDialog& _dialog;
160         Glib::RefPtr<Gtk::ListStore> _model;
161         PrimitiveColumns _columns;
162         CellRendererConnection _connection_cell;
163         Glib::RefPtr<Gtk::Menu> _primitive_menu;
164         Glib::RefPtr<Pango::Layout> _vertical_layout;
165         int _in_drag;
166         SPFilterPrimitive* _drag_prim;
167     };
169     FilterEffectsDialog();
170     void init_settings_widgets();
172     // Handlers
173     void add_primitive();
174     void remove_primitive();
175     void duplicate_primitive();
176     void convolve_order_changed();
178     void set_attr_direct(const AttrWidget*);
179     void set_child_attr_direct(const AttrWidget*);
180     void set_attr(SPObject*, const SPAttributeEnum, const gchar* val);
181     void update_settings_view();
182     void update_settings_sensitivity();
184     // Filter effect selection
185     FilterModifier _filter_modifier;
187     // View/add primitives
188     Gtk::VBox _primitive_box;
189     PrimitiveList _primitive_list;
190     UI::Widget::ComboBoxEnum<NR::FilterPrimitiveType> _add_primitive_type;
191     Gtk::Button _add_primitive;
193     // Bottom pane (filter effect primitive settings)
194     Gtk::VBox _settings_box;
195     Gtk::Label _empty_settings;
197     class Settings;
198     class ConvolveMatrix;
199     class LightSourceControl;
200     Settings* _settings;
201     Glib::RefPtr<Gtk::SizeGroup> _sizegroup;
203     // Convolve Matrix
204     ConvolveMatrix* _convolve_matrix;
205     DualSpinButton* _convolve_order;
206     MultiSpinButton* _convolve_target;
208     // For controlling setting sensitivity
209     Gtk::Widget* _k1, *_k2, *_k3, *_k4;
211     // To prevent unwanted signals
212     bool _locked;
214     FilterEffectsDialog(FilterEffectsDialog const &d);
215     FilterEffectsDialog& operator=(FilterEffectsDialog const &d);
216 };
218 } // namespace Dialog
219 } // namespace UI
220 } // namespace Inkscape
222 #endif // INKSCAPE_UI_DIALOG_FILTER_EFFECTS_H
224 /*
225   Local Variables:
226   mode:c++
227   c-file-style:"stroustrup"
228   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
229   indent-tabs-mode:nil
230   fill-column:99
231   End:
232 */
233 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :