[2] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
[561] | 4 | ** All rights reserved.
|
---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
---|
[2] | 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 | **
|
---|
[561] | 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.
|
---|
[2] | 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 | **
|
---|
[561] | 36 | ** If you have questions regarding the use of this file, please contact
|
---|
| 37 | ** Nokia at [email protected].
|
---|
[2] | 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()); }
|
---|
[561] | 94 | void ensureCursorVisible() {
|
---|
| 95 | textEdit->ensureCursorVisible();
|
---|
| 96 | emit microFocusChanged();
|
---|
| 97 | }
|
---|
[2] | 98 |
|
---|
| 99 |
|
---|
| 100 | QPlainTextEdit *textEdit;
|
---|
| 101 | int topBlock;
|
---|
| 102 | QTextBlock firstVisibleBlock() const;
|
---|
| 103 |
|
---|
| 104 | QVariant loadResource(int type, const QUrl &name) {
|
---|
| 105 | return textEdit->loadResource(type, name);
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | };
|
---|
| 109 |
|
---|
| 110 |
|
---|
| 111 | class QPlainTextEditPrivate : public QAbstractScrollAreaPrivate
|
---|
| 112 | {
|
---|
| 113 | Q_DECLARE_PUBLIC(QPlainTextEdit)
|
---|
| 114 | public:
|
---|
| 115 | QPlainTextEditPrivate();
|
---|
| 116 |
|
---|
| 117 | void init(const QString &txt = QString());
|
---|
| 118 | void _q_repaintContents(const QRectF &contentsRect);
|
---|
| 119 |
|
---|
| 120 | inline QPoint mapToContents(const QPoint &point) const
|
---|
| 121 | { return QPoint(point.x() + horizontalOffset(), point.y() + verticalOffset()); }
|
---|
| 122 |
|
---|
| 123 | void _q_adjustScrollbars();
|
---|
| 124 | void _q_verticalScrollbarActionTriggered(int action);
|
---|
| 125 | void ensureViewportLayouted();
|
---|
| 126 | void relayoutDocument();
|
---|
| 127 |
|
---|
| 128 | void pageUpDown(QTextCursor::MoveOperation op, QTextCursor::MoveMode moveMode, bool moveCursor = true);
|
---|
| 129 |
|
---|
| 130 | inline int horizontalOffset() const
|
---|
| 131 | { return (q_func()->isRightToLeft() ? (hbar->maximum() - hbar->value()) : hbar->value()); }
|
---|
| 132 | int verticalOffset(int topBlock, int topLine) const;
|
---|
| 133 | int verticalOffset() const;
|
---|
| 134 |
|
---|
| 135 | inline void sendControlEvent(QEvent *e)
|
---|
| 136 | { control->processEvent(e, QPointF(horizontalOffset(), verticalOffset()), viewport); }
|
---|
| 137 |
|
---|
| 138 | void updateDefaultTextOption();
|
---|
| 139 |
|
---|
| 140 | QPlainTextEditControl *control;
|
---|
| 141 |
|
---|
| 142 | bool tabChangesFocus;
|
---|
| 143 |
|
---|
| 144 | QBasicTimer autoScrollTimer;
|
---|
| 145 | QPoint autoScrollDragPos;
|
---|
| 146 |
|
---|
| 147 | QPlainTextEdit::LineWrapMode lineWrap;
|
---|
| 148 | QTextOption::WrapMode wordWrap;
|
---|
| 149 |
|
---|
| 150 | uint showCursorOnInitialShow : 1;
|
---|
| 151 | uint backgroundVisible : 1;
|
---|
| 152 | uint centerOnScroll : 1;
|
---|
| 153 | uint inDrag : 1;
|
---|
[561] | 154 | uint clickCausedFocus : 1;
|
---|
[2] | 155 |
|
---|
| 156 | int topLine;
|
---|
| 157 |
|
---|
| 158 | void setTopLine(int visualTopLine, int dx = 0);
|
---|
| 159 | void setTopBlock(int newTopBlock, int newTopLine, int dx = 0);
|
---|
| 160 |
|
---|
| 161 | void ensureVisible(int position, bool center, bool forceCenter = false);
|
---|
| 162 | void ensureCursorVisible(bool center = false);
|
---|
| 163 | void updateViewport();
|
---|
| 164 |
|
---|
| 165 | QPointer<QPlainTextDocumentLayout> documentLayoutPtr;
|
---|
| 166 |
|
---|
| 167 | void append(const QString &text, Qt::TextFormat format = Qt::AutoText);
|
---|
| 168 |
|
---|
| 169 | qreal pageUpDownLastCursorY;
|
---|
| 170 | bool pageUpDownLastCursorYIsValid;
|
---|
| 171 |
|
---|
| 172 |
|
---|
| 173 | #ifdef QT_KEYPAD_NAVIGATION
|
---|
| 174 | QBasicTimer deleteAllTimer;
|
---|
| 175 | #endif
|
---|
| 176 |
|
---|
| 177 | void _q_cursorPositionChanged();
|
---|
[561] | 178 | void _q_modificationChanged(bool);
|
---|
[2] | 179 |
|
---|
[561] | 180 | int originalOffsetY;
|
---|
[2] | 181 | };
|
---|
| 182 |
|
---|
| 183 | QT_END_NAMESPACE
|
---|
| 184 |
|
---|
| 185 | #endif // QT_NO_TEXTEDIT
|
---|
| 186 |
|
---|
| 187 | #endif // QPLAINTEXTEDIT_P_H
|
---|