0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the QtGui module of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
15 |
**
|
|
16 |
** GNU Lesser General Public License Usage
|
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
18 |
** General Public License version 2.1 as published by the Free Software
|
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
20 |
** packaging of this file. Please review the following information to
|
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
23 |
**
|
|
24 |
** In addition, as a special exception, Nokia gives you certain additional
|
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
27 |
**
|
|
28 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
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 |
|
|
273 |
friend class QPlainTextEditControl;
|
|
274 |
};
|
|
275 |
|
|
276 |
|
|
277 |
class QPlainTextDocumentLayoutPrivate;
|
|
278 |
class Q_GUI_EXPORT QPlainTextDocumentLayout : public QAbstractTextDocumentLayout
|
|
279 |
{
|
|
280 |
Q_OBJECT
|
|
281 |
Q_DECLARE_PRIVATE(QPlainTextDocumentLayout)
|
|
282 |
Q_PROPERTY(int cursorWidth READ cursorWidth WRITE setCursorWidth)
|
|
283 |
|
|
284 |
public:
|
|
285 |
QPlainTextDocumentLayout(QTextDocument *document);
|
|
286 |
~QPlainTextDocumentLayout();
|
|
287 |
|
|
288 |
void draw(QPainter *, const PaintContext &);
|
|
289 |
int hitTest(const QPointF &, Qt::HitTestAccuracy ) const;
|
|
290 |
|
|
291 |
int pageCount() const;
|
|
292 |
QSizeF documentSize() const;
|
|
293 |
|
|
294 |
QRectF frameBoundingRect(QTextFrame *) const;
|
|
295 |
QRectF blockBoundingRect(const QTextBlock &block) const;
|
|
296 |
|
|
297 |
void ensureBlockLayout(const QTextBlock &block) const;
|
|
298 |
|
|
299 |
void setCursorWidth(int width);
|
|
300 |
int cursorWidth() const;
|
|
301 |
|
|
302 |
void requestUpdate();
|
|
303 |
|
|
304 |
protected:
|
|
305 |
void documentChanged(int from, int /*charsRemoved*/, int charsAdded);
|
|
306 |
|
|
307 |
|
|
308 |
private:
|
|
309 |
void setTextWidth(qreal newWidth);
|
|
310 |
qreal textWidth() const;
|
|
311 |
void layoutBlock(const QTextBlock &block);
|
|
312 |
qreal blockWidth(const QTextBlock &block);
|
|
313 |
|
|
314 |
QPlainTextDocumentLayoutPrivate *priv() const;
|
|
315 |
|
|
316 |
friend class QPlainTextEdit;
|
|
317 |
friend class QPlainTextEditPrivate;
|
|
318 |
};
|
|
319 |
|
|
320 |
QT_END_NAMESPACE
|
|
321 |
|
|
322 |
QT_END_HEADER
|
|
323 |
|
|
324 |
|
|
325 |
#endif // QT_NO_TEXTEDIT
|
|
326 |
|
|
327 |
#endif // QPLAINTEXTEDIT_H
|