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
|
// SPDX-License-Identifier: GPL-2.0-or-later
/** @file
* @brief A dialog for CSS selectors
*/
/* Authors:
* Kamalpreet Kaur Grewal
* Tavmjong Bah
*
* Copyright (C) Kamalpreet Kaur Grewal 2016 <grewalkamal005@gmail.com>
* Copyright (C) Tavmjong Bah 2017 <tavmjong@free.fr>
*
* Released under GNU GPL v2+, read the file 'COPYING' for more information.
*/
#ifndef SEEN_UI_DIALOGS_CSSDIALOG_H
#define SEEN_UI_DIALOGS_CSSDIALOG_H
#include "desktop.h"
#include "message.h"
#include <glibmm/regex.h>
#include <gtkmm/dialog.h>
#include <gtkmm/liststore.h>
#include <gtkmm/scrolledwindow.h>
#include <gtkmm/treeview.h>
#include <ui/widget/panel.h>
#define CSS_DIALOG(obj) (dynamic_cast<Inkscape::UI::Dialog::CssDialog *>((Inkscape::UI::Dialog::CssDialog *)obj))
#define REMOVE_SPACES(x) \
x.erase(0, x.find_first_not_of(' ')); \
x.erase(x.find_last_not_of(' ') + 1);
namespace Inkscape {
class MessageStack;
class MessageContext;
namespace UI {
namespace Dialog {
/**
* @brief The CssDialog class
* This dialog allows to add, delete and modify CSS properties for selectors
* created in Style Dialog. Double clicking any selector in Style dialog, a list
* of CSS properties will show up in this dialog (if any exist), else new properties
* can be added and each new property forms a new row in this pane.
*/
class CssDialog : public UI::Widget::Panel
{
public:
CssDialog();
~CssDialog() override;
static CssDialog &getInstance() { return *new CssDialog(); }
// Data structure
class CssColumns : public Gtk::TreeModel::ColumnRecord {
public:
CssColumns() {
add(deleteButton);
add(label);
add(_styleSheetVal);
add(_styleAttrVal);
add(label_color);
add(attr_color);
add(attr_strike);
add(editable);
}
Gtk::TreeModelColumn<bool> deleteButton;
Gtk::TreeModelColumn<Glib::ustring> label;
Gtk::TreeModelColumn<Glib::ustring> _styleAttrVal;
Gtk::TreeModelColumn<Glib::ustring> _styleSheetVal;
Gtk::TreeModelColumn<Gdk::RGBA> label_color;
Gtk::TreeModelColumn<Gdk::RGBA> attr_color;
Gtk::TreeModelColumn<bool> attr_strike;
Gtk::TreeModelColumn<bool> editable;
};
CssColumns _cssColumns;
/**
* Status bar
*/
std::shared_ptr<Inkscape::MessageStack> _message_stack;
std::unique_ptr<Inkscape::MessageContext> _message_context;
// TreeView
Gtk::TreeView _treeView;
Glib::RefPtr<Gtk::ListStore> _store;
Gtk::TreeModel::Row _propRow;
Gtk::TreeViewColumn *_propCol;
Gtk::TreeViewColumn *_sheetCol;
Gtk::TreeViewColumn *_attrCol;
Gtk::HBox status_box;
Gtk::Label status;
/**
* Sets the XML status bar, depending on which attr is selected.
*/
void css_reset_context(gint css);
static void _set_status_message(Inkscape::MessageType type, const gchar *message, GtkWidget *dialog);
// Variables - Inkscape
SPDesktop* _desktop;
Inkscape::XML::Node *_repr;
// Helper functions
void setDesktop(SPDesktop* desktop) override;
void setRepr(Inkscape::XML::Node *repr);
// Parsing functions
std::map<Glib::ustring, Glib::ustring> parseStyle(Glib::ustring style_string);
Glib::ustring compileStyle(std::map<Glib::ustring, Glib::ustring> props);
// Signal handlers
void onAttrChanged(Inkscape::XML::Node *repr, const gchar *name, const gchar *new_value);
private:
Glib::RefPtr<Glib::Regex> r_props = Glib::Regex::create("\\s*;\\s*");
Glib::RefPtr<Glib::Regex> r_pair = Glib::Regex::create("\\s*:\\s*");
bool onPropertyCreate(GdkEventButton *event);
void onPropertyDelete(Glib::ustring path);
bool setStyleProperty(Glib::ustring name, Glib::ustring value);
/**
* Signal handlers
*/
sigc::connection _message_changed_connection;
bool _addProperty(GdkEventButton *event);
};
} // namespace Dialog
} // namespace UI
} // namespace Inkscape
#endif // CSSDIALOG_H
|