| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
|---|
| 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 | **
|
|---|
| 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 | ** 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 have questions regarding the use of this file, please contact
|
|---|
| 37 | ** Nokia at [email protected].
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #ifndef QTEXTCONTROL_P_H
|
|---|
| 43 | #define QTEXTCONTROL_P_H
|
|---|
| 44 |
|
|---|
| 45 | //
|
|---|
| 46 | // W A R N I N G
|
|---|
| 47 | // -------------
|
|---|
| 48 | //
|
|---|
| 49 | // This file is not part of the Qt API. It exists purely as an
|
|---|
| 50 | // implementation detail. This header file may change from version to
|
|---|
| 51 | // version without notice, or even be removed.
|
|---|
| 52 | //
|
|---|
| 53 | // We mean it.
|
|---|
| 54 | //
|
|---|
| 55 |
|
|---|
| 56 | #include <QtGui/qtextdocument.h>
|
|---|
| 57 | #include <QtGui/qtextoption.h>
|
|---|
| 58 | #include <QtGui/qtextcursor.h>
|
|---|
| 59 | #include <QtGui/qtextformat.h>
|
|---|
| 60 | #include <QtGui/qtextedit.h>
|
|---|
| 61 | #include <QtGui/qmenu.h>
|
|---|
| 62 | #include <QtCore/qrect.h>
|
|---|
| 63 | #include <QtGui/qabstracttextdocumentlayout.h>
|
|---|
| 64 | #include <QtGui/qtextdocumentfragment.h>
|
|---|
| 65 | #include <QtGui/qclipboard.h>
|
|---|
| 66 |
|
|---|
| 67 | #ifdef QT3_SUPPORT
|
|---|
| 68 | #include <QtGui/qtextobject.h>
|
|---|
| 69 | #include <QtGui/qtextlayout.h>
|
|---|
| 70 | #endif
|
|---|
| 71 |
|
|---|
| 72 | QT_BEGIN_HEADER
|
|---|
| 73 |
|
|---|
| 74 | QT_BEGIN_NAMESPACE
|
|---|
| 75 |
|
|---|
| 76 | QT_MODULE(Gui)
|
|---|
| 77 |
|
|---|
| 78 | class QStyleSheet;
|
|---|
| 79 | class QTextDocument;
|
|---|
| 80 | class QMenu;
|
|---|
| 81 | class QTextControlPrivate;
|
|---|
| 82 | class QMimeData;
|
|---|
| 83 | class QAbstractScrollArea;
|
|---|
| 84 | class QEvent;
|
|---|
| 85 | class QTimerEvent;
|
|---|
| 86 |
|
|---|
| 87 | class Q_GUI_EXPORT QTextControl : public QObject
|
|---|
| 88 | {
|
|---|
| 89 | Q_OBJECT
|
|---|
| 90 | Q_DECLARE_PRIVATE(QTextControl)
|
|---|
| 91 | #ifndef QT_NO_TEXTHTMLPARSER
|
|---|
| 92 | Q_PROPERTY(QString html READ toHtml WRITE setHtml NOTIFY textChanged USER true)
|
|---|
| 93 | #endif
|
|---|
| 94 | Q_PROPERTY(bool overwriteMode READ overwriteMode WRITE setOverwriteMode)
|
|---|
| 95 | Q_PROPERTY(bool acceptRichText READ acceptRichText WRITE setAcceptRichText)
|
|---|
| 96 | Q_PROPERTY(int cursorWidth READ cursorWidth WRITE setCursorWidth)
|
|---|
| 97 | Q_PROPERTY(Qt::TextInteractionFlags textInteractionFlags READ textInteractionFlags WRITE setTextInteractionFlags)
|
|---|
| 98 | Q_PROPERTY(bool openExternalLinks READ openExternalLinks WRITE setOpenExternalLinks)
|
|---|
| 99 | Q_PROPERTY(bool ignoreUnusedNavigationEvents READ ignoreUnusedNavigationEvents WRITE setIgnoreUnusedNavigationEvents)
|
|---|
| 100 | public:
|
|---|
| 101 | explicit QTextControl(QObject *parent = 0);
|
|---|
| 102 | explicit QTextControl(const QString &text, QObject *parent = 0);
|
|---|
| 103 | explicit QTextControl(QTextDocument *doc, QObject *parent = 0);
|
|---|
| 104 | virtual ~QTextControl();
|
|---|
| 105 |
|
|---|
| 106 | void setDocument(QTextDocument *document);
|
|---|
| 107 | QTextDocument *document() const;
|
|---|
| 108 |
|
|---|
| 109 | void setTextCursor(const QTextCursor &cursor);
|
|---|
| 110 | QTextCursor textCursor() const;
|
|---|
| 111 |
|
|---|
| 112 | void setTextInteractionFlags(Qt::TextInteractionFlags flags);
|
|---|
| 113 | Qt::TextInteractionFlags textInteractionFlags() const;
|
|---|
| 114 |
|
|---|
| 115 | void mergeCurrentCharFormat(const QTextCharFormat &modifier);
|
|---|
| 116 |
|
|---|
| 117 | void setCurrentCharFormat(const QTextCharFormat &format);
|
|---|
| 118 | QTextCharFormat currentCharFormat() const;
|
|---|
| 119 |
|
|---|
| 120 | bool find(const QString &exp, QTextDocument::FindFlags options = 0);
|
|---|
| 121 |
|
|---|
| 122 | inline QString toPlainText() const
|
|---|
| 123 | { return document()->toPlainText(); }
|
|---|
| 124 | #ifndef QT_NO_TEXTHTMLPARSER
|
|---|
| 125 | inline QString toHtml() const
|
|---|
| 126 | { return document()->toHtml(); }
|
|---|
| 127 | #endif
|
|---|
| 128 |
|
|---|
| 129 | virtual void ensureCursorVisible();
|
|---|
| 130 |
|
|---|
| 131 | virtual QVariant loadResource(int type, const QUrl &name);
|
|---|
| 132 | #ifndef QT_NO_CONTEXTMENU
|
|---|
| 133 | QMenu *createStandardContextMenu(const QPointF &pos, QWidget *parent);
|
|---|
| 134 | #endif
|
|---|
| 135 |
|
|---|
| 136 | QTextCursor cursorForPosition(const QPointF &pos) const;
|
|---|
| 137 | QRectF cursorRect(const QTextCursor &cursor) const;
|
|---|
| 138 | QRectF cursorRect() const;
|
|---|
| 139 | QRectF selectionRect(const QTextCursor &cursor) const;
|
|---|
| 140 | QRectF selectionRect() const;
|
|---|
| 141 |
|
|---|
| 142 | QString anchorAt(const QPointF &pos) const;
|
|---|
| 143 | QPointF anchorPosition(const QString &name) const;
|
|---|
| 144 |
|
|---|
| 145 | QString anchorAtCursor() const;
|
|---|
| 146 |
|
|---|
| 147 | bool overwriteMode() const;
|
|---|
| 148 | void setOverwriteMode(bool overwrite);
|
|---|
| 149 |
|
|---|
| 150 | int cursorWidth() const;
|
|---|
| 151 | void setCursorWidth(int width);
|
|---|
| 152 |
|
|---|
| 153 | bool acceptRichText() const;
|
|---|
| 154 | void setAcceptRichText(bool accept);
|
|---|
| 155 |
|
|---|
| 156 | #ifndef QT_NO_TEXTEDIT
|
|---|
| 157 | void setExtraSelections(const QList<QTextEdit::ExtraSelection> &selections);
|
|---|
| 158 | QList<QTextEdit::ExtraSelection> extraSelections() const;
|
|---|
| 159 | #endif
|
|---|
| 160 |
|
|---|
| 161 | void setTextWidth(qreal width);
|
|---|
| 162 | qreal textWidth() const;
|
|---|
| 163 | QSizeF size() const;
|
|---|
| 164 |
|
|---|
| 165 | void setOpenExternalLinks(bool open);
|
|---|
| 166 | bool openExternalLinks() const;
|
|---|
| 167 |
|
|---|
| 168 | void setIgnoreUnusedNavigationEvents(bool ignore);
|
|---|
| 169 | bool ignoreUnusedNavigationEvents() const;
|
|---|
| 170 |
|
|---|
| 171 | void moveCursor(QTextCursor::MoveOperation op, QTextCursor::MoveMode mode = QTextCursor::MoveAnchor);
|
|---|
| 172 |
|
|---|
| 173 | bool canPaste() const;
|
|---|
| 174 |
|
|---|
| 175 | void setCursorIsFocusIndicator(bool b);
|
|---|
| 176 | bool cursorIsFocusIndicator() const;
|
|---|
| 177 |
|
|---|
| 178 | #ifndef QT_NO_PRINTER
|
|---|
| 179 | void print(QPrinter *printer) const;
|
|---|
| 180 | #endif
|
|---|
| 181 |
|
|---|
| 182 | virtual int hitTest(const QPointF &point, Qt::HitTestAccuracy accuracy) const;
|
|---|
| 183 | virtual QRectF blockBoundingRect(const QTextBlock &block) const;
|
|---|
| 184 | QAbstractTextDocumentLayout::PaintContext getPaintContext(QWidget *widget) const;
|
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 |
|
|---|
| 188 | public Q_SLOTS:
|
|---|
| 189 | void setPlainText(const QString &text);
|
|---|
| 190 | void setHtml(const QString &text);
|
|---|
| 191 |
|
|---|
| 192 | #ifndef QT_NO_CLIPBOARD
|
|---|
| 193 | void cut();
|
|---|
| 194 | void copy();
|
|---|
| 195 | void paste(QClipboard::Mode mode = QClipboard::Clipboard);
|
|---|
| 196 | #endif
|
|---|
| 197 |
|
|---|
| 198 | void undo();
|
|---|
| 199 | void redo();
|
|---|
| 200 |
|
|---|
| 201 | void clear();
|
|---|
| 202 | void selectAll();
|
|---|
| 203 |
|
|---|
| 204 | void insertPlainText(const QString &text);
|
|---|
| 205 | #ifndef QT_NO_TEXTHTMLPARSER
|
|---|
| 206 | void insertHtml(const QString &text);
|
|---|
| 207 | #endif
|
|---|
| 208 |
|
|---|
| 209 | void append(const QString &text);
|
|---|
| 210 | void appendHtml(const QString &html);
|
|---|
| 211 | void appendPlainText(const QString &text);
|
|---|
| 212 |
|
|---|
| 213 | void adjustSize();
|
|---|
| 214 |
|
|---|
| 215 | Q_SIGNALS:
|
|---|
| 216 | void textChanged();
|
|---|
| 217 | void undoAvailable(bool b);
|
|---|
| 218 | void redoAvailable(bool b);
|
|---|
| 219 | void currentCharFormatChanged(const QTextCharFormat &format);
|
|---|
| 220 | void copyAvailable(bool b);
|
|---|
| 221 | void selectionChanged();
|
|---|
| 222 | void cursorPositionChanged();
|
|---|
| 223 |
|
|---|
| 224 | // control signals
|
|---|
| 225 | void updateRequest(const QRectF &rect = QRectF());
|
|---|
| 226 | void documentSizeChanged(const QSizeF &);
|
|---|
| 227 | void blockCountChanged(int newBlockCount);
|
|---|
| 228 | void visibilityRequest(const QRectF &rect);
|
|---|
| 229 | void microFocusChanged();
|
|---|
| 230 | void linkActivated(const QString &link);
|
|---|
| 231 | void linkHovered(const QString &);
|
|---|
| 232 | void modificationChanged(bool m);
|
|---|
| 233 |
|
|---|
| 234 | public:
|
|---|
| 235 | // control properties
|
|---|
| 236 | QPalette palette() const;
|
|---|
| 237 | void setPalette(const QPalette &pal);
|
|---|
| 238 |
|
|---|
| 239 | virtual void processEvent(QEvent *e, const QMatrix &matrix, QWidget *contextWidget = 0);
|
|---|
| 240 | void processEvent(QEvent *e, const QPointF &coordinateOffset = QPointF(), QWidget *contextWidget = 0);
|
|---|
| 241 |
|
|---|
| 242 | // control methods
|
|---|
| 243 | void drawContents(QPainter *painter, const QRectF &rect = QRectF(), QWidget *widget = 0);
|
|---|
| 244 |
|
|---|
| 245 | void setFocus(bool focus, Qt::FocusReason = Qt::OtherFocusReason);
|
|---|
| 246 |
|
|---|
| 247 | virtual QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
|
|---|
| 248 |
|
|---|
| 249 | virtual QMimeData *createMimeDataFromSelection() const;
|
|---|
| 250 | virtual bool canInsertFromMimeData(const QMimeData *source) const;
|
|---|
| 251 | virtual void insertFromMimeData(const QMimeData *source);
|
|---|
| 252 |
|
|---|
| 253 | bool setFocusToAnchor(const QTextCursor &newCursor);
|
|---|
| 254 | bool setFocusToNextOrPreviousAnchor(bool next);
|
|---|
| 255 | bool findNextPrevAnchor(const QTextCursor& from, bool next, QTextCursor& newAnchor);
|
|---|
| 256 |
|
|---|
| 257 | protected:
|
|---|
| 258 | virtual void timerEvent(QTimerEvent *e);
|
|---|
| 259 |
|
|---|
| 260 | virtual bool event(QEvent *e);
|
|---|
| 261 |
|
|---|
| 262 | private:
|
|---|
| 263 | Q_DISABLE_COPY(QTextControl)
|
|---|
| 264 | Q_PRIVATE_SLOT(d_func(), void _q_updateCurrentCharFormatAndSelection())
|
|---|
| 265 | Q_PRIVATE_SLOT(d_func(), void _q_emitCursorPosChanged(const QTextCursor &))
|
|---|
| 266 | Q_PRIVATE_SLOT(d_func(), void _q_deleteSelected())
|
|---|
| 267 | Q_PRIVATE_SLOT(d_func(), void _q_copyLink())
|
|---|
| 268 | Q_PRIVATE_SLOT(d_func(), void _q_updateBlock(const QTextBlock &))
|
|---|
| 269 | Q_PRIVATE_SLOT(d_func(), void _q_documentLayoutChanged())
|
|---|
| 270 | };
|
|---|
| 271 |
|
|---|
| 272 |
|
|---|
| 273 | #ifndef QT_NO_CONTEXTMENU
|
|---|
| 274 | class QUnicodeControlCharacterMenu : public QMenu
|
|---|
| 275 | {
|
|---|
| 276 | Q_OBJECT
|
|---|
| 277 | public:
|
|---|
| 278 | QUnicodeControlCharacterMenu(QObject *editWidget, QWidget *parent);
|
|---|
| 279 |
|
|---|
| 280 | private Q_SLOTS:
|
|---|
| 281 | void menuActionTriggered();
|
|---|
| 282 |
|
|---|
| 283 | private:
|
|---|
| 284 | QObject *editWidget;
|
|---|
| 285 | };
|
|---|
| 286 | #endif // QT_NO_CONTEXTMENU
|
|---|
| 287 |
|
|---|
| 288 |
|
|---|
| 289 | // also used by QLabel
|
|---|
| 290 | class QTextEditMimeData : public QMimeData
|
|---|
| 291 | {
|
|---|
| 292 | public:
|
|---|
| 293 | inline QTextEditMimeData(const QTextDocumentFragment &aFragment) : fragment(aFragment) {}
|
|---|
| 294 |
|
|---|
| 295 | virtual QStringList formats() const;
|
|---|
| 296 | protected:
|
|---|
| 297 | virtual QVariant retrieveData(const QString &mimeType, QVariant::Type type) const;
|
|---|
| 298 | private:
|
|---|
| 299 | void setup() const;
|
|---|
| 300 |
|
|---|
| 301 | mutable QTextDocumentFragment fragment;
|
|---|
| 302 | };
|
|---|
| 303 |
|
|---|
| 304 | QT_END_NAMESPACE
|
|---|
| 305 |
|
|---|
| 306 | QT_END_HEADER
|
|---|
| 307 |
|
|---|
| 308 | #endif // QTEXTCONTROL_H
|
|---|