| 1 | // Copyright (C) 2023 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QQUICKTEXTSELECTION_H |
| 5 | #define QQUICKTEXTSELECTION_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <private/qtquickglobal_p.h> |
| 19 | |
| 20 | #include <QtQuick/qquicktextdocument.h> |
| 21 | |
| 22 | #include <QtQml/qqml.h> |
| 23 | |
| 24 | #include <QtGui/qtextcursor.h> |
| 25 | |
| 26 | QT_BEGIN_NAMESPACE |
| 27 | |
| 28 | class QFont; |
| 29 | class QQuickTextControl; |
| 30 | |
| 31 | class Q_QUICK_EXPORT QQuickTextSelection : public QObject |
| 32 | { |
| 33 | Q_OBJECT |
| 34 | |
| 35 | Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged FINAL) |
| 36 | Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged FINAL) |
| 37 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged FINAL) |
| 38 | Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged FINAL) |
| 39 | |
| 40 | QML_ANONYMOUS |
| 41 | QML_ADDED_IN_VERSION(6, 7) |
| 42 | |
| 43 | public: |
| 44 | explicit QQuickTextSelection(QObject *parent = nullptr); |
| 45 | |
| 46 | QString text() const; |
| 47 | void setText(const QString &text); |
| 48 | |
| 49 | QFont font() const; |
| 50 | void setFont(const QFont &font); |
| 51 | |
| 52 | QColor color() const; |
| 53 | void setColor(QColor color); |
| 54 | |
| 55 | Qt::Alignment alignment() const; |
| 56 | void setAlignment(Qt::Alignment align); |
| 57 | |
| 58 | Q_SIGNALS: |
| 59 | void textChanged(); |
| 60 | void fontChanged(); |
| 61 | void colorChanged(); |
| 62 | void alignmentChanged(); |
| 63 | |
| 64 | private: |
| 65 | QTextCursor cursor() const; |
| 66 | void updateFromCharFormat(const QTextCharFormat &fmt); |
| 67 | void updateFromBlockFormat(); |
| 68 | |
| 69 | private: |
| 70 | QTextCursor m_cursor; |
| 71 | QTextCharFormat m_charFormat; |
| 72 | QTextBlockFormat m_blockFormat; |
| 73 | QQuickTextControl *m_control = nullptr; |
| 74 | }; |
| 75 | |
| 76 | QT_END_NAMESPACE |
| 77 | |
| 78 | QML_DECLARE_TYPE(QQuickTextSelection) |
| 79 | |
| 80 | #endif // QQUICKTEXTSELECTION_H |
| 81 | |