1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** 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>
57 QT_MODULE(Declarative)
60 class QDeclarative1TextEditPrivate;
61 class Q_AUTOTEST_EXPORT QDeclarative1TextEdit : public QDeclarative1ImplicitSizePaintedItem
68 Q_ENUMS(SelectionMode)
70 Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
71 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
72 Q_PROPERTY(QColor selectionColor READ selectionColor WRITE setSelectionColor NOTIFY selectionColorChanged)
73 Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor NOTIFY selectedTextColorChanged)
74 Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
75 Q_PROPERTY(HAlignment horizontalAlignment READ hAlign WRITE setHAlign RESET resetHAlign NOTIFY horizontalAlignmentChanged)
76 Q_PROPERTY(HAlignment effectiveHorizontalAlignment READ effectiveHAlign NOTIFY effectiveHorizontalAlignmentChanged REVISION 1)
77 Q_PROPERTY(VAlignment verticalAlignment READ vAlign WRITE setVAlign NOTIFY verticalAlignmentChanged)
78 Q_PROPERTY(WrapMode wrapMode READ wrapMode WRITE setWrapMode NOTIFY wrapModeChanged)
79 Q_PROPERTY(int lineCount READ lineCount NOTIFY lineCountChanged REVISION 1)
80 Q_PROPERTY(qreal paintedWidth READ paintedWidth NOTIFY paintedSizeChanged)
81 Q_PROPERTY(qreal paintedHeight READ paintedHeight NOTIFY paintedSizeChanged)
82 Q_PROPERTY(TextFormat textFormat READ textFormat WRITE setTextFormat NOTIFY textFormatChanged)
83 Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly NOTIFY readOnlyChanged)
84 Q_PROPERTY(bool cursorVisible READ isCursorVisible WRITE setCursorVisible NOTIFY cursorVisibleChanged)
85 Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition NOTIFY cursorPositionChanged)
86 Q_PROPERTY(QRect cursorRectangle READ cursorRectangle NOTIFY cursorRectangleChanged)
87 Q_PROPERTY(QDeclarativeComponent* cursorDelegate READ cursorDelegate WRITE setCursorDelegate NOTIFY cursorDelegateChanged)
88 Q_PROPERTY(int selectionStart READ selectionStart NOTIFY selectionStartChanged)
89 Q_PROPERTY(int selectionEnd READ selectionEnd NOTIFY selectionEndChanged)
90 Q_PROPERTY(QString selectedText READ selectedText NOTIFY selectionChanged)
91 Q_PROPERTY(bool activeFocusOnPress READ focusOnPress WRITE setFocusOnPress NOTIFY activeFocusOnPressChanged)
92 Q_PROPERTY(bool persistentSelection READ persistentSelection WRITE setPersistentSelection NOTIFY persistentSelectionChanged)
93 Q_PROPERTY(qreal textMargin READ textMargin WRITE setTextMargin NOTIFY textMarginChanged)
94 Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints WRITE setInputMethodHints)
95 Q_PROPERTY(bool selectByMouse READ selectByMouse WRITE setSelectByMouse NOTIFY selectByMouseChanged)
96 Q_PROPERTY(SelectionMode mouseSelectionMode READ mouseSelectionMode WRITE setMouseSelectionMode NOTIFY mouseSelectionModeChanged REVISION 1)
97 Q_PROPERTY(bool canPaste READ canPaste NOTIFY canPasteChanged REVISION 1)
98 Q_PROPERTY(bool inputMethodComposing READ isInputMethodComposing NOTIFY inputMethodComposingChanged REVISION 1)
101 QDeclarative1TextEdit(QDeclarativeItem *parent=0);
104 AlignLeft = Qt::AlignLeft,
105 AlignRight = Qt::AlignRight,
106 AlignHCenter = Qt::AlignHCenter,
107 AlignJustify = Qt::AlignJustify // ### VERSIONING: Only in QtQuick 1.1
111 AlignTop = Qt::AlignTop,
112 AlignBottom = Qt::AlignBottom,
113 AlignVCenter = Qt::AlignVCenter
117 PlainText = Qt::PlainText,
118 RichText = Qt::RichText,
119 AutoText = Qt::AutoText
122 enum WrapMode { NoWrap = QTextOption::NoWrap,
123 WordWrap = QTextOption::WordWrap,
124 WrapAnywhere = QTextOption::WrapAnywhere,
125 WrapAtWordBoundaryOrAnywhere = QTextOption::WrapAtWordBoundaryOrAnywhere, // COMPAT
126 Wrap = QTextOption::WrapAtWordBoundaryOrAnywhere
134 Q_INVOKABLE void openSoftwareInputPanel();
135 Q_INVOKABLE void closeSoftwareInputPanel();
137 QString text() const;
138 void setText(const QString &);
140 TextFormat textFormat() const;
141 void setTextFormat(TextFormat format);
144 void setFont(const QFont &font);
146 QColor color() const;
147 void setColor(const QColor &c);
149 QColor selectionColor() const;
150 void setSelectionColor(const QColor &c);
152 QColor selectedTextColor() const;
153 void setSelectedTextColor(const QColor &c);
155 HAlignment hAlign() const;
156 void setHAlign(HAlignment align);
158 HAlignment effectiveHAlign() const;
160 VAlignment vAlign() const;
161 void setVAlign(VAlignment align);
163 WrapMode wrapMode() const;
164 void setWrapMode(WrapMode w);
166 int lineCount() const;
168 bool isCursorVisible() const;
169 void setCursorVisible(bool on);
171 int cursorPosition() const;
172 void setCursorPosition(int pos);
174 QDeclarativeComponent* cursorDelegate() const;
175 void setCursorDelegate(QDeclarativeComponent*);
177 int selectionStart() const;
178 int selectionEnd() const;
180 QString selectedText() const;
182 bool focusOnPress() const;
183 void setFocusOnPress(bool on);
185 bool persistentSelection() const;
186 void setPersistentSelection(bool on);
188 qreal textMargin() const;
189 void setTextMargin(qreal margin);
191 bool selectByMouse() const;
192 void setSelectByMouse(bool);
194 SelectionMode mouseSelectionMode() const;
195 void setMouseSelectionMode(SelectionMode mode);
197 bool canPaste() const;
199 virtual void componentComplete();
202 void setReadOnly(bool);
203 bool isReadOnly() const;
205 void setTextInteractionFlags(Qt::TextInteractionFlags flags);
206 Qt::TextInteractionFlags textInteractionFlags() const;
208 QRect cursorRectangle() const;
210 QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
212 qreal paintedWidth() const;
213 qreal paintedHeight() const;
215 Q_INVOKABLE QRectF positionToRectangle(int) const;
216 Q_INVOKABLE int positionAt(int x, int y) const;
217 Q_INVOKABLE void moveCursorSelection(int pos);
218 Q_INVOKABLE Q_REVISION(1) void moveCursorSelection(int pos, SelectionMode mode);
220 QRectF boundingRect() const;
222 bool isInputMethodComposing() const;
225 void textChanged(const QString &);
226 void paintedSizeChanged();
227 void cursorPositionChanged();
228 void cursorRectangleChanged();
229 void selectionStartChanged();
230 void selectionEndChanged();
231 void selectionChanged();
232 void colorChanged(const QColor &color);
233 void selectionColorChanged(const QColor &color);
234 void selectedTextColorChanged(const QColor &color);
235 void fontChanged(const QFont &font);
236 void horizontalAlignmentChanged(HAlignment alignment);
237 void verticalAlignmentChanged(VAlignment alignment);
238 void wrapModeChanged();
239 void lineCountChanged();
240 void textFormatChanged(TextFormat textFormat);
241 void readOnlyChanged(bool isReadOnly);
242 void cursorVisibleChanged(bool isCursorVisible);
243 void cursorDelegateChanged();
244 void activeFocusOnPressChanged(bool activeFocusOnPressed);
245 void persistentSelectionChanged(bool isPersistentSelection);
246 void textMarginChanged(qreal textMargin);
247 void selectByMouseChanged(bool selectByMouse);
248 Q_REVISION(1) void mouseSelectionModeChanged(SelectionMode mode);
249 Q_REVISION(1) void linkActivated(const QString &link);
250 Q_REVISION(1) void canPasteChanged();
251 Q_REVISION(1) void inputMethodComposingChanged();
252 Q_REVISION(1) void effectiveHorizontalAlignmentChanged();
257 void select(int start, int end);
258 Q_REVISION(1) void deselect();
259 Q_REVISION(1) bool isRightToLeft(int start, int end);
260 #ifndef QT_NO_CLIPBOARD
267 void updateImgCache(const QRectF &rect);
268 void q_textChanged();
269 void updateSelectionMarkers();
270 void moveCursorDelegate();
271 void loadCursorDelegate();
272 void q_canPasteChanged();
276 void updateTotalLines();
279 virtual void geometryChanged(const QRectF &newGeometry,
280 const QRectF &oldGeometry);
282 bool event(QEvent *);
283 void keyPressEvent(QKeyEvent *);
284 void keyReleaseEvent(QKeyEvent *);
285 void focusInEvent(QFocusEvent *event);
288 void mousePressEvent(QGraphicsSceneMouseEvent *event);
289 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
290 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
291 void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
293 void inputMethodEvent(QInputMethodEvent *e);
295 void drawContents(QPainter *, const QRect &);
297 Q_DISABLE_COPY(QDeclarative1TextEdit)
298 Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarative1TextEdit)
303 QML_DECLARE_TYPE(QDeclarative1TextEdit)