49343c0ce78504804b72c84e9e602299d843de9a
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 "ui/widget/panel.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 UI::Widget::Panel {
42 public:
44 FilterEffectsDialog();
45 ~FilterEffectsDialog();
47 static FilterEffectsDialog &getInstance()
48 { return *new FilterEffectsDialog(); }
50 void set_attrs_locked(const bool);
51 protected:
52 virtual void show_all_vfunc();
53 private:
54 class SignalObserver;
56 class FilterModifier : public Gtk::VBox
57 {
58 public:
59 FilterModifier(FilterEffectsDialog&);
60 ~FilterModifier();
62 SPFilter* get_selected_filter();
63 void select_filter(const SPFilter*);
65 sigc::signal<void>& signal_filter_changed()
66 {
67 return _signal_filter_changed;
68 }
69 private:
70 class Columns : public Gtk::TreeModel::ColumnRecord
71 {
72 public:
73 Columns()
74 {
75 add(filter);
76 add(label);
77 add(sel);
78 }
80 Gtk::TreeModelColumn<SPFilter*> filter;
81 Gtk::TreeModelColumn<Glib::ustring> label;
82 Gtk::TreeModelColumn<int> sel;
83 };
85 static void on_activate_desktop(Application*, SPDesktop*, FilterModifier*);
86 void on_document_replaced(SPDesktop*, SPDocument*)
87 {
88 update_filters();
89 }
91 static void on_inkscape_change_selection(Application *, Selection *, FilterModifier*);
93 void update_selection(Selection *);
94 void on_filter_selection_changed();
96 void on_name_edited(const Glib::ustring&, const Glib::ustring&);
97 void on_selection_toggled(const Glib::ustring&);
99 void update_filters();
100 void filter_list_button_release(GdkEventButton*);
101 void add_filter();
102 void remove_filter();
103 void duplicate_filter();
104 void rename_filter();
106 sigc::connection _doc_replaced;
107 sigc::connection _resource_changed;
109 FilterEffectsDialog& _dialog;
110 Gtk::TreeView _list;
111 Glib::RefPtr<Gtk::ListStore> _model;
112 Columns _columns;
113 Gtk::CellRendererToggle _cell_toggle;
114 Gtk::Button _add;
115 Glib::RefPtr<Gtk::Menu> _menu;
116 sigc::signal<void> _signal_filter_changed;
117 std::auto_ptr<SignalObserver> _observer;
118 };
120 class PrimitiveColumns : public Gtk::TreeModel::ColumnRecord
121 {
122 public:
123 PrimitiveColumns()
124 {
125 add(primitive);
126 add(type_id);
127 add(type);
128 add(id);
129 }
131 Gtk::TreeModelColumn<SPFilterPrimitive*> primitive;
132 Gtk::TreeModelColumn<NR::FilterPrimitiveType> type_id;
133 Gtk::TreeModelColumn<Glib::ustring> type;
134 Gtk::TreeModelColumn<Glib::ustring> id;
135 };
137 class CellRendererConnection : public Gtk::CellRenderer
138 {
139 public:
140 CellRendererConnection();
141 Glib::PropertyProxy<void*> property_primitive();
143 static const int size = 24;
145 void set_text_width(const int w);
146 int get_text_width() const;
147 protected:
148 virtual void get_size_vfunc(Gtk::Widget& widget, const Gdk::Rectangle* cell_area,
149 int* x_offset, int* y_offset, int* width, int* height) const;
150 private:
151 // void* should be SPFilterPrimitive*, some weirdness with properties prevents this
152 Glib::Property<void*> _primitive;
153 int _text_width;
154 };
156 class PrimitiveList : public Gtk::TreeView
157 {
158 public:
159 PrimitiveList(FilterEffectsDialog&);
161 sigc::signal<void>& signal_primitive_changed();
163 void update();
164 void set_menu(Glib::RefPtr<Gtk::Menu>);
166 SPFilterPrimitive* get_selected();
167 void select(SPFilterPrimitive *prim);
169 int primitive_count() const;
170 protected:
171 bool on_expose_signal(GdkEventExpose*);
172 bool on_button_press_event(GdkEventButton*);
173 bool on_motion_notify_event(GdkEventMotion*);
174 bool on_button_release_event(GdkEventButton*);
175 void on_drag_end(const Glib::RefPtr<Gdk::DragContext>&);
176 private:
177 int init_text();
179 bool do_connection_node(const Gtk::TreeIter& row, const int input, std::vector<Gdk::Point>& points,
180 const int ix, const int iy);
181 const Gtk::TreeIter find_result(const Gtk::TreeIter& start, const int attr, int& src_id);
182 int find_index(const Gtk::TreeIter& target);
183 void draw_connection(const Gtk::TreeIter&, const int attr, const int text_start_x,
184 const int x1, const int y1, const int row_count);
185 void sanitize_connections(const Gtk::TreeIter& prim_iter);
186 void on_primitive_selection_changed();
187 bool on_scroll_timeout();
189 FilterEffectsDialog& _dialog;
190 Glib::RefPtr<Gtk::ListStore> _model;
191 PrimitiveColumns _columns;
192 CellRendererConnection _connection_cell;
193 Glib::RefPtr<Gtk::Menu> _primitive_menu;
194 Glib::RefPtr<Pango::Layout> _vertical_layout;
195 int _in_drag;
196 SPFilterPrimitive* _drag_prim;
197 sigc::signal<void> _signal_primitive_changed;
198 sigc::connection _scroll_connection;
199 int _autoscroll;
200 std::auto_ptr<SignalObserver> _observer;
201 };
203 void init_settings_widgets();
205 // Handlers
206 void add_primitive();
207 void remove_primitive();
208 void duplicate_primitive();
209 void convolve_order_changed();
211 void set_attr_direct(const AttrWidget*);
212 void set_child_attr_direct(const AttrWidget*);
213 void set_attr(SPObject*, const SPAttributeEnum, const gchar* val);
214 void update_settings_view();
215 void update_settings_sensitivity();
216 void update_color_matrix();
218 // Filter effect selection
219 FilterModifier _filter_modifier;
221 // View/add primitives
222 Gtk::VBox _primitive_box;
223 PrimitiveList _primitive_list;
224 UI::Widget::ComboBoxEnum<NR::FilterPrimitiveType> _add_primitive_type;
225 Gtk::Button _add_primitive;
227 // Bottom pane (filter effect primitive settings)
228 Gtk::VBox _settings_box;
229 Gtk::Label _empty_settings;
231 class Settings;
232 class MatrixAttr;
233 class ColorMatrixValues;
234 class LightSourceControl;
235 Settings* _settings;
236 Glib::RefPtr<Gtk::SizeGroup> _sizegroup;
238 // Color Matrix
239 ColorMatrixValues* _color_matrix_values;
241 // Convolve Matrix
242 MatrixAttr* _convolve_matrix;
243 DualSpinButton* _convolve_order;
244 MultiSpinButton* _convolve_target;
246 // For controlling setting sensitivity
247 Gtk::Widget* _k1, *_k2, *_k3, *_k4;
248 Gtk::Widget* _ct_table, *_ct_slope, *_ct_intercept, *_ct_amplitude, *_ct_exponent, *_ct_offset;
250 // To prevent unwanted signals
251 bool _locked;
252 bool _attr_lock;
254 FilterEffectsDialog(FilterEffectsDialog const &d);
255 FilterEffectsDialog& operator=(FilterEffectsDialog const &d);
256 };
258 } // namespace Dialog
259 } // namespace UI
260 } // namespace Inkscape
262 #endif // INKSCAPE_UI_DIALOG_FILTER_EFFECTS_H
264 /*
265 Local Variables:
266 mode:c++
267 c-file-style:"stroustrup"
268 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
269 indent-tabs-mode:nil
270 fill-column:99
271 End:
272 */
273 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :