QElectroTech
0.200.1-dev
Loading...
Searching...
No Matches
shapetransform.h
Go to the documentation of this file.
1
/*
2
Copyright 2006-2026 The QElectroTech Team
3
This file is part of QElectroTech.
4
5
QElectroTech is free software: you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation, either version 2 of the License, or
8
(at your option) any later version.
9
10
QElectroTech is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
14
15
You should have received a copy of the GNU General Public License
16
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17
*/
18
#ifndef SHAPETRANSFORM_H
19
#define SHAPETRANSFORM_H
20
21
#include <QPointF>
22
#include <QTransform>
23
49
struct
ShapeTransform
50
{
51
qreal
rotation
= 0;
// degrees
52
qreal
skewX
= 0;
// degrees
53
qreal
skewY
= 0;
// degrees
54
qreal
scaleX
= 1;
55
qreal
scaleY
= 1;
56
QPointF
pivot
;
// local coordinates; caller decides the default (usually local bbox center)
57
58
bool
isIdentity
()
const
;
59
60
// Rotate+shear+scale about the origin, ignoring pivot -- this is the
61
// "linear part" used by compensatedPositionForNewPivot() and by
62
// anything that needs to map a direction/offset rather than a point.
63
QTransform
linearPart
()
const
;
64
65
// The pivot-centered matrix to pass to QGraphicsItem::setTransform().
66
QTransform
toMatrix
()
const
;
67
68
bool
operator==
(
const
ShapeTransform
&other)
const
;
69
bool
operator!=
(
const
ShapeTransform
&other)
const
{
return
!(*
this
== other); }
70
};
71
72
// Canonical decomposition of an arbitrary 2x2 linear map into the five
73
// scalars above, always returning skewY == 0 (all shear folded into
74
// skewX -- matching how most authoring tools represent shear on export).
75
// Rebuilding via ShapeTransform::linearPart() from the result reproduces
76
// the input matrix exactly; the individual scalar values are not
77
// guaranteed to match whatever scalars (if any) originally produced that
78
// matrix, only the matrix itself is guaranteed to match.
79
ShapeTransform
decomposeLinear
(
const
QTransform &linear);
80
81
// Position adjustment needed when the pivot moves, so the shape does not
82
// visibly jump on screen: call once, at the end of a pivot-handle drag,
83
// alongside setting the new pivot.
84
QPointF
compensatedPositionForNewPivot
(
85
const
QPointF &position,
86
const
QPointF &oldPivot,
87
const
QPointF &newPivot,
88
const
QTransform &linearPart);
89
90
#endif
// SHAPETRANSFORM_H
decomposeLinear
ShapeTransform decomposeLinear(const QTransform &linear)
Definition
shapetransform.cpp:58
compensatedPositionForNewPivot
QPointF compensatedPositionForNewPivot(const QPointF &position, const QPointF &oldPivot, const QPointF &newPivot, const QTransform &linearPart)
Definition
shapetransform.cpp:80
ShapeTransform
The ShapeTransform struct Rotation, skew and scale applied to a shape's local geometry around an arbi...
Definition
shapetransform.h:50
ShapeTransform::rotation
qreal rotation
Definition
shapetransform.h:51
ShapeTransform::scaleX
qreal scaleX
Definition
shapetransform.h:54
ShapeTransform::linearPart
QTransform linearPart() const
Definition
shapetransform.cpp:28
ShapeTransform::isIdentity
bool isIdentity() const
Definition
shapetransform.cpp:22
ShapeTransform::skewX
qreal skewX
Definition
shapetransform.h:52
ShapeTransform::toMatrix
QTransform toMatrix() const
Definition
shapetransform.cpp:37
ShapeTransform::pivot
QPointF pivot
Definition
shapetransform.h:56
ShapeTransform::scaleY
qreal scaleY
Definition
shapetransform.h:55
ShapeTransform::operator==
bool operator==(const ShapeTransform &other) const
Definition
shapetransform.cpp:48
ShapeTransform::operator!=
bool operator!=(const ShapeTransform &other) const
Definition
shapetransform.h:69
ShapeTransform::skewY
qreal skewY
Definition
shapetransform.h:53
sources
qetgraphicsitem
shapetransform.h
Generated by
1.15.0