Inkscape
Vector Graphics Editor
color-palette.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
5/* Authors:
6 * Michael Kowalski
7 *
8 * Copyright (C) 2021 Michael Kowalski
9 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
10 */
11
12#ifndef SEEN_COLOR_PALETTE_H
13#define SEEN_COLOR_PALETTE_H
14
15#include <memory>
16#include <vector>
17#include <glibmm/ustring.h>
18#include <glibmm/refptr.h>
19#include <gtkmm/box.h>
20#include <sigc++/signal.h>
21#include <2geom/int-point.h>
22
24#include "ui/widget/palette_t.h"
25#include "ui/widget/bin.h"
26
27namespace Gtk {
28class Builder;
29class Button;
30class FlowBox;
31class Popover;
32class ScrolledWindow;
33} // namespace Gtk
34
35namespace Inkscape::UI {
36
37namespace Dialog {
38class ColorItem;
39} // namespace Dialog
40
41namespace Widget {
42
43class ColorPaletteMenuItem;
44class PopoverMenu;
45
47{
48public:
50 ~ColorPalette() override;
51
52 // set colors presented in a palette
53 void set_colors(std::vector<Dialog::ColorItem*> const &swatches);
54 // list of palettes to present in the menu
55 void set_palettes(const std::vector<palette_t>& palettes);
56 // enable compact mode (true) with mini-scroll buttons, or normal mode (false) with regular scrollbars
57 void set_compact(bool compact);
58 // enlarge color tiles in a pinned panel
59 void set_large_pinned_panel(bool large);
60 // preferred number of colors in a group (used for color alignment in columns)
61 void set_page_size(int page_size);
62
63 void set_tile_size(int size_px);
64 void set_tile_border(int border_px);
65 void set_rows(int rows);
66 void set_aspect(double aspect);
67 // show horizontal scrollbar when only 1 row is set
68 void enable_scrollbar(bool show);
69 // allow tile stretching (horizontally)
70 void enable_stretch(bool enable);
71 // Show labels in swatches dialog
72 void enable_labels(bool labels);
73 // Show/hide settings
74 void set_settings_visibility(bool show);
75
76 int get_tile_size() const;
77 int get_tile_border() const;
78 int get_rows() const;
79 double get_aspect() const;
80 bool is_scrollbar_enabled() const;
81 bool is_stretch_enabled() const;
82 bool is_pinned_panel_large() const;
83 bool are_labels_enabled() const;
84
85 void set_selected(const Glib::ustring& id);
86
87 sigc::signal<void (Glib::ustring)>& get_palette_selected_signal();
88 sigc::signal<void ()>& get_settings_changed_signal();
89
90 Gtk::Popover& get_settings_popover();
91
92 void set_filter(std::function<bool (const Dialog::ColorItem&)> filter);
93 void apply_filter();
94
95private:
96 void resize();
97 void set_up_scrolling();
98 void scroll(int dx, int dy, double snap, bool smooth);
99 void do_scroll(int dx, int dy);
100 static gboolean scroll_cb(gpointer self);
101 void _set_tile_size(int size_px);
102 void _set_tile_border(int border_px);
103 void _set_rows(int rows);
104 void _set_aspect(double aspect);
105 void _enable_scrollbar(bool show);
106 void _enable_stretch(bool enable);
107 void _set_large_pinned_panel(bool large);
108 static gboolean check_scrollbar(gpointer self);
109 void update_checkbox();
110 void update_stretch();
111 int get_tile_size(bool horz) const;
112 int get_tile_width() const;
113 int get_tile_height() const;
114 int get_palette_height() const;
115
116 Gtk::Widget *_get_widget(Dialog::ColorItem *item);
117 void rebuild_widgets();
118 void refresh();
119
120 std::vector<Dialog::ColorItem *> _normal_items;
121 std::vector<Dialog::ColorItem *> _pinned_items;
122
123 Glib::RefPtr<Gtk::Builder> _builder;
124 Gtk::FlowBox& _normal_box;
125 Gtk::FlowBox& _pinned_box;
126 Gtk::ScrolledWindow& _scroll;
127 Gtk::FlowBox& _scroll_btn;
132 std::unique_ptr<PopoverMenu> _menu;
133 std::vector<std::unique_ptr<ColorPaletteMenuItem>> _palette_menu_items;
134 int _size = 10;
135 int _border = 0;
136 int _rows = 1;
137 double _aspect = 0.0;
138 bool _compact = true;
139 sigc::signal<void (Glib::ustring)> _signal_palette_selected;
140 sigc::signal<void ()> _signal_settings_changed;
141 bool _in_update = false;
143 bool _force_scrollbar = false;
144 bool _stretch_tiles = false;
145 double _scroll_step = 0.0; // smooth scrolling step
146 double _scroll_final = 0.0; // smooth scroll final value
148 bool _show_labels = false;
149 int _page_size = 0;
152};
153
154} // namespace Widget
155} // namespace Inkscape::UI
156
157#endif // SEEN_COLOR_PALETTE_H
158
159/*
160 Local Variables:
161 mode:c++
162 c-file-style:"stroustrup"
163 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
164 indent-tabs-mode:nil
165 fill-column:99
166 End:
167*/
168// vim:filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99:
Bin: widget that can hold one child, useful as a base class of custom widgets.
Two-dimensional point with integer coordinates.
Definition: int-point.h:57
The color item you see on-screen as a clickable box.
Definition: color-item.h:51
The Bin is a widget that can hold a single child.
Definition: bin.h:30
std::vector< Dialog::ColorItem * > _normal_items
sigc::signal< void()> _signal_settings_changed
Gtk::Widget * _get_widget(Dialog::ColorItem *item)
Glib::RefPtr< Gtk::Builder > _builder
static gboolean scroll_cb(gpointer self)
static gboolean check_scrollbar(gpointer self)
sigc::signal< void(Glib::ustring)> _signal_palette_selected
std::unique_ptr< PopoverMenu > _menu
void set_selected(const Glib::ustring &id)
void set_filter(std::function< bool(const Dialog::ColorItem &)> filter)
void set_colors(std::vector< Dialog::ColorItem * > const &swatches)
sigc::signal< void()> & get_settings_changed_signal()
sigc::signal< void(Glib::ustring)> & get_palette_selected_signal()
void set_palettes(const std::vector< palette_t > &palettes)
std::vector< std::unique_ptr< ColorPaletteMenuItem > > _palette_menu_items
std::vector< Dialog::ColorItem * > _pinned_items
void scroll(int dx, int dy, double snap, bool smooth)
SPItem * item
Definition: imagemagick.cpp:43
Cartesian point / 2D vector with integer coordinates.
Definition: desktop.h:51
Button
helper to stop accidents on int vs gtkmm3's weak=typed enums, & looks nicer!
Definition: controller.h:70
static constexpr int dx
User interface code.
Definition: desktop.h:114
Color palette widget.
Glib::RefPtr< Gtk::Adjustment > smooth