summaryrefslogtreecommitdiffstats
path: root/framework/src/domain/textdocumenthandler.h
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-10-06 11:43:33 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-10-06 11:46:58 +0200
commit737770bfa4bb91ed96412d18d6490db3450bcb1c (patch)
tree9b4bd7a6252c687b4cb5ac3d91ebe786e7891377 /framework/src/domain/textdocumenthandler.h
parent41e3f3544f3ec7ae3c14f18010005e3e55c003e7 (diff)
downloadkube-737770bfa4bb91ed96412d18d6490db3450bcb1c.tar.gz
kube-737770bfa4bb91ed96412d18d6490db3450bcb1c.zip
TextDocumentHandler to deal with HTML formatting
Diffstat (limited to 'framework/src/domain/textdocumenthandler.h')
-rw-r--r--framework/src/domain/textdocumenthandler.h121
1 files changed, 121 insertions, 0 deletions
diff --git a/framework/src/domain/textdocumenthandler.h b/framework/src/domain/textdocumenthandler.h
new file mode 100644
index 00000000..b8ae5bdb
--- /dev/null
+++ b/framework/src/domain/textdocumenthandler.h
@@ -0,0 +1,121 @@
1/*
2 Copyright (c) 2017 Christian Mollekopf <mollekopf@kolabsystems.com>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19#pragma once
20
21#include <QObject>
22#include <QFont>
23#include <QTextCursor>
24
25class QTextDocument;
26class QQuickTextDocument;
27
28class TextDocumentHandler : public QObject
29{
30 Q_OBJECT
31
32 Q_PROPERTY(QQuickTextDocument *document READ document WRITE setDocument NOTIFY documentChanged)
33 Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition NOTIFY cursorPositionChanged)
34 Q_PROPERTY(int selectionStart READ selectionStart WRITE setSelectionStart NOTIFY selectionStartChanged)
35 Q_PROPERTY(int selectionEnd READ selectionEnd WRITE setSelectionEnd NOTIFY selectionEndChanged)
36
37 Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor NOTIFY textColorChanged)
38 Q_PROPERTY(QString fontFamily READ fontFamily WRITE setFontFamily NOTIFY fontFamilyChanged)
39 Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged)
40
41 Q_PROPERTY(bool bold READ bold WRITE setBold NOTIFY boldChanged)
42 Q_PROPERTY(bool italic READ italic WRITE setItalic NOTIFY italicChanged)
43 Q_PROPERTY(bool underline READ underline WRITE setUnderline NOTIFY underlineChanged)
44
45 Q_PROPERTY(int fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged)
46
47 Q_PROPERTY(QString plainText READ plainText NOTIFY textChanged)
48 Q_PROPERTY(QString htmlText READ htmlText NOTIFY textChanged)
49
50public:
51 explicit TextDocumentHandler(QObject *parent = nullptr);
52
53 QQuickTextDocument *document() const;
54 void setDocument(QQuickTextDocument *document);
55
56 QString plainText() const;
57 QString htmlText() const;
58
59 int cursorPosition() const;
60 void setCursorPosition(int position);
61
62 int selectionStart() const;
63 void setSelectionStart(int position);
64
65 int selectionEnd() const;
66 void setSelectionEnd(int position);
67
68 QString fontFamily() const;
69 void setFontFamily(const QString &family);
70
71 QColor textColor() const;
72 void setTextColor(const QColor &color);
73
74 Qt::Alignment alignment() const;
75 void setAlignment(Qt::Alignment alignment);
76
77 bool bold() const;
78 void setBold(bool bold);
79
80 bool italic() const;
81 void setItalic(bool italic);
82
83 bool underline() const;
84 void setUnderline(bool underline);
85
86 int fontSize() const;
87 void setFontSize(int size);
88
89Q_SIGNALS:
90 void documentChanged();
91 void cursorPositionChanged();
92 void selectionStartChanged();
93 void selectionEndChanged();
94
95 void fontFamilyChanged();
96 void textColorChanged();
97 void alignmentChanged();
98
99 void boldChanged();
100 void italicChanged();
101 void underlineChanged();
102
103 void fontSizeChanged();
104
105 void textChanged();
106
107private Q_SLOTS:
108 void contentsChange(int position, int charsRemoved, int charsAdded);
109
110private:
111 void reset();
112 QTextCharFormat charFormat() const;
113 QTextCursor textCursor() const;
114 void mergeFormatOnWordOrSelection(const QTextCharFormat &format);
115
116 QQuickTextDocument *mDocument;
117 int mCursorPosition;
118 int mSelectionStart;
119 int mSelectionEnd;
120 QSharedPointer<QTextCharFormat> mCachedTextFormat;
121};