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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
// SPDX-License-Identifier: GPL-2.0-or-later
/**
* @file
* Dialog for moving knots. Only used by Measure Tool.
*/
/* Author:
* Bryce W. Harrington <bryce@bryceharrington.com>
* Andrius R. <knutux@gmail.com>
* Abhishek Sharma
*
* Copyright (C) 2004 Bryce Harrington
* Copyright (C) 2006 Andrius R.
*
* Released under GNU GPL v2+, read the file 'COPYING' for more information.
*/
#include "knot-properties.h"
#include <boost/lexical_cast.hpp>
#include <glibmm/i18n.h>
#include <glibmm/main.h>
#include "desktop.h"
#include "ui/knot/knot.h"
#include "util/units.h"
namespace Inkscape {
namespace UI {
namespace Dialogs {
KnotPropertiesDialog::KnotPropertiesDialog()
: _knotpoint(nullptr),
_position_visible(false),
_close_button(_("_Close"), true)
{
Gtk::Box *mainVBox = get_content_area();
_layout_table.set_row_spacing(4);
_layout_table.set_column_spacing(4);
_unit_name = "";
// Layer name widgets
_knot_x_entry.set_activates_default(true);
_knot_x_entry.set_digits(4);
_knot_x_entry.set_increments(1,1);
_knot_x_entry.set_range(-G_MAXDOUBLE, G_MAXDOUBLE);
_knot_x_entry.set_hexpand();
_knot_x_label.set_label(_("Position X:"));
_knot_x_label.set_halign(Gtk::ALIGN_END);
_knot_x_label.set_valign(Gtk::ALIGN_CENTER);
_knot_y_entry.set_activates_default(true);
_knot_y_entry.set_digits(4);
_knot_y_entry.set_increments(1,1);
_knot_y_entry.set_range(-G_MAXDOUBLE, G_MAXDOUBLE);
_knot_y_entry.set_hexpand();
_knot_y_label.set_label(_("Position Y:"));
_knot_y_label.set_halign(Gtk::ALIGN_END);
_knot_y_label.set_valign(Gtk::ALIGN_CENTER);
_layout_table.attach(_knot_x_label, 0, 0, 1, 1);
_layout_table.attach(_knot_x_entry, 1, 0, 1, 1);
_layout_table.attach(_knot_y_label, 0, 1, 1, 1);
_layout_table.attach(_knot_y_entry, 1, 1, 1, 1);
mainVBox->pack_start(_layout_table, true, true, 4);
// Buttons
_close_button.set_can_default();
_apply_button.set_use_underline(true);
_apply_button.set_can_default();
_close_button.signal_clicked()
.connect(sigc::mem_fun(*this, &KnotPropertiesDialog::_close));
_apply_button.signal_clicked()
.connect(sigc::mem_fun(*this, &KnotPropertiesDialog::_apply));
signal_delete_event().connect(
sigc::bind_return(
sigc::hide(sigc::mem_fun(*this, &KnotPropertiesDialog::_close)),
true
)
);
add_action_widget(_close_button, Gtk::RESPONSE_CLOSE);
add_action_widget(_apply_button, Gtk::RESPONSE_APPLY);
_apply_button.grab_default();
show_all_children();
set_focus(_knot_y_entry);
}
KnotPropertiesDialog::~KnotPropertiesDialog() {
}
void KnotPropertiesDialog::showDialog(SPDesktop *desktop, const SPKnot *pt, Glib::ustring const unit_name)
{
KnotPropertiesDialog *dialog = new KnotPropertiesDialog();
dialog->_setKnotPoint(pt->position(), unit_name);
dialog->_setPt(pt);
dialog->set_title(_("Modify Knot Position"));
dialog->_apply_button.set_label(_("_Move"));
dialog->set_modal(true);
desktop->setWindowTransient (dialog->gobj());
dialog->property_destroy_with_parent() = true;
dialog->show();
dialog->present();
}
void
KnotPropertiesDialog::_apply()
{
double d_x = Inkscape::Util::Quantity::convert(_knot_x_entry.get_value(), _unit_name, "px");
double d_y = Inkscape::Util::Quantity::convert(_knot_y_entry.get_value(), _unit_name, "px");
_knotpoint->moveto(Geom::Point(d_x, d_y));
_knotpoint->moved_signal.emit(_knotpoint, _knotpoint->position(), 0);
_close();
}
void
KnotPropertiesDialog::_close()
{
destroy_();
Glib::signal_idle().connect(
sigc::bind_return(
sigc::bind(sigc::ptr_fun<void*, void>(&::operator delete), this),
false
)
);
}
bool KnotPropertiesDialog::_handleKeyEvent(GdkEventKey * /*event*/)
{
/*switch (get_latin_keyval(event)) {
case GDK_KEY_Return:
case GDK_KEY_KP_Enter: {
_apply();
return true;
}
break;
}*/
return false;
}
void KnotPropertiesDialog::_handleButtonEvent(GdkEventButton* event)
{
if ( (event->type == GDK_2BUTTON_PRESS) && (event->button == 1) ) {
_apply();
}
}
void KnotPropertiesDialog::_setKnotPoint(Geom::Point knotpoint, Glib::ustring const unit_name)
{
_unit_name = unit_name;
_knot_x_entry.set_value( Inkscape::Util::Quantity::convert(knotpoint.x(), "px", _unit_name));
_knot_y_entry.set_value( Inkscape::Util::Quantity::convert(knotpoint.y(), "px", _unit_name));
_knot_x_label.set_label(g_strdup_printf(_("Position X (%s):"), _unit_name.c_str()));
_knot_y_label.set_label(g_strdup_printf(_("Position Y (%s):"), _unit_name.c_str()));
}
void KnotPropertiesDialog::_setPt(const SPKnot *pt)
{
_knotpoint = const_cast<SPKnot *>(pt);
}
} // namespace
} // namespace
} // namespace
/*
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:fileencoding=utf-8:textwidth=99 :
|