summaryrefslogtreecommitdiffstats
path: root/src/ui/widget/gradient-selector.h
blob: f76949deaa05e32dc48091ef89f3b055dd01ada2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// SPDX-License-Identifier: GPL-2.0-or-later
#ifndef SEEN_GRADIENT_SELECTOR_H
#define SEEN_GRADIENT_SELECTOR_H

/*
 * Gradient vector and position widget
 *
 * Authors:
 *   Lauris Kaplinski <lauris@kaplinski.com>
 *   Jon A. Cruz <jon@joncruz.org>
 *
 * Copyright (C) 2001-2002 Lauris Kaplinski
 * Copyright (C) 2001 Ximian, Inc.
 * Copyright (C) 2010 Jon A. Cruz
 *
 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
 */

#include <gtkmm/box.h>
#include <gtkmm/liststore.h>
#include <gtkmm/scrolledwindow.h>

#include "object/sp-gradient-spread.h"
#include "object/sp-gradient-units.h"
#include <vector>
#include "gradient-selector-interface.h"

class SPDocument;
class SPGradient;

namespace Gtk {
class Button;
class CellRendererPixbuf;
class CellRendererText;
class ScrolledWindow;
class TreeView;
} // namespace Gtk


namespace Inkscape {
namespace UI {
namespace Widget {
class GradientVectorSelector;

class GradientSelector : public Gtk::Box, public GradientSelectorInterface {
  public:
   //  enum SelectorMode { MODE_LINEAR, MODE_RADIAL, MODE_SWATCH };

    class ModelColumns : public Gtk::TreeModel::ColumnRecord {
      public:
        ModelColumns()
        {
            add(name);
            add(refcount);
            add(color);
            add(data);
            add(pixbuf);
        }
        ~ModelColumns() override = default;

        Gtk::TreeModelColumn<Glib::ustring> name;
        Gtk::TreeModelColumn<unsigned long> color;
        Gtk::TreeModelColumn<gint> refcount;
        Gtk::TreeModelColumn<SPGradient *> data;
        Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf>> pixbuf;
    };


  private:
    sigc::signal<void> _signal_grabbed;
    sigc::signal<void> _signal_dragged;
    sigc::signal<void> _signal_released;
    sigc::signal<void, SPGradient *> _signal_changed;
    SelectorMode _mode;

    SPGradientUnits _gradientUnits;
    SPGradientSpread _gradientSpread;

    /* Vector selector */
    GradientVectorSelector *_vectors;

    /* Tree */
    bool _checkForSelected(const Gtk::TreePath &path, const Gtk::TreeIter &iter, SPGradient *vector);
    bool onKeyPressEvent(GdkEventKey *event);
    void onTreeSelection();
    void onGradientRename(const Glib::ustring &path_string, const Glib::ustring &new_text);
    void onTreeNameColClick();
    void onTreeColorColClick();
    void onTreeCountColClick();

    Gtk::TreeView *_treeview;
    Gtk::ScrolledWindow *_scrolled_window;
    ModelColumns *_columns;
    Glib::RefPtr<Gtk::ListStore> _store;
    Gtk::CellRendererPixbuf *_icon_renderer;
    Gtk::CellRendererText *_text_renderer;

    /* Editing buttons */
    Gtk::Button *_edit;
    Gtk::Button *_add;
    Gtk::Button *_del;
    Gtk::Button *_del2;

    bool _blocked;

    std::vector<Gtk::Widget *> _nonsolid;
    std::vector<Gtk::Widget *> _swatch_widgets;

    void selectGradientInTree(SPGradient *vector);
    void moveSelection(int amount, bool down = true, bool toEnd = false);

    void style_button(Gtk::Button *btn, char const *iconName);
    void check_del_button();

    // Signal handlers
    void add_vector_clicked();
    void edit_vector_clicked();
    void delete_vector_clicked();
    void delete_vector_clicked_2();
    void vector_set(SPGradient *gr);

  public:
    GradientSelector();

    void show_edit_button(bool show);
    void set_name_col_size(int min_width);
    void set_gradient_size(int width, int height);

    inline decltype(_signal_changed) signal_changed() const { return _signal_changed; }
    inline decltype(_signal_grabbed) signal_grabbed() const { return _signal_grabbed; }
    inline decltype(_signal_dragged) signal_dragged() const { return _signal_dragged; }
    inline decltype(_signal_released) signal_released() const { return _signal_released; }

    void setGradient(SPGradient* gradient) override { /* no op */ }
    SPGradient *getVector() override;
    void setVector(SPDocument *doc, SPGradient *vector) override;
    void setMode(SelectorMode mode) override;
    void setUnits(SPGradientUnits units) override;
    SPGradientUnits getUnits() override;
    void setSpread(SPGradientSpread spread) override;
    SPGradientSpread getSpread() override;
};

} // namespace Widget
} // namespace UI
} // namespace Inkscape

#endif // SEEN_GRADIENT_SELECTOR_H


/*
  Local Variables:
  mode:c++
  c-file-style:"stroustrup"
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
  indent-tabs-mode:nil
  fill-column:99
  End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :