|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (developer.feedback@nokia.com) |
|
6 ** |
|
7 ** This file is part of the HbWidgets module of the UI Extensions for Mobile. |
|
8 ** |
|
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 file. |
|
13 ** Please review the following information to ensure the GNU Lesser General |
|
14 ** 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 ** If you have questions regarding the use of this file, please contact |
|
22 ** Nokia at developer.feedback@nokia.com. |
|
23 ** |
|
24 ****************************************************************************/ |
|
25 |
|
26 // |
|
27 // W A R N I N G |
|
28 // ------------- |
|
29 // |
|
30 // This file is not part of the Hb API. It exists purely as an |
|
31 // implementation detail. This file may change from version to |
|
32 // version without notice, or even be removed. |
|
33 // |
|
34 // We mean it. |
|
35 // |
|
36 |
|
37 #ifndef HBABSTRACTEDIT_P_H |
|
38 #define HBABSTRACTEDIT_P_H |
|
39 |
|
40 //#define HB_DEBUG_EDITOR_DRAW_RECTS |
|
41 //#define HB_DEBUG_EDITOR_HANDLES |
|
42 |
|
43 #include "hbglobal.h" |
|
44 #include "hbstyle.h" |
|
45 #include "hbwidget_p.h" |
|
46 #include "hbscrollarea.h" |
|
47 #include "hbscrollarea_p.h" |
|
48 #include "hbabstractedit.h" |
|
49 #include "hbvalidator.h" |
|
50 #include "hbformatdialog.h" |
|
51 |
|
52 #include <QEvent> |
|
53 #include <QTextCursor> |
|
54 #include <QBasicTimer> |
|
55 #include <QTextDocumentFragment> |
|
56 #include <QPainter> |
|
57 #include <QDebug> |
|
58 |
|
59 class QEvent; |
|
60 class QGraphicsSceneMouseEvent; |
|
61 class QTextDocument; |
|
62 class HbWidget; |
|
63 class HbScrollArea; |
|
64 class HbValidator; |
|
65 class HbSelectionControl; |
|
66 class HbSmileyEngine; |
|
67 class HbFormatDialog; |
|
68 |
|
69 class HbEditScrollArea: public HbScrollArea |
|
70 { |
|
71 Q_OBJECT |
|
72 |
|
73 public: |
|
74 explicit HbEditScrollArea(HbAbstractEdit* edit, QGraphicsItem* parent = 0); |
|
75 virtual ~HbEditScrollArea() {}; |
|
76 |
|
77 void updateScrollMetrics(); |
|
78 void resizeEvent(QGraphicsSceneResizeEvent *event); |
|
79 |
|
80 #ifdef HB_DEBUG_EDITOR_DRAW_RECTS |
|
81 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); |
|
82 #endif//HB_DEBUG_EDITOR_DRAW_RECTS |
|
83 |
|
84 signals: |
|
85 void scrollAreaSizeChanged(); |
|
86 |
|
87 public slots: |
|
88 void longPressGesture(const QPointF &point); |
|
89 |
|
90 void upGesture(int value); |
|
91 void downGesture(int value); |
|
92 void leftGesture(int value); |
|
93 void rightGesture(int value); |
|
94 void panGesture(const QPointF &point); |
|
95 |
|
96 private: |
|
97 Q_DECLARE_PRIVATE_D( d_ptr, HbScrollArea ) |
|
98 HbAbstractEdit* mEdit; |
|
99 }; |
|
100 |
|
101 class HbAbstractEditMimeData : public QMimeData |
|
102 { |
|
103 public: |
|
104 inline HbAbstractEditMimeData(const QTextDocumentFragment &aFragment) : fragment(aFragment) {} |
|
105 |
|
106 virtual QStringList formats() const; |
|
107 protected: |
|
108 virtual QVariant retrieveData(const QString &mimeType, QVariant::Type type) const; |
|
109 private: |
|
110 void setup() const; |
|
111 |
|
112 mutable QTextDocumentFragment fragment; |
|
113 }; |
|
114 |
|
115 class HB_AUTOTEST_EXPORT HbAbstractEditPrivate: public HbWidgetPrivate { |
|
116 Q_DECLARE_PUBLIC(HbAbstractEdit) |
|
117 |
|
118 typedef HbValidator::ChangeSource CursorChange; |
|
119 |
|
120 public: |
|
121 HbAbstractEditPrivate (); |
|
122 virtual ~HbAbstractEditPrivate (); |
|
123 |
|
124 void init(); |
|
125 virtual void updatePaletteFromTheme(); |
|
126 |
|
127 void acceptKeyPressEvent(QKeyEvent *event); |
|
128 public: |
|
129 void removeCurrentDocument(); |
|
130 void connectToNewDocument(QTextDocument *newDoc); |
|
131 void setContent(Qt::TextFormat format = Qt::RichText, const QString &text = QString()); |
|
132 void ensurePositionVisible(int position); |
|
133 void ensureCursorVisible(); |
|
134 bool setFocusToAnchor(const QTextCursor &newCursor); |
|
135 bool setFocusToNextOrPreviousAnchor(bool next); |
|
136 bool findNextPrevAnchor(const QTextCursor& from, bool next, QTextCursor& newAnchor); |
|
137 void setCursorPosition(int pos, QTextCursor::MoveMode mode = QTextCursor::MoveAnchor); |
|
138 bool cursorMoveKeyEvent(QKeyEvent *e); |
|
139 void repaintOldAndNewSelection(const QTextCursor &oldSelection); |
|
140 void updateCurrentCharFormat(); |
|
141 QRectF cursorRectPlusUnicodeDirectionMarkers(int position) const; |
|
142 void setBlinkingCursorEnabled(bool enable); |
|
143 void repaintCursor(); |
|
144 void setTextInteractionFlags(Qt::TextInteractionFlags flags); |
|
145 void cursorChanged(CursorChange origin); |
|
146 void selectionChanged(bool forceEmitSelectionChanged = false); |
|
147 QAbstractTextDocumentLayout::PaintContext getPaintContext() const; |
|
148 int hitTest(const QPointF &point, Qt::HitTestAccuracy accuracy) const; |
|
149 QRectF cursorRect(const QTextCursor &cursor) const; |
|
150 QRectF cursorRect() const; |
|
151 QRectF selectionRect(const QTextCursor &cursor) const; |
|
152 QRectF selectionRect() const; |
|
153 QRectF rectForPositionInCanvasCoords(int position, QTextLine::Edge edge) const; |
|
154 QValidator::State validateContent(int position, int charsRemoved, int charsAdded); |
|
155 void initValidator(); |
|
156 bool undo(); |
|
157 virtual bool canPaste() const; |
|
158 virtual bool canCopy() const; |
|
159 virtual void prepDocForPaste(); |
|
160 bool canFormat() const; |
|
161 virtual bool isCursorVisible() const; |
|
162 |
|
163 void longPressGesture(const QPointF &point); |
|
164 void gestureReceived(); |
|
165 |
|
166 void sendInputPanelEvent(QEvent::Type type); |
|
167 void openInputPanel(); |
|
168 void closeInputPanel(); |
|
169 void minimizeInputPanel(); |
|
170 |
|
171 int contentLength() const; |
|
172 bool hasAcceptableInput() const; |
|
173 void sendMouseEventToInputContext(const QGraphicsSceneMouseEvent *e) const; |
|
174 virtual void updateEditingSize(); |
|
175 void hideSelectionHandles(); |
|
176 void drawSelectionEdges(QPainter *painter, QAbstractTextDocumentLayout::PaintContext); |
|
177 HbSmileyEngine* smileyEngineInstance() const; |
|
178 |
|
179 virtual void drawContentBackground(QPainter *painter, |
|
180 const QStyleOptionGraphicsItem &option) const; |
|
181 |
|
182 void _q_updateRequest(QRectF rect); |
|
183 void _q_updateBlock(QTextBlock block); |
|
184 void _q_contentsChanged(); |
|
185 void _q_contentsChange(int position, int charsRemoved, int charsAdded); |
|
186 void _q_selectionChanged(); |
|
187 static Qt::Alignment alignmentFromString(const QString &text); |
|
188 |
|
189 void validateAndCorrect(); |
|
190 |
|
191 QTextDocument *doc; |
|
192 int previousCursorAnchor; |
|
193 int previousCursorPosition; |
|
194 QTextCursor cursor; |
|
195 QTextCursor selectionCursor; |
|
196 |
|
197 HbValidator* validator; |
|
198 bool imEditInProgress; |
|
199 int imPosition; |
|
200 int imAdded; |
|
201 int imRemoved; |
|
202 |
|
203 Qt::TextInteractionFlags interactionFlags; |
|
204 QPointF mousePressPos; |
|
205 bool cursorOn; |
|
206 |
|
207 QTextCharFormat lastCharFormat; |
|
208 QBasicTimer cursorBlinkTimer; |
|
209 |
|
210 int preeditCursor; |
|
211 bool preeditCursorVisible; // used to hide the cursor in the preedit area |
|
212 bool apiCursorVisible; |
|
213 |
|
214 HbWidget *canvas; |
|
215 HbEditScrollArea *scrollArea; |
|
216 |
|
217 bool scrollable; |
|
218 bool hadSelectionOnMousePress; |
|
219 |
|
220 HbSelectionControl *selectionControl; |
|
221 |
|
222 bool acceptSignalContentsChange; |
|
223 bool acceptSignalContentsChanged; |
|
224 |
|
225 int validRevision; |
|
226 |
|
227 bool wasGesture; |
|
228 |
|
229 Hb::TextContextMenuFlags contextMenuShownOn; |
|
230 bool smileysEnabled; |
|
231 mutable HbSmileyEngine *smileyEngine; |
|
232 |
|
233 HbFormatDialogPointer formatDialog; |
|
234 QTextCursor nextCharCursor; |
|
235 |
|
236 private: |
|
237 static HbAbstractEditPrivate *d_ptr(HbAbstractEdit *edit) { |
|
238 Q_ASSERT(edit); |
|
239 return edit->d_func(); |
|
240 } |
|
241 friend class HbEditScrollArea; |
|
242 friend class HbFormatDialog; |
|
243 friend class HbFormatDialogPrivate; |
|
244 // To be able to unit test private features |
|
245 friend class TestHbAbstractEdit; |
|
246 friend class TestHbLineEdit; |
|
247 friend class HbSelectionControl; |
|
248 friend class HbSelectionControlPrivate; |
|
249 }; |
|
250 |
|
251 #endif // HBABSTRACTEDIT_P_H |