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 QPLAINTEXTEDIT_H
|
---|
43 | #define QPLAINTEXTEDIT_H
|
---|
44 |
|
---|
45 | #include <QtGui/qtextedit.h>
|
---|
46 |
|
---|
47 | #include <QtGui/qabstractscrollarea.h>
|
---|
48 | #include <QtGui/qtextdocument.h>
|
---|
49 | #include <QtGui/qtextoption.h>
|
---|
50 | #include <QtGui/qtextcursor.h>
|
---|
51 | #include <QtGui/qtextformat.h>
|
---|
52 | #include <QtGui/qabstracttextdocumentlayout.h>
|
---|
53 |
|
---|
54 | #ifndef QT_NO_TEXTEDIT
|
---|
55 |
|
---|
56 | QT_BEGIN_HEADER
|
---|
57 |
|
---|
58 | QT_BEGIN_NAMESPACE
|
---|
59 |
|
---|
60 | QT_MODULE(Gui)
|
---|
61 |
|
---|
62 | class QStyleSheet;
|
---|
63 | class QTextDocument;
|
---|
64 | class QMenu;
|
---|
65 | class QPlainTextEditPrivate;
|
---|
66 | class QMimeData;
|
---|
67 |
|
---|
68 |
|
---|
69 | class Q_GUI_EXPORT QPlainTextEdit : public QAbstractScrollArea
|
---|
70 | {
|
---|
71 | Q_OBJECT
|
---|
72 | Q_DECLARE_PRIVATE(QPlainTextEdit)
|
---|
73 | Q_ENUMS(LineWrapMode)
|
---|
74 | Q_PROPERTY(bool tabChangesFocus READ tabChangesFocus WRITE setTabChangesFocus)
|
---|
75 | Q_PROPERTY(QString documentTitle READ documentTitle WRITE setDocumentTitle)
|
---|
76 | Q_PROPERTY(bool undoRedoEnabled READ isUndoRedoEnabled WRITE setUndoRedoEnabled)
|
---|
77 | Q_PROPERTY(LineWrapMode lineWrapMode READ lineWrapMode WRITE setLineWrapMode)
|
---|
78 | QDOC_PROPERTY(QTextOption::WrapMode wordWrapMode READ wordWrapMode WRITE setWordWrapMode)
|
---|
79 | Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
|
---|
80 | Q_PROPERTY(QString plainText READ toPlainText WRITE setPlainText NOTIFY textChanged USER true)
|
---|
81 | Q_PROPERTY(bool overwriteMode READ overwriteMode WRITE setOverwriteMode)
|
---|
82 | Q_PROPERTY(int tabStopWidth READ tabStopWidth WRITE setTabStopWidth)
|
---|
83 | Q_PROPERTY(int cursorWidth READ cursorWidth WRITE setCursorWidth)
|
---|
84 | Q_PROPERTY(Qt::TextInteractionFlags textInteractionFlags READ textInteractionFlags WRITE setTextInteractionFlags)
|
---|
85 | Q_PROPERTY(int blockCount READ blockCount)
|
---|
86 | Q_PROPERTY(int maximumBlockCount READ maximumBlockCount WRITE setMaximumBlockCount)
|
---|
87 | Q_PROPERTY(bool backgroundVisible READ backgroundVisible WRITE setBackgroundVisible)
|
---|
88 | Q_PROPERTY(bool centerOnScroll READ centerOnScroll WRITE setCenterOnScroll)
|
---|
89 | public:
|
---|
90 | enum LineWrapMode {
|
---|
91 | NoWrap,
|
---|
92 | WidgetWidth
|
---|
93 | };
|
---|
94 |
|
---|
95 | explicit QPlainTextEdit(QWidget *parent = 0);
|
---|
96 | explicit QPlainTextEdit(const QString &text, QWidget *parent = 0);
|
---|
97 | virtual ~QPlainTextEdit();
|
---|
98 |
|
---|
99 | void setDocument(QTextDocument *document);
|
---|
100 | QTextDocument *document() const;
|
---|
101 |
|
---|
102 | void setTextCursor(const QTextCursor &cursor);
|
---|
103 | QTextCursor textCursor() const;
|
---|
104 |
|
---|
105 | bool isReadOnly() const;
|
---|
106 | void setReadOnly(bool ro);
|
---|
107 |
|
---|
108 | void setTextInteractionFlags(Qt::TextInteractionFlags flags);
|
---|
109 | Qt::TextInteractionFlags textInteractionFlags() const;
|
---|
110 |
|
---|
111 | void mergeCurrentCharFormat(const QTextCharFormat &modifier);
|
---|
112 | void setCurrentCharFormat(const QTextCharFormat &format);
|
---|
113 | QTextCharFormat currentCharFormat() const;
|
---|
114 |
|
---|
115 | bool tabChangesFocus() const;
|
---|
116 | void setTabChangesFocus(bool b);
|
---|
117 |
|
---|
118 | inline void setDocumentTitle(const QString &title)
|
---|
119 | { document()->setMetaInformation(QTextDocument::DocumentTitle, title); }
|
---|
120 | inline QString documentTitle() const
|
---|
121 | { return document()->metaInformation(QTextDocument::DocumentTitle); }
|
---|
122 |
|
---|
123 | inline bool isUndoRedoEnabled() const
|
---|
124 | { return document()->isUndoRedoEnabled(); }
|
---|
125 | inline void setUndoRedoEnabled(bool enable)
|
---|
126 | { document()->setUndoRedoEnabled(enable); }
|
---|
127 |
|
---|
128 | inline void setMaximumBlockCount(int maximum)
|
---|
129 | { document()->setMaximumBlockCount(maximum); }
|
---|
130 | inline int maximumBlockCount() const
|
---|
131 | { return document()->maximumBlockCount(); }
|
---|
132 |
|
---|
133 |
|
---|
134 | LineWrapMode lineWrapMode() const;
|
---|
135 | void setLineWrapMode(LineWrapMode mode);
|
---|
136 |
|
---|
137 | QTextOption::WrapMode wordWrapMode() const;
|
---|
138 | void setWordWrapMode(QTextOption::WrapMode policy);
|
---|
139 |
|
---|
140 | void setBackgroundVisible(bool visible);
|
---|
141 | bool backgroundVisible() const;
|
---|
142 |
|
---|
143 | void setCenterOnScroll(bool enabled);
|
---|
144 | bool centerOnScroll() const;
|
---|
145 |
|
---|
146 | bool find(const QString &exp, QTextDocument::FindFlags options = 0);
|
---|
147 |
|
---|
148 | inline QString toPlainText() const
|
---|
149 | { return document()->toPlainText(); }
|
---|
150 |
|
---|
151 | void ensureCursorVisible();
|
---|
152 |
|
---|
153 | virtual QVariant loadResource(int type, const QUrl &name);
|
---|
154 | #ifndef QT_NO_CONTEXTMENU
|
---|
155 | QMenu *createStandardContextMenu();
|
---|
156 | #endif
|
---|
157 |
|
---|
158 | QTextCursor cursorForPosition(const QPoint &pos) const;
|
---|
159 | QRect cursorRect(const QTextCursor &cursor) const;
|
---|
160 | QRect cursorRect() const;
|
---|
161 |
|
---|
162 | bool overwriteMode() const;
|
---|
163 | void setOverwriteMode(bool overwrite);
|
---|
164 |
|
---|
165 | int tabStopWidth() const;
|
---|
166 | void setTabStopWidth(int width);
|
---|
167 |
|
---|
168 | int cursorWidth() const;
|
---|
169 | void setCursorWidth(int width);
|
---|
170 |
|
---|
171 | void setExtraSelections(const QList<QTextEdit::ExtraSelection> &selections);
|
---|
172 | QList<QTextEdit::ExtraSelection> extraSelections() const;
|
---|
173 |
|
---|
174 | void moveCursor(QTextCursor::MoveOperation operation, QTextCursor::MoveMode mode = QTextCursor::MoveAnchor);
|
---|
175 |
|
---|
176 | bool canPaste() const;
|
---|
177 |
|
---|
178 | #ifndef QT_NO_PRINTER
|
---|
179 | void print(QPrinter *printer) const;
|
---|
180 | #endif
|
---|
181 |
|
---|
182 | int blockCount() const;
|
---|
183 |
|
---|
184 | public Q_SLOTS:
|
---|
185 |
|
---|
186 | void setPlainText(const QString &text);
|
---|
187 |
|
---|
188 | #ifndef QT_NO_CLIPBOARD
|
---|
189 | void cut();
|
---|
190 | void copy();
|
---|
191 | void paste();
|
---|
192 | #endif
|
---|
193 |
|
---|
194 | void undo();
|
---|
195 | void redo();
|
---|
196 |
|
---|
197 | void clear();
|
---|
198 | void selectAll();
|
---|
199 |
|
---|
200 | void insertPlainText(const QString &text);
|
---|
201 |
|
---|
202 | void appendPlainText(const QString &text);
|
---|
203 | void appendHtml(const QString &html);
|
---|
204 |
|
---|
205 | void centerCursor();
|
---|
206 |
|
---|
207 | Q_SIGNALS:
|
---|
208 | void textChanged();
|
---|
209 | void undoAvailable(bool b);
|
---|
210 | void redoAvailable(bool b);
|
---|
211 | void copyAvailable(bool b);
|
---|
212 | void selectionChanged();
|
---|
213 | void cursorPositionChanged();
|
---|
214 |
|
---|
215 | void updateRequest(const QRect &rect, int dy);
|
---|
216 | void blockCountChanged(int newBlockCount);
|
---|
217 | void modificationChanged(bool);
|
---|
218 |
|
---|
219 | protected:
|
---|
220 | virtual bool event(QEvent *e);
|
---|
221 | virtual void timerEvent(QTimerEvent *e);
|
---|
222 | virtual void keyPressEvent(QKeyEvent *e);
|
---|
223 | virtual void keyReleaseEvent(QKeyEvent *e);
|
---|
224 | virtual void resizeEvent(QResizeEvent *e);
|
---|
225 | virtual void paintEvent(QPaintEvent *e);
|
---|
226 | virtual void mousePressEvent(QMouseEvent *e);
|
---|
227 | virtual void mouseMoveEvent(QMouseEvent *e);
|
---|
228 | virtual void mouseReleaseEvent(QMouseEvent *e);
|
---|
229 | virtual void mouseDoubleClickEvent(QMouseEvent *e);
|
---|
230 | virtual bool focusNextPrevChild(bool next);
|
---|
231 | #ifndef QT_NO_CONTEXTMENU
|
---|
232 | virtual void contextMenuEvent(QContextMenuEvent *e);
|
---|
233 | #endif
|
---|
234 | #ifndef QT_NO_DRAGANDDROP
|
---|
235 | virtual void dragEnterEvent(QDragEnterEvent *e);
|
---|
236 | virtual void dragLeaveEvent(QDragLeaveEvent *e);
|
---|
237 | virtual void dragMoveEvent(QDragMoveEvent *e);
|
---|
238 | virtual void dropEvent(QDropEvent *e);
|
---|
239 | #endif
|
---|
240 | virtual void focusInEvent(QFocusEvent *e);
|
---|
241 | virtual void focusOutEvent(QFocusEvent *e);
|
---|
242 | virtual void showEvent(QShowEvent *);
|
---|
243 | virtual void changeEvent(QEvent *e);
|
---|
244 | #ifndef QT_NO_WHEELEVENT
|
---|
245 | virtual void wheelEvent(QWheelEvent *e);
|
---|
246 | #endif
|
---|
247 |
|
---|
248 | virtual QMimeData *createMimeDataFromSelection() const;
|
---|
249 | virtual bool canInsertFromMimeData(const QMimeData *source) const;
|
---|
250 | virtual void insertFromMimeData(const QMimeData *source);
|
---|
251 |
|
---|
252 | virtual void inputMethodEvent(QInputMethodEvent *);
|
---|
253 | QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
|
---|
254 |
|
---|
255 | QPlainTextEdit(QPlainTextEditPrivate &dd, QWidget *parent);
|
---|
256 |
|
---|
257 | virtual void scrollContentsBy(int dx, int dy);
|
---|
258 |
|
---|
259 | QTextBlock firstVisibleBlock() const;
|
---|
260 | QPointF contentOffset() const;
|
---|
261 | QRectF blockBoundingRect(const QTextBlock &block) const;
|
---|
262 | QRectF blockBoundingGeometry(const QTextBlock &block) const;
|
---|
263 | QAbstractTextDocumentLayout::PaintContext getPaintContext() const;
|
---|
264 |
|
---|
265 |
|
---|
266 | private:
|
---|
267 | Q_DISABLE_COPY(QPlainTextEdit)
|
---|
268 | Q_PRIVATE_SLOT(d_func(), void _q_repaintContents(const QRectF &r))
|
---|
269 | Q_PRIVATE_SLOT(d_func(), void _q_adjustScrollbars())
|
---|
270 | Q_PRIVATE_SLOT(d_func(), void _q_verticalScrollbarActionTriggered(int))
|
---|
271 | Q_PRIVATE_SLOT(d_func(), void _q_cursorPositionChanged())
|
---|
272 | friend class QPlainTextEditControl;
|
---|
273 | };
|
---|
274 |
|
---|
275 |
|
---|
276 | class QPlainTextDocumentLayoutPrivate;
|
---|
277 | class Q_GUI_EXPORT QPlainTextDocumentLayout : public QAbstractTextDocumentLayout
|
---|
278 | {
|
---|
279 | Q_OBJECT
|
---|
280 | Q_DECLARE_PRIVATE(QPlainTextDocumentLayout)
|
---|
281 | Q_PROPERTY(int cursorWidth READ cursorWidth WRITE setCursorWidth)
|
---|
282 |
|
---|
283 | public:
|
---|
284 | QPlainTextDocumentLayout(QTextDocument *document);
|
---|
285 | ~QPlainTextDocumentLayout();
|
---|
286 |
|
---|
287 | void draw(QPainter *, const PaintContext &);
|
---|
288 | int hitTest(const QPointF &, Qt::HitTestAccuracy ) const;
|
---|
289 |
|
---|
290 | int pageCount() const;
|
---|
291 | QSizeF documentSize() const;
|
---|
292 |
|
---|
293 | QRectF frameBoundingRect(QTextFrame *) const;
|
---|
294 | QRectF blockBoundingRect(const QTextBlock &block) const;
|
---|
295 |
|
---|
296 | void ensureBlockLayout(const QTextBlock &block) const;
|
---|
297 |
|
---|
298 | void setCursorWidth(int width);
|
---|
299 | int cursorWidth() const;
|
---|
300 |
|
---|
301 | void requestUpdate();
|
---|
302 |
|
---|
303 | protected:
|
---|
304 | void documentChanged(int from, int /*charsRemoved*/, int charsAdded);
|
---|
305 |
|
---|
306 |
|
---|
307 | private:
|
---|
308 | void setTextWidth(qreal newWidth);
|
---|
309 | qreal textWidth() const;
|
---|
310 | void layoutBlock(const QTextBlock &block);
|
---|
311 | qreal blockWidth(const QTextBlock &block);
|
---|
312 |
|
---|
313 | QPlainTextDocumentLayoutPrivate *priv() const;
|
---|
314 |
|
---|
315 | friend class QPlainTextEdit;
|
---|
316 | friend class QPlainTextEditPrivate;
|
---|
317 | };
|
---|
318 |
|
---|
319 | QT_END_NAMESPACE
|
---|
320 |
|
---|
321 | QT_END_HEADER
|
---|
322 |
|
---|
323 |
|
---|
324 | #endif // QT_NO_TEXTEDIT
|
---|
325 |
|
---|
326 | #endif // QPLAINTEXTEDIT_H
|
---|