[2] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
[846] | 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
[561] | 4 | ** All rights reserved.
|
---|
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com)
|
---|
[2] | 6 | **
|
---|
| 7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
---|
| 8 | **
|
---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
| 10 | ** Commercial Usage
|
---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
| 14 | ** a written agreement between you and Nokia.
|
---|
| 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 | **
|
---|
[561] | 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.
|
---|
[2] | 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 | **
|
---|
[561] | 36 | ** If you have questions regarding the use of this file, please contact
|
---|
| 37 | ** Nokia at qt-info@nokia.com.
|
---|
[2] | 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 |
|
---|
[846] | 162 | QString anchorAt(const QPoint &pos) const;
|
---|
| 163 |
|
---|
[2] | 164 | bool overwriteMode() const;
|
---|
| 165 | void setOverwriteMode(bool overwrite);
|
---|
| 166 |
|
---|
| 167 | int tabStopWidth() const;
|
---|
| 168 | void setTabStopWidth(int width);
|
---|
| 169 |
|
---|
| 170 | int cursorWidth() const;
|
---|
| 171 | void setCursorWidth(int width);
|
---|
| 172 |
|
---|
| 173 | void setExtraSelections(const QList<QTextEdit::ExtraSelection> &selections);
|
---|
| 174 | QList<QTextEdit::ExtraSelection> extraSelections() const;
|
---|
| 175 |
|
---|
| 176 | void moveCursor(QTextCursor::MoveOperation operation, QTextCursor::MoveMode mode = QTextCursor::MoveAnchor);
|
---|
| 177 |
|
---|
| 178 | bool canPaste() const;
|
---|
| 179 |
|
---|
| 180 | #ifndef QT_NO_PRINTER
|
---|
| 181 | void print(QPrinter *printer) const;
|
---|
| 182 | #endif
|
---|
| 183 |
|
---|
| 184 | int blockCount() const;
|
---|
| 185 |
|
---|
| 186 | public Q_SLOTS:
|
---|
| 187 |
|
---|
| 188 | void setPlainText(const QString &text);
|
---|
| 189 |
|
---|
| 190 | #ifndef QT_NO_CLIPBOARD
|
---|
| 191 | void cut();
|
---|
| 192 | void copy();
|
---|
| 193 | void paste();
|
---|
| 194 | #endif
|
---|
| 195 |
|
---|
| 196 | void undo();
|
---|
| 197 | void redo();
|
---|
| 198 |
|
---|
| 199 | void clear();
|
---|
| 200 | void selectAll();
|
---|
| 201 |
|
---|
| 202 | void insertPlainText(const QString &text);
|
---|
| 203 |
|
---|
| 204 | void appendPlainText(const QString &text);
|
---|
| 205 | void appendHtml(const QString &html);
|
---|
| 206 |
|
---|
| 207 | void centerCursor();
|
---|
| 208 |
|
---|
| 209 | Q_SIGNALS:
|
---|
| 210 | void textChanged();
|
---|
| 211 | void undoAvailable(bool b);
|
---|
| 212 | void redoAvailable(bool b);
|
---|
| 213 | void copyAvailable(bool b);
|
---|
| 214 | void selectionChanged();
|
---|
| 215 | void cursorPositionChanged();
|
---|
| 216 |
|
---|
| 217 | void updateRequest(const QRect &rect, int dy);
|
---|
| 218 | void blockCountChanged(int newBlockCount);
|
---|
| 219 | void modificationChanged(bool);
|
---|
| 220 |
|
---|
| 221 | protected:
|
---|
| 222 | virtual bool event(QEvent *e);
|
---|
| 223 | virtual void timerEvent(QTimerEvent *e);
|
---|
| 224 | virtual void keyPressEvent(QKeyEvent *e);
|
---|
| 225 | virtual void keyReleaseEvent(QKeyEvent *e);
|
---|
| 226 | virtual void resizeEvent(QResizeEvent *e);
|
---|
| 227 | virtual void paintEvent(QPaintEvent *e);
|
---|
| 228 | virtual void mousePressEvent(QMouseEvent *e);
|
---|
| 229 | virtual void mouseMoveEvent(QMouseEvent *e);
|
---|
| 230 | virtual void mouseReleaseEvent(QMouseEvent *e);
|
---|
| 231 | virtual void mouseDoubleClickEvent(QMouseEvent *e);
|
---|
| 232 | virtual bool focusNextPrevChild(bool next);
|
---|
| 233 | #ifndef QT_NO_CONTEXTMENU
|
---|
| 234 | virtual void contextMenuEvent(QContextMenuEvent *e);
|
---|
| 235 | #endif
|
---|
| 236 | #ifndef QT_NO_DRAGANDDROP
|
---|
| 237 | virtual void dragEnterEvent(QDragEnterEvent *e);
|
---|
| 238 | virtual void dragLeaveEvent(QDragLeaveEvent *e);
|
---|
| 239 | virtual void dragMoveEvent(QDragMoveEvent *e);
|
---|
| 240 | virtual void dropEvent(QDropEvent *e);
|
---|
| 241 | #endif
|
---|
| 242 | virtual void focusInEvent(QFocusEvent *e);
|
---|
| 243 | virtual void focusOutEvent(QFocusEvent *e);
|
---|
| 244 | virtual void showEvent(QShowEvent *);
|
---|
| 245 | virtual void changeEvent(QEvent *e);
|
---|
| 246 | #ifndef QT_NO_WHEELEVENT
|
---|
| 247 | virtual void wheelEvent(QWheelEvent *e);
|
---|
| 248 | #endif
|
---|
| 249 |
|
---|
| 250 | virtual QMimeData *createMimeDataFromSelection() const;
|
---|
| 251 | virtual bool canInsertFromMimeData(const QMimeData *source) const;
|
---|
| 252 | virtual void insertFromMimeData(const QMimeData *source);
|
---|
| 253 |
|
---|
| 254 | virtual void inputMethodEvent(QInputMethodEvent *);
|
---|
| 255 | QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
|
---|
| 256 |
|
---|
| 257 | QPlainTextEdit(QPlainTextEditPrivate &dd, QWidget *parent);
|
---|
| 258 |
|
---|
| 259 | virtual void scrollContentsBy(int dx, int dy);
|
---|
| 260 |
|
---|
| 261 | QTextBlock firstVisibleBlock() const;
|
---|
| 262 | QPointF contentOffset() const;
|
---|
| 263 | QRectF blockBoundingRect(const QTextBlock &block) const;
|
---|
| 264 | QRectF blockBoundingGeometry(const QTextBlock &block) const;
|
---|
| 265 | QAbstractTextDocumentLayout::PaintContext getPaintContext() const;
|
---|
| 266 |
|
---|
| 267 |
|
---|
| 268 | private:
|
---|
| 269 | Q_DISABLE_COPY(QPlainTextEdit)
|
---|
| 270 | Q_PRIVATE_SLOT(d_func(), void _q_repaintContents(const QRectF &r))
|
---|
| 271 | Q_PRIVATE_SLOT(d_func(), void _q_adjustScrollbars())
|
---|
| 272 | Q_PRIVATE_SLOT(d_func(), void _q_verticalScrollbarActionTriggered(int))
|
---|
| 273 | Q_PRIVATE_SLOT(d_func(), void _q_cursorPositionChanged())
|
---|
[561] | 274 |
|
---|
[2] | 275 | friend class QPlainTextEditControl;
|
---|
| 276 | };
|
---|
| 277 |
|
---|
| 278 |
|
---|
| 279 | class QPlainTextDocumentLayoutPrivate;
|
---|
| 280 | class Q_GUI_EXPORT QPlainTextDocumentLayout : public QAbstractTextDocumentLayout
|
---|
| 281 | {
|
---|
| 282 | Q_OBJECT
|
---|
| 283 | Q_DECLARE_PRIVATE(QPlainTextDocumentLayout)
|
---|
| 284 | Q_PROPERTY(int cursorWidth READ cursorWidth WRITE setCursorWidth)
|
---|
| 285 |
|
---|
| 286 | public:
|
---|
| 287 | QPlainTextDocumentLayout(QTextDocument *document);
|
---|
| 288 | ~QPlainTextDocumentLayout();
|
---|
| 289 |
|
---|
| 290 | void draw(QPainter *, const PaintContext &);
|
---|
| 291 | int hitTest(const QPointF &, Qt::HitTestAccuracy ) const;
|
---|
| 292 |
|
---|
| 293 | int pageCount() const;
|
---|
| 294 | QSizeF documentSize() const;
|
---|
| 295 |
|
---|
| 296 | QRectF frameBoundingRect(QTextFrame *) const;
|
---|
| 297 | QRectF blockBoundingRect(const QTextBlock &block) const;
|
---|
| 298 |
|
---|
| 299 | void ensureBlockLayout(const QTextBlock &block) const;
|
---|
| 300 |
|
---|
| 301 | void setCursorWidth(int width);
|
---|
| 302 | int cursorWidth() const;
|
---|
| 303 |
|
---|
| 304 | void requestUpdate();
|
---|
| 305 |
|
---|
| 306 | protected:
|
---|
| 307 | void documentChanged(int from, int /*charsRemoved*/, int charsAdded);
|
---|
| 308 |
|
---|
| 309 |
|
---|
| 310 | private:
|
---|
| 311 | void setTextWidth(qreal newWidth);
|
---|
| 312 | qreal textWidth() const;
|
---|
| 313 | void layoutBlock(const QTextBlock &block);
|
---|
| 314 | qreal blockWidth(const QTextBlock &block);
|
---|
| 315 |
|
---|
| 316 | QPlainTextDocumentLayoutPrivate *priv() const;
|
---|
| 317 |
|
---|
| 318 | friend class QPlainTextEdit;
|
---|
| 319 | friend class QPlainTextEditPrivate;
|
---|
| 320 | };
|
---|
| 321 |
|
---|
| 322 | QT_END_NAMESPACE
|
---|
| 323 |
|
---|
| 324 | QT_END_HEADER
|
---|
| 325 |
|
---|
| 326 |
|
---|
| 327 | #endif // QT_NO_TEXTEDIT
|
---|
| 328 |
|
---|
| 329 | #endif // QPLAINTEXTEDIT_H
|
---|