Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
canvas-grid.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
5/*
6 * Author:
7 * Tavmjong Bah
8 *
9 * Copyright (C) 2020 Tavmjong Bah
10 *
11 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
12 */
13
14#ifndef INKSCAPE_UI_WIDGET_CANVASGRID_H
15#define INKSCAPE_UI_WIDGET_CANVASGRID_H
16
17#include <memory>
18#include <2geom/point.h>
19#include <2geom/int-point.h>
20#include <gtkmm/gesture.h> // Gtk::EventSequenceState
21#include <gtkmm/grid.h>
22#include <gtkmm/menubutton.h>
23#include <gtkmm/overlay.h>
24#include <gtkmm/scrollbar.h>
25#include <gtkmm/togglebutton.h>
26#include <gtkmm/label.h>
27
29#include "preferences.h"
30#include <sigc++/scoped_connection.h>
32#include "util/action-accel.h"
33
34namespace Gtk {
35class Adjustment;
36class Builder;
37class CheckButton;
38class EventControllerMotion;
39class GestureClick;
40} // namespace Gtk
41
42class SPDesktop;
43class SPDocument;
44class SPDesktopWidget;
45
46namespace Inkscape {
47
48struct MotionEvent;
49class CanvasItemGuideLine;
50
51namespace UI {
52
53namespace Dialog {
54class CommandPalette;
55} // namespace Dialog
56
57namespace Widget {
58
59class Canvas;
60class CanvasNotice;
61class Ruler;
62class Stack;
63class TabsWidget;
64
69class CanvasGrid : public Gtk::Grid
70{
71 using parent_type = Gtk::Grid;
72
73public:
75 ~CanvasGrid() override;
76
77 void ShowScrollbars(bool state = true);
78 void ToggleScrollbars();
79
80 void ShowRulers(bool state = true);
81 void ToggleRulers();
82 void updateRulers();
83
84 void ShowCommandPalette(bool state = true);
86
87 void showNotice(Glib::ustring const &msg, int timeout = 0);
88
89 void setPopover(Gtk::Popover *popover) { _popoverbin.setPopover(popover); }
90
91 void addTab(Canvas *canvas);
92 void removeTab(Canvas *canvas);
93 void switchTab(Canvas *canvas);
94
95 Canvas *GetCanvas() { return _canvas; };
96
97 // Hopefully temp.
100 Gtk::Adjustment *GetHAdj() { return _hadj.get(); };
101 Gtk::Adjustment *GetVAdj() { return _vadj.get(); };
102 Gtk::ToggleButton *GetGuideLock() { return &_guide_lock; }
103 Gtk::ToggleButton *GetCmsAdjust() { return &_cms_adjust; }
104 Gtk::CheckButton *GetStickyZoom();
107
108 // Motion event handler, and delayed snap event callback.
109 void rulerMotion(MotionEvent const &event, bool horiz);
110
111 // Scroll handling.
112 void updateScrollbars(double scale);
113
114private:
115 // Signal callbacks
116 void size_allocate_vfunc(int width, int height, int baseline) override;
117 void on_realize() override;
118
120
121 // The widgets
122 Gtk::Label* _quick_preview_label = nullptr;
123 Gtk::Label* _quick_zoom_label = nullptr;
126
129 std::unique_ptr<Dialog::CommandPalette> _command_palette;
131 Gtk::Overlay _canvas_overlay;
132 Gtk::Grid _subgrid;
134 std::unique_ptr<Inkscape::UI::Widget::TabsWidget> _tabs_widget;
135
136 Glib::RefPtr<Gtk::Adjustment> _hadj;
137 Glib::RefPtr<Gtk::Adjustment> _vadj;
138 Gtk::Scrollbar _hscrollbar;
139 Gtk::Scrollbar _vscrollbar;
140
141 std::unique_ptr<Inkscape::UI::Widget::Ruler> _hruler;
142 std::unique_ptr<Inkscape::UI::Widget::Ruler> _vruler;
143
144 Gtk::ToggleButton _guide_lock;
145 Gtk::ToggleButton _cms_adjust;
146 Gtk::MenuButton _quick_actions;
147 Glib::RefPtr<Gtk::Builder> _builder_display_popup;
148
149 // To be replaced by stateful Gio::Actions
150 bool _show_scrollbars = true;
151 bool _show_rulers = true;
152
153 // Hopefully temp
156
157 // Store allocation so we don't redraw too often.
158 int _width{}, _height{};
159
160 // Connections for page and selection tracking
161 sigc::scoped_connection _update_preview_connection;
162 sigc::scoped_connection _update_zoom_connection;
163 sigc::scoped_connection _page_selected_connection;
164 sigc::scoped_connection _page_modified_connection;
165 sigc::scoped_connection _sel_changed_connection;
166 sigc::scoped_connection _sel_modified_connection;
167 sigc::scoped_connection _blink_lock_button_timeout;
168
169 // Ruler event handling.
170 bool _ruler_clicked = false;
171 bool _ruler_dragged = false;
172 bool _ruler_ctrl_clicked = false;
176
177 Geom::IntPoint _rulerToCanvas(bool horiz) const;
178 void _createGuideItem(Geom::Point const &pos, bool horiz);
180
182 Gtk::EventSequenceState _rulerButtonPress (Gtk::GestureClick const &gesture,
183 int n_press, double x, double y);
184 Gtk::EventSequenceState _rulerButtonRelease(Gtk::GestureClick const &gesture,
185 int n_press, double x, double y, RulerOrientation orientation);
186 void _rulerMotion(Gtk::EventControllerMotion const &controller,
187 double x, double y, RulerOrientation orientation);
188 void _blinkLockButton();
189
190 // Scroll handling.
191 bool _updating = false;
192 void _adjustmentChanged();
193};
194
195} // namespace Widget
196} // namespace UI
197} // namespace Inkscape
198
199#endif // INKSCAPE_UI_WIDGET_CANVASGRID_H
200
201/*
202 Local Variables:
203 mode:c++
204 c-file-style:"stroustrup"
205 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
206 indent-tabs-mode:nil
207 fill-column:99
208 End:
209*/
210// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
Cartesian point / 2D vector and related operations.
Point origin
Definition aa.cpp:227
Action Accel A simple tracker for accelerator keys associated to an action.
std::unique_ptr< T, CanvasItemUnlinkDeleter > CanvasItemPtr
Smart pointer used to hold CanvasItems, like std::unique_ptr.
Two-dimensional point with integer coordinates.
Definition int-point.h:57
Two-dimensional point that doubles as a vector.
Definition point.h:66
A Gtk::Grid widget that contains rulers, scrollbars, buttons, and, of course, the canvas.
Definition canvas-grid.h:70
CanvasItemPtr< CanvasItemGuideLine > _active_guide
The guide being handled during a ruler event.
sigc::scoped_connection _sel_modified_connection
Inkscape::UI::Widget::Canvas * _canvas
void updateScrollbars(double scale)
void _rulerMotion(Gtk::EventControllerMotion const &controller, double x, double y, RulerOrientation orientation)
std::unique_ptr< Inkscape::UI::Widget::Ruler > _vruler
std::unique_ptr< Inkscape::UI::Widget::TabsWidget > _tabs_widget
sigc::scoped_connection _page_modified_connection
sigc::scoped_connection _update_zoom_connection
Glib::RefPtr< Gtk::Builder > _builder_display_popup
bool _ruler_ctrl_clicked
Whether ctrl was held when the ruler was clicked.
Inkscape::UI::Widget::Stack * _canvas_stack
Dialog::CommandPalette * getCommandPalette()
Inkscape::UI::Widget::PopoverBin _popoverbin
void ShowRulers(bool state=true)
bool _ruler_dragged
True if a drag on the ruler is occurring.
Gtk::EventSequenceState _rulerButtonPress(Gtk::GestureClick const &gesture, int n_press, double x, double y)
sigc::scoped_connection _update_preview_connection
Gtk::ToggleButton * GetGuideLock()
std::unique_ptr< Dialog::CommandPalette > _command_palette
Gtk::CheckButton * GetStickyZoom()
Gtk::EventSequenceState _rulerButtonRelease(Gtk::GestureClick const &gesture, int n_press, double x, double y, RulerOrientation orientation)
sigc::scoped_connection _blink_lock_button_timeout
void size_allocate_vfunc(int width, int height, int baseline) override
void ShowScrollbars(bool state=true)
void setPopover(Gtk::Popover *popover)
Definition canvas-grid.h:89
bool _ruler_clicked
True if the ruler has been clicked.
Geom::IntPoint _rulerToCanvas(bool horiz) const
sigc::scoped_connection _sel_changed_connection
std::unique_ptr< Inkscape::UI::Widget::Ruler > _hruler
void _createGuideItem(Geom::Point const &pos, bool horiz)
Inkscape::UI::Widget::Ruler * GetVRuler()
Definition canvas-grid.h:99
Glib::RefPtr< Gtk::Adjustment > _vadj
void showNotice(Glib::ustring const &msg, int timeout=0)
Gtk::ToggleButton * GetCmsAdjust()
void _createGuide(Geom::Point origin, Geom::Point normal)
Inkscape::Util::ActionAccel _preview_accel
sigc::scoped_connection _page_selected_connection
Inkscape::UI::Widget::Ruler * GetHRuler()
Definition canvas-grid.h:98
void rulerMotion(MotionEvent const &event, bool horiz)
Glib::RefPtr< Gtk::Adjustment > _hadj
Geom::Point _normal
Normal to the guide currently being handled during ruler event.
void ShowCommandPalette(bool state=true)
Geom::IntPoint _ruler_drag_origin
Position of start of drag.
Inkscape::UI::Widget::TabsWidget * getTabsWidget()
Inkscape::Util::ActionAccel _zoom_accel
A widget for Inkscape's canvas.
Definition canvas.h:62
Holds a single child widget while allowing a single popover to be displayed over it.
Definition popover-bin.h:19
void setPopover(Gtk::Popover *popover)
Definition popover-bin.h:24
Like Gtk::Stack, but for holding a stack of Inkscape canvases.
Definition stack.h:16
Widget that implements the document tab bar.
Definition tabs-widget.h:36
The ActionAccel class stores the keyboard shortcuts for a given action and automatically keeps track ...
A GtkBox on an SPDesktop.
To do: update description of desktop.
Definition desktop.h:149
Typed SVG document implementation.
Definition document.h:101
sigc::scoped_connection timeout
Glib::ustring msg
Cartesian point / 2D vector with integer coordinates.
Definition desktop.h:50
static constexpr int height
Helper class to stream background task notifications as a series of messages.
std::unique_ptr< Preferences::PreferencesObserver > PrefObserver
Singleton class to access the preferences file in a convenient way.
Movement of the mouse pointer.
double width