OSDN Git Service

remove redundant QTextControl::event() reimplementation
[kde/Katie.git] / src / gui / text / qtextcontrol_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Copyright (C) 2016 Ivailo Monev
5 **
6 ** This file is part of the QtGui module of the Katie Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 **
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser
12 ** General Public License version 2.1 as published by the Free Software
13 ** Foundation and appearing in the file LICENSE.LGPL included in the
14 ** packaging of this file.  Please review the following information to
15 ** ensure the GNU Lesser General Public License version 2.1 requirements
16 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** $QT_END_LICENSE$
19 **
20 ****************************************************************************/
21
22 #ifndef QTEXTCONTROL_P_H
23 #define QTEXTCONTROL_P_H
24
25 //
26 //  W A R N I N G
27 //  -------------
28 //
29 // This file is not part of the Katie API.  It exists purely as an
30 // implementation detail.  This header file may change from version to
31 // version without notice, or even be removed.
32 //
33 // We mean it.
34 //
35
36 #include <QtGui/qtextdocument.h>
37 #include <QtGui/qtextoption.h>
38 #include <QtGui/qtextcursor.h>
39 #include <QtGui/qtextformat.h>
40 #include <QtGui/qtextedit.h>
41 #include <QtGui/qmenu.h>
42 #include <QtCore/qrect.h>
43 #include <QtGui/qabstracttextdocumentlayout.h>
44 #include <QtGui/qtextdocumentfragment.h>
45 #include <QtGui/qclipboard.h>
46
47
48
49 QT_BEGIN_NAMESPACE
50
51 class QTextDocument;
52 class QTextControlPrivate;
53 class QMimeData;
54 class QEvent;
55 class QTimerEvent;
56
57 class Q_GUI_EXPORT QTextControl : public QObject
58 {
59     Q_OBJECT
60     Q_DECLARE_PRIVATE(QTextControl)
61 #ifndef QT_NO_TEXTHTMLPARSER
62     Q_PROPERTY(QString html READ toHtml WRITE setHtml NOTIFY textChanged USER true)
63 #endif
64     Q_PROPERTY(bool overwriteMode READ overwriteMode WRITE setOverwriteMode)
65     Q_PROPERTY(bool acceptRichText READ acceptRichText WRITE setAcceptRichText)
66     Q_PROPERTY(int cursorWidth READ cursorWidth WRITE setCursorWidth)
67     Q_PROPERTY(Qt::TextInteractionFlags textInteractionFlags READ textInteractionFlags WRITE setTextInteractionFlags)
68     Q_PROPERTY(bool openExternalLinks READ openExternalLinks WRITE setOpenExternalLinks)
69     Q_PROPERTY(bool ignoreUnusedNavigationEvents READ ignoreUnusedNavigationEvents WRITE setIgnoreUnusedNavigationEvents)
70 public:
71     explicit QTextControl(QObject *parent = nullptr);
72     explicit QTextControl(const QString &text, QObject *parent = nullptr);
73     explicit QTextControl(QTextDocument *doc, QObject *parent = nullptr);
74     virtual ~QTextControl();
75
76     void setDocument(QTextDocument *document);
77     QTextDocument *document() const;
78
79     void setTextCursor(const QTextCursor &cursor);
80     QTextCursor textCursor() const;
81
82     void setTextInteractionFlags(Qt::TextInteractionFlags flags);
83     Qt::TextInteractionFlags textInteractionFlags() const;
84
85     void mergeCurrentCharFormat(const QTextCharFormat &modifier);
86
87     void setCurrentCharFormat(const QTextCharFormat &format);
88     QTextCharFormat currentCharFormat() const;
89
90     bool find(const QString &exp, QTextDocument::FindFlags options = 0);
91
92     inline QString toPlainText() const
93     { return document()->toPlainText(); }
94 #ifndef QT_NO_TEXTHTMLPARSER
95     inline QString toHtml() const
96     { return document()->toHtml(); }
97 #endif
98
99     virtual void ensureCursorVisible();
100
101     virtual QVariant loadResource(int type, const QUrl &name);
102 #ifndef QT_NO_CONTEXTMENU
103     QMenu *createStandardContextMenu(const QPointF &pos, QWidget *parent);
104 #endif
105
106     QTextCursor cursorForPosition(const QPointF &pos) const;
107     QRectF cursorRect(const QTextCursor &cursor) const;
108     QRectF cursorRect() const;
109     QRectF selectionRect(const QTextCursor &cursor) const;
110     QRectF selectionRect() const;
111
112     QString anchorAt(const QPointF &pos) const;
113     QPointF anchorPosition(const QString &name) const;
114
115     QString anchorAtCursor() const;
116
117     bool overwriteMode() const;
118     void setOverwriteMode(bool overwrite);
119
120     int cursorWidth() const;
121     void setCursorWidth(int width);
122
123     bool acceptRichText() const;
124     void setAcceptRichText(bool accept);
125
126 #ifndef QT_NO_TEXTEDIT
127     void setExtraSelections(const QList<QTextEdit::ExtraSelection> &selections);
128     QList<QTextEdit::ExtraSelection> extraSelections() const;
129 #endif
130
131     void setTextWidth(qreal width);
132     qreal textWidth() const;
133     QSizeF size() const;
134
135     void setOpenExternalLinks(bool open);
136     bool openExternalLinks() const;
137
138     void setIgnoreUnusedNavigationEvents(bool ignore);
139     bool ignoreUnusedNavigationEvents() const;
140
141     void moveCursor(QTextCursor::MoveOperation op, QTextCursor::MoveMode mode = QTextCursor::MoveAnchor);
142
143     bool canPaste() const;
144
145     void setCursorIsFocusIndicator(bool b);
146     bool cursorIsFocusIndicator() const;
147
148     void setDragEnabled(bool enabled);
149     bool isDragEnabled() const;
150
151     bool isWordSelectionEnabled() const;
152     void setWordSelectionEnabled(bool enabled);
153
154 #ifndef QT_NO_PRINTER
155     void print(QPrinter *printer) const;
156 #endif
157
158     virtual int hitTest(const QPointF &point, Qt::HitTestAccuracy accuracy) const;
159     virtual QRectF blockBoundingRect(const QTextBlock &block) const;
160     QAbstractTextDocumentLayout::PaintContext getPaintContext(QWidget *widget) const;
161
162 public Q_SLOTS:
163     void setPlainText(const QString &text);
164     void setHtml(const QString &text);
165
166 #ifndef QT_NO_CLIPBOARD
167     void cut();
168     void copy();
169     void paste(QClipboard::Mode mode = QClipboard::Clipboard);
170 #endif
171
172     void undo();
173     void redo();
174
175     void clear();
176     void selectAll();
177
178     void insertPlainText(const QString &text);
179 #ifndef QT_NO_TEXTHTMLPARSER
180     void insertHtml(const QString &text);
181 #endif
182
183     void append(const QString &text);
184     void appendHtml(const QString &html);
185     void appendPlainText(const QString &text);
186
187     void adjustSize();
188
189 Q_SIGNALS:
190     void textChanged();
191     void undoAvailable(bool b);
192     void redoAvailable(bool b);
193     void currentCharFormatChanged(const QTextCharFormat &format);
194     void copyAvailable(bool b);
195     void selectionChanged();
196     void cursorPositionChanged();
197
198     // control signals
199     void updateRequest(const QRectF &rect = QRectF());
200     void documentSizeChanged(const QSizeF &);
201     void blockCountChanged(int newBlockCount);
202     void visibilityRequest(const QRectF &rect);
203     void linkActivated(const QString &link);
204     void linkHovered(const QString &);
205     void modificationChanged(bool m);
206
207 public:
208     // control properties
209     QPalette palette() const;
210     void setPalette(const QPalette &pal);
211
212     virtual void processEvent(QEvent *e, const QMatrix &matrix, QWidget *contextWidget = 0);
213     void processEvent(QEvent *e, const QPointF &coordinateOffset = QPointF(), QWidget *contextWidget = 0);
214
215     // control methods
216     void drawContents(QPainter *painter, const QRectF &rect = QRectF(), QWidget *widget = 0);
217
218     void setFocus(bool focus, Qt::FocusReason = Qt::OtherFocusReason);
219
220     virtual QMimeData *createMimeDataFromSelection() const;
221     virtual bool canInsertFromMimeData(const QMimeData *source) const;
222     virtual void insertFromMimeData(const QMimeData *source);
223
224     bool setFocusToAnchor(const QTextCursor &newCursor);
225     bool setFocusToNextOrPreviousAnchor(bool next);
226     bool findNextPrevAnchor(const QTextCursor& from, bool next, QTextCursor& newAnchor);
227
228 protected:
229     virtual void timerEvent(QTimerEvent *e);
230
231 private:
232     Q_DISABLE_COPY(QTextControl)
233     Q_PRIVATE_SLOT(d_func(), void _q_updateCurrentCharFormatAndSelection())
234     Q_PRIVATE_SLOT(d_func(), void _q_emitCursorPosChanged(const QTextCursor &))
235     Q_PRIVATE_SLOT(d_func(), void _q_deleteSelected())
236     Q_PRIVATE_SLOT(d_func(), void _q_copyLink())
237     Q_PRIVATE_SLOT(d_func(), void _q_updateBlock(const QTextBlock &))
238     Q_PRIVATE_SLOT(d_func(), void _q_documentLayoutChanged())
239 };
240
241
242 #ifndef QT_NO_CONTEXTMENU
243 class QUnicodeControlCharacterMenu : public QMenu
244 {
245     Q_OBJECT
246 public:
247     QUnicodeControlCharacterMenu(QObject *editWidget, QWidget *parent);
248
249 private Q_SLOTS:
250     void menuActionTriggered();
251
252 private:
253     QObject *editWidget;
254 };
255 #endif // QT_NO_CONTEXTMENU
256
257
258 // also used by QLabel
259 class QTextEditMimeData : public QMimeData
260 {
261 public:
262     inline QTextEditMimeData(const QTextDocumentFragment &aFragment) : fragment(aFragment) {}
263
264     virtual QStringList formats() const;
265 protected:
266     virtual QVariant retrieveData(const QString &mimeType, QVariant::Type type) const;
267 private:
268     void setup() const;
269
270     mutable QTextDocumentFragment fragment;
271 };
272
273 QT_END_NAMESPACE
274
275
276 #endif // QTEXTCONTROL_H