Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
color-picker.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
5/* Authors:
6 * Lauris Kaplinski <lauris@kaplinski.com>
7 * Ralf Stephan <ralf@ark.in-berlin.de>
8 *
9 * Copyright (C) Authors 2000-2005
10 *
11 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
12 */
13
14#ifndef SEEN_INKSCAPE_COLOR_PICKER_H
15#define SEEN_INKSCAPE_COLOR_PICKER_H
16
17#include "labelled.h"
18#include <cstdint>
19#include <glibmm/ustring.h>
20#include <gtkmm/builder.h>
21#include <gtkmm/popover.h>
22#include <gtkmm/widget.h>
23#include <utility>
24
25#include "colors/color.h"
26#include "colors/color-set.h"
28#include <gtkmm/menubutton.h>
29#include <gtkmm/dialog.h>
30#include <sigc++/signal.h>
31
32namespace Gtk {
33class Builder;
34}
35
36namespace Inkscape::UI::Widget {
37
38class ColorNotebook;
39
40class ColorPicker : public Gtk::MenuButton {
41public:
42 [[nodiscard]] ColorPicker(Glib::ustring title,
43 Glib::ustring const &tip,
44 Colors::Color const &initial,
45 bool undo,
46 bool use_transparency = true);
47
48 ColorPicker(BaseObjectType *cobject, Glib::RefPtr<Gtk::Builder> const &,
49 Glib::ustring title, bool use_transparency = true);
50
51 ~ColorPicker() override;
52
53 void setColor(Colors::Color const &);
54 void open();
55 void close();
56 void setTitle(Glib::ustring title);
57
58 sigc::connection connectChanged(sigc::slot<void (Colors::Color const &)> slot)
59 {
60 return _changed_signal.connect(std::move(slot));
61 }
62
63 [[nodiscard]] Colors::Color get_current_color() const {
64 if (_colors->isEmpty())
65 return Colors::Color(0x0);
66 return _colors->getAverage();
67 }
68
69private:
71 virtual void on_changed(Colors::Color const &);
72 void _construct();
73 void set_preview(std::uint32_t rgba);
74
76 Glib::ustring _title;
77 sigc::signal<void (Colors::Color const &)> _changed_signal;
78 bool _undo = false;
79 bool _updating = false;
80 std::shared_ptr<Colors::ColorSet> _colors;
81 Gtk::Popover _popup;
83};
84
85
87public:
88 [[nodiscard]] LabelledColorPicker(Glib::ustring const &label,
89 Glib::ustring const &title,
90 Glib::ustring const &tip,
91 Colors::Color const &initial,
92 bool undo)
93 : Labelled(label, tip, new ColorPicker(title, tip, initial, undo)) {
94 property_sensitive().signal_changed().connect([this](){
95 getWidget()->set_sensitive(is_sensitive());
96 });
97 }
98
99 void setColor(Colors::Color const &color)
100 {
101 static_cast<ColorPicker *>(getWidget())->setColor(color);
102 }
103
105 {
106 static_cast<ColorPicker *>(getWidget())->close();
107 }
108
109 sigc::connection connectChanged(sigc::slot<void (Colors::Color const &)> slot)
110 {
111 return static_cast<ColorPicker*>(getWidget())->connectChanged(std::move(slot));
112 }
113};
114
115} // namespace Inkscape::UI::Widget
116
117#endif // SEEN_INKSCAPE_COLOR_PICKER_H
118
119/*
120 Local Variables:
121 mode:c++
122 c-file-style:"stroustrup"
123 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
124 indent-tabs-mode:nil
125 fill-column:99
126 End:
127*/
128// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
void undo(SPDocument *document)
Colors::Color get_current_color() const
void set_preview(std::uint32_t rgba)
sigc::connection connectChanged(sigc::slot< void(Colors::Color const &)> slot)
void setTitle(Glib::ustring title)
virtual void on_changed(Colors::Color const &)
void setColor(Colors::Color const &)
sigc::signal< void(Colors::Color const &)> _changed_signal
std::shared_ptr< Colors::ColorSet > _colors
A color preview widget, used within a picker button and style indicator.
void setColor(Colors::Color const &color)
sigc::connection connectChanged(sigc::slot< void(Colors::Color const &)> slot)
LabelledColorPicker(Glib::ustring const &label, Glib::ustring const &title, Glib::ustring const &tip, Colors::Color const &initial, bool undo)
Adds a label with optional icon to another widget.
Definition labelled.h:31
Gtk::Widget const * getWidget() const
Definition labelled.h:48
A set of colors which can be modified together used for color pickers.
Glib::ustring label
Definition desktop.h:50
Custom widgets.
Definition desktop.h:126