1 // Commit: 27e4302b7f45f22180693d26747f419177c81e27
2 /****************************************************************************
4 ** Copyright (C) 2011 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 QSGTEXTEDIT_P_H
44 #define QSGTEXTEDIT_P_H
46 #include "qsgimplicitsizeitem_p.h"
48 #include <QtGui/qtextoption.h>
54 QT_MODULE(Declarative)
56 class QSGTextEditPrivate;
57 class Q_AUTOTEST_EXPORT QSGTextEdit : public QSGImplicitSizeItem
64 Q_ENUMS(SelectionMode)
66 Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
67 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
68 Q_PROPERTY(QColor selectionColor READ selectionColor WRITE setSelectionColor NOTIFY selectionColorChanged)
69 Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor NOTIFY selectedTextColorChanged)
70 Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
71 Q_PROPERTY(HAlignment horizontalAlignment READ hAlign WRITE setHAlign RESET resetHAlign NOTIFY horizontalAlignmentChanged)
72 Q_PROPERTY(HAlignment effectiveHorizontalAlignment READ effectiveHAlign NOTIFY effectiveHorizontalAlignmentChanged)
73 Q_PROPERTY(VAlignment verticalAlignment READ vAlign WRITE setVAlign NOTIFY verticalAlignmentChanged)
74 Q_PROPERTY(WrapMode wrapMode READ wrapMode WRITE setWrapMode NOTIFY wrapModeChanged)
75 Q_PROPERTY(int lineCount READ lineCount NOTIFY lineCountChanged)
76 Q_PROPERTY(qreal paintedWidth READ paintedWidth NOTIFY paintedSizeChanged)
77 Q_PROPERTY(qreal paintedHeight READ paintedHeight NOTIFY paintedSizeChanged)
78 Q_PROPERTY(TextFormat textFormat READ textFormat WRITE setTextFormat NOTIFY textFormatChanged)
79 Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly NOTIFY readOnlyChanged)
80 Q_PROPERTY(bool cursorVisible READ isCursorVisible WRITE setCursorVisible NOTIFY cursorVisibleChanged)
81 Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition NOTIFY cursorPositionChanged)
82 Q_PROPERTY(QRect cursorRectangle READ cursorRectangle NOTIFY cursorRectangleChanged)
83 Q_PROPERTY(QDeclarativeComponent* cursorDelegate READ cursorDelegate WRITE setCursorDelegate NOTIFY cursorDelegateChanged)
84 Q_PROPERTY(int selectionStart READ selectionStart NOTIFY selectionStartChanged)
85 Q_PROPERTY(int selectionEnd READ selectionEnd NOTIFY selectionEndChanged)
86 Q_PROPERTY(QString selectedText READ selectedText NOTIFY selectionChanged)
87 Q_PROPERTY(bool activeFocusOnPress READ focusOnPress WRITE setFocusOnPress NOTIFY activeFocusOnPressChanged)
88 Q_PROPERTY(bool persistentSelection READ persistentSelection WRITE setPersistentSelection NOTIFY persistentSelectionChanged)
89 Q_PROPERTY(qreal textMargin READ textMargin WRITE setTextMargin NOTIFY textMarginChanged)
90 Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints WRITE setInputMethodHints)
91 Q_PROPERTY(bool selectByMouse READ selectByMouse WRITE setSelectByMouse NOTIFY selectByMouseChanged)
92 Q_PROPERTY(SelectionMode mouseSelectionMode READ mouseSelectionMode WRITE setMouseSelectionMode NOTIFY mouseSelectionModeChanged)
93 Q_PROPERTY(bool canPaste READ canPaste NOTIFY canPasteChanged)
94 Q_PROPERTY(bool inputMethodComposing READ isInputMethodComposing NOTIFY inputMethodComposingChanged)
97 QSGTextEdit(QSGItem *parent=0);
100 AlignLeft = Qt::AlignLeft,
101 AlignRight = Qt::AlignRight,
102 AlignHCenter = Qt::AlignHCenter,
103 AlignJustify = Qt::AlignJustify
107 AlignTop = Qt::AlignTop,
108 AlignBottom = Qt::AlignBottom,
109 AlignVCenter = Qt::AlignVCenter
113 PlainText = Qt::PlainText,
114 RichText = Qt::RichText,
115 AutoText = Qt::AutoText
118 enum WrapMode { NoWrap = QTextOption::NoWrap,
119 WordWrap = QTextOption::WordWrap,
120 WrapAnywhere = QTextOption::WrapAnywhere,
121 WrapAtWordBoundaryOrAnywhere = QTextOption::WrapAtWordBoundaryOrAnywhere, // COMPAT
122 Wrap = QTextOption::WrapAtWordBoundaryOrAnywhere
130 Q_INVOKABLE void openSoftwareInputPanel();
131 Q_INVOKABLE void closeSoftwareInputPanel();
133 QString text() const;
134 void setText(const QString &);
136 TextFormat textFormat() const;
137 void setTextFormat(TextFormat format);
140 void setFont(const QFont &font);
142 QColor color() const;
143 void setColor(const QColor &c);
145 QColor selectionColor() const;
146 void setSelectionColor(const QColor &c);
148 QColor selectedTextColor() const;
149 void setSelectedTextColor(const QColor &c);
151 HAlignment hAlign() const;
152 void setHAlign(HAlignment align);
154 HAlignment effectiveHAlign() const;
156 VAlignment vAlign() const;
157 void setVAlign(VAlignment align);
159 WrapMode wrapMode() const;
160 void setWrapMode(WrapMode w);
162 int lineCount() const;
164 bool isCursorVisible() const;
165 void setCursorVisible(bool on);
167 int cursorPosition() const;
168 void setCursorPosition(int pos);
170 QDeclarativeComponent* cursorDelegate() const;
171 void setCursorDelegate(QDeclarativeComponent*);
173 int selectionStart() const;
174 int selectionEnd() const;
176 QString selectedText() const;
178 bool focusOnPress() const;
179 void setFocusOnPress(bool on);
181 bool persistentSelection() const;
182 void setPersistentSelection(bool on);
184 qreal textMargin() const;
185 void setTextMargin(qreal margin);
187 bool selectByMouse() const;
188 void setSelectByMouse(bool);
190 SelectionMode mouseSelectionMode() const;
191 void setMouseSelectionMode(SelectionMode mode);
193 bool canPaste() const;
195 virtual void componentComplete();
198 void setReadOnly(bool);
199 bool isReadOnly() const;
201 void setTextInteractionFlags(Qt::TextInteractionFlags flags);
202 Qt::TextInteractionFlags textInteractionFlags() const;
204 QRect cursorRectangle() const;
206 QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
208 qreal paintedWidth() const;
209 qreal paintedHeight() const;
211 Q_INVOKABLE QRectF positionToRectangle(int) const;
212 Q_INVOKABLE int positionAt(int x, int y) const;
213 Q_INVOKABLE void moveCursorSelection(int pos);
214 Q_INVOKABLE void moveCursorSelection(int pos, SelectionMode mode);
216 QRectF boundingRect() const;
218 bool isInputMethodComposing() const;
221 void textChanged(const QString &);
222 void paintedSizeChanged();
223 void cursorPositionChanged();
224 void cursorRectangleChanged();
225 void selectionStartChanged();
226 void selectionEndChanged();
227 void selectionChanged();
228 void colorChanged(const QColor &color);
229 void selectionColorChanged(const QColor &color);
230 void selectedTextColorChanged(const QColor &color);
231 void fontChanged(const QFont &font);
232 void horizontalAlignmentChanged(HAlignment alignment);
233 void verticalAlignmentChanged(VAlignment alignment);
234 void wrapModeChanged();
235 void lineCountChanged();
236 void textFormatChanged(TextFormat textFormat);
237 void readOnlyChanged(bool isReadOnly);
238 void cursorVisibleChanged(bool isCursorVisible);
239 void cursorDelegateChanged();
240 void activeFocusOnPressChanged(bool activeFocusOnPressed);
241 void persistentSelectionChanged(bool isPersistentSelection);
242 void textMarginChanged(qreal textMargin);
243 void selectByMouseChanged(bool selectByMouse);
244 void mouseSelectionModeChanged(SelectionMode mode);
245 void linkActivated(const QString &link);
246 void canPasteChanged();
247 void inputMethodComposingChanged();
248 void effectiveHorizontalAlignmentChanged();
253 void select(int start, int end);
255 bool isRightToLeft(int start, int end);
256 #ifndef QT_NO_CLIPBOARD
263 void q_textChanged();
264 void updateSelectionMarkers();
265 void moveCursorDelegate();
266 void loadCursorDelegate();
267 void q_canPasteChanged();
268 void updateDocument();
273 void updateTotalLines();
274 void updateImageCache(const QRectF &rect = QRectF());
277 virtual void geometryChanged(const QRectF &newGeometry,
278 const QRectF &oldGeometry);
280 bool event(QEvent *);
281 void keyPressEvent(QKeyEvent *);
282 void keyReleaseEvent(QKeyEvent *);
283 void focusInEvent(QFocusEvent *event);
286 void mousePressEvent(QMouseEvent *event);
287 void mouseReleaseEvent(QMouseEvent *event);
288 void mouseDoubleClickEvent(QMouseEvent *event);
289 void mouseMoveEvent(QMouseEvent *event);
290 void inputMethodEvent(QInputMethodEvent *e);
291 virtual void itemChange(ItemChange, const ItemChangeData &);
293 QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData);
296 Q_DISABLE_COPY(QSGTextEdit)
297 Q_DECLARE_PRIVATE(QSGTextEdit)
302 QML_DECLARE_TYPE(QSGTextEdit)
306 #endif // QSGTEXTEDIT_P_H