Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
font-selector.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
22/*
23 * Author:
24 * Tavmjong Bah <tavmjong@free.fr>
25 *
26 * Copyright (C) 2018 Tavmong Bah
27 *
28 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
29 */
30
31#ifndef INKSCAPE_UI_WIDGET_FONT_SELECTOR_H
32#define INKSCAPE_UI_WIDGET_FONT_SELECTOR_H
33
34#include <gtkmm/comboboxtext.h>
35#include <gtkmm/frame.h>
36#include <gtkmm/scrolledwindow.h>
37
40
41namespace Gdk {
42class Drag;
43} // namespace Gdk
44
45namespace Gtk {
46class DragSource;
47} // namespace Gtk
48
49namespace Inkscape::UI::Widget {
50
66class FontSelector : public Gtk::Box, public FontSelectorInterface
67{
68public:
69 static std::unique_ptr<FontSelectorInterface> create_font_selector();
70
74 FontSelector (bool with_size = true, bool with_variations = true);
75 void hide_others();
76
77protected:
78
79 // Font family
80 Gtk::Frame family_frame;
81 Gtk::ScrolledWindow family_scroll;
82 Gtk::TreeView family_treeview;
83 Gtk::TreeViewColumn family_treecolumn;
84 Gtk::CellRendererText family_cell;
85
86 // Font style
87 Gtk::Frame style_frame;
88 Gtk::ScrolledWindow style_scroll;
89 Gtk::TreeView style_treeview;
90 Gtk::TreeViewColumn style_treecolumn;
91 Gtk::CellRendererText style_cell;
92
93 // Font size
94 Gtk::Label size_label;
95 Gtk::ComboBoxText size_combobox;
96
97 // Font variations
98 Gtk::ScrolledWindow font_variations_scroll;
100
101private:
102 // Set sizes in font size combobox.
103 void set_sizes();
105
106 // Use font style when listing style names.
107 void style_cell_data_func(Gtk::CellRenderer *renderer,
108 Gtk::TreeModel::const_iterator const &iter);
109
110 // Signal handlers
111 void on_family_changed();
112 void on_style_changed();
113 void on_size_changed();
115
116 // Signals
117 sigc::signal<void (Glib::ustring)> _signal_changed;
118 sigc::signal<void ()> _signal_apply;
119 void changed_emit();
121
122 sigc::scoped_connection _idle_connection;
123
124 // Variables
125 double font_size;
126
127 bool initial = true;
128
129 // control font variations update and UI element size
130 void update_variations(const Glib::ustring& fontspec);
131
132 bool set_cell_markup();
133 void on_realize_list();
134 // For drag and drop.
135 Glib::RefPtr<Gdk::ContentProvider> on_drag_prepare(double x, double y);
136 void on_drag_begin(Gtk::DragSource &source, Glib::RefPtr<Gdk::Drag> const &drag);
137
138 // font selector interface
139 Gtk::Widget* box() override { return this; }
140 Glib::ustring get_fontspec() const override { return const_cast<FontSelector*>(this)->get_fontspec(true); }
141 double get_fontsize() const override { return font_size; };
142 void set_current_font(const Glib::ustring& family, const Glib::ustring& face) override { update_font(); }
143 void set_current_size(double size) override { update_size(size); };
144 sigc::signal<void ()>& signal_changed() override { return dummy; }
145 sigc::signal<void ()>& signal_apply() override { return _signal_apply; }
146 sigc::signal<void ()> dummy;
147
148public:
152 void update_font ();
153 void update_size (double size);
154 void unset_model() override;
155 void set_model() override;
156
160 Glib::ustring get_fontspec(bool use_variations = true);
161
165 double get_fontsize() { return font_size; };
166
171 sigc::connection connectChanged(sigc::slot<void (Glib::ustring)> slot) {
172 return _signal_changed.connect(slot);
173 }
174};
175
176} // namespace Inkscape::UI::Widget
177
178#endif // INKSCAPE_UI_WIDGET_FONT_SETTINGS_H
179
180/*
181 Local Variables:
182 mode:c++
183 c-file-style:"stroustrup"
184 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
185 indent-tabs-mode:nil
186 fill-column:99
187 End:
188*/
189// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8 :
A container of widgets for selecting font faces.
void on_drag_begin(Gtk::DragSource &source, Glib::RefPtr< Gdk::Drag > const &drag)
sigc::signal< void()> & signal_changed() override
void update_font()
Update GUI based on fontspec.
Gtk::ScrolledWindow font_variations_scroll
sigc::signal< void()> & signal_apply() override
Gtk::TreeViewColumn style_treecolumn
sigc::connection connectChanged(sigc::slot< void(Glib::ustring)> slot)
Let others know that user has changed GUI settings.
sigc::signal< void(Glib::ustring)> _signal_changed
void style_cell_data_func(Gtk::CellRenderer *renderer, Gtk::TreeModel::const_iterator const &iter)
void set_current_size(double size) override
double get_fontsize()
Get font size.
sigc::scoped_connection _idle_connection
Gtk::TreeViewColumn family_treecolumn
Gtk::CellRendererText family_cell
Glib::ustring get_fontspec() const override
Gtk::CellRendererText style_cell
static std::unique_ptr< FontSelectorInterface > create_font_selector()
sigc::signal< void()> _signal_apply
void update_variations(const Glib::ustring &fontspec)
Glib::RefPtr< Gdk::ContentProvider > on_drag_prepare(double x, double y)
double get_fontsize() const override
Gtk::Widget * box() override
void set_current_font(const Glib::ustring &family, const Glib::ustring &face) override
A widget for selecting font variations (OpenType Variations).
Definition desktop.h:50
Custom widgets.
Definition desktop.h:126