|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the QtDeclarative module of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #ifndef QDECLARATIVETEXTEDIT_H |
|
43 #define QDECLARATIVETEXTEDIT_H |
|
44 |
|
45 #include "private/qdeclarativetext_p.h" |
|
46 #include "private/qdeclarativepainteditem_p.h" |
|
47 |
|
48 #include <QtGui/qtextdocument.h> |
|
49 #include <QtGui/qtextoption.h> |
|
50 #include <QtGui/qtextcursor.h> |
|
51 #include <QtGui/qtextformat.h> |
|
52 |
|
53 QT_BEGIN_HEADER |
|
54 |
|
55 QT_BEGIN_NAMESPACE |
|
56 |
|
57 QT_MODULE(Declarative) |
|
58 |
|
59 |
|
60 class QDeclarativeTextEditPrivate; |
|
61 class Q_DECLARATIVE_EXPORT QDeclarativeTextEdit : public QDeclarativePaintedItem |
|
62 { |
|
63 Q_OBJECT |
|
64 Q_ENUMS(VAlignment) |
|
65 Q_ENUMS(HAlignment) |
|
66 Q_ENUMS(TextFormat) |
|
67 Q_ENUMS(WrapMode) |
|
68 |
|
69 Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) |
|
70 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) |
|
71 Q_PROPERTY(QColor selectionColor READ selectionColor WRITE setSelectionColor NOTIFY selectionColorChanged) |
|
72 Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor NOTIFY selectedTextColorChanged) |
|
73 Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged) |
|
74 Q_PROPERTY(HAlignment horizontalAlignment READ hAlign WRITE setHAlign NOTIFY horizontalAlignmentChanged) |
|
75 Q_PROPERTY(VAlignment verticalAlignment READ vAlign WRITE setVAlign NOTIFY verticalAlignmentChanged) |
|
76 Q_PROPERTY(WrapMode wrapMode READ wrapMode WRITE setWrapMode NOTIFY wrapModeChanged) |
|
77 Q_PROPERTY(TextFormat textFormat READ textFormat WRITE setTextFormat NOTIFY textFormatChanged) |
|
78 Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly NOTIFY readOnlyChanged) |
|
79 Q_PROPERTY(bool cursorVisible READ isCursorVisible WRITE setCursorVisible NOTIFY cursorVisibleChanged) |
|
80 Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition NOTIFY cursorPositionChanged) |
|
81 Q_PROPERTY(QDeclarativeComponent* cursorDelegate READ cursorDelegate WRITE setCursorDelegate NOTIFY cursorDelegateChanged) |
|
82 Q_PROPERTY(int selectionStart READ selectionStart WRITE setSelectionStart NOTIFY selectionStartChanged) |
|
83 Q_PROPERTY(int selectionEnd READ selectionEnd WRITE setSelectionEnd NOTIFY selectionEndChanged) |
|
84 Q_PROPERTY(QString selectedText READ selectedText NOTIFY selectionChanged) |
|
85 Q_PROPERTY(bool focusOnPress READ focusOnPress WRITE setFocusOnPress NOTIFY focusOnPressChanged) |
|
86 Q_PROPERTY(bool persistentSelection READ persistentSelection WRITE setPersistentSelection NOTIFY persistentSelectionChanged) |
|
87 Q_PROPERTY(qreal textMargin READ textMargin WRITE setTextMargin NOTIFY textMarginChanged) |
|
88 Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints WRITE setInputMethodHints) |
|
89 Q_PROPERTY(bool selectByMouse READ selectByMouse WRITE setSelectByMouse NOTIFY selectByMouseChanged) |
|
90 |
|
91 public: |
|
92 QDeclarativeTextEdit(QDeclarativeItem *parent=0); |
|
93 |
|
94 enum HAlignment { |
|
95 AlignLeft = Qt::AlignLeft, |
|
96 AlignRight = Qt::AlignRight, |
|
97 AlignHCenter = Qt::AlignHCenter |
|
98 }; |
|
99 |
|
100 enum VAlignment { |
|
101 AlignTop = Qt::AlignTop, |
|
102 AlignBottom = Qt::AlignBottom, |
|
103 AlignVCenter = Qt::AlignVCenter |
|
104 }; |
|
105 |
|
106 enum TextFormat { |
|
107 PlainText = Qt::PlainText, |
|
108 RichText = Qt::RichText, |
|
109 AutoText = Qt::AutoText |
|
110 }; |
|
111 |
|
112 enum WrapMode { NoWrap = QTextOption::NoWrap, |
|
113 WordWrap = QTextOption::WordWrap, |
|
114 WrapAnywhere = QTextOption::WrapAnywhere, |
|
115 WrapAtWordBoundaryOrAnywhere = QTextOption::WrapAtWordBoundaryOrAnywhere |
|
116 }; |
|
117 |
|
118 QString text() const; |
|
119 void setText(const QString &); |
|
120 |
|
121 TextFormat textFormat() const; |
|
122 void setTextFormat(TextFormat format); |
|
123 |
|
124 QFont font() const; |
|
125 void setFont(const QFont &font); |
|
126 |
|
127 QColor color() const; |
|
128 void setColor(const QColor &c); |
|
129 |
|
130 QColor selectionColor() const; |
|
131 void setSelectionColor(const QColor &c); |
|
132 |
|
133 QColor selectedTextColor() const; |
|
134 void setSelectedTextColor(const QColor &c); |
|
135 |
|
136 HAlignment hAlign() const; |
|
137 void setHAlign(HAlignment align); |
|
138 |
|
139 VAlignment vAlign() const; |
|
140 void setVAlign(VAlignment align); |
|
141 |
|
142 WrapMode wrapMode() const; |
|
143 void setWrapMode(WrapMode w); |
|
144 |
|
145 bool isCursorVisible() const; |
|
146 void setCursorVisible(bool on); |
|
147 |
|
148 int cursorPosition() const; |
|
149 void setCursorPosition(int pos); |
|
150 |
|
151 QDeclarativeComponent* cursorDelegate() const; |
|
152 void setCursorDelegate(QDeclarativeComponent*); |
|
153 |
|
154 int selectionStart() const; |
|
155 void setSelectionStart(int); |
|
156 |
|
157 int selectionEnd() const; |
|
158 void setSelectionEnd(int); |
|
159 |
|
160 QString selectedText() const; |
|
161 |
|
162 bool focusOnPress() const; |
|
163 void setFocusOnPress(bool on); |
|
164 |
|
165 bool persistentSelection() const; |
|
166 void setPersistentSelection(bool on); |
|
167 |
|
168 qreal textMargin() const; |
|
169 void setTextMargin(qreal margin); |
|
170 |
|
171 bool selectByMouse() const; |
|
172 void setSelectByMouse(bool); |
|
173 |
|
174 virtual void componentComplete(); |
|
175 |
|
176 /* FROM EDIT */ |
|
177 void setReadOnly(bool); |
|
178 bool isReadOnly() const; |
|
179 |
|
180 void setTextInteractionFlags(Qt::TextInteractionFlags flags); |
|
181 Qt::TextInteractionFlags textInteractionFlags() const; |
|
182 |
|
183 QRect cursorRect() const; |
|
184 |
|
185 QVariant inputMethodQuery(Qt::InputMethodQuery property) const; |
|
186 |
|
187 Q_SIGNALS: |
|
188 void textChanged(const QString &); |
|
189 void cursorPositionChanged(); |
|
190 void selectionStartChanged(); |
|
191 void selectionEndChanged(); |
|
192 void selectionChanged(); |
|
193 void colorChanged(const QColor &color); |
|
194 void selectionColorChanged(const QColor &color); |
|
195 void selectedTextColorChanged(const QColor &color); |
|
196 void fontChanged(const QFont &font); |
|
197 void horizontalAlignmentChanged(HAlignment alignment); |
|
198 void verticalAlignmentChanged(VAlignment alignment); |
|
199 void wrapModeChanged(); |
|
200 void textFormatChanged(TextFormat textFormat); |
|
201 void readOnlyChanged(bool isReadOnly); |
|
202 void cursorVisibleChanged(bool isCursorVisible); |
|
203 void cursorDelegateChanged(); |
|
204 void focusOnPressChanged(bool focusIsPressed); |
|
205 void persistentSelectionChanged(bool isPersistentSelection); |
|
206 void textMarginChanged(qreal textMargin); |
|
207 void selectByMouseChanged(bool selectByMouse); |
|
208 |
|
209 public Q_SLOTS: |
|
210 void selectAll(); |
|
211 |
|
212 private Q_SLOTS: |
|
213 void updateImgCache(const QRectF &rect); |
|
214 void q_textChanged(); |
|
215 void updateSelectionMarkers(); |
|
216 void moveCursorDelegate(); |
|
217 void loadCursorDelegate(); |
|
218 |
|
219 private: |
|
220 void updateSize(); |
|
221 |
|
222 protected: |
|
223 virtual void geometryChanged(const QRectF &newGeometry, |
|
224 const QRectF &oldGeometry); |
|
225 |
|
226 bool event(QEvent *); |
|
227 void keyPressEvent(QKeyEvent *); |
|
228 void keyReleaseEvent(QKeyEvent *); |
|
229 |
|
230 // mouse filter? |
|
231 void mousePressEvent(QGraphicsSceneMouseEvent *event); |
|
232 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); |
|
233 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); |
|
234 void mouseMoveEvent(QGraphicsSceneMouseEvent *event); |
|
235 |
|
236 void inputMethodEvent(QInputMethodEvent *e); |
|
237 |
|
238 void drawContents(QPainter *, const QRect &); |
|
239 private: |
|
240 Q_DISABLE_COPY(QDeclarativeTextEdit) |
|
241 Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeTextEdit) |
|
242 }; |
|
243 |
|
244 QT_END_NAMESPACE |
|
245 |
|
246 QML_DECLARE_TYPE(QDeclarativeTextEdit) |
|
247 |
|
248 QT_END_HEADER |
|
249 |
|
250 #endif |