8#include "resizehandle.h"
9#include "resizerectangle.h"
19 auto syncCursor = [
this]() {
20 switch (m_resizeCorner) {
41 connect(
this, &ResizeHandle::resizeCornerChanged,
this, syncCursor);
49void ResizeHandle::setResizeCorner(ResizeHandle::Corner corner)
51 if (m_resizeCorner == corner) {
54 m_resizeCorner = corner;
55 Q_EMIT resizeCornerChanged();
58void ResizeHandle::setRectangle(
QQuickItem *rectangle)
60 if (m_rectangle == rectangle) {
67bool ResizeHandle::resizeBlocked()
const
72bool ResizeHandle::resizeLeft()
const
74 return m_resizeCorner == Left || m_resizeCorner == TopLeft || m_resizeCorner == BottomLeft;
77bool ResizeHandle::resizeTop()
const
79 return m_resizeCorner == Top || m_resizeCorner == TopLeft || m_resizeCorner == TopRight;
82bool ResizeHandle::resizeRight()
const
84 return m_resizeCorner == Right || m_resizeCorner == TopRight || m_resizeCorner == BottomRight;
87bool ResizeHandle::resizeBottom()
const
89 return m_resizeCorner == Bottom || m_resizeCorner == BottomLeft || m_resizeCorner == BottomRight;
92void ResizeHandle::setResizeBlocked(
bool width,
bool height)
94 if (m_resizeWidthBlocked ==
width && m_resizeHeightBlocked ==
height) {
98 m_resizeWidthBlocked =
width;
99 m_resizeHeightBlocked =
height;
101 Q_EMIT resizeBlockedChanged();
104void ResizeHandle::mousePressEvent(
QMouseEvent *event)
106 m_mouseDownPosition =
event->windowPos();
107 m_mouseDownGeometry =
QRectF(m_rectangle->insideX(), m_rectangle->insideY(), m_rectangle->insideWidth(), m_rectangle->insideHeight());
108 setResizeBlocked(
false,
false);
112void ResizeHandle::mouseMoveEvent(
QMouseEvent *event)
114 const QPointF difference = m_mouseDownPosition -
event->windowPos();
120 const qreal
width = qMax(minimumSize.
width(), m_mouseDownGeometry.
width() + difference.
x());
121 const qreal
x = m_mouseDownGeometry.
x() + (m_mouseDownGeometry.
width() -
width);
123 m_rectangle->setInsideX(
x);
124 m_rectangle->setInsideWidth(
width);
125 setResizeBlocked(m_mouseDownGeometry.
width() + difference.
x() < minimumSize.
width(), m_resizeHeightBlocked);
126 }
else if (resizeRight()) {
127 const qreal
width = qMax(minimumSize.
width(), m_mouseDownGeometry.
width() - difference.
x());
129 m_rectangle->setInsideWidth(
width);
130 setResizeBlocked(m_mouseDownGeometry.
width() - difference.
x() < minimumSize.
width(), m_resizeHeightBlocked);
135 const qreal
height = qMax(minimumSize.
height(), m_mouseDownGeometry.
height() + difference.
y());
136 const qreal
y = m_mouseDownGeometry.
y() + (m_mouseDownGeometry.
height() -
height);
138 m_rectangle->setInsideY(
y);
139 m_rectangle->setInsideHeight(
height);
140 setResizeBlocked(m_resizeWidthBlocked, m_mouseDownGeometry.
height() + difference.
y() < minimumSize.
height());
141 }
else if (resizeBottom()) {
142 const qreal
height = qMax(minimumSize.
height(), m_mouseDownGeometry.
height() - difference.
y());
144 m_rectangle->setInsideHeight(qMax(
height, minimumSize.
height()));
145 setResizeBlocked(m_resizeWidthBlocked, m_mouseDownGeometry.
height() - difference.
y() < minimumSize.
height());
151void ResizeHandle::mouseReleaseEvent(
QMouseEvent *event)
155 setResizeBlocked(
false,
false);
156 Q_EMIT resizeBlockedChanged();
159#include "moc_resizehandle.cpp"
T qobject_cast(QObject *object)
qreal height() const const
qreal width() const const
qreal height() const const
qreal width() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)