source: trunk/src/declarative/graphicsitems/qdeclarativetextedit_p.h

Last change on this file was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 9.6 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 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** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
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** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at qt-info@nokia.com.
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
53QT_BEGIN_HEADER
54
55QT_BEGIN_NAMESPACE
56
57QT_MODULE(Declarative)
58
59
60class QDeclarativeTextEditPrivate;
61class Q_AUTOTEST_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(qreal paintedWidth READ paintedWidth NOTIFY paintedSizeChanged)
78 Q_PROPERTY(qreal paintedHeight READ paintedHeight NOTIFY paintedSizeChanged)
79 Q_PROPERTY(TextFormat textFormat READ textFormat WRITE setTextFormat NOTIFY textFormatChanged)
80 Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly NOTIFY readOnlyChanged)
81 Q_PROPERTY(bool cursorVisible READ isCursorVisible WRITE setCursorVisible NOTIFY cursorVisibleChanged)
82 Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition NOTIFY cursorPositionChanged)
83 Q_PROPERTY(QRect cursorRectangle READ cursorRectangle NOTIFY cursorRectangleChanged)
84 Q_PROPERTY(QDeclarativeComponent* cursorDelegate READ cursorDelegate WRITE setCursorDelegate NOTIFY cursorDelegateChanged)
85 Q_PROPERTY(int selectionStart READ selectionStart NOTIFY selectionStartChanged)
86 Q_PROPERTY(int selectionEnd READ selectionEnd NOTIFY selectionEndChanged)
87 Q_PROPERTY(QString selectedText READ selectedText NOTIFY selectionChanged)
88 Q_PROPERTY(bool activeFocusOnPress READ focusOnPress WRITE setFocusOnPress NOTIFY activeFocusOnPressChanged)
89 Q_PROPERTY(bool persistentSelection READ persistentSelection WRITE setPersistentSelection NOTIFY persistentSelectionChanged)
90 Q_PROPERTY(qreal textMargin READ textMargin WRITE setTextMargin NOTIFY textMarginChanged)
91 Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints WRITE setInputMethodHints)
92 Q_PROPERTY(bool selectByMouse READ selectByMouse WRITE setSelectByMouse NOTIFY selectByMouseChanged)
93
94public:
95 QDeclarativeTextEdit(QDeclarativeItem *parent=0);
96
97 enum HAlignment {
98 AlignLeft = Qt::AlignLeft,
99 AlignRight = Qt::AlignRight,
100 AlignHCenter = Qt::AlignHCenter
101 };
102
103 enum VAlignment {
104 AlignTop = Qt::AlignTop,
105 AlignBottom = Qt::AlignBottom,
106 AlignVCenter = Qt::AlignVCenter
107 };
108
109 enum TextFormat {
110 PlainText = Qt::PlainText,
111 RichText = Qt::RichText,
112 AutoText = Qt::AutoText
113 };
114
115 enum WrapMode { NoWrap = QTextOption::NoWrap,
116 WordWrap = QTextOption::WordWrap,
117 WrapAnywhere = QTextOption::WrapAnywhere,
118 WrapAtWordBoundaryOrAnywhere = QTextOption::WrapAtWordBoundaryOrAnywhere, // COMPAT
119 Wrap = QTextOption::WrapAtWordBoundaryOrAnywhere
120 };
121
122 Q_INVOKABLE void openSoftwareInputPanel();
123 Q_INVOKABLE void closeSoftwareInputPanel();
124
125 QString text() const;
126 void setText(const QString &);
127
128 TextFormat textFormat() const;
129 void setTextFormat(TextFormat format);
130
131 QFont font() const;
132 void setFont(const QFont &font);
133
134 QColor color() const;
135 void setColor(const QColor &c);
136
137 QColor selectionColor() const;
138 void setSelectionColor(const QColor &c);
139
140 QColor selectedTextColor() const;
141 void setSelectedTextColor(const QColor &c);
142
143 HAlignment hAlign() const;
144 void setHAlign(HAlignment align);
145
146 VAlignment vAlign() const;
147 void setVAlign(VAlignment align);
148
149 WrapMode wrapMode() const;
150 void setWrapMode(WrapMode w);
151
152 bool isCursorVisible() const;
153 void setCursorVisible(bool on);
154
155 int cursorPosition() const;
156 void setCursorPosition(int pos);
157
158 QDeclarativeComponent* cursorDelegate() const;
159 void setCursorDelegate(QDeclarativeComponent*);
160
161 int selectionStart() const;
162 int selectionEnd() const;
163
164 QString selectedText() const;
165
166 bool focusOnPress() const;
167 void setFocusOnPress(bool on);
168
169 bool persistentSelection() const;
170 void setPersistentSelection(bool on);
171
172 qreal textMargin() const;
173 void setTextMargin(qreal margin);
174
175 bool selectByMouse() const;
176 void setSelectByMouse(bool);
177
178 virtual void componentComplete();
179
180 /* FROM EDIT */
181 void setReadOnly(bool);
182 bool isReadOnly() const;
183
184 void setTextInteractionFlags(Qt::TextInteractionFlags flags);
185 Qt::TextInteractionFlags textInteractionFlags() const;
186
187 QRect cursorRectangle() const;
188
189 QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
190
191 qreal paintedWidth() const;
192 qreal paintedHeight() const;
193
194 Q_INVOKABLE QRectF positionToRectangle(int) const;
195 Q_INVOKABLE int positionAt(int x, int y) const;
196 Q_INVOKABLE void moveCursorSelection(int pos);
197
198 QRectF boundingRect() const;
199
200Q_SIGNALS:
201 void textChanged(const QString &);
202 void paintedSizeChanged();
203 void cursorPositionChanged();
204 void cursorRectangleChanged();
205 void selectionStartChanged();
206 void selectionEndChanged();
207 void selectionChanged();
208 void colorChanged(const QColor &color);
209 void selectionColorChanged(const QColor &color);
210 void selectedTextColorChanged(const QColor &color);
211 void fontChanged(const QFont &font);
212 void horizontalAlignmentChanged(HAlignment alignment);
213 void verticalAlignmentChanged(VAlignment alignment);
214 void wrapModeChanged();
215 void textFormatChanged(TextFormat textFormat);
216 void readOnlyChanged(bool isReadOnly);
217 void cursorVisibleChanged(bool isCursorVisible);
218 void cursorDelegateChanged();
219 void activeFocusOnPressChanged(bool activeFocusOnPressed);
220 void persistentSelectionChanged(bool isPersistentSelection);
221 void textMarginChanged(qreal textMargin);
222 void selectByMouseChanged(bool selectByMouse);
223
224public Q_SLOTS:
225 void selectAll();
226 void selectWord();
227 void select(int start, int end);
228#ifndef QT_NO_CLIPBOARD
229 void cut();
230 void copy();
231 void paste();
232#endif
233
234private Q_SLOTS:
235 void updateImgCache(const QRectF &rect);
236 void q_textChanged();
237 void updateSelectionMarkers();
238 void moveCursorDelegate();
239 void loadCursorDelegate();
240
241private:
242 void updateSize();
243
244protected:
245 virtual void geometryChanged(const QRectF &newGeometry,
246 const QRectF &oldGeometry);
247
248 bool event(QEvent *);
249 void keyPressEvent(QKeyEvent *);
250 void keyReleaseEvent(QKeyEvent *);
251 void focusInEvent(QFocusEvent *event);
252
253 // mouse filter?
254 void mousePressEvent(QGraphicsSceneMouseEvent *event);
255 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
256 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
257 void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
258
259 void inputMethodEvent(QInputMethodEvent *e);
260
261 void drawContents(QPainter *, const QRect &);
262private:
263 Q_DISABLE_COPY(QDeclarativeTextEdit)
264 Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeTextEdit)
265};
266
267QT_END_NAMESPACE
268
269QML_DECLARE_TYPE(QDeclarativeTextEdit)
270
271QT_END_HEADER
272
273#endif
Note: See TracBrowser for help on using the repository browser.