1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2015 The Qt Company Ltd. 4 ** Contact: http://www.qt.io/licensing/ 5 ** 6 ** This file is part of the QtGui module of the Qt Toolkit. 7 ** 8 ** $QT_BEGIN_LICENSE:LGPL$ 9 ** Commercial License Usage 10 ** Licensees holding valid commercial Qt licenses may use this file in 11 ** accordance with the commercial license agreement provided with the 12 ** Software or, alternatively, in accordance with the terms contained in 13 ** a written agreement between you and The Qt Company. For licensing terms 14 ** and conditions see http://www.qt.io/terms-conditions. For further 15 ** information use the contact form at http://www.qt.io/contact-us. 16 ** 17 ** GNU Lesser General Public License Usage 18 ** Alternatively, this file may be used under the terms of the GNU Lesser 19 ** General Public License version 2.1 or version 3 as published by the Free 20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and 21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the 22 ** following information to ensure the GNU Lesser General Public License 23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and 24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 25 ** 26 ** As a special exception, The Qt Company gives you certain additional 27 ** rights. These rights are described in The Qt Company LGPL Exception 28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 29 ** 30 ** GNU General Public License Usage 31 ** Alternatively, this file may be used under the terms of the GNU 32 ** General Public License version 3.0 as published by the Free Software 33 ** Foundation and appearing in the file LICENSE.GPL included in the 34 ** packaging of this file. Please review the following information to 35 ** ensure the GNU General Public License version 3.0 requirements will be 36 ** met: http://www.gnu.org/copyleft/gpl.html. 37 ** 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; cursorRect(const QTextCursor & cursor)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 } cursorRect()93 inline QRectF cursorRect() { return cursorRect(textCursor()); } ensureCursorVisible()94 void ensureCursorVisible() { 95 textEdit->ensureCursorVisible(); 96 emit microFocusChanged(); 97 } 98 99 100 QPlainTextEdit *textEdit; 101 int topBlock; 102 QTextBlock firstVisibleBlock() const; 103 loadResource(int type,const QUrl & name)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 mapToContents(const QPoint & point)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 horizontalOffset()130 inline int horizontalOffset() const 131 { return (q_func()->isRightToLeft() ? (hbar->maximum() - hbar->value()) : hbar->value()); } 132 qreal verticalOffset(int topBlock, int topLine) const; 133 qreal verticalOffset() const; 134 sendControlEvent(QEvent * e)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; 154 uint clickCausedFocus : 1; 155 156 int topLine; 157 qreal topLineFracture; // for non-int sized fonts 158 159 void setTopLine(int visualTopLine, int dx = 0); 160 void setTopBlock(int newTopBlock, int newTopLine, int dx = 0); 161 162 void ensureVisible(int position, bool center, bool forceCenter = false); 163 void ensureCursorVisible(bool center = false); 164 void updateViewport(); 165 166 QPointer<QPlainTextDocumentLayout> documentLayoutPtr; 167 168 void append(const QString &text, Qt::TextFormat format = Qt::AutoText); 169 170 qreal pageUpDownLastCursorY; 171 bool pageUpDownLastCursorYIsValid; 172 173 174 #ifdef QT_KEYPAD_NAVIGATION 175 QBasicTimer deleteAllTimer; 176 #endif 177 178 void _q_cursorPositionChanged(); 179 void _q_modificationChanged(bool); 180 181 int originalOffsetY; 182 }; 183 184 QT_END_NAMESPACE 185 186 #endif // QT_NO_TEXTEDIT 187 188 #endif // QPLAINTEXTEDIT_P_H 189