Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
togglebutton.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>
4 * Copyright (C) Jabiertxo Arraiza Cenoz 2014 <j.b.c.engelen@utwente.nl>
5 *
6 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
7 */
8
9#include "togglebutton.h"
10
11#include <utility>
12#include <glibmm/i18n.h>
13#include <gtkmm/image.h>
14#include <gtkmm/label.h>
15
16#include "inkscape.h"
17#include "selection.h"
18
19#include "live_effects/effect.h"
20#include "ui/icon-loader.h"
21#include "ui/icon-names.h"
22#include "ui/pack.h"
23#include "ui/util.h"
26
28
29ToggleButtonParam::ToggleButtonParam(const Glib::ustring &label, const Glib::ustring &tip, const Glib::ustring &key,
30 Inkscape::UI::Widget::Registry *wr, Effect *effect, bool default_value,
31 Glib::ustring inactive_label, char const *_icon_active, char const *_icon_inactive,
32 Gtk::IconSize _icon_size)
33 : Parameter(label, tip, key, wr, effect)
34 , value(default_value)
35 , defvalue(default_value)
36 , inactive_label(std::move(inactive_label))
37 , _icon_active(_icon_active)
38 , _icon_inactive(_icon_inactive)
39 , _icon_size(_icon_size)
40{
41 checkwdg = nullptr;
42}
43
45 if (_toggled_connection.connected()) {
46 _toggled_connection.disconnect();
47 }
48}
49
50void
55
56bool
58{
60 return true; // not correct: if value is unacceptable, should return false!
61}
62
63Glib::ustring
65{
66 return value ? "true" : "false";
67}
68
69Glib::ustring
71{
72 return defvalue ? "true" : "false";
73}
74
75void
77{
78 defvalue = default_value;
79}
80
81void
86
87Gtk::Widget *
89{
90 if (_toggled_connection.connected()) {
91 _toggled_connection.disconnect();
92 }
93
94 auto const checkwdg = Gtk::make_managed<UI::Widget::RegisteredToggleButton>( param_label,
97 *param_wr,
98 false,
101
102 auto const box_button = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL);
103
104 auto const label = Gtk::make_managed<Gtk::Label>();
105 if (!param_label.empty()) {
106 if (value || inactive_label.empty()) {
107 label->set_text(param_label.c_str());
108 } else {
109 label->set_text(inactive_label.c_str());
110 }
111 }
112 label->set_visible(true);
113 if (_icon_active) {
114 if (!_icon_inactive) {
116 }
117 box_button->set_visible(true);
118 Gtk::Widget *icon_button = nullptr;
119 if (!value) {
121 } else {
123 }
124 icon_button->set_visible(true);
125 UI::pack_start(*box_button, *icon_button, false, false, 1);
126 if (!param_label.empty()) {
127 UI::pack_start(*box_button, *label, false, false, 1);
128 }
129 } else {
130 UI::pack_start(*box_button, *label, false, false, 1);
131 }
132
133 checkwdg->set_child(*box_button);
136 checkwdg->set_undo_parameters(_("Change togglebutton parameter"), INKSCAPE_ICON("dialog-path-effects"));
137
138 _toggled_connection = checkwdg->signal_toggled().connect(sigc::mem_fun(*this, &ToggleButtonParam::toggled));
139 return checkwdg;
140}
141
142void
144{
145 if (!_toggled_connection.connected()) {
146 return;
147 }
148
149 if (!checkwdg){
150 return;
151 }
152
153 auto const box_button = dynamic_cast<Gtk::Box *>(checkwdg->get_child());
154 if (!box_button){
155 return;
156 }
157
158 auto const children = UI::get_children(*box_button);
159 g_assert(!children.empty());
160
161 if (!param_label.empty()) {
162 auto const lab = dynamic_cast<Gtk::Label *>(children.back());
163 if (!lab) return;
164
165 if (value || inactive_label.empty()) {
166 lab->set_text(param_label.c_str());
167 } else {
168 lab->set_text(inactive_label.c_str());
169 }
170 }
171
172 if ( _icon_active ) {
173 auto const im = dynamic_cast<Gtk::Image *>(children.front());
174 if (!im) return;
175
176 gtk_image_set_from_icon_name(im->gobj(), value ? _icon_active : _icon_inactive);
177 im->set_icon_size(_icon_size);
178 }
179}
180
181void
183{
184 if (value != newvalue) {
186 }
187 value = newvalue;
189}
190
191void
193 if (SP_ACTIVE_DESKTOP) {
194 Inkscape::Selection *selection = SP_ACTIVE_DESKTOP->getSelection();
195 selection->emitModified();
196 }
197 _signal_toggled.emit();
198}
199
200} // namespace Inkscape::LivePathEffect
201
202/*
203 Local Variables:
204 mode:c++
205 c-file-style:"stroustrup"
206 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
207 indent-tabs-mode:nil
208 fill-column:99
209 End:
210*/
211 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
Inkscape::XML::Node * getRepr()
Definition effect.cpp:1928
Inkscape::UI::Widget::Registry * param_wr
Definition parameter.h:99
Glib::ustring param_getDefaultSVGValue() const override
bool param_readSVGValue(const gchar *strvalue) override
void param_update_default(bool default_value)
Inkscape::UI::Widget::RegisteredToggleButton * checkwdg
ToggleButtonParam(const Glib::ustring &label, const Glib::ustring &tip, const Glib::ustring &key, Inkscape::UI::Widget::Registry *wr, Effect *effect, bool default_value=false, Glib::ustring inactive_label="", char const *icon_active=nullptr, char const *icon_inactive=nullptr, Gtk::IconSize icon_size=Gtk::IconSize::NORMAL)
Glib::ustring param_getSVGValue() const override
The set of selected SPObjects for a given document and layer model.
Definition selection.h:80
void set_undo_parameters(Glib::ustring _event_description, Glib::ustring _icon_name, std::string undo_id="")
Utility functions to convert ascii representations to numbers.
Gtk::Image * sp_get_icon_image(Glib::ustring const &icon_name, int size)
Icon Loader.
Macro for icon names used in Inkscape.
Glib::ustring label
Live Path Effects code.
std::vector< Gtk::Widget * > get_children(Gtk::Widget &widget)
Get a vector of the widgetʼs children, from get_first_child() through each get_next_sibling().
Definition util.cpp:141
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
bool read_bool(gchar const *value, bool default_value)
Definition converters.h:61
STL namespace.
static cairo_user_data_key_t key
Helpers for using Gtk::Boxes, encapsulating large changes between GTK3 & GTK4.