Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/QtWidgets/qplaintextedit.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // Copyright (C) 2016 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 
0004 #ifndef QPLAINTEXTEDIT_H
0005 #define QPLAINTEXTEDIT_H
0006 
0007 #include <QtWidgets/qtwidgetsglobal.h>
0008 #include <QtWidgets/qtextedit.h>
0009 
0010 #include <QtWidgets/qabstractscrollarea.h>
0011 #include <QtGui/qtextdocument.h>
0012 #include <QtGui/qtextoption.h>
0013 #include <QtGui/qtextcursor.h>
0014 #include <QtGui/qtextformat.h>
0015 #include <QtGui/qabstracttextdocumentlayout.h>
0016 
0017 QT_REQUIRE_CONFIG(textedit);
0018 
0019 QT_BEGIN_NAMESPACE
0020 
0021 class QStyleSheet;
0022 class QTextDocument;
0023 class QMenu;
0024 class QPlainTextEditPrivate;
0025 class QMimeData;
0026 class QPagedPaintDevice;
0027 class QRegularExpression;
0028 
0029 class Q_WIDGETS_EXPORT QPlainTextEdit : public QAbstractScrollArea
0030 {
0031     Q_OBJECT
0032     Q_DECLARE_PRIVATE(QPlainTextEdit)
0033     Q_PROPERTY(bool tabChangesFocus READ tabChangesFocus WRITE setTabChangesFocus)
0034     Q_PROPERTY(QString documentTitle READ documentTitle WRITE setDocumentTitle)
0035     Q_PROPERTY(bool undoRedoEnabled READ isUndoRedoEnabled WRITE setUndoRedoEnabled)
0036     Q_PROPERTY(LineWrapMode lineWrapMode READ lineWrapMode WRITE setLineWrapMode)
0037     QDOC_PROPERTY(QTextOption::WrapMode wordWrapMode READ wordWrapMode WRITE setWordWrapMode)
0038     Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
0039     Q_PROPERTY(QString plainText READ toPlainText WRITE setPlainText NOTIFY textChanged USER true)
0040     Q_PROPERTY(bool overwriteMode READ overwriteMode WRITE setOverwriteMode)
0041     Q_PROPERTY(qreal tabStopDistance READ tabStopDistance WRITE setTabStopDistance)
0042     Q_PROPERTY(int cursorWidth READ cursorWidth WRITE setCursorWidth)
0043     Q_PROPERTY(Qt::TextInteractionFlags textInteractionFlags READ textInteractionFlags
0044                WRITE setTextInteractionFlags)
0045     Q_PROPERTY(int blockCount READ blockCount)
0046     Q_PROPERTY(int maximumBlockCount READ maximumBlockCount WRITE setMaximumBlockCount)
0047     Q_PROPERTY(bool backgroundVisible READ backgroundVisible WRITE setBackgroundVisible)
0048     Q_PROPERTY(bool centerOnScroll READ centerOnScroll WRITE setCenterOnScroll)
0049     Q_PROPERTY(QString placeholderText READ placeholderText WRITE setPlaceholderText)
0050 public:
0051     enum LineWrapMode {
0052         NoWrap,
0053         WidgetWidth
0054     };
0055     Q_ENUM(LineWrapMode)
0056 
0057     explicit QPlainTextEdit(QWidget *parent = nullptr);
0058     explicit QPlainTextEdit(const QString &text, QWidget *parent = nullptr);
0059     virtual ~QPlainTextEdit();
0060 
0061     void setDocument(QTextDocument *document);
0062     QTextDocument *document() const;
0063 
0064     void setPlaceholderText(const QString &placeholderText);
0065     QString placeholderText() const;
0066 
0067     void setTextCursor(const QTextCursor &cursor);
0068     QTextCursor textCursor() const;
0069 
0070     bool isReadOnly() const;
0071     void setReadOnly(bool ro);
0072 
0073     void setTextInteractionFlags(Qt::TextInteractionFlags flags);
0074     Qt::TextInteractionFlags textInteractionFlags() const;
0075 
0076     void mergeCurrentCharFormat(const QTextCharFormat &modifier);
0077     void setCurrentCharFormat(const QTextCharFormat &format);
0078     QTextCharFormat currentCharFormat() const;
0079 
0080     bool tabChangesFocus() const;
0081     void setTabChangesFocus(bool b);
0082 
0083     inline void setDocumentTitle(const QString &title)
0084     { document()->setMetaInformation(QTextDocument::DocumentTitle, title); }
0085     inline QString documentTitle() const
0086     { return document()->metaInformation(QTextDocument::DocumentTitle); }
0087 
0088     inline bool isUndoRedoEnabled() const
0089     { return document()->isUndoRedoEnabled(); }
0090     inline void setUndoRedoEnabled(bool enable)
0091     { document()->setUndoRedoEnabled(enable); }
0092 
0093     inline void setMaximumBlockCount(int maximum)
0094     { document()->setMaximumBlockCount(maximum); }
0095     inline int maximumBlockCount() const
0096     { return document()->maximumBlockCount(); }
0097 
0098 
0099     LineWrapMode lineWrapMode() const;
0100     void setLineWrapMode(LineWrapMode mode);
0101 
0102     QTextOption::WrapMode wordWrapMode() const;
0103     void setWordWrapMode(QTextOption::WrapMode policy);
0104 
0105     void setBackgroundVisible(bool visible);
0106     bool backgroundVisible() const;
0107 
0108     void setCenterOnScroll(bool enabled);
0109     bool centerOnScroll() const;
0110 
0111     bool find(const QString &exp, QTextDocument::FindFlags options = QTextDocument::FindFlags());
0112 #if QT_CONFIG(regularexpression)
0113     bool find(const QRegularExpression &exp, QTextDocument::FindFlags options = QTextDocument::FindFlags());
0114 #endif
0115 
0116     inline QString toPlainText() const
0117     { return document()->toPlainText(); }
0118 
0119     void ensureCursorVisible();
0120 
0121     virtual QVariant loadResource(int type, const QUrl &name);
0122 #ifndef QT_NO_CONTEXTMENU
0123     QMenu *createStandardContextMenu();
0124     QMenu *createStandardContextMenu(const QPoint &position);
0125 #endif
0126 
0127     QTextCursor cursorForPosition(const QPoint &pos) const;
0128     QRect cursorRect(const QTextCursor &cursor) const;
0129     QRect cursorRect() const;
0130 
0131     QString anchorAt(const QPoint &pos) const;
0132 
0133     bool overwriteMode() const;
0134     void setOverwriteMode(bool overwrite);
0135 
0136     qreal tabStopDistance() const;
0137     void setTabStopDistance(qreal distance);
0138 
0139     int cursorWidth() const;
0140     void setCursorWidth(int width);
0141 
0142     void setExtraSelections(const QList<QTextEdit::ExtraSelection> &selections);
0143     QList<QTextEdit::ExtraSelection> extraSelections() const;
0144 
0145     void moveCursor(QTextCursor::MoveOperation operation, QTextCursor::MoveMode mode = QTextCursor::MoveAnchor);
0146 
0147     bool canPaste() const;
0148 
0149     void print(QPagedPaintDevice *printer) const;
0150 
0151     int blockCount() const;
0152     QVariant inputMethodQuery(Qt::InputMethodQuery property) const override;
0153     Q_INVOKABLE QVariant inputMethodQuery(Qt::InputMethodQuery query, QVariant argument) const;
0154 
0155 public Q_SLOTS:
0156 
0157     void setPlainText(const QString &text);
0158 
0159 #ifndef QT_NO_CLIPBOARD
0160     void cut();
0161     void copy();
0162     void paste();
0163 #endif
0164 
0165     void undo();
0166     void redo();
0167 
0168     void clear();
0169     void selectAll();
0170 
0171     void insertPlainText(const QString &text);
0172 
0173     void appendPlainText(const QString &text);
0174     void appendHtml(const QString &html);
0175 
0176     void centerCursor();
0177 
0178     void zoomIn(int range = 1);
0179     void zoomOut(int range = 1);
0180 
0181 Q_SIGNALS:
0182     void textChanged();
0183     void undoAvailable(bool b);
0184     void redoAvailable(bool b);
0185     void copyAvailable(bool b);
0186     void selectionChanged();
0187     void cursorPositionChanged();
0188 
0189     void updateRequest(const QRect &rect, int dy);
0190     void blockCountChanged(int newBlockCount);
0191     void modificationChanged(bool);
0192 
0193 protected:
0194     virtual bool event(QEvent *e) override;
0195     virtual void timerEvent(QTimerEvent *e) override;
0196     virtual void keyPressEvent(QKeyEvent *e) override;
0197     virtual void keyReleaseEvent(QKeyEvent *e) override;
0198     virtual void resizeEvent(QResizeEvent *e) override;
0199     virtual void paintEvent(QPaintEvent *e) override;
0200     virtual void mousePressEvent(QMouseEvent *e) override;
0201     virtual void mouseMoveEvent(QMouseEvent *e) override;
0202     virtual void mouseReleaseEvent(QMouseEvent *e) override;
0203     virtual void mouseDoubleClickEvent(QMouseEvent *e) override;
0204     virtual bool focusNextPrevChild(bool next) override;
0205 #ifndef QT_NO_CONTEXTMENU
0206     virtual void contextMenuEvent(QContextMenuEvent *e) override;
0207 #endif
0208 #if QT_CONFIG(draganddrop)
0209     virtual void dragEnterEvent(QDragEnterEvent *e) override;
0210     virtual void dragLeaveEvent(QDragLeaveEvent *e) override;
0211     virtual void dragMoveEvent(QDragMoveEvent *e) override;
0212     virtual void dropEvent(QDropEvent *e) override;
0213 #endif
0214     virtual void focusInEvent(QFocusEvent *e) override;
0215     virtual void focusOutEvent(QFocusEvent *e) override;
0216     virtual void showEvent(QShowEvent *) override;
0217     virtual void changeEvent(QEvent *e) override;
0218 #if QT_CONFIG(wheelevent)
0219     virtual void wheelEvent(QWheelEvent *e) override;
0220 #endif
0221 
0222     virtual QMimeData *createMimeDataFromSelection() const;
0223     virtual bool canInsertFromMimeData(const QMimeData *source) const;
0224     virtual void insertFromMimeData(const QMimeData *source);
0225 
0226     virtual void inputMethodEvent(QInputMethodEvent *) override;
0227 
0228     QPlainTextEdit(QPlainTextEditPrivate &dd, QWidget *parent);
0229 
0230     virtual void scrollContentsBy(int dx, int dy) override;
0231     virtual void doSetTextCursor(const QTextCursor &cursor);
0232 
0233     QTextBlock firstVisibleBlock() const;
0234     QPointF contentOffset() const;
0235     QRectF blockBoundingRect(const QTextBlock &block) const;
0236     QRectF blockBoundingGeometry(const QTextBlock &block) const;
0237     QAbstractTextDocumentLayout::PaintContext getPaintContext() const;
0238 
0239     void zoomInF(float range);
0240 
0241 private:
0242     Q_DISABLE_COPY(QPlainTextEdit)
0243 
0244     friend class QPlainTextEditControl;
0245 };
0246 
0247 
0248 class QPlainTextDocumentLayoutPrivate;
0249 class Q_WIDGETS_EXPORT QPlainTextDocumentLayout : public QAbstractTextDocumentLayout
0250 {
0251     Q_OBJECT
0252     Q_DECLARE_PRIVATE(QPlainTextDocumentLayout)
0253     Q_PROPERTY(int cursorWidth READ cursorWidth WRITE setCursorWidth)
0254 
0255 public:
0256     QPlainTextDocumentLayout(QTextDocument *document);
0257     ~QPlainTextDocumentLayout();
0258 
0259     void draw(QPainter *, const PaintContext &) override;
0260     int hitTest(const QPointF &, Qt::HitTestAccuracy ) const override;
0261 
0262     int pageCount() const override;
0263     QSizeF documentSize() const override;
0264 
0265     QRectF frameBoundingRect(QTextFrame *) const override;
0266     QRectF blockBoundingRect(const QTextBlock &block) const override;
0267 
0268     void ensureBlockLayout(const QTextBlock &block) const;
0269 
0270     void setCursorWidth(int width);
0271     int cursorWidth() const;
0272 
0273     void requestUpdate();
0274 
0275 protected:
0276     void documentChanged(int from, int /*charsRemoved*/, int charsAdded) override;
0277 
0278 
0279 private:
0280     void setTextWidth(qreal newWidth);
0281     qreal textWidth() const;
0282     void layoutBlock(const QTextBlock &block);
0283     qreal blockWidth(const QTextBlock &block);
0284 
0285     QPlainTextDocumentLayoutPrivate *priv() const;
0286 
0287     friend class QPlainTextEdit;
0288     friend class QPlainTextEditPrivate;
0289 };
0290 
0291 QT_END_NAMESPACE
0292 
0293 #endif // QPLAINTEXTEDIT_H