20#include <glibmm/i18n.h>
21#include <glibmm/main.h>
22#include <gtkmm/adjustment.h>
23#include <gtkmm/builder.h>
24#include <gtkmm/checkbutton.h>
25#include <gtkmm/enums.h>
26#include <gtkmm/eventcontrollermotion.h>
27#include <gtkmm/gestureclick.h>
28#include <gtkmm/image.h>
29#include <gtkmm/label.h>
30#include <gtkmm/popover.h>
31#include <sigc++/adaptors/bind.h>
32#include <sigc++/functors/mem_fun.h>
66 set_name(
"CanvasGrid");
69 _tabs_widget = std::make_unique<Inkscape::UI::Widget::TabsWidget>(dtw);
83 _canvas_stack = Gtk::make_managed<Inkscape::UI::Widget::Stack>();
88 _hruler = std::make_unique<Inkscape::UI::Widget::Ruler>(Gtk::Orientation::HORIZONTAL);
93 _vruler = std::make_unique<Inkscape::UI::Widget::Ruler>(Gtk::Orientation::VERTICAL);
100 auto set_lock_icon = [
this](){
112 _guide_lock.set_tooltip_text(_(
"Toggle lock of all guides in the document"));
122 _hadj = Gtk::Adjustment::create(0.0, -4000.0, 4000.0, 10.0, 100.0, 4.0);
129 _vadj = Gtk::Adjustment::create(0.0, -4000.0, 4000.0, 10.0, 100.0, 4.0);
137 _cms_adjust.set_action_name(
"win.canvas-color-manage");
138 _cms_adjust.set_tooltip_text(_(
"Toggle color-managed display for this document window"));
139 auto set_cms_icon = [
this](){
140 _cms_adjust.set_image_from_icon_name(
_cms_adjust.get_active() ?
"color-management" :
"color-management-off");
143 _cms_adjust.signal_toggled().connect([=,
this](){ set_cms_icon(); });
165 if (!quick_preview_shortcut.empty()) {
171 if (!quick_zoom_shortcut.empty()) {
179 _quick_preview_label->set_label(
"");
202 auto const bind_controllers = [&](
auto& ruler,
RulerOrientation orientation) {
203 auto const click = Gtk::GestureClick::create();
204 click->set_button(1);
207 ruler->add_controller(click);
209 auto const motion = Gtk::EventControllerMotion::create();
210 motion->signal_motion().connect([
this, orientation, &motion = *motion](
auto &&...args) {
_rulerMotion(motion, args..., orientation); });
211 ruler->add_controller(motion);
227 canvas->set_hexpand(
true);
228 canvas->set_vexpand(
true);
229 canvas->set_focusable(
true);
258 parent_type::on_realize();
262 g_warning(
"No action map available to canvas-grid");
266 auto const cms_action = std::dynamic_pointer_cast<Gio::SimpleAction>(map->lookup_action(
"canvas-color-manage"));
267 auto const disp_action = std::dynamic_pointer_cast<Gio::SimpleAction>(map->lookup_action(
"canvas-display-mode"));
268 if (!cms_action || !disp_action) {
269 g_warning(
"No canvas-display-mode and/or canvas-color-manage action available to canvas-grid");
273 auto set_display_icon = [=,
this] {
275 disp_action->get_state<
int>(display_mode);
283 id =
"display-outline";
286 id =
"display-outline-overlay";
289 id =
"display-enhance-stroke";
292 id =
"display-no-filter";
295 g_warning(
"Unknown display mode in canvas-grid");
300 cms_action->get_state<
bool>(cms_mode);
311 disp_action->property_state().signal_changed().connect([=] { set_display_icon(); });
312 cms_action-> property_state().signal_changed().connect([=] { set_display_icon(); });
349 if (document->get_origin_follows_page()) {
351 auto page_transform = pm.getSelectedPageAffine().inverse() *
desktop->
d2w();
352 startbox += page_transform.translation();
359 double w2r_scale =
_dtw->
get_dt2r() / d2c_scalerot.expansionX();
360 auto const rulerbox = startbox *
Geom::Scale{w2r_scale};
361 _hruler->set_range(rulerbox.left(), rulerbox.right());
363 _vruler->set_range(rulerbox.top(), rulerbox.bottom());
365 _vruler->set_range(-rulerbox.top(), -rulerbox.bottom());
370 auto pagebox = (pm.getSelectedPageRect() * d2c).roundOutwards();
371 _hruler->set_page(pagebox.left(), pagebox.right());
372 _vruler->set_page(pagebox.top(), pagebox.bottom());
376 if (
auto const bbox = sel->preferredBounds()) {
377 selbox = (*bbox * d2c).roundOutwards();
427 prefs->setBool(
"/fullscreen/rulers/state",
_show_rulers);
455 Gtk::Grid::size_allocate_vfunc(
width,
height, baseline);
473 int ,
double x,
double y)
476 return Gtk::EventSequenceState::NONE;
479 auto const state = gesture.get_current_event_state();
486 return Gtk::EventSequenceState::CLAIMED;
504 auto const angle_x = Geom::rad_from_deg(grid->getAngleX());
505 auto const angle_z = Geom::rad_from_deg(grid->getAngleZ());
508 normal_bl_to_tr = Geom::Point::polar(angle_x * y_dir, 1.0);
509 normal_tr_to_bl = Geom::Point::polar(-angle_z * y_dir, 1.0);
511 normal_bl_to_tr = Geom::Point::polar(-angle_z * y_dir, 1.0).
cw();
512 normal_tr_to_bl = Geom::Point::polar(angle_x * y_dir, 1.0).
cw();
519 }
else if (pos.
x() >
_canvas->get_width() - 50) {
527 }
else if (pos.
y() >
_canvas->get_height() - 50) {
551 int tolerance = prefs->getIntLimited(
"/options/dragtolerance/value", 0, 0, 100);
563 event.modifiers = (unsigned)controller.get_current_event_state();
564 event.device = controller.get_current_event_device();
566 event.time = controller.get_current_event_time();
590 auto const normal_orig = normal;
591 m.guideFreeSnap(event_dt, normal,
false,
false);
596 if (normal != normal_orig) {
601 if (!(pref_tang || pref_perp)) {
602 normal = normal_orig;
628 if (!(event.
modifiers & GDK_SHIFT_MASK)) {
658 if (
root->viewBox_set) {
663 repr->setAttributePoint(
"position",
origin);
664 repr->setAttributePoint(
"orientation", normal);
675 return Gtk::EventSequenceState::NONE;
685 auto const state = gesture.get_current_event_state();
691 if (!(
bool)(state & Gdk::ModifierType::SHIFT_MASK)) {
715 return Gtk::EventSequenceState::CLAIMED;
720 _guide_lock.get_style_context()->add_class(
"blink");
722 _guide_lock.get_style_context()->remove_class(
"blink");
727static void set_adjustment(Gtk::Adjustment *adj,
double l,
double u,
double ps,
double si,
double pi)
729 if (l != adj->get_lower() ||
730 u != adj->get_upper() ||
731 ps != adj->get_page_size() ||
732 si != adj->get_step_increment() ||
733 pi != adj->get_page_increment())
737 adj->set_page_size(ps);
738 adj->set_step_increment(si);
739 adj->set_page_increment(pi);
755 deskarea.expandBy(doc->getDimensions());
758 deskarea |= doc->getPageManager().getDesktopRect();
761 deskarea |= doc->getRoot()->desktopVisualBounds();
763 deskarea |= doc->getRoot()->desktopGeometricBounds();
778 0.1 * viewbox.width(),
780 _hadj->set_value(viewbox.left());
784 0.1 * viewbox.height(),
786 _vadj->set_value(viewbox.top());
Rewrite of code originally in desktop-widget.cpp.
C right() const
Return rightmost coordinate of the rectangle (+X is to the right).
C top() const
Return top coordinate of the rectangle (+Y is downwards).
C left() const
Return leftmost coordinate of the rectangle (+X is to the right).
C bottom() const
Return bottom coordinate of the rectangle (+Y is downwards).
Two-dimensional point with integer coordinates.
Two-dimensional point that doubles as a vector.
IntPoint floor() const
Round coordinates downwards.
constexpr Coord y() const noexcept
constexpr Coord x() const noexcept
IntPoint round() const
Round to nearest integer coordinates.
constexpr Point cw() const
Return a point like this point but rotated +90 degrees.
Axis aligned, non-empty rectangle.
static void done(SPDocument *document, Glib::ustring const &event_description, Glib::ustring const &undo_icon, unsigned int object_modified_tag=0)
void flash(MessageType type, char const *message)
pushes a message onto the stack for a brief period of time without disturbing our "current" message
Data type representing a typeless value of a preference.
static Preferences * get()
Access the singleton Preferences object.
The set of selected SPObjects for a given document and layer model.
sigc::connection connectModified(sigc::slot< void()> const &slot)
Connects a void callback which will run whenever the keybindings for the action change.
std::vector< Glib::ustring > getShortcutText() const
Returns all keyboard shortcuts for the action in the form of text.
double value(Unit const *u) const
Return the quantity's value in the specified unit.
To do: update description of desktop.
Inkscape::UI::Widget::Canvas * getCanvas() const
Inkscape::CanvasItemGroup * getCanvasGuides() const
SPDocument * getDocument() const
Geom::Affine const & d2w() const
Transformation from desktop to window coordinates.
SPNamedView * getNamedView() const
Inkscape::Selection * getSelection() const
Inkscape::UI::Tools::ToolBase * getTool() const
void set_coordinate_status(Geom::Point const &p)
Sets the coordinate status to a given point.
Inkscape::MessageContext * guidesMessageContext() const
bool is_yaxisdown() const
void scroll_absolute(Geom::Point const &point)
Scroll canvas by to a particular point (window coordinates).
Geom::Affine const & w2d() const
Transformation from window to desktop coordinates (zoom/rotate).
SPRoot * getRoot()
Returns our SPRoot.
Geom::OptRect preferredBounds() const
sigc::connection connectModified(ModifiedSignal::slot_type slot)
Inkscape::PageManager & getPageManager()
Inkscape::XML::Document * getReprDoc()
Our Inkscape::XML::Document.
Inkscape::Util::Quantity getHeight() const
SPGrid * getFirstEnabledGrid()
Returns the first grid it could find that isEnabled().
void setLockGuides(bool v)
Colors::Color getGuideHiColor() const
void setShowGuides(bool v)
void appendChild(Inkscape::XML::Node *child)
void setup(SPDesktop const *desktop, bool snapindicator=true, SPObject const *item_to_ignore=nullptr, std::vector< Inkscape::SnapCandidatePoint > *unselected_nodes=nullptr)
Convenience shortcut when there is only one item to ignore.
CommandPalette: Class providing Command Palette feature.
Utilities to more easily use Gtk::EventController & subclasses like Gesture.
sigc::scoped_connection timeout
Editable view implementation.
TODO: insert short description here.
void ink_drag_setup(SPDesktopWidget *dtw, Gtk::Widget *widget)
Drag and drop of drawings onto canvas.
auto floor(Geom::Rect const &rect)
Interface for locally managing a current status message.
GenericRect< IntCoord > IntRect
D2< T > rot90(D2< T > const &a)
Coord LInfty(Point const &p)
static R & release(R &r)
Decrements the reference count of a anchored object.
auto use_state(Slot &&slot)
bool has_flag(Gdk::ModifierType const state, Gdk::ModifierType const flags)
Helper to query if ModifierType state contains one or more of given flag(s).
Glib::RefPtr< Gtk::Builder > create_builder(const char *filename)
@ SNAPTARGET_PATH_TANGENTIAL
@ SNAPTARGET_PATH_PERPENDICULAR
ExtendedInput extinput_from_gdkevent(Gdk::Event const &event)
Read the extended input data from a Gdk::Event.
Inkscape::IO::Resource - simple resource API.
SPRoot: SVG <svg> implementation.
unsigned modifiers
The modifiers mask immediately before the event.
Movement of the mouse pointer.
Geom::Point pos
Location of the cursor.
virtual Node * createElement(char const *name)=0