#include <KisLongPressEventFilter.h>
Definition at line 13 of file KisLongPressEventFilter.h.
◆ KisLongPressEventFilter()
| KisLongPressEventFilter::KisLongPressEventFilter |
( |
QObject * | parent = nullptr | ) |
|
|
explicit |
Definition at line 24 of file KisLongPressEventFilter.cpp.
25 : QObject(parent)
26{
28 m_timer->setTimerType(Qt::CoarseTimer);
31#ifdef Q_OS_ANDROID
32 m_longPressTimeout =
33 QAndroidJniObject::callStaticMethod<jint>("org/krita/android/MainActivity", "getLongPressTimeout", "()I");
34#endif
35}
References m_timer, and triggerLongPress().
◆ cancel()
| void KisLongPressEventFilter::cancel |
( |
| ) |
|
|
private |
◆ eventFilter()
| bool KisLongPressEventFilter::eventFilter |
( |
QObject * | watched, |
|
|
QEvent * | event ) |
|
override |
Definition at line 37 of file KisLongPressEventFilter.cpp.
38{
41 switch (event->type()) {
42 case QEvent::MouseButtonPress:
43 if (
handleMousePress(qobject_cast<QWidget *>(watched),
static_cast<QMouseEvent *
>(event))) {
44 event->setAccepted(true);
45 return true;
46 }
47 break;
48 case QEvent::MouseMove:
50 return true;
51 }
52 break;
53 case QEvent::MouseButtonDblClick:
54 case QEvent::MouseButtonRelease:
56 break;
57 default:
58 break;
59 }
60 }
61 return QObject::eventFilter(watched, event);
62}
bool handleMouseMove(const QMouseEvent *me)
bool handleMousePress(QWidget *target, const QMouseEvent *me)
References flush(), handleMouseMove(), handleMousePress(), and m_handlingEvent.
◆ flush()
| void KisLongPressEventFilter::flush |
( |
| ) |
|
|
private |
◆ getKineticScrollDelay()
| int KisLongPressEventFilter::getKineticScrollDelay |
( |
QWidget * | target | ) |
const |
|
private |
◆ handleMouseMove()
| bool KisLongPressEventFilter::handleMouseMove |
( |
const QMouseEvent * | me | ) |
|
|
private |
Definition at line 105 of file KisLongPressEventFilter.cpp.
106{
108#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
109 QPoint globalPos = me->globalPos();
110#else
111 QPoint globalPos = me->globalPosition().toPoint();
112#endif
114 return true;
115 } else {
117 }
118 }
119 return false;
120}
bool isWithinDistance(const QPoint &globalPos) const
References flush(), isWithinDistance(), and m_timer.
◆ handleMousePress()
| bool KisLongPressEventFilter::handleMousePress |
( |
QWidget * | target, |
|
|
const QMouseEvent * | me ) |
|
private |
Definition at line 64 of file KisLongPressEventFilter.cpp.
65{
67 const QStyleHints *sh = qApp->styleHints();
70#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
73#else
76#endif
77
78
79
80
81
82
86#ifdef Q_OS_ANDROID
87 int longPressInterval = m_longPressTimeout;
88#else
89 int longPressInterval = sh->mousePressAndHoldInterval();
90#endif
93 }
94
95
96
97 m_timer->start(qMax(0, longPressInterval - kineticScrollDelay));
98 return true;
99 }
100 }
102 return false;
103}
qreal distance(const QPointF &p1, const QPointF &p2)
int getKineticScrollDelay(QWidget *target) const
long long m_distanceSquared
static constexpr int MINIMUM_DISTANCE
static constexpr int MINIMUM_DELAY
static bool isContextMenuTarget(QWidget *target)
References cancel(), distance(), getKineticScrollDelay(), isContextMenuTarget(), isWithinDistance(), m_distanceSquared, m_pressGlobalPos, m_pressLocalPos, m_target, m_timer, MINIMUM_DELAY, MINIMUM_DISTANCE, and target().
◆ isContextMenuTarget()
| bool KisLongPressEventFilter::isContextMenuTarget |
( |
QWidget * | target | ) |
|
|
staticprivate |
Definition at line 213 of file KisLongPressEventFilter.cpp.
214{
216 switch (
target->contextMenuPolicy()) {
217 case Qt::NoContextMenu:
219 break;
220 case Qt::PreventContextMenu:
221 return false;
222 default:
223 return true;
224 }
225 }
226 return false;
227}
static bool isLongPressableWidget(QWidget *target)
References isLongPressableWidget(), and target().
◆ isLongPressableWidget()
| bool KisLongPressEventFilter::isLongPressableWidget |
( |
QWidget * | target | ) |
|
|
staticprivate |
Definition at line 229 of file KisLongPressEventFilter.cpp.
230{
232 if (prop.isValid()) {
233 return prop.toBool();
234 }
235
236
237
238
239
240
241
242
243
244
245 if (qobject_cast<QAbstractButton *>(
target)) {
246 return false;
247 }
248
249
250
251 if (qobject_cast<QAbstractScrollArea *>(
target)) {
252 return false;
253 }
254
255
256 if (qobject_cast<QAbstractSlider *>(
target)) {
257 return false;
258 }
259
260
261 if (qobject_cast<QAbstractSpinBox *>(
target)) {
262 return false;
263 }
264
265
266 if (qobject_cast<QComboBox *>(
target)) {
267 return false;
268 }
269
270
271 if (qobject_cast<QLineEdit *>(
target)) {
272 return false;
273 }
274
275
276 if (qobject_cast<QMenu *>(
target)) {
277 return false;
278 }
279
280
281 if (qobject_cast<QMenuBar *>(
target)) {
282 return false;
283 }
284
285 return true;
286}
static constexpr char ENABLED_PROPERTY[]
References ENABLED_PROPERTY, and target().
◆ isWithinDistance()
| bool KisLongPressEventFilter::isWithinDistance |
( |
const QPoint & | globalPos | ) |
const |
|
private |
◆ searchScroller()
| const QScroller * KisLongPressEventFilter::searchScroller |
( |
QWidget * | target | ) |
|
|
staticprivate |
◆ triggerLongPress()
| void KisLongPressEventFilter::triggerLongPress |
( |
| ) |
|
|
private |
Definition at line 150 of file KisLongPressEventFilter.cpp.
151{
156
157
158
159
160 {
161 QMouseEvent pressEvent(QEvent::MouseButtonPress,
164 Qt::RightButton,
165 Qt::RightButton,
166 Qt::NoModifier);
167 qApp->sendEvent(
target, &pressEvent);
168 }
169 {
170 QMouseEvent releaseEvent(QEvent::MouseButtonRelease,
173 Qt::RightButton,
174 Qt::NoButton,
175 Qt::NoModifier);
176 qApp->sendEvent(
target, &releaseEvent);
177 }
179 }
180}
References cancel(), isContextMenuTarget(), m_handlingEvent, m_pressGlobalPos, m_pressLocalPos, m_target, and target().
◆ ENABLED_PROPERTY
| constexpr char KisLongPressEventFilter::ENABLED_PROPERTY[] = "KRITA_LONG_PRESS" |
|
staticconstexpr |
◆ m_distanceSquared
| long long KisLongPressEventFilter::m_distanceSquared = 0LL |
|
private |
◆ m_handlingEvent
| bool KisLongPressEventFilter::m_handlingEvent = false |
|
private |
◆ m_pressGlobalPos
| QPoint KisLongPressEventFilter::m_pressGlobalPos |
|
private |
◆ m_pressLocalPos
| QPoint KisLongPressEventFilter::m_pressLocalPos |
|
private |
◆ m_target
| QPointer<QWidget> KisLongPressEventFilter::m_target |
|
private |
◆ m_timer
| QTimer* KisLongPressEventFilter::m_timer |
|
private |
◆ MINIMUM_DELAY
| constexpr int KisLongPressEventFilter::MINIMUM_DELAY = 100 |
|
staticconstexprprivate |
◆ MINIMUM_DISTANCE
| constexpr int KisLongPressEventFilter::MINIMUM_DISTANCE = 0 |
|
staticconstexprprivate |
The documentation for this class was generated from the following files: