1 // Commit: 27e4302b7f45f22180693d26747f419177c81e27
2 /****************************************************************************
4 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
5 ** All rights reserved.
6 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 ** This file is part of the QtDeclarative module of the Qt Toolkit.
10 ** $QT_BEGIN_LICENSE:LGPL$
11 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this
15 ** file. Please review the following information to ensure the GNU Lesser
16 ** General Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
23 ** GNU General Public License Usage
24 ** Alternatively, this file may be used under the terms of the GNU General
25 ** Public License version 3.0 as published by the Free Software Foundation
26 ** and appearing in the file LICENSE.GPL included in the packaging of this
27 ** file. Please review the following information to ensure the GNU General
28 ** Public License version 3.0 requirements will be met:
29 ** http://www.gnu.org/copyleft/gpl.html.
32 ** Alternatively, this file may be used in accordance with the terms and
33 ** conditions contained in a signed written agreement between you and Nokia.
41 ****************************************************************************/
43 #ifndef QQUICKTEXTEDIT_P_H
44 #define QQUICKTEXTEDIT_P_H
46 #include "qquickimplicitsizeitem_p.h"
48 #include <QtGui/qtextoption.h>
54 class QQuickTextEditPrivate;
55 class Q_AUTOTEST_EXPORT QQuickTextEdit : public QQuickImplicitSizeItem
62 Q_ENUMS(SelectionMode)
64 Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
65 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
66 Q_PROPERTY(QColor selectionColor READ selectionColor WRITE setSelectionColor NOTIFY selectionColorChanged)
67 Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor NOTIFY selectedTextColorChanged)
68 Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
69 Q_PROPERTY(HAlignment horizontalAlignment READ hAlign WRITE setHAlign RESET resetHAlign NOTIFY horizontalAlignmentChanged)
70 Q_PROPERTY(HAlignment effectiveHorizontalAlignment READ effectiveHAlign NOTIFY effectiveHorizontalAlignmentChanged)
71 Q_PROPERTY(VAlignment verticalAlignment READ vAlign WRITE setVAlign NOTIFY verticalAlignmentChanged)
72 Q_PROPERTY(WrapMode wrapMode READ wrapMode WRITE setWrapMode NOTIFY wrapModeChanged)
73 Q_PROPERTY(int lineCount READ lineCount NOTIFY lineCountChanged)
74 Q_PROPERTY(int length READ length NOTIFY textChanged)
75 Q_PROPERTY(qreal paintedWidth READ paintedWidth NOTIFY paintedSizeChanged)
76 Q_PROPERTY(qreal paintedHeight READ paintedHeight NOTIFY paintedSizeChanged)
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(QRect cursorRectangle READ cursorRectangle NOTIFY cursorRectangleChanged)
82 Q_PROPERTY(QDeclarativeComponent* cursorDelegate READ cursorDelegate WRITE setCursorDelegate NOTIFY cursorDelegateChanged)
83 Q_PROPERTY(int selectionStart READ selectionStart NOTIFY selectionStartChanged)
84 Q_PROPERTY(int selectionEnd READ selectionEnd NOTIFY selectionEndChanged)
85 Q_PROPERTY(QString selectedText READ selectedText NOTIFY selectionChanged)
86 Q_PROPERTY(bool activeFocusOnPress READ focusOnPress WRITE setFocusOnPress NOTIFY activeFocusOnPressChanged)
87 Q_PROPERTY(bool persistentSelection READ persistentSelection WRITE setPersistentSelection NOTIFY persistentSelectionChanged)
88 Q_PROPERTY(qreal textMargin READ textMargin WRITE setTextMargin NOTIFY textMarginChanged)
89 Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints WRITE setInputMethodHints)
90 Q_PROPERTY(bool selectByMouse READ selectByMouse WRITE setSelectByMouse NOTIFY selectByMouseChanged)
91 Q_PROPERTY(SelectionMode mouseSelectionMode READ mouseSelectionMode WRITE setMouseSelectionMode NOTIFY mouseSelectionModeChanged)
92 Q_PROPERTY(bool canPaste READ canPaste NOTIFY canPasteChanged)
93 Q_PROPERTY(bool canUndo READ canUndo NOTIFY canUndoChanged)
94 Q_PROPERTY(bool canRedo READ canRedo NOTIFY canRedoChanged)
95 Q_PROPERTY(bool inputMethodComposing READ isInputMethodComposing NOTIFY inputMethodComposingChanged)
98 QQuickTextEdit(QQuickItem *parent=0);
101 AlignLeft = Qt::AlignLeft,
102 AlignRight = Qt::AlignRight,
103 AlignHCenter = Qt::AlignHCenter,
104 AlignJustify = Qt::AlignJustify
108 AlignTop = Qt::AlignTop,
109 AlignBottom = Qt::AlignBottom,
110 AlignVCenter = Qt::AlignVCenter
114 PlainText = Qt::PlainText,
115 RichText = Qt::RichText,
116 AutoText = Qt::AutoText
119 enum WrapMode { NoWrap = QTextOption::NoWrap,
120 WordWrap = QTextOption::WordWrap,
121 WrapAnywhere = QTextOption::WrapAnywhere,
122 WrapAtWordBoundaryOrAnywhere = QTextOption::WrapAtWordBoundaryOrAnywhere, // COMPAT
123 Wrap = QTextOption::WrapAtWordBoundaryOrAnywhere
131 Q_INVOKABLE void openSoftwareInputPanel();
132 Q_INVOKABLE void closeSoftwareInputPanel();
134 QString text() const;
135 void setText(const QString &);
137 TextFormat textFormat() const;
138 void setTextFormat(TextFormat format);
141 void setFont(const QFont &font);
143 QColor color() const;
144 void setColor(const QColor &c);
146 QColor selectionColor() const;
147 void setSelectionColor(const QColor &c);
149 QColor selectedTextColor() const;
150 void setSelectedTextColor(const QColor &c);
152 HAlignment hAlign() const;
153 void setHAlign(HAlignment align);
155 HAlignment effectiveHAlign() const;
157 VAlignment vAlign() const;
158 void setVAlign(VAlignment align);
160 WrapMode wrapMode() const;
161 void setWrapMode(WrapMode w);
163 int lineCount() const;
167 bool isCursorVisible() const;
168 void setCursorVisible(bool on);
170 int cursorPosition() const;
171 void setCursorPosition(int pos);
173 QDeclarativeComponent* cursorDelegate() const;
174 void setCursorDelegate(QDeclarativeComponent*);
176 int selectionStart() const;
177 int selectionEnd() const;
179 QString selectedText() const;
181 bool focusOnPress() const;
182 void setFocusOnPress(bool on);
184 bool persistentSelection() const;
185 void setPersistentSelection(bool on);
187 qreal textMargin() const;
188 void setTextMargin(qreal margin);
190 bool selectByMouse() const;
191 void setSelectByMouse(bool);
193 SelectionMode mouseSelectionMode() const;
194 void setMouseSelectionMode(SelectionMode mode);
196 bool canPaste() const;
198 bool canUndo() const;
199 bool canRedo() const;
201 virtual void componentComplete();
204 void setReadOnly(bool);
205 bool isReadOnly() const;
207 void setTextInteractionFlags(Qt::TextInteractionFlags flags);
208 Qt::TextInteractionFlags textInteractionFlags() const;
210 QRect cursorRectangle() const;
212 QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
214 qreal paintedWidth() const;
215 qreal paintedHeight() const;
217 Q_INVOKABLE QRectF positionToRectangle(int) const;
218 Q_INVOKABLE int positionAt(int x, int y) const;
219 Q_INVOKABLE void moveCursorSelection(int pos);
220 Q_INVOKABLE void moveCursorSelection(int pos, SelectionMode mode);
222 QRectF boundingRect() const;
224 bool isInputMethodComposing() const;
226 Q_INVOKABLE QString getText(int start, int end) const;
227 Q_INVOKABLE QString getFormattedText(int start, int end) const;
231 void paintedSizeChanged();
232 void cursorPositionChanged();
233 void cursorRectangleChanged();
234 void selectionStartChanged();
235 void selectionEndChanged();
236 void selectionChanged();
237 void colorChanged(const QColor &color);
238 void selectionColorChanged(const QColor &color);
239 void selectedTextColorChanged(const QColor &color);
240 void fontChanged(const QFont &font);
241 void horizontalAlignmentChanged(HAlignment alignment);
242 void verticalAlignmentChanged(VAlignment alignment);
243 void wrapModeChanged();
244 void lineCountChanged();
245 void textFormatChanged(TextFormat textFormat);
246 void readOnlyChanged(bool isReadOnly);
247 void cursorVisibleChanged(bool isCursorVisible);
248 void cursorDelegateChanged();
249 void activeFocusOnPressChanged(bool activeFocusOnPressed);
250 void persistentSelectionChanged(bool isPersistentSelection);
251 void textMarginChanged(qreal textMargin);
252 void selectByMouseChanged(bool selectByMouse);
253 void mouseSelectionModeChanged(SelectionMode mode);
254 void linkActivated(const QString &link);
255 void canPasteChanged();
256 void canUndoChanged();
257 void canRedoChanged();
258 void inputMethodComposingChanged();
259 void effectiveHorizontalAlignmentChanged();
264 void select(int start, int end);
266 bool isRightToLeft(int start, int end);
267 #ifndef QT_NO_CLIPBOARD
274 void insert(int position, const QString &text);
275 void remove(int start, int end);
278 void q_textChanged();
279 void updateSelectionMarkers();
280 void moveCursorDelegate();
281 void loadCursorDelegate();
282 void q_canPasteChanged();
283 void updateDocument();
288 void updateTotalLines();
289 void updateImageCache(const QRectF &rect = QRectF());
292 virtual void geometryChanged(const QRectF &newGeometry,
293 const QRectF &oldGeometry);
295 bool event(QEvent *);
296 void keyPressEvent(QKeyEvent *);
297 void keyReleaseEvent(QKeyEvent *);
298 void focusInEvent(QFocusEvent *event);
301 void mousePressEvent(QMouseEvent *event);
302 void mouseReleaseEvent(QMouseEvent *event);
303 void mouseDoubleClickEvent(QMouseEvent *event);
304 void mouseMoveEvent(QMouseEvent *event);
305 void inputMethodEvent(QInputMethodEvent *e);
306 virtual void itemChange(ItemChange, const ItemChangeData &);
308 QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData);
311 Q_DISABLE_COPY(QQuickTextEdit)
312 Q_DECLARE_PRIVATE(QQuickTextEdit)
317 QML_DECLARE_TYPE(QQuickTextEdit)
321 #endif // QQUICKTEXTEDIT_P_H