Engauge Digitizer 2
Loading...
Searching...
No Matches
GuidelineOffset.cpp
Go to the documentation of this file.
1/******************************************************************************************************
2 * (C) 2019 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3 * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4 * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5 ******************************************************************************************************/
6
7#include "GuidelineOffset.h"
8#include "Logger.h"
9#include <QGraphicsView>
10#include "QtToString.h"
11#include "Transformation.h"
12
13const bool ADD_TO_EDGE = true;
15const bool SUBTRACT_FROM_EDGE = false;
16
20
21QPointF GuidelineOffset::bottom (const QGraphicsView &view,
22 const Transformation &transformation) const
23{
24 return bottomTop (view,
25 transformation,
27}
28
29QPointF GuidelineOffset::bottomTop (const QGraphicsView &view,
30 const Transformation &transformation,
31 bool add) const
32{
33 // Get scrolled extent so new Guideline appears in visible portion
34 QRect viewportRect = view.viewport()->rect();
35 QRect scrolledRect = view.viewportTransform ().inverted ().mapRect (viewportRect);
36
37 QRectF sceneRect = view.scene()->sceneRect();
38
39 LOG4CPP_DEBUG_S ((*mainCat)) << "GuidelineOffset::bottomTop"
40 << " viewportRect=" << QRectFToString (viewportRect).toLatin1().data()
41 << " scrolledRect=" << QRectFToString (scrolledRect).toLatin1().data()
42 << " sceneRect=" << QRectFToString (sceneRect).toLatin1().data();
43
45
46 // Halfway across and a little above-bottom/below-top if offsetVertical is negative/positive. If viewport
47 // bigger than the scene (=there is an empty margin) then scrolledRect offsets are negative, and we use
48 // sceneRect, otherwise we use scrolledRect
49 double x = scrolledRect.center().x();
50 double y = (add ?
51 qMax (scrolledRect.y () + offset, offset) :
52 qMin (scrolledRect.y () + scrolledRect.height () - offset, sceneRect.height () - offset));
53
54 QPointF posScene (x, y), posGraph;
55
56 transformation.transformScreenToRawGraph (posScene,
57 posGraph);
58
59 return posGraph;
60}
61
62QPointF GuidelineOffset::left (const QGraphicsView &view,
63 const Transformation &transformation) const
64{
65 return leftRight (view,
66 transformation,
68}
69
70QPointF GuidelineOffset::leftRight(const QGraphicsView &view,
71 const Transformation &transformation,
72 bool add) const
73{
74 // Get scrolled extent so new Guideline appears in visible portion
75 QRect viewportRect = view.viewport()->rect();
76 QRect scrolledRect = view.viewportTransform ().inverted ().mapRect (viewportRect);
77
78 QRectF sceneRect = view.scene()->sceneRect();
79
80 LOG4CPP_DEBUG_S ((*mainCat)) << "GuidelineOffset::leftRight"
81 << " viewportRect=" << QRectFToString (viewportRect).toLatin1().data()
82 << " scrolledRect=" << QRectFToString (scrolledRect).toLatin1().data()
83 << " sceneRect=" << QRectFToString (sceneRect).toLatin1().data();
84
86
87 // Halfway down and a little left-of-right/right-of-left if offsetHorizontal is negative/positive. If viewport
88 // bigger than the scene (=there is an empty margin) then scrolledRect offsets are negative, and we use
89 // sceneRect, otherwise we use scrolledRect
90 double x = (add ?
91 qMax (scrolledRect.x () + offset, offset) :
92 qMin (scrolledRect.x () + scrolledRect.width () - offset, sceneRect.width () - offset));
93 double y = scrolledRect.center().y();
94
95 QPointF posScene (x, y), posGraph;
96
97 transformation.transformScreenToRawGraph (posScene,
98 posGraph);
99
100 return posGraph;
101}
102
103QPointF GuidelineOffset::right (const QGraphicsView &view,
104 const Transformation &transformation) const
105{
106 return leftRight (view,
107 transformation,
109}
110
111QPointF GuidelineOffset::top (const QGraphicsView &view,
112 const Transformation &transformation) const
113{
114 return bottomTop (view,
115 transformation,
117}
const int INNER_RADIUS_MIN
const double GUIDELINE_OFFSET_PORTION_OF_SCREEN_WIDTH
const bool ADD_TO_EDGE
const bool SUBTRACT_FROM_EDGE
log4cpp::Category * mainCat
Definition Logger.cpp:14
QString QRectFToString(const QRectF &rectF)
QPointF top(const QGraphicsView &view, const Transformation &transformation) const
Compute offset from top side and returns point in graph coordinates.
QPointF right(const QGraphicsView &view, const Transformation &transformation) const
Compute offset from right side and returns point in graph coordinates.
QPointF bottom(const QGraphicsView &view, const Transformation &transformation) const
Compute offset from bottom side and returns point in graph coordinates.
QPointF left(const QGraphicsView &view, const Transformation &transformation) const
Compute offset from left side and returns point in graph coordinates.
Affine transformation between screen and graph coordinates, based on digitized axis points.
void transformScreenToRawGraph(const QPointF &coordScreen, QPointF &coordGraph) const
Transform from cartesian pixel screen coordinates to cartesian/polar graph coordinates.
#define LOG4CPP_DEBUG_S(logger)
Definition convenience.h:20