KDStateMachineEditor API Documentation 2.3
Loading...
Searching...
No Matches
quickmaskedmousearea.cpp
Go to the documentation of this file.
1/*
2 This file is part of the KDAB State Machine Editor Library.
3
4 SPDX-FileCopyrightText: 2014 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
5 Author: Kevin Funk <kevin.funk@kdab.com>
6
7 SPDX-License-Identifier: LGPL-2.1-only OR LicenseRef-KDAB-KDStateMachineEditor
8
9 Licensees holding valid commercial KDAB State Machine Editor Library
10 licenses may use this file in accordance with the KDAB State Machine Editor
11 Library License Agreement provided with the Software.
12
13 Contact info@kdab.com if any conditions of this licensing are not clear to you.
14*/
15
17
18#include "debug.h"
19#include <QGuiApplication>
20#include <QStyleHints>
21
23 : QObject(parent)
24{
25}
26
28 : AbstractMask(parent)
29{
30}
31
32QPainterPath PainterPathMask::path() const
33{
34 return m_path;
35}
36
37void PainterPathMask::setPath(const QPainterPath &path)
38{
39 if (m_path == path)
40 return;
41
42 m_path = path;
43 Q_EMIT pathChanged(m_path);
44}
45
46bool PainterPathMask::contains(const QPointF &point) const
47{
48 return m_path.contains(point);
49}
50
51bool PainterPathMask::intersects(const QRectF &rect) const
52{
53 return m_path.intersects(rect);
54}
55
57 : QQuickItem(parent)
58 , m_pressed(false)
59 , m_containsMouse(false)
60 , m_mask(nullptr)
61 , m_tolerance(0.)
62{
63 setAcceptHoverEvents(true);
64 setAcceptedMouseButtons(Qt::LeftButton);
65}
66
68{
69 if (m_pressed == pressed)
70 return;
71
72 m_pressed = pressed;
73 Q_EMIT pressedChanged(m_pressed);
74}
75
77{
78 if (m_containsMouse == containsMouse)
79 return;
80
81 m_containsMouse = containsMouse;
82 Q_EMIT containsMouseChanged(m_containsMouse);
83}
84
86{
87 return m_mask;
88}
89
91{
92 if (m_mask == mask)
93 return;
94
95 m_mask = mask;
96 Q_EMIT maskChanged(m_mask);
97}
98
100{
101 return m_tolerance;
102}
103
105{
106 if (qFuzzyCompare(m_tolerance, tolerance)) {
107 return;
108 }
109
110 m_tolerance = qMax(tolerance, qreal(0.0));
111 Q_EMIT toleranceChanged(m_tolerance);
112}
113
114bool QuickMaskedMouseArea::contains(const QPointF &point) const
115{
116 if (!m_mask) {
117 return QQuickItem::contains(point);
118 }
119
120 const QRectF rect = boundingRect();
121 const bool ignoreBoundingRect = rect.isEmpty();
122 if (m_tolerance > 0.) {
123 const QRectF fuzzyClickRect(point.x() - m_tolerance, point.y() - m_tolerance,
124 2 * m_tolerance, 2 * m_tolerance);
125 if (!ignoreBoundingRect && !rect.intersects(fuzzyClickRect)) {
126 return false;
127 }
128 return m_mask->intersects(fuzzyClickRect);
129 }
130
131 if (!ignoreBoundingRect && !rect.contains(point)) {
132 return false;
133 }
134 return m_mask->contains(point);
135}
136
138{
139 setPressed(true);
140 m_pressPoint = event->pos();
141 Q_EMIT pressed();
142}
143
145{
146 setPressed(false);
147 Q_EMIT released();
148
149
150 const int threshold = qApp->styleHints()->startDragDistance();
151 const int eventX = static_cast<int>(event->position().x());
152 const int eventY = static_cast<int>(event->position().y());
153 const bool isClick = (threshold >= qAbs(eventX - m_pressPoint.x()) && threshold >= qAbs(eventY - m_pressPoint.y()));
154
155 if (isClick)
156 Q_EMIT clicked();
157}
158
160{
161 setPressed(false);
162 Q_EMIT canceled();
163}
164
166{
167 Q_UNUSED(event);
168 setContainsMouse(true);
169}
170
172{
173 Q_UNUSED(event);
174 setContainsMouse(false);
175}
virtual bool intersects(const QRectF &rect) const =0
AbstractMask(QObject *parent=nullptr)
virtual bool contains(const QPointF &point) const =0
bool intersects(const QRectF &rect) const override
void pathChanged(const QPainterPath &path)
PainterPathMask(QObject *parent=nullptr)
bool contains(const QPointF &point) const override
void setPath(const QPainterPath &path)
bool contains(const QPointF &point) const override
void mousePressEvent(QMouseEvent *event) override
void toleranceChanged(qreal tolerance)
void hoverLeaveEvent(QHoverEvent *event) override
void containsMouseChanged(bool containsMouse)
QuickMaskedMouseArea(QQuickItem *parent=nullptr)
void hoverEnterEvent(QHoverEvent *event) override
void pressedChanged(bool pressed)
void mouseReleaseEvent(QMouseEvent *event) override
void setTolerance(qreal tolerance)
void setPressed(bool pressed)
void setMask(AbstractMask *mask)
void setContainsMouse(bool containsMouse)
void maskChanged(AbstractMask *mask)

© Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/
KDStateMachineEditor
Create Qt State Machine metacode using a graphical user interface
https://github.com/KDAB/KDStateMachineEditor
Generated on Mon Mar 9 2026 12:16:36 for KDStateMachineEditor API Documentation by doxygen 1.9.8