1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the QtGui module of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** 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 are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #ifndef QPLAINTEXTEDIT_P_H
|
---|
43 | #define QPLAINTEXTEDIT_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 "private/qabstractscrollarea_p.h"
|
---|
57 | #include "QtGui/qtextdocumentfragment.h"
|
---|
58 | #include "QtGui/qscrollbar.h"
|
---|
59 | #include "QtGui/qtextcursor.h"
|
---|
60 | #include "QtGui/qtextformat.h"
|
---|
61 | #include "QtGui/qmenu.h"
|
---|
62 | #include "QtGui/qabstracttextdocumentlayout.h"
|
---|
63 | #include "QtCore/qbasictimer.h"
|
---|
64 | #include "private/qtextcontrol_p.h"
|
---|
65 | #include "qplaintextedit.h"
|
---|
66 |
|
---|
67 | #ifndef QT_NO_TEXTEDIT
|
---|
68 |
|
---|
69 | QT_BEGIN_NAMESPACE
|
---|
70 |
|
---|
71 | class QMimeData;
|
---|
72 |
|
---|
73 | class QPlainTextEdit;
|
---|
74 | class ExtraArea;
|
---|
75 |
|
---|
76 | class QPlainTextEditControl : public QTextControl
|
---|
77 | {
|
---|
78 | Q_OBJECT
|
---|
79 | public:
|
---|
80 | QPlainTextEditControl(QPlainTextEdit *parent);
|
---|
81 |
|
---|
82 |
|
---|
83 | QMimeData *createMimeDataFromSelection() const;
|
---|
84 | bool canInsertFromMimeData(const QMimeData *source) const;
|
---|
85 | void insertFromMimeData(const QMimeData *source);
|
---|
86 | int hitTest(const QPointF &point, Qt::HitTestAccuracy = Qt::FuzzyHit) const;
|
---|
87 | QRectF blockBoundingRect(const QTextBlock &block) const;
|
---|
88 | inline QRectF cursorRect(const QTextCursor &cursor) const {
|
---|
89 | QRectF r = QTextControl::cursorRect(cursor);
|
---|
90 | r.setLeft(qMax(r.left(), (qreal) 0.));
|
---|
91 | return r;
|
---|
92 | }
|
---|
93 | inline QRectF cursorRect() { return cursorRect(textCursor()); }
|
---|
94 | void ensureCursorVisible() { textEdit->ensureCursorVisible(); }
|
---|
95 |
|
---|
96 |
|
---|
97 | QPlainTextEdit *textEdit;
|
---|
98 | int topBlock;
|
---|
99 | QTextBlock firstVisibleBlock() const;
|
---|
100 |
|
---|
101 | QVariant loadResource(int type, const QUrl &name) {
|
---|
102 | return textEdit->loadResource(type, name);
|
---|
103 | }
|
---|
104 |
|
---|
105 | };
|
---|
106 |
|
---|
107 |
|
---|
108 | class QPlainTextEditPrivate : public QAbstractScrollAreaPrivate
|
---|
109 | {
|
---|
110 | Q_DECLARE_PUBLIC(QPlainTextEdit)
|
---|
111 | public:
|
---|
112 | QPlainTextEditPrivate();
|
---|
113 |
|
---|
114 | void init(const QString &txt = QString());
|
---|
115 | void _q_repaintContents(const QRectF &contentsRect);
|
---|
116 |
|
---|
117 | inline QPoint mapToContents(const QPoint &point) const
|
---|
118 | { return QPoint(point.x() + horizontalOffset(), point.y() + verticalOffset()); }
|
---|
119 |
|
---|
120 | void _q_adjustScrollbars();
|
---|
121 | void _q_verticalScrollbarActionTriggered(int action);
|
---|
122 | void ensureViewportLayouted();
|
---|
123 | void relayoutDocument();
|
---|
124 |
|
---|
125 | void pageUpDown(QTextCursor::MoveOperation op, QTextCursor::MoveMode moveMode, bool moveCursor = true);
|
---|
126 |
|
---|
127 | inline int horizontalOffset() const
|
---|
128 | { return (q_func()->isRightToLeft() ? (hbar->maximum() - hbar->value()) : hbar->value()); }
|
---|
129 | int verticalOffset(int topBlock, int topLine) const;
|
---|
130 | int verticalOffset() const;
|
---|
131 |
|
---|
132 | inline void sendControlEvent(QEvent *e)
|
---|
133 | { control->processEvent(e, QPointF(horizontalOffset(), verticalOffset()), viewport); }
|
---|
134 |
|
---|
135 | void updateDefaultTextOption();
|
---|
136 |
|
---|
137 | QPlainTextEditControl *control;
|
---|
138 |
|
---|
139 | bool tabChangesFocus;
|
---|
140 |
|
---|
141 | QBasicTimer autoScrollTimer;
|
---|
142 | QPoint autoScrollDragPos;
|
---|
143 |
|
---|
144 | QPlainTextEdit::LineWrapMode lineWrap;
|
---|
145 | QTextOption::WrapMode wordWrap;
|
---|
146 |
|
---|
147 | uint showCursorOnInitialShow : 1;
|
---|
148 | uint backgroundVisible : 1;
|
---|
149 | uint centerOnScroll : 1;
|
---|
150 | uint inDrag : 1;
|
---|
151 |
|
---|
152 | int topLine;
|
---|
153 |
|
---|
154 | void setTopLine(int visualTopLine, int dx = 0);
|
---|
155 | void setTopBlock(int newTopBlock, int newTopLine, int dx = 0);
|
---|
156 |
|
---|
157 | void ensureVisible(int position, bool center, bool forceCenter = false);
|
---|
158 | void ensureCursorVisible(bool center = false);
|
---|
159 | void updateViewport();
|
---|
160 |
|
---|
161 | QPointer<QPlainTextDocumentLayout> documentLayoutPtr;
|
---|
162 |
|
---|
163 | void append(const QString &text, Qt::TextFormat format = Qt::AutoText);
|
---|
164 |
|
---|
165 | qreal pageUpDownLastCursorY;
|
---|
166 | bool pageUpDownLastCursorYIsValid;
|
---|
167 |
|
---|
168 |
|
---|
169 | #ifdef QT_KEYPAD_NAVIGATION
|
---|
170 | QBasicTimer deleteAllTimer;
|
---|
171 | #endif
|
---|
172 |
|
---|
173 | void _q_cursorPositionChanged();
|
---|
174 |
|
---|
175 | void _q_modificationChanged(bool);
|
---|
176 | };
|
---|
177 |
|
---|
178 | QT_END_NAMESPACE
|
---|
179 |
|
---|
180 | #endif // QT_NO_TEXTEDIT
|
---|
181 |
|
---|
182 | #endif // QPLAINTEXTEDIT_P_H
|
---|