Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquicktextselection_p.h
Go to the documentation of this file.
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// Qt-Security score:significant reason:default
4
5#ifndef QQUICKTEXTSELECTION_H
6#define QQUICKTEXTSELECTION_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <private/qtquickglobal_p.h>
20
21#include <QtQuick/qquicktextdocument.h>
22
23#include <QtQml/qqml.h>
24
25#include <QtGui/qtextcursor.h>
26
27QT_BEGIN_NAMESPACE
28
29class QFont;
30class QQuickTextControl;
31
32class Q_QUICK_EXPORT QQuickTextSelection : public QObject, public QQmlParserStatus
33{
34 Q_OBJECT
35 Q_INTERFACES(QQmlParserStatus)
36
37 // specify the selection
38 Q_PROPERTY(QQuickTextDocument *document READ document WRITE setDocument NOTIFY documentChanged FINAL REVISION(6, 11))
39 Q_PROPERTY(int selectionStart READ selectionStart WRITE setSelectionStart NOTIFY selectionStartChanged FINAL REVISION(6, 11))
40 Q_PROPERTY(int selectionEnd READ selectionEnd WRITE setSelectionEnd NOTIFY selectionEndChanged FINAL REVISION(6, 11))
41
42 // modify the selected text
43 Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged FINAL)
44 Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged FINAL)
45 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged FINAL)
46 Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged FINAL)
47
48 QML_NAMED_ELEMENT(TextSelection)
49 QML_ADDED_IN_VERSION(6, 7)
50
51public:
52
53 // keep this in sync with QTextCursor::MoveOperation
54 enum MoveOperation {
55 NoMove = QTextCursor::NoMove,
56
57 Start,
58 Up,
59 StartOfLine,
60 StartOfBlock,
61 StartOfWord,
62 PreviousBlock,
63 PreviousCharacter,
64 PreviousWord,
65 Left,
66 WordLeft,
67
68 End,
69 Down,
70 EndOfLine,
71 EndOfWord,
72 EndOfBlock,
73 NextBlock,
74 NextCharacter,
75 NextWord,
76 Right,
77 WordRight,
78
79 NextCell,
80 PreviousCell,
81 NextRow,
82 PreviousRow
83 };
84 Q_ENUM(MoveOperation);
85
86 explicit QQuickTextSelection(QObject *parent = nullptr);
87
88 void classBegin() override {}
89 void componentComplete() override;
90
91 QQuickTextDocument *document() const;
92 void setDocument(QQuickTextDocument *doc);
93
94 int selectionStart() const;
95 void setSelectionStart(int start);
96
97 int selectionEnd() const;
98 void setSelectionEnd(int end);
99
100 QString text() const;
101 void setText(const QString &text);
102
103 QFont font() const;
104 void setFont(const QFont &font);
105
106 QColor color() const;
107 void setColor(QColor color);
108
109 Qt::Alignment alignment() const;
110 void setAlignment(Qt::Alignment align);
111
112 Q_REVISION(6, 11) Q_INVOKABLE bool moveSelectionStart(MoveOperation op, int n = 1);
113 Q_REVISION(6, 11) Q_INVOKABLE bool moveSelectionEnd(MoveOperation op, int n = 1);
114
115 Q_REVISION(6, 11) Q_INVOKABLE void duplicate();
116
117 Q_REVISION(6, 11) Q_INVOKABLE void linkTo(const QUrl &destination);
118
119Q_SIGNALS:
120 Q_REVISION(6, 11) void documentChanged();
121 Q_REVISION(6, 11) void selectionStartChanged();
122 Q_REVISION(6, 11) void selectionEndChanged();
123 void textChanged();
124 void fontChanged();
125 void colorChanged();
126 void alignmentChanged();
127
128private:
129 QTextCursor cursor() const;
130 void updateFromCharFormat(const QTextCharFormat &fmt);
131 void updateFromBlockFormat();
132
133private:
134 QTextCursor m_cursor;
135 QTextCharFormat m_charFormat;
136 QTextBlockFormat m_blockFormat;
137 QQuickTextDocument *m_doc = nullptr;
138 QQuickTextControl *m_control = nullptr;
139};
140
141QT_END_NAMESPACE
142
143QML_DECLARE_TYPE(QQuickTextSelection)
144
145#endif // QQUICKTEXTSELECTION_H