1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QDECLARATIVETEXTEDIT_H
43 #define QDECLARATIVETEXTEDIT_H
45 #include "private/qdeclarativetext_p.h"
46 #include "private/qdeclarativeimplicitsizeitem_p.h"
48 #include <QtGui/qtextdocument.h>
49 #include <QtGui/qtextoption.h>
50 #include <QtGui/qtextcursor.h>
51 #include <QtGui/qtextformat.h>
59 class QDeclarative1TextEditPrivate;
60 class Q_AUTOTEST_EXPORT QDeclarative1TextEdit : public QDeclarative1ImplicitSizePaintedItem
67 Q_ENUMS(SelectionMode)
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 RESET resetHAlign NOTIFY horizontalAlignmentChanged)
75 Q_PROPERTY(HAlignment effectiveHorizontalAlignment READ effectiveHAlign NOTIFY effectiveHorizontalAlignmentChanged REVISION 1)
76 Q_PROPERTY(VAlignment verticalAlignment READ vAlign WRITE setVAlign NOTIFY verticalAlignmentChanged)
77 Q_PROPERTY(WrapMode wrapMode READ wrapMode WRITE setWrapMode NOTIFY wrapModeChanged)
78 Q_PROPERTY(int lineCount READ lineCount NOTIFY lineCountChanged REVISION 1)
79 Q_PROPERTY(qreal paintedWidth READ paintedWidth NOTIFY paintedSizeChanged)
80 Q_PROPERTY(qreal paintedHeight READ paintedHeight NOTIFY paintedSizeChanged)
81 Q_PROPERTY(TextFormat textFormat READ textFormat WRITE setTextFormat NOTIFY textFormatChanged)
82 Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly NOTIFY readOnlyChanged)
83 Q_PROPERTY(bool cursorVisible READ isCursorVisible WRITE setCursorVisible NOTIFY cursorVisibleChanged)
84 Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition NOTIFY cursorPositionChanged)
85 Q_PROPERTY(QRect cursorRectangle READ cursorRectangle NOTIFY cursorRectangleChanged)
86 Q_PROPERTY(QDeclarativeComponent* cursorDelegate READ cursorDelegate WRITE setCursorDelegate NOTIFY cursorDelegateChanged)
87 Q_PROPERTY(int selectionStart READ selectionStart NOTIFY selectionStartChanged)
88 Q_PROPERTY(int selectionEnd READ selectionEnd NOTIFY selectionEndChanged)
89 Q_PROPERTY(QString selectedText READ selectedText NOTIFY selectionChanged)
90 Q_PROPERTY(bool activeFocusOnPress READ focusOnPress WRITE setFocusOnPress NOTIFY activeFocusOnPressChanged)
91 Q_PROPERTY(bool persistentSelection READ persistentSelection WRITE setPersistentSelection NOTIFY persistentSelectionChanged)
92 Q_PROPERTY(qreal textMargin READ textMargin WRITE setTextMargin NOTIFY textMarginChanged)
93 Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints WRITE setInputMethodHints)
94 Q_PROPERTY(bool selectByMouse READ selectByMouse WRITE setSelectByMouse NOTIFY selectByMouseChanged)
95 Q_PROPERTY(SelectionMode mouseSelectionMode READ mouseSelectionMode WRITE setMouseSelectionMode NOTIFY mouseSelectionModeChanged REVISION 1)
96 Q_PROPERTY(bool canPaste READ canPaste NOTIFY canPasteChanged REVISION 1)
97 Q_PROPERTY(bool inputMethodComposing READ isInputMethodComposing NOTIFY inputMethodComposingChanged REVISION 1)
100 QDeclarative1TextEdit(QDeclarativeItem *parent=0);
103 AlignLeft = Qt::AlignLeft,
104 AlignRight = Qt::AlignRight,
105 AlignHCenter = Qt::AlignHCenter,
106 AlignJustify = Qt::AlignJustify // ### VERSIONING: Only in QtQuick 1.1
110 AlignTop = Qt::AlignTop,
111 AlignBottom = Qt::AlignBottom,
112 AlignVCenter = Qt::AlignVCenter
116 PlainText = Qt::PlainText,
117 RichText = Qt::RichText,
118 AutoText = Qt::AutoText
121 enum WrapMode { NoWrap = QTextOption::NoWrap,
122 WordWrap = QTextOption::WordWrap,
123 WrapAnywhere = QTextOption::WrapAnywhere,
124 WrapAtWordBoundaryOrAnywhere = QTextOption::WrapAtWordBoundaryOrAnywhere, // COMPAT
125 Wrap = QTextOption::WrapAtWordBoundaryOrAnywhere
133 Q_INVOKABLE void openSoftwareInputPanel();
134 Q_INVOKABLE void closeSoftwareInputPanel();
136 QString text() const;
137 void setText(const QString &);
139 TextFormat textFormat() const;
140 void setTextFormat(TextFormat format);
143 void setFont(const QFont &font);
145 QColor color() const;
146 void setColor(const QColor &c);
148 QColor selectionColor() const;
149 void setSelectionColor(const QColor &c);
151 QColor selectedTextColor() const;
152 void setSelectedTextColor(const QColor &c);
154 HAlignment hAlign() const;
155 void setHAlign(HAlignment align);
157 HAlignment effectiveHAlign() const;
159 VAlignment vAlign() const;
160 void setVAlign(VAlignment align);
162 WrapMode wrapMode() const;
163 void setWrapMode(WrapMode w);
165 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 virtual void componentComplete();
201 void setReadOnly(bool);
202 bool isReadOnly() const;
204 void setTextInteractionFlags(Qt::TextInteractionFlags flags);
205 Qt::TextInteractionFlags textInteractionFlags() const;
207 QRect cursorRectangle() const;
209 QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
211 qreal paintedWidth() const;
212 qreal paintedHeight() const;
214 Q_INVOKABLE QRectF positionToRectangle(int) const;
215 Q_INVOKABLE int positionAt(int x, int y) const;
216 Q_INVOKABLE void moveCursorSelection(int pos);
217 Q_INVOKABLE Q_REVISION(1) void moveCursorSelection(int pos, SelectionMode mode);
219 QRectF boundingRect() const;
221 bool isInputMethodComposing() const;
224 void textChanged(const QString &);
225 void paintedSizeChanged();
226 void cursorPositionChanged();
227 void cursorRectangleChanged();
228 void selectionStartChanged();
229 void selectionEndChanged();
230 void selectionChanged();
231 void colorChanged(const QColor &color);
232 void selectionColorChanged(const QColor &color);
233 void selectedTextColorChanged(const QColor &color);
234 void fontChanged(const QFont &font);
235 void horizontalAlignmentChanged(HAlignment alignment);
236 void verticalAlignmentChanged(VAlignment alignment);
237 void wrapModeChanged();
238 void lineCountChanged();
239 void textFormatChanged(TextFormat textFormat);
240 void readOnlyChanged(bool isReadOnly);
241 void cursorVisibleChanged(bool isCursorVisible);
242 void cursorDelegateChanged();
243 void activeFocusOnPressChanged(bool activeFocusOnPressed);
244 void persistentSelectionChanged(bool isPersistentSelection);
245 void textMarginChanged(qreal textMargin);
246 void selectByMouseChanged(bool selectByMouse);
247 Q_REVISION(1) void mouseSelectionModeChanged(SelectionMode mode);
248 Q_REVISION(1) void linkActivated(const QString &link);
249 Q_REVISION(1) void canPasteChanged();
250 Q_REVISION(1) void inputMethodComposingChanged();
251 Q_REVISION(1) void effectiveHorizontalAlignmentChanged();
256 void select(int start, int end);
257 Q_REVISION(1) void deselect();
258 Q_REVISION(1) bool isRightToLeft(int start, int end);
259 #ifndef QT_NO_CLIPBOARD
266 void updateImgCache(const QRectF &rect);
267 void q_textChanged();
268 void updateSelectionMarkers();
269 void moveCursorDelegate();
270 void loadCursorDelegate();
271 void q_canPasteChanged();
275 void updateTotalLines();
278 virtual void geometryChanged(const QRectF &newGeometry,
279 const QRectF &oldGeometry);
281 bool event(QEvent *);
282 void keyPressEvent(QKeyEvent *);
283 void keyReleaseEvent(QKeyEvent *);
284 void focusInEvent(QFocusEvent *event);
287 void mousePressEvent(QGraphicsSceneMouseEvent *event);
288 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
289 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
290 void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
292 void inputMethodEvent(QInputMethodEvent *e);
294 void drawContents(QPainter *, const QRect &);
296 Q_DISABLE_COPY(QDeclarative1TextEdit)
297 Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarative1TextEdit)
302 QML_DECLARE_TYPE(QDeclarative1TextEdit)