Code

3509e21ad63244d0d993ff508a7fa4e33235a24f
[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/colorbutton.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 "dialog.h"
31 #include "sp-filter.h"
32 #include "sp-feconvolvematrix.h"
33 #include "ui/widget/filter-effect-chooser.h"
34 #include "ui/widget/spin-slider.h"
36 using namespace Inkscape::UI::Widget;
38 namespace Inkscape {
39 namespace UI {
40 namespace Dialog {
42 class FilterEffectsDialog : public Dialog {
43 public:
44     ~FilterEffectsDialog();
46     static FilterEffectsDialog *create() { return new FilterEffectsDialog(); }
47 private:
48     class FilterModifier : public Gtk::VBox, public FilterEffectChooser
49     {
50     public:
51         FilterModifier();
53         virtual SPFilter* get_selected_filter();
54         virtual void select_filter(const SPFilter*);
55         virtual Glib::SignalProxy0<void> signal_selection_changed();
56     private:
57         class CellRendererSel : public Gtk::CellRenderer
58         {
59         public:
60             CellRendererSel();
61             Glib::PropertyProxy<int> property_sel();
62         protected:
63             virtual void get_size_vfunc(Gtk::Widget&, const Gdk::Rectangle*,
64                                     int*, int*, int*, int*) const;
65             virtual void render_vfunc(const Glib::RefPtr<Gdk::Drawable>& win, Gtk::Widget& w,
66                                       const Gdk::Rectangle& bg_area, const Gdk::Rectangle& cell_area,
67                                       const Gdk::Rectangle& expose_area, Gtk::CellRendererState flags);
68         private:
69             const int _size;
70             Glib::Property<int> _sel;
71         };
72         
73         static void on_inkscape_change_selection(Inkscape::Application *, Inkscape::Selection *,
74                                                  FilterModifier*);
76         void filter_list_button_release(GdkEventButton*);
77         void add_filter();
78         void remove_filter();
79         void duplicate_filter();
80         void filter_name_edited(const Glib::ustring& path, const Glib::ustring& text);
82         Gtk::TreeView _list;
83         CellRendererSel _cell_sel;
84         Gtk::Button _add;
85         Glib::RefPtr<Gtk::Menu> _menu;
86     };
88     class PrimitiveColumns : public Gtk::TreeModel::ColumnRecord
89     {
90     public:
91         PrimitiveColumns()
92         {
93             add(primitive);
94             add(type_id);
95             add(type);
96             add(id);
97         }
99         Gtk::TreeModelColumn<SPFilterPrimitive*> primitive;
100         Gtk::TreeModelColumn<NR::FilterPrimitiveType> type_id;
101         Gtk::TreeModelColumn<Glib::ustring> type;
102         Gtk::TreeModelColumn<Glib::ustring> id;
103     };
105     class CellRendererConnection : public Gtk::CellRenderer
106     {
107     public:
108         CellRendererConnection();
109         Glib::PropertyProxy<void*> property_primitive();
110         static int input_count(const SPFilterPrimitive* prim);
112         static const int size = 24;
113         
114         void set_text_width(const int w);
115         int get_text_width() const;
116     protected:
117         virtual void get_size_vfunc(Gtk::Widget& widget, const Gdk::Rectangle* cell_area,
118                                     int* x_offset, int* y_offset, int* width, int* height) const;
119     private:
120         // void* should be SPFilterPrimitive*, some weirdness with properties prevents this
121         Glib::Property<void*> _primitive;
122         int _text_width;
123     };
125     class PrimitiveList : public Gtk::TreeView
126     {
127     public:
128         PrimitiveList(FilterEffectsDialog&);
130         Glib::SignalProxy0<void> signal_selection_changed();
132         void update();
133         void set_menu(Glib::RefPtr<Gtk::Menu>);
135         SPFilterPrimitive* get_selected();
136         void select(SPFilterPrimitive *prim);
138         int primitive_count() const;
139     protected:
140         bool on_expose_signal(GdkEventExpose*);
141         bool on_button_press_event(GdkEventButton*);
142         bool on_motion_notify_event(GdkEventMotion*);
143         bool on_button_release_event(GdkEventButton*);
144         void on_drag_end(const Glib::RefPtr<Gdk::DragContext>&);
145     private:
146         int init_text();
148         bool do_connection_node(const Gtk::TreeIter& row, const int input, std::vector<Gdk::Point>& points,
149                                 const int ix, const int iy);
150         const Gtk::TreeIter find_result(const Gtk::TreeIter& start, const SPAttributeEnum attr);
151         int find_index(const Gtk::TreeIter& target);
152         void draw_connection(const Gtk::TreeIter&, const SPAttributeEnum attr, const int text_start_x,
153                              const int x1, const int y1, const int row_count);
154         void sanitize_connections(const Gtk::TreeIter& prim_iter);
156         FilterEffectsDialog& _dialog;
157         Glib::RefPtr<Gtk::ListStore> _model;
158         PrimitiveColumns _columns;
159         CellRendererConnection _connection_cell;
160         Glib::RefPtr<Gtk::Menu> _primitive_menu;
161         Glib::RefPtr<Pango::Layout> _vertical_layout;
162         int _in_drag;
163         SPFilterPrimitive* _drag_prim;
164     };
166     FilterEffectsDialog();
167     void init_settings_widgets();
169     // Handlers
170     void add_primitive();
171     void remove_primitive();
172     void duplicate_primitive();
174     void set_attr_color(const SPAttributeEnum attr, const Gtk::ColorButton*);
175     void set_attr_direct(const SPAttributeEnum attr, const AttrWidget*);
176     void set_attr_special(const SPAttributeEnum);
177     void set_attr(const SPAttributeEnum, const gchar* val);
178     void update_settings_view();
179     void update_settings_sensitivity();
181     // Filter effect selection
182     FilterModifier _filter_modifier;
184     // View/add primitives
185     Gtk::VBox _primitive_box;
186     PrimitiveList _primitive_list;
187     UI::Widget::ComboBoxEnum<NR::FilterPrimitiveType> _add_primitive_type;
188     Gtk::Button _add_primitive;
190     // Bottom pane (filter effect primitive settings)
191     Gtk::VBox _settings_box;
192     Gtk::Label _empty_settings;
194     class Settings;
195     class ConvolveMatrix;
196     Settings* _settings;
198     // For controlling setting sensitivity
199     Gtk::Widget* _k1, *_k2, *_k3, *_k4;
201     FilterEffectsDialog(FilterEffectsDialog const &d);
202     FilterEffectsDialog& operator=(FilterEffectsDialog const &d);
203 };
205 } // namespace Dialog
206 } // namespace UI
207 } // namespace Inkscape
209 #endif // INKSCAPE_UI_DIALOG_FILTER_EFFECTS_H
211 /*
212   Local Variables:
213   mode:c++
214   c-file-style:"stroustrup"
215   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
216   indent-tabs-mode:nil
217   fill-column:99
218   End:
219 */
220 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :