source: trunk/src/gui/text/qtextcontrol_p.h@ 371

Last change on this file since 371 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 9.3 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** 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 are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QTEXTCONTROL_P_H
43#define QTEXTCONTROL_P_H
44
45//
46// W A R N I N G
47// -------------
48//
49// This file is not part of the Qt API. It exists purely as an
50// implementation detail. This header file may change from version to
51// version without notice, or even be removed.
52//
53// We mean it.
54//
55
56#include <QtGui/qtextdocument.h>
57#include <QtGui/qtextoption.h>
58#include <QtGui/qtextcursor.h>
59#include <QtGui/qtextformat.h>
60#include <QtGui/qtextedit.h>
61#include <QtGui/qmenu.h>
62#include <QtCore/qrect.h>
63#include <QtGui/qabstracttextdocumentlayout.h>
64#include <QtGui/qtextdocumentfragment.h>
65
66#ifdef QT3_SUPPORT
67#include <QtGui/qtextobject.h>
68#include <QtGui/qtextlayout.h>
69#endif
70
71QT_BEGIN_HEADER
72
73QT_BEGIN_NAMESPACE
74
75QT_MODULE(Gui)
76
77class QStyleSheet;
78class QTextDocument;
79class QMenu;
80class QTextControlPrivate;
81class QMimeData;
82class QAbstractScrollArea;
83class QEvent;
84class QTimerEvent;
85
86class Q_GUI_EXPORT QTextControl : public QObject
87{
88 Q_OBJECT
89 Q_DECLARE_PRIVATE(QTextControl)
90#ifndef QT_NO_TEXTHTMLPARSER
91 Q_PROPERTY(QString html READ toHtml WRITE setHtml NOTIFY textChanged USER true)
92#endif
93 Q_PROPERTY(bool overwriteMode READ overwriteMode WRITE setOverwriteMode)
94 Q_PROPERTY(bool acceptRichText READ acceptRichText WRITE setAcceptRichText)
95 Q_PROPERTY(int cursorWidth READ cursorWidth WRITE setCursorWidth)
96 Q_PROPERTY(Qt::TextInteractionFlags textInteractionFlags READ textInteractionFlags WRITE setTextInteractionFlags)
97 Q_PROPERTY(bool openExternalLinks READ openExternalLinks WRITE setOpenExternalLinks)
98public:
99 explicit QTextControl(QObject *parent = 0);
100 explicit QTextControl(const QString &text, QObject *parent = 0);
101 explicit QTextControl(QTextDocument *doc, QObject *parent = 0);
102 virtual ~QTextControl();
103
104 void setDocument(QTextDocument *document);
105 QTextDocument *document() const;
106
107 void setTextCursor(const QTextCursor &cursor);
108 QTextCursor textCursor() const;
109
110 void setTextInteractionFlags(Qt::TextInteractionFlags flags);
111 Qt::TextInteractionFlags textInteractionFlags() const;
112
113 void mergeCurrentCharFormat(const QTextCharFormat &modifier);
114
115 void setCurrentCharFormat(const QTextCharFormat &format);
116 QTextCharFormat currentCharFormat() const;
117
118 bool find(const QString &exp, QTextDocument::FindFlags options = 0);
119
120 inline QString toPlainText() const
121 { return document()->toPlainText(); }
122#ifndef QT_NO_TEXTHTMLPARSER
123 inline QString toHtml() const
124 { return document()->toHtml(); }
125#endif
126
127 virtual void ensureCursorVisible();
128
129 virtual QVariant loadResource(int type, const QUrl &name);
130#ifndef QT_NO_CONTEXTMENU
131 QMenu *createStandardContextMenu(const QPointF &pos, QWidget *parent);
132#endif
133
134 QTextCursor cursorForPosition(const QPointF &pos) const;
135 QRectF cursorRect(const QTextCursor &cursor) const;
136 QRectF cursorRect() const;
137 QRectF selectionRect(const QTextCursor &cursor) const;
138 QRectF selectionRect() const;
139
140 QString anchorAt(const QPointF &pos) const;
141 QPointF anchorPosition(const QString &name) const;
142
143 QString anchorAtCursor() const;
144
145 bool overwriteMode() const;
146 void setOverwriteMode(bool overwrite);
147
148 int cursorWidth() const;
149 void setCursorWidth(int width);
150
151 bool acceptRichText() const;
152 void setAcceptRichText(bool accept);
153
154#ifndef QT_NO_TEXTEDIT
155 void setExtraSelections(const QList<QTextEdit::ExtraSelection> &selections);
156 QList<QTextEdit::ExtraSelection> extraSelections() const;
157#endif
158
159 void setTextWidth(qreal width);
160 qreal textWidth() const;
161 QSizeF size() const;
162
163 void setOpenExternalLinks(bool open);
164 bool openExternalLinks() const;
165
166 void moveCursor(QTextCursor::MoveOperation op, QTextCursor::MoveMode mode = QTextCursor::MoveAnchor);
167
168 bool canPaste() const;
169
170 void setCursorIsFocusIndicator(bool b);
171 bool cursorIsFocusIndicator() const;
172
173#ifndef QT_NO_PRINTER
174 void print(QPrinter *printer) const;
175#endif
176
177 virtual int hitTest(const QPointF &point, Qt::HitTestAccuracy accuracy) const;
178 virtual QRectF blockBoundingRect(const QTextBlock &block) const;
179 QAbstractTextDocumentLayout::PaintContext getPaintContext(QWidget *widget) const;
180
181
182
183public Q_SLOTS:
184 void setPlainText(const QString &text);
185 void setHtml(const QString &text);
186
187#ifndef QT_NO_CLIPBOARD
188 void cut();
189 void copy();
190 void paste();
191#endif
192
193 void undo();
194 void redo();
195
196 void clear();
197 void selectAll();
198
199 void insertPlainText(const QString &text);
200#ifndef QT_NO_TEXTHTMLPARSER
201 void insertHtml(const QString &text);
202#endif
203
204 void append(const QString &text);
205 void appendHtml(const QString &html);
206 void appendPlainText(const QString &text);
207
208 void adjustSize();
209
210Q_SIGNALS:
211 void textChanged();
212 void undoAvailable(bool b);
213 void redoAvailable(bool b);
214 void currentCharFormatChanged(const QTextCharFormat &format);
215 void copyAvailable(bool b);
216 void selectionChanged();
217 void cursorPositionChanged();
218
219 // control signals
220 void updateRequest(const QRectF &rect = QRectF());
221 void documentSizeChanged(const QSizeF &);
222 void blockCountChanged(int newBlockCount);
223 void visibilityRequest(const QRectF &rect);
224 void microFocusChanged();
225 void linkActivated(const QString &link);
226 void linkHovered(const QString &);
227 void modificationChanged(bool m);
228
229public:
230 // control properties
231 QPalette palette() const;
232 void setPalette(const QPalette &pal);
233
234 virtual void processEvent(QEvent *e, const QMatrix &matrix, QWidget *contextWidget = 0);
235 void processEvent(QEvent *e, const QPointF &coordinateOffset = QPointF(), QWidget *contextWidget = 0);
236
237 // control methods
238 void drawContents(QPainter *painter, const QRectF &rect = QRectF(), QWidget *widget = 0);
239
240 void setFocus(bool focus, Qt::FocusReason = Qt::OtherFocusReason);
241
242 virtual QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
243
244 virtual QMimeData *createMimeDataFromSelection() const;
245 virtual bool canInsertFromMimeData(const QMimeData *source) const;
246 virtual void insertFromMimeData(const QMimeData *source);
247
248 bool setFocusToAnchor(const QTextCursor &newCursor);
249 bool setFocusToNextOrPreviousAnchor(bool next);
250 bool findNextPrevAnchor(const QTextCursor& from, bool next, QTextCursor& newAnchor);
251
252protected:
253 virtual void timerEvent(QTimerEvent *e);
254
255 virtual bool event(QEvent *e);
256
257private:
258 Q_DISABLE_COPY(QTextControl)
259 Q_PRIVATE_SLOT(d_func(), void _q_updateCurrentCharFormatAndSelection())
260 Q_PRIVATE_SLOT(d_func(), void _q_emitCursorPosChanged(const QTextCursor &))
261 Q_PRIVATE_SLOT(d_func(), void _q_deleteSelected())
262 Q_PRIVATE_SLOT(d_func(), void _q_copyLink())
263 Q_PRIVATE_SLOT(d_func(), void _q_updateBlock(const QTextBlock &))
264 Q_PRIVATE_SLOT(d_func(), void _q_documentLayoutChanged())
265};
266
267
268#ifndef QT_NO_CONTEXTMENU
269class QUnicodeControlCharacterMenu : public QMenu
270{
271 Q_OBJECT
272public:
273 QUnicodeControlCharacterMenu(QObject *editWidget, QWidget *parent);
274
275private Q_SLOTS:
276 void menuActionTriggered();
277
278private:
279 QObject *editWidget;
280};
281#endif // QT_NO_CONTEXTMENU
282
283
284// also used by QLabel
285class QTextEditMimeData : public QMimeData
286{
287public:
288 inline QTextEditMimeData(const QTextDocumentFragment &aFragment) : fragment(aFragment) {}
289
290 virtual QStringList formats() const;
291protected:
292 virtual QVariant retrieveData(const QString &mimeType, QVariant::Type type) const;
293private:
294 void setup() const;
295
296 mutable QTextDocumentFragment fragment;
297};
298
299QT_END_NAMESPACE
300
301QT_END_HEADER
302
303#endif // QTEXTCONTROL_H
Note: See TracBrowser for help on using the repository browser.