- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- File List
- File Members

# qplaintextedit.h

Go to the documentation of this file.

    00001 /****************************************************************************
    00002 **
    00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
    00004 ** All rights reserved.
    00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
    00006 **
    00007 ** This file is part of the QtGui module of the Qt Toolkit.
    00008 **
    00009 ** $QT_BEGIN_LICENSE:LGPL$
    00010 ** Commercial Usage
    00011 ** Licensees holding valid Qt Commercial licenses may use this file in
    00012 ** accordance with the Qt Commercial License Agreement provided with the
    00013 ** Software or, alternatively, in accordance with the terms contained in
    00014 ** a written agreement between you and Nokia.
    00015 **
    00016 ** GNU Lesser General Public License Usage
    00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
    00018 ** General Public License version 2.1 as published by the Free Software
    00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
    00020 ** packaging of this file.  Please review the following information to
    00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
    00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    00023 **
    00024 ** In addition, as a special exception, Nokia gives you certain additional
    00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
    00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
    00027 **
    00028 ** GNU General Public License Usage
    00029 ** Alternatively, this file may be used under the terms of the GNU
    00030 ** General Public License version 3.0 as published by the Free Software
    00031 ** Foundation and appearing in the file LICENSE.GPL included in the
    00032 ** packaging of this file.  Please review the following information to
    00033 ** ensure the GNU General Public License version 3.0 requirements will be
    00034 ** met: http://www.gnu.org/copyleft/gpl.html.
    00035 **
    00036 ** If you have questions regarding the use of this file, please contact
    00037 ** Nokia at qt-info@nokia.com.
    00038 ** $QT_END_LICENSE$
    00039 **
    00040 ****************************************************************************/
    00041
    00042 #ifndef QPLAINTEXTEDIT_H
    00043 #define QPLAINTEXTEDIT_H
    00044
    00045 #include <QtGui/qtextedit.h>
    00046
    00047 #include <QtGui/qabstractscrollarea.h>
    00048 #include <QtGui/qtextdocument.h>
    00049 #include <QtGui/qtextoption.h>
    00050 #include <QtGui/qtextcursor.h>
    00051 #include <QtGui/qtextformat.h>
    00052 #include <QtGui/qabstracttextdocumentlayout.h>
    00053
    00054 #ifndef QT_NO_TEXTEDIT
    00055
    00056 QT_BEGIN_HEADER
    00057
    00058 QT_BEGIN_NAMESPACE
    00059
    00060 QT_MODULE(Gui)
    00061
    00062 class QStyleSheet;
    00063 class QTextDocument;
    00064 class QMenu;
    00065 class QPlainTextEditPrivate;
    00066 class QMimeData;
    00067
    00068
    00069 class Q_GUI_EXPORT QPlainTextEdit : public QAbstractScrollArea
    00070 {
    00071     Q_OBJECT
    00072     Q_DECLARE_PRIVATE(QPlainTextEdit)
    00073     Q_ENUMS(LineWrapMode)
    00074     Q_PROPERTY(bool tabChangesFocus READ tabChangesFocus WRITE setTabChangesFocus)
    00075     Q_PROPERTY(QString documentTitle READ documentTitle WRITE setDocumentTitle)
    00076     Q_PROPERTY(bool undoRedoEnabled READ isUndoRedoEnabled WRITE setUndoRedoEnabled)
    00077     Q_PROPERTY(LineWrapMode lineWrapMode READ lineWrapMode WRITE setLineWrapMode)
    00078     QDOC_PROPERTY(QTextOption::WrapMode wordWrapMode READ wordWrapMode WRITE setWordWrapMode)
    00079     Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
    00080     Q_PROPERTY(QString plainText READ toPlainText WRITE setPlainText NOTIFY textChanged USER true)
    00081     Q_PROPERTY(bool overwriteMode READ overwriteMode WRITE setOverwriteMode)
    00082     Q_PROPERTY(int tabStopWidth READ tabStopWidth WRITE setTabStopWidth)
    00083     Q_PROPERTY(int cursorWidth READ cursorWidth WRITE setCursorWidth)
    00084     Q_PROPERTY(Qt::TextInteractionFlags textInteractionFlags READ textInteractionFlags WRITE setTextInteractionFlags)
    00085     Q_PROPERTY(int blockCount READ blockCount)
    00086     Q_PROPERTY(int maximumBlockCount READ maximumBlockCount WRITE setMaximumBlockCount)
    00087     Q_PROPERTY(bool backgroundVisible READ backgroundVisible WRITE setBackgroundVisible)
    00088     Q_PROPERTY(bool centerOnScroll READ centerOnScroll WRITE setCenterOnScroll)
    00089 public:
    00090     enum LineWrapMode {
    00091         NoWrap,
    00092         WidgetWidth
    00093     };
    00094
    00095     explicit QPlainTextEdit(QWidget *parent = 0);
    00096     explicit QPlainTextEdit(const QString &text, QWidget *parent = 0);
    00097     virtual ~QPlainTextEdit();
    00098
    00099     void setDocument(QTextDocument *document);
    00100     QTextDocument *document() const;
    00101
    00102     void setTextCursor(const QTextCursor &cursor);
    00103     QTextCursor textCursor() const;
    00104
    00105     bool isReadOnly() const;
    00106     void setReadOnly(bool ro);
    00107
    00108     void setTextInteractionFlags(Qt::TextInteractionFlags flags);
    00109     Qt::TextInteractionFlags textInteractionFlags() const;
    00110
    00111     void mergeCurrentCharFormat(const QTextCharFormat &modifier);
    00112     void setCurrentCharFormat(const QTextCharFormat &format);
    00113     QTextCharFormat currentCharFormat() const;
    00114
    00115     bool tabChangesFocus() const;
    00116     void setTabChangesFocus(bool b);
    00117
    00118     inline void setDocumentTitle(const QString &title)
    00119     { document()->setMetaInformation(QTextDocument::DocumentTitle, title); }
    00120     inline QString documentTitle() const
    00121     { return document()->metaInformation(QTextDocument::DocumentTitle); }
    00122
    00123     inline bool isUndoRedoEnabled() const
    00124     { return document()->isUndoRedoEnabled(); }
    00125     inline void setUndoRedoEnabled(bool enable)
    00126     { document()->setUndoRedoEnabled(enable); }
    00127
    00128     inline void setMaximumBlockCount(int maximum)
    00129     { document()->setMaximumBlockCount(maximum); }
    00130     inline int maximumBlockCount() const
    00131     { return document()->maximumBlockCount(); }
    00132
    00133
    00134     LineWrapMode lineWrapMode() const;
    00135     void setLineWrapMode(LineWrapMode mode);
    00136
    00137     QTextOption::WrapMode wordWrapMode() const;
    00138     void setWordWrapMode(QTextOption::WrapMode policy);
    00139
    00140     void setBackgroundVisible(bool visible);
    00141     bool backgroundVisible() const;
    00142
    00143     void setCenterOnScroll(bool enabled);
    00144     bool centerOnScroll() const;
    00145
    00146     bool find(const QString &exp, QTextDocument::FindFlags options = 0);
    00147
    00148     inline QString toPlainText() const
    00149     { return document()->toPlainText(); }
    00150
    00151     void ensureCursorVisible();
    00152
    00153     virtual QVariant loadResource(int type, const QUrl &name);
    00154 #ifndef QT_NO_CONTEXTMENU
    00155     QMenu *createStandardContextMenu();
    00156 #endif
    00157
    00158     QTextCursor cursorForPosition(const QPoint &pos) const;
    00159     QRect cursorRect(const QTextCursor &cursor) const;
    00160     QRect cursorRect() const;
    00161
    00162     QString anchorAt(const QPoint &pos) const;
    00163
    00164     bool overwriteMode() const;
    00165     void setOverwriteMode(bool overwrite);
    00166
    00167     int tabStopWidth() const;
    00168     void setTabStopWidth(int width);
    00169
    00170     int cursorWidth() const;
    00171     void setCursorWidth(int width);
    00172
    00173     void setExtraSelections(const QList<QTextEdit::ExtraSelection> &selections);
    00174     QList<QTextEdit::ExtraSelection> extraSelections() const;
    00175
    00176     void moveCursor(QTextCursor::MoveOperation operation, QTextCursor::MoveMode mode = QTextCursor::MoveAnchor);
    00177
    00178     bool canPaste() const;
    00179
    00180 #ifndef QT_NO_PRINTER
    00181     void print(QPrinter *printer) const;
    00182 #endif
    00183
    00184     int blockCount() const;
    00185
    00186 public Q_SLOTS:
    00187
    00188     void setPlainText(const QString &text);
    00189
    00190 #ifndef QT_NO_CLIPBOARD
    00191     void cut();
    00192     void copy();
    00193     void paste();
    00194 #endif
    00195
    00196     void undo();
    00197     void redo();
    00198
    00199     void clear();
    00200     void selectAll();
    00201
    00202     void insertPlainText(const QString &text);
    00203
    00204     void appendPlainText(const QString &text);
    00205     void appendHtml(const QString &html);
    00206
    00207     void centerCursor();
    00208
    00209 Q_SIGNALS:
    00210     void textChanged();
    00211     void undoAvailable(bool b);
    00212     void redoAvailable(bool b);
    00213     void copyAvailable(bool b);
    00214     void selectionChanged();
    00215     void cursorPositionChanged();
    00216
    00217     void updateRequest(const QRect &rect, int dy);
    00218     void blockCountChanged(int newBlockCount);
    00219     void modificationChanged(bool);
    00220
    00221 protected:
    00222     virtual bool event(QEvent *e);
    00223     virtual void timerEvent(QTimerEvent *e);
    00224     virtual void keyPressEvent(QKeyEvent *e);
    00225     virtual void keyReleaseEvent(QKeyEvent *e);
    00226     virtual void resizeEvent(QResizeEvent *e);
    00227     virtual void paintEvent(QPaintEvent *e);
    00228     virtual void mousePressEvent(QMouseEvent *e);
    00229     virtual void mouseMoveEvent(QMouseEvent *e);
    00230     virtual void mouseReleaseEvent(QMouseEvent *e);
    00231     virtual void mouseDoubleClickEvent(QMouseEvent *e);
    00232     virtual bool focusNextPrevChild(bool next);
    00233 #ifndef QT_NO_CONTEXTMENU
    00234     virtual void contextMenuEvent(QContextMenuEvent *e);
    00235 #endif
    00236 #ifndef QT_NO_DRAGANDDROP
    00237     virtual void dragEnterEvent(QDragEnterEvent *e);
    00238     virtual void dragLeaveEvent(QDragLeaveEvent *e);
    00239     virtual void dragMoveEvent(QDragMoveEvent *e);
    00240     virtual void dropEvent(QDropEvent *e);
    00241 #endif
    00242     virtual void focusInEvent(QFocusEvent *e);
    00243     virtual void focusOutEvent(QFocusEvent *e);
    00244     virtual void showEvent(QShowEvent *);
    00245     virtual void changeEvent(QEvent *e);
    00246 #ifndef QT_NO_WHEELEVENT
    00247     virtual void wheelEvent(QWheelEvent *e);
    00248 #endif
    00249
    00250     virtual QMimeData *createMimeDataFromSelection() const;
    00251     virtual bool canInsertFromMimeData(const QMimeData *source) const;
    00252     virtual void insertFromMimeData(const QMimeData *source);
    00253
    00254     virtual void inputMethodEvent(QInputMethodEvent *);
    00255     QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
    00256
    00257     QPlainTextEdit(QPlainTextEditPrivate &dd, QWidget *parent);
    00258
    00259     virtual void scrollContentsBy(int dx, int dy);
    00260
    00261     QTextBlock firstVisibleBlock() const;
    00262     QPointF contentOffset() const;
    00263     QRectF blockBoundingRect(const QTextBlock &block) const;
    00264     QRectF blockBoundingGeometry(const QTextBlock &block) const;
    00265     QAbstractTextDocumentLayout::PaintContext getPaintContext() const;
    00266
    00267
    00268 private:
    00269     Q_DISABLE_COPY(QPlainTextEdit)
    00270     Q_PRIVATE_SLOT(d_func(), void _q_repaintContents(const QRectF &r))
    00271     Q_PRIVATE_SLOT(d_func(), void _q_adjustScrollbars())
    00272     Q_PRIVATE_SLOT(d_func(), void _q_verticalScrollbarActionTriggered(int))
    00273     Q_PRIVATE_SLOT(d_func(), void _q_cursorPositionChanged())
    00274
    00275     friend class QPlainTextEditControl;
    00276 };
    00277
    00278
    00279 class QPlainTextDocumentLayoutPrivate;
    00280 class Q_GUI_EXPORT QPlainTextDocumentLayout : public QAbstractTextDocumentLayout
    00281 {
    00282     Q_OBJECT
    00283     Q_DECLARE_PRIVATE(QPlainTextDocumentLayout)
    00284     Q_PROPERTY(int cursorWidth READ cursorWidth WRITE setCursorWidth)
    00285
    00286 public:
    00287     QPlainTextDocumentLayout(QTextDocument *document);
    00288     ~QPlainTextDocumentLayout();
    00289
    00290     void draw(QPainter *, const PaintContext &);
    00291     int hitTest(const QPointF &, Qt::HitTestAccuracy ) const;
    00292
    00293     int pageCount() const;
    00294     QSizeF documentSize() const;
    00295
    00296     QRectF frameBoundingRect(QTextFrame *) const;
    00297     QRectF blockBoundingRect(const QTextBlock &block) const;
    00298
    00299     void ensureBlockLayout(const QTextBlock &block) const;
    00300
    00301     void setCursorWidth(int width);
    00302     int cursorWidth() const;
    00303
    00304     void requestUpdate();
    00305
    00306 protected:
    00307     void documentChanged(int from, int /*charsRemoved*/, int charsAdded);
    00308
    00309
    00310 private:
    00311     void setTextWidth(qreal newWidth);
    00312     qreal textWidth() const;
    00313     void layoutBlock(const QTextBlock &block);
    00314     qreal blockWidth(const QTextBlock &block);
    00315
    00316     QPlainTextDocumentLayoutPrivate *priv() const;
    00317
    00318     friend class QPlainTextEdit;
    00319     friend class QPlainTextEditPrivate;
    00320 };
    00321
    00322 QT_END_NAMESPACE
    00323
    00324 QT_END_HEADER
    00325
    00326
    00327 #endif // QT_NO_TEXTEDIT
    00328
    00329 #endif // QPLAINTEXTEDIT_H