|
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 #ifndef HBABSTRACTEDIT_H |
|
27 #define HBABSTRACTEDIT_H |
|
28 |
|
29 #include <hbglobal.h> |
|
30 #include <hbnamespace.h> |
|
31 #include <hbwidget.h> |
|
32 #include <hbsmileytheme.h> |
|
33 #include <hbformatdialog.h> |
|
34 |
|
35 #include <QTextDocument> |
|
36 #include <QTextCursor> |
|
37 #include <QAbstractTextDocumentLayout> |
|
38 |
|
39 class HbEditItem; |
|
40 class HbAbstractEditPrivate; |
|
41 class HbScrollArea; |
|
42 class HbValidator; |
|
43 class HbMenu; |
|
44 |
|
45 class HB_WIDGETS_EXPORT HbAbstractEdit: public HbWidget { |
|
46 |
|
47 Q_OBJECT |
|
48 |
|
49 Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly) |
|
50 Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition) |
|
51 Q_PROPERTY(bool acceptableInput READ hasAcceptableInput) |
|
52 Q_PROPERTY(Qt::Alignment alignment WRITE setAlignment READ alignment) |
|
53 Q_PROPERTY(bool smileysEnabled READ isSmileysEnabled WRITE setSmileysEnabled) |
|
54 Q_PROPERTY(Hb::TextCursorVisibility cursorVisibility READ cursorVisibility WRITE setCursorVisibility) |
|
55 Q_PROPERTY(Hb::TextContextMenuFlags contextMenuFlags |
|
56 READ contextMenuFlags |
|
57 WRITE setContextMenuFlags) |
|
58 |
|
59 public: |
|
60 virtual ~HbAbstractEdit(); |
|
61 |
|
62 bool isReadOnly() const; |
|
63 void setReadOnly(bool value); |
|
64 |
|
65 int cursorPosition() const; |
|
66 |
|
67 Hb::TextCursorVisibility cursorVisibility() const; |
|
68 void setCursorVisibility(Hb::TextCursorVisibility value); |
|
69 |
|
70 HbValidator *validator() const; |
|
71 void setValidator(HbValidator *validator); |
|
72 bool hasAcceptableInput() const; |
|
73 |
|
74 QGraphicsItem *primitive(HbStyle::Primitive primitive) const; |
|
75 |
|
76 bool event(QEvent* event); |
|
77 bool eventFilter(QObject *obj, QEvent *event); |
|
78 |
|
79 enum { Type = Hb::ItemType_AbstractEdit }; |
|
80 int type() const; |
|
81 |
|
82 void setAlignment(Qt::Alignment alignment); |
|
83 Qt::Alignment alignment() const; |
|
84 |
|
85 Hb::TextContextMenuFlags contextMenuFlags() const; |
|
86 void setContextMenuFlags(Hb::TextContextMenuFlags flags); |
|
87 void setContextMenuFlag(Hb::TextContextMenuFlag flag); |
|
88 void clearContextMenuFlag(Hb::TextContextMenuFlag flag); |
|
89 |
|
90 QString anchorAt(const QPointF &pos) const; |
|
91 QString anchorAt(int pos) const; |
|
92 |
|
93 void setSmileyTheme(const HbSmileyTheme& theme); |
|
94 HbSmileyTheme smileyTheme() const; |
|
95 HbSmileyTheme defaultSmileyTheme() const; |
|
96 void resetSmileyTheme(); |
|
97 |
|
98 bool isSmileysEnabled() const; |
|
99 void setSmileysEnabled(bool enabled); |
|
100 |
|
101 void setFormatDialog(HbFormatDialogPointer dialog); |
|
102 |
|
103 QChar characterAt(int pos) const; |
|
104 |
|
105 signals: |
|
106 void contentsChanged(); |
|
107 void cursorPositionChanged(int oldPos, int newPos); |
|
108 void selectionChanged(const QTextCursor &oldCursor, const QTextCursor& newCursor); |
|
109 void aboutToShowContextMenu(HbMenu *contextMenu, const QPointF &pos); |
|
110 |
|
111 public slots: |
|
112 void updatePrimitives(); |
|
113 virtual void setCursorPosition(int pos, QTextCursor::MoveMode mode = QTextCursor::MoveAnchor); |
|
114 void cut(); |
|
115 void copy(); |
|
116 void paste(); |
|
117 void selectClickedWord(); |
|
118 void selectAll(); |
|
119 void deselect(); |
|
120 void format(); |
|
121 |
|
122 protected: |
|
123 explicit HbAbstractEdit(QGraphicsItem *parent = 0); |
|
124 HbAbstractEdit(HbAbstractEditPrivate &dd, QGraphicsItem *parent); |
|
125 |
|
126 void drawContents(QPainter *painter, const QStyleOptionGraphicsItem &option); |
|
127 |
|
128 void resizeEvent(QGraphicsSceneResizeEvent *event); |
|
129 |
|
130 void inputMethodEvent(QInputMethodEvent *event); |
|
131 QVariant inputMethodQuery(Qt::InputMethodQuery query) const; |
|
132 |
|
133 void keyPressEvent(QKeyEvent *event); |
|
134 void keyReleaseEvent(QKeyEvent *event); |
|
135 |
|
136 void mousePressEvent(QGraphicsSceneMouseEvent *event); |
|
137 void mouseMoveEvent(QGraphicsSceneMouseEvent *event); |
|
138 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); |
|
139 |
|
140 void focusInEvent(QFocusEvent *event); |
|
141 void focusOutEvent(QFocusEvent *event); |
|
142 |
|
143 void changeEvent(QEvent *event); |
|
144 void hideEvent(QHideEvent *event); |
|
145 |
|
146 void setDocument(QTextDocument *document); |
|
147 QTextDocument *document() const; |
|
148 |
|
149 void setTextCursor(const QTextCursor &cursor); |
|
150 QTextCursor textCursor() const; |
|
151 |
|
152 QString toPlainText() const; |
|
153 QString toHtml() const; |
|
154 |
|
155 void moveCursor(QTextCursor::MoveOperation op, QTextCursor::MoveMode mode = QTextCursor::MoveAnchor); |
|
156 |
|
157 QRectF blockBoundingRect(const QTextBlock &block) const; |
|
158 |
|
159 bool isScrollable() const; |
|
160 void setScrollable(bool value); |
|
161 |
|
162 HbScrollArea *scrollArea() const; |
|
163 |
|
164 virtual HbMenu* createContextMenu(); |
|
165 void showContextMenu(QPointF position = QPointF(0,0)); |
|
166 virtual QMimeData *createMimeDataFromSelection() const; |
|
167 virtual bool canInsertFromMimeData(const QMimeData *source) const; |
|
168 virtual void insertFromMimeData(const QMimeData *source); |
|
169 |
|
170 QRectF rectForPosition(int position, QTextLine::Edge edge = QTextLine::Leading) const; |
|
171 |
|
172 void updateGeometry(); |
|
173 |
|
174 void polish( HbStyleParameters& params ); |
|
175 QVariant itemChange(GraphicsItemChange change, const QVariant &value); |
|
176 |
|
177 protected slots: |
|
178 void setPlainText(const QString &text); |
|
179 void setHtml(const QString &text); |
|
180 |
|
181 virtual void documentLayoutChanged(); |
|
182 virtual void documentSizeChanged(const QSizeF &size); |
|
183 virtual void blockCountChanged(int newBlockCount); |
|
184 |
|
185 void timerEvent(QTimerEvent *e); |
|
186 |
|
187 private: |
|
188 Q_DISABLE_COPY(HbAbstractEdit) |
|
189 Q_DECLARE_PRIVATE_D(d_ptr, HbAbstractEdit) |
|
190 |
|
191 Q_PRIVATE_SLOT(d_func(), void _q_updateRequest(QRectF)) |
|
192 Q_PRIVATE_SLOT(d_func(), void _q_updateBlock(QTextBlock)) |
|
193 Q_PRIVATE_SLOT(d_func(), void _q_contentsChanged()) |
|
194 Q_PRIVATE_SLOT(d_func(), void _q_contentsChange(int, int, int)) |
|
195 Q_PRIVATE_SLOT(d_func(), void _q_selectionChanged()) |
|
196 |
|
197 friend class HbEditItem; |
|
198 friend class HbEditorFocusObject; |
|
199 friend class HbSelectionControl; |
|
200 friend class HbSelectionControlPrivate; |
|
201 friend class HbFormatDialog; |
|
202 friend class HbFormatDialogPrivate; |
|
203 }; |
|
204 |
|
205 #endif // HBABSTRACTEDIT_H |