diff options
Diffstat (limited to 'framework/src/domain/documenthandler.h')
-rw-r--r-- | framework/src/domain/documenthandler.h | 170 |
1 files changed, 170 insertions, 0 deletions
diff --git a/framework/src/domain/documenthandler.h b/framework/src/domain/documenthandler.h new file mode 100644 index 00000000..a6125bc3 --- /dev/null +++ b/framework/src/domain/documenthandler.h | |||
@@ -0,0 +1,170 @@ | |||
1 | /**************************************************************************** | ||
2 | ** | ||
3 | ** Copyright (C) 2017 The Qt Company Ltd. | ||
4 | ** Contact: https://www.qt.io/licensing/ | ||
5 | ** | ||
6 | ** This file is part of the examples of the Qt Toolkit. | ||
7 | ** | ||
8 | ** $QT_BEGIN_LICENSE:BSD$ | ||
9 | ** Commercial License Usage | ||
10 | ** Licensees holding valid commercial Qt licenses may use this file in | ||
11 | ** accordance with the commercial license agreement provided with the | ||
12 | ** Software or, alternatively, in accordance with the terms contained in | ||
13 | ** a written agreement between you and The Qt Company. For licensing terms | ||
14 | ** and conditions see https://www.qt.io/terms-conditions. For further | ||
15 | ** information use the contact form at https://www.qt.io/contact-us. | ||
16 | ** | ||
17 | ** BSD License Usage | ||
18 | ** Alternatively, you may use this file under the terms of the BSD license | ||
19 | ** as follows: | ||
20 | ** | ||
21 | ** "Redistribution and use in source and binary forms, with or without | ||
22 | ** modification, are permitted provided that the following conditions are | ||
23 | ** met: | ||
24 | ** * Redistributions of source code must retain the above copyright | ||
25 | ** notice, this list of conditions and the following disclaimer. | ||
26 | ** * Redistributions in binary form must reproduce the above copyright | ||
27 | ** notice, this list of conditions and the following disclaimer in | ||
28 | ** the documentation and/or other materials provided with the | ||
29 | ** distribution. | ||
30 | ** * Neither the name of The Qt Company Ltd nor the names of its | ||
31 | ** contributors may be used to endorse or promote products derived | ||
32 | ** from this software without specific prior written permission. | ||
33 | ** | ||
34 | ** | ||
35 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
36 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
37 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
38 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
39 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
40 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
41 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
42 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
43 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
44 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
45 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." | ||
46 | ** | ||
47 | ** $QT_END_LICENSE$ | ||
48 | ** | ||
49 | ****************************************************************************/ | ||
50 | |||
51 | #ifndef DOCUMENTHANDLER_H | ||
52 | #define DOCUMENTHANDLER_H | ||
53 | |||
54 | #include <QFont> | ||
55 | #include <QObject> | ||
56 | #include <QTextCursor> | ||
57 | #include <QUrl> | ||
58 | |||
59 | QT_BEGIN_NAMESPACE | ||
60 | class QTextDocument; | ||
61 | class QQuickTextDocument; | ||
62 | QT_END_NAMESPACE | ||
63 | |||
64 | class DocumentHandler : public QObject | ||
65 | { | ||
66 | Q_OBJECT | ||
67 | |||
68 | Q_PROPERTY(QQuickTextDocument *document READ document WRITE setDocument NOTIFY documentChanged) | ||
69 | Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition NOTIFY cursorPositionChanged) | ||
70 | Q_PROPERTY(int selectionStart READ selectionStart WRITE setSelectionStart NOTIFY selectionStartChanged) | ||
71 | Q_PROPERTY(int selectionEnd READ selectionEnd WRITE setSelectionEnd NOTIFY selectionEndChanged) | ||
72 | |||
73 | Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor NOTIFY textColorChanged) | ||
74 | Q_PROPERTY(QString fontFamily READ fontFamily WRITE setFontFamily NOTIFY fontFamilyChanged) | ||
75 | Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged) | ||
76 | |||
77 | Q_PROPERTY(bool bold READ bold WRITE setBold NOTIFY boldChanged) | ||
78 | Q_PROPERTY(bool italic READ italic WRITE setItalic NOTIFY italicChanged) | ||
79 | Q_PROPERTY(bool underline READ underline WRITE setUnderline NOTIFY underlineChanged) | ||
80 | |||
81 | Q_PROPERTY(int fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged) | ||
82 | |||
83 | Q_PROPERTY(QString fileName READ fileName NOTIFY fileUrlChanged) | ||
84 | Q_PROPERTY(QString fileType READ fileType NOTIFY fileUrlChanged) | ||
85 | Q_PROPERTY(QUrl fileUrl READ fileUrl NOTIFY fileUrlChanged) | ||
86 | |||
87 | public: | ||
88 | explicit DocumentHandler(QObject *parent = nullptr); | ||
89 | |||
90 | QQuickTextDocument *document() const; | ||
91 | void setDocument(QQuickTextDocument *document); | ||
92 | |||
93 | int cursorPosition() const; | ||
94 | void setCursorPosition(int position); | ||
95 | |||
96 | int selectionStart() const; | ||
97 | void setSelectionStart(int position); | ||
98 | |||
99 | int selectionEnd() const; | ||
100 | void setSelectionEnd(int position); | ||
101 | |||
102 | QString fontFamily() const; | ||
103 | void setFontFamily(const QString &family); | ||
104 | |||
105 | QColor textColor() const; | ||
106 | void setTextColor(const QColor &color); | ||
107 | |||
108 | Qt::Alignment alignment() const; | ||
109 | void setAlignment(Qt::Alignment alignment); | ||
110 | |||
111 | bool bold() const; | ||
112 | void setBold(bool bold); | ||
113 | |||
114 | bool italic() const; | ||
115 | void setItalic(bool italic); | ||
116 | |||
117 | bool underline() const; | ||
118 | void setUnderline(bool underline); | ||
119 | |||
120 | int fontSize() const; | ||
121 | void setFontSize(int size); | ||
122 | |||
123 | QString fileName() const; | ||
124 | QString fileType() const; | ||
125 | QUrl fileUrl() const; | ||
126 | |||
127 | public Q_SLOTS: | ||
128 | void load(const QUrl &fileUrl); | ||
129 | void saveAs(const QUrl &fileUrl); | ||
130 | |||
131 | Q_SIGNALS: | ||
132 | void documentChanged(); | ||
133 | void cursorPositionChanged(); | ||
134 | void selectionStartChanged(); | ||
135 | void selectionEndChanged(); | ||
136 | |||
137 | void fontFamilyChanged(); | ||
138 | void textColorChanged(); | ||
139 | void alignmentChanged(); | ||
140 | |||
141 | void boldChanged(); | ||
142 | void italicChanged(); | ||
143 | void underlineChanged(); | ||
144 | |||
145 | void fontSizeChanged(); | ||
146 | |||
147 | void textChanged(); | ||
148 | void fileUrlChanged(); | ||
149 | |||
150 | void loaded(const QString &text); | ||
151 | void error(const QString &message); | ||
152 | |||
153 | private: | ||
154 | void reset(); | ||
155 | QTextCursor textCursor() const; | ||
156 | QTextDocument *textDocument() const; | ||
157 | void mergeFormatOnWordOrSelection(const QTextCharFormat &format); | ||
158 | |||
159 | QQuickTextDocument *m_document; | ||
160 | |||
161 | int m_cursorPosition; | ||
162 | int m_selectionStart; | ||
163 | int m_selectionEnd; | ||
164 | |||
165 | QFont m_font; | ||
166 | int m_fontSize; | ||
167 | QUrl m_fileUrl; | ||
168 | }; | ||
169 | |||
170 | #endif // DOCUMENTHANDLER_H | ||