Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
colorpicker.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Authors:
4 *
5 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
6 */
7
8#include "colorpicker.h"
9
10#include <glibmm/i18n.h>
11#include <gtkmm/box.h>
12
13#include "document-undo.h" // for DocumentUndo
14#include "live_effects/effect.h" // for Effect
15#include "live_effects/parameter/colorpicker.h" // for ColorPickerParam
16#include "ui/icon-names.h" // for INKSCAPE_ICON
17#include "ui/pack.h" // for pack_start
18#include "ui/widget/registered-widget.h" // for RegisteredColorPicker
19#include "util/safe-printf.h" // for safeprintf
20
21class SPDocument;
22
23namespace Inkscape {
24namespace LivePathEffect {
25
26ColorPickerParam::ColorPickerParam( const Glib::ustring& label, const Glib::ustring& tip,
27 const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr,
28 Effect* effect, std::optional<Colors::Color> default_color)
29 : Parameter(label, tip, key, wr, effect),
30 value(default_color),
31 defvalue(default_color)
32{
33}
34
35void
40
41void
42ColorPickerParam::param_update_default(const gchar * default_value)
43{
44 defvalue->set(default_value ? default_value : "");
45}
46
47bool
49{
50 param_setValue(Colors::Color::parse(val));
51 return true;
52}
53
54Glib::ustring
56{
57 return value->toString();
58}
59
60Glib::ustring
62{
63 return defvalue->toString();
64}
65
66Gtk::Widget *
68{
69 auto const hbox = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL, 2);
70 hbox->set_margin(5);
71
72 auto const colorpickerwdg = Gtk::make_managed<UI::Widget::RegisteredColorPicker>( param_label,
76 param_key + "_opacity_LPE",
77 *param_wr,
80
81 {
82 SPDocument *document = param_effect->getSPDoc();
83 DocumentUndo::ScopedInsensitive _no_undo(document);
84 colorpickerwdg->setColor(*value);
85 }
86
87 colorpickerwdg->set_undo_parameters(_("Change color button parameter"), INKSCAPE_ICON("dialog-path-effects"));
88
89 UI::pack_start(*hbox, *colorpickerwdg, true, true);
90 return hbox;
91}
92
93void
94ColorPickerParam::param_setValue(std::optional<Colors::Color> newvalue)
95{
96 value = newvalue;
97}
98
99} /* namespace LivePathEffect */
100} /* namespace Inkscape */
101
102/*
103 Local Variables:
104 mode:c++
105 c-file-style:"stroustrup"
106 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
107 indent-tabs-mode:nil
108 fill-column:99
109 End:
110*/
111// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
RAII-style mechanism for creating a temporary undo-insensitive context.
void param_setValue(std::optional< Colors::Color > newvalue)
std::optional< Colors::Color > value
Definition colorpicker.h:44
Glib::ustring param_getDefaultSVGValue() const override
bool param_readSVGValue(const gchar *strvalue) override
void param_update_default(const gchar *default_value) override
std::optional< Colors::Color > defvalue
Definition colorpicker.h:45
ColorPickerParam(const Glib::ustring &label, const Glib::ustring &tip, const Glib::ustring &key, Inkscape::UI::Widget::Registry *wr, Effect *effect, std::optional< Colors::Color >={})
Glib::ustring param_getSVGValue() const override
Inkscape::XML::Node * getRepr()
Definition effect.cpp:1928
Inkscape::UI::Widget::Registry * param_wr
Definition parameter.h:99
Typed SVG document implementation.
Definition document.h:101
TODO: insert short description here.
Macro for icon names used in Inkscape.
Glib::ustring label
void pack_start(Gtk::Box &box, Gtk::Widget &child, bool const expand, bool const fill, unsigned const padding)
Adds child to box, packed with reference to the start of box.
Definition pack.cpp:141
Helper class to stream background task notifications as a series of messages.
static cairo_user_data_key_t key
Helpers for using Gtk::Boxes, encapsulating large changes between GTK3 & GTK4.
static Inkscape::Colors::Color default_color(SPItem *item)
Find default color based on colors in existing fill.