File indexing completed on 2024-05-12 17:08:48

0001 /*
0002     SPDX-FileCopyrightText: 2021 Kai Uwe Broulik <kde@broulik.de>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <QObject>
0010 #include <QPointF>
0011 #include <QPointer>
0012 
0013 class QQuickItem;
0014 
0015 /**
0016  * Simple event filter that emits a clicked() signal when clicking
0017  * on a TextEdit while still letting the user select text like normal.
0018  *
0019  * It's just for this very specific use case, which is also why it has
0020  * no acceptedButtons, MouseEvent argument on clicked signal, etc.
0021  */
0022 class TextEditClickHandler : public QObject
0023 {
0024     Q_OBJECT
0025 
0026     Q_PROPERTY(QQuickItem *target READ target WRITE setTarget NOTIFY targetChanged)
0027 
0028 public:
0029     explicit TextEditClickHandler(QObject *parent = nullptr);
0030     ~TextEditClickHandler() override;
0031 
0032     QQuickItem *target() const;
0033     void setTarget(QQuickItem *target);
0034     Q_SIGNAL void targetChanged(QQuickItem *target);
0035 
0036     bool eventFilter(QObject *watched, QEvent *event) override;
0037 
0038 Q_SIGNALS:
0039     void clicked();
0040 
0041 private:
0042     QPointer<QQuickItem> m_target;
0043     QPointF m_pressPos{-1, -1};
0044 };