Remove "All rights reserved" line from license headers.
[profile/ivi/qtdeclarative.git] / src / qtquick1 / graphicsitems / qdeclarativetextedit_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
7 **
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.
16 **
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.
20 **
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.
28 **
29 ** Other Usage
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.
32 **
33 **
34 **
35 **
36 **
37 **
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/qdeclarativeimplicitsizeitem_p.h"
47
48 #include <QtGui/qtextdocument.h>
49 #include <QtGui/qtextoption.h>
50 #include <QtGui/qtextcursor.h>
51 #include <QtGui/qtextformat.h>
52
53 QT_BEGIN_HEADER
54
55 QT_BEGIN_NAMESPACE
56
57
58
59 class QDeclarative1TextEditPrivate;
60 class Q_AUTOTEST_EXPORT QDeclarative1TextEdit : public QDeclarative1ImplicitSizePaintedItem
61 {
62     Q_OBJECT
63     Q_ENUMS(VAlignment)
64     Q_ENUMS(HAlignment)
65     Q_ENUMS(TextFormat)
66     Q_ENUMS(WrapMode)
67     Q_ENUMS(SelectionMode)
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 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)
98
99 public:
100     QDeclarative1TextEdit(QDeclarativeItem *parent=0);
101
102     enum HAlignment {
103         AlignLeft = Qt::AlignLeft,
104         AlignRight = Qt::AlignRight,
105         AlignHCenter = Qt::AlignHCenter,
106         AlignJustify = Qt::AlignJustify // ### VERSIONING: Only in QtQuick 1.1
107     };
108
109     enum VAlignment {
110         AlignTop = Qt::AlignTop,
111         AlignBottom = Qt::AlignBottom,
112         AlignVCenter = Qt::AlignVCenter
113     };
114
115     enum TextFormat {
116         PlainText = Qt::PlainText,
117         RichText = Qt::RichText,
118         AutoText = Qt::AutoText
119     };
120
121     enum WrapMode { NoWrap = QTextOption::NoWrap,
122                     WordWrap = QTextOption::WordWrap,
123                     WrapAnywhere = QTextOption::WrapAnywhere,
124                     WrapAtWordBoundaryOrAnywhere = QTextOption::WrapAtWordBoundaryOrAnywhere, // COMPAT
125                     Wrap = QTextOption::WrapAtWordBoundaryOrAnywhere
126                   };
127
128     enum SelectionMode {
129         SelectCharacters,
130         SelectWords
131     };
132
133     Q_INVOKABLE void openSoftwareInputPanel();
134     Q_INVOKABLE void closeSoftwareInputPanel();
135
136     QString text() const;
137     void setText(const QString &);
138
139     TextFormat textFormat() const;
140     void setTextFormat(TextFormat format);
141
142     QFont font() const;
143     void setFont(const QFont &font);
144
145     QColor color() const;
146     void setColor(const QColor &c);
147
148     QColor selectionColor() const;
149     void setSelectionColor(const QColor &c);
150
151     QColor selectedTextColor() const;
152     void setSelectedTextColor(const QColor &c);
153
154     HAlignment hAlign() const;
155     void setHAlign(HAlignment align);
156     void resetHAlign();
157     HAlignment effectiveHAlign() const;
158
159     VAlignment vAlign() const;
160     void setVAlign(VAlignment align);
161
162     WrapMode wrapMode() const;
163     void setWrapMode(WrapMode w);
164
165     int lineCount() const;
166
167     bool isCursorVisible() const;
168     void setCursorVisible(bool on);
169
170     int cursorPosition() const;
171     void setCursorPosition(int pos);
172
173     QDeclarativeComponent* cursorDelegate() const;
174     void setCursorDelegate(QDeclarativeComponent*);
175
176     int selectionStart() const;
177     int selectionEnd() const;
178
179     QString selectedText() const;
180
181     bool focusOnPress() const;
182     void setFocusOnPress(bool on);
183
184     bool persistentSelection() const;
185     void setPersistentSelection(bool on);
186
187     qreal textMargin() const;
188     void setTextMargin(qreal margin);
189
190     bool selectByMouse() const;
191     void setSelectByMouse(bool);
192
193     SelectionMode mouseSelectionMode() const;
194     void setMouseSelectionMode(SelectionMode mode);
195
196     bool canPaste() const;
197
198     virtual void componentComplete();
199
200     /* FROM EDIT */
201     void setReadOnly(bool);
202     bool isReadOnly() const;
203
204     void setTextInteractionFlags(Qt::TextInteractionFlags flags);
205     Qt::TextInteractionFlags textInteractionFlags() const;
206
207     QRect cursorRectangle() const;
208
209     QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
210
211     qreal paintedWidth() const;
212     qreal paintedHeight() const;
213
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);
218
219     QRectF boundingRect() const;
220
221     bool isInputMethodComposing() const;
222
223 Q_SIGNALS:
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();
252
253 public Q_SLOTS:
254     void selectAll();
255     void selectWord();
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
260     void cut();
261     void copy();
262     void paste();
263 #endif
264
265 private Q_SLOTS:
266     void updateImgCache(const QRectF &rect);
267     void q_textChanged();
268     void updateSelectionMarkers();
269     void moveCursorDelegate();
270     void loadCursorDelegate();
271     void q_canPasteChanged();
272
273 private:
274     void updateSize();
275     void updateTotalLines();
276
277 protected:
278     virtual void geometryChanged(const QRectF &newGeometry, 
279                                  const QRectF &oldGeometry);
280
281     bool event(QEvent *);
282     void keyPressEvent(QKeyEvent *);
283     void keyReleaseEvent(QKeyEvent *);
284     void focusInEvent(QFocusEvent *event);
285
286     // mouse filter?
287     void mousePressEvent(QGraphicsSceneMouseEvent *event);
288     void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
289     void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
290     void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
291
292     void inputMethodEvent(QInputMethodEvent *e);
293
294     void drawContents(QPainter *, const QRect &);
295 private:
296     Q_DISABLE_COPY(QDeclarative1TextEdit)
297     Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarative1TextEdit)
298 };
299
300 QT_END_NAMESPACE
301
302 QML_DECLARE_TYPE(QDeclarative1TextEdit)
303
304 QT_END_HEADER
305
306 #endif