2011-04-27 12:13:26 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2013-01-02 11:17:46 +00:00
|
|
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
2012-09-20 05:21:40 +00:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2011-04-27 12:13:26 +00:00
|
|
|
**
|
2013-09-30 05:28:31 +00:00
|
|
|
** This file is part of the QtQuick module of the Qt Toolkit.
|
2011-04-27 12:13:26 +00:00
|
|
|
**
|
|
|
|
** $QT_BEGIN_LICENSE:LGPL$
|
2012-09-20 05:21:40 +00:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
|
|
|
**
|
2011-04-27 12:13:26 +00:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-09-20 05:21:40 +00:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2011-04-27 12:13:26 +00:00
|
|
|
**
|
2012-09-20 05:21:40 +00:00
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2011-04-27 12:13:26 +00:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
2011-07-07 12:52:03 +00:00
|
|
|
** GNU General Public License Usage
|
2012-09-20 05:21:40 +00:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3.0 as published by the Free Software
|
|
|
|
** Foundation and appearing in the file LICENSE.GPL included in the
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
** ensure the GNU General Public License version 3.0 requirements will be
|
|
|
|
** met: http://www.gnu.org/copyleft/gpl.html.
|
2011-04-27 12:13:26 +00:00
|
|
|
**
|
2012-01-24 03:37:23 +00:00
|
|
|
**
|
2011-04-27 12:13:26 +00:00
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
#ifndef QQUICKTEXTEDIT_P_P_H
|
|
|
|
#define QQUICKTEXTEDIT_P_P_H
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// W A R N I N G
|
|
|
|
// -------------
|
|
|
|
//
|
|
|
|
// This file is not part of the Qt API. It exists purely as an
|
|
|
|
// implementation detail. This header file may change from version to
|
|
|
|
// version without notice, or even be removed.
|
|
|
|
//
|
|
|
|
// We mean it.
|
|
|
|
//
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
#include "qquicktextedit_p.h"
|
|
|
|
#include "qquickimplicitsizeitem_p_p.h"
|
2012-05-04 06:07:32 +00:00
|
|
|
#include "qquicktextcontrol_p.h"
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
#include <QtQml/qqml.h>
|
2013-03-18 15:25:59 +00:00
|
|
|
#include <QtCore/qlist.h>
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
class QTextLayout;
|
2011-12-05 01:36:55 +00:00
|
|
|
class QQuickTextDocumentWithImageResources;
|
2011-11-10 04:58:17 +00:00
|
|
|
class QQuickTextControl;
|
2013-03-18 15:25:59 +00:00
|
|
|
class QQuickTextNode;
|
|
|
|
class QSGSimpleRectNode;
|
2011-10-14 08:51:42 +00:00
|
|
|
class QQuickTextEditPrivate : public QQuickImplicitSizeItemPrivate
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
2012-05-04 06:07:32 +00:00
|
|
|
public:
|
2011-10-14 08:51:42 +00:00
|
|
|
Q_DECLARE_PUBLIC(QQuickTextEdit)
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2012-05-04 06:07:32 +00:00
|
|
|
typedef QQuickTextEdit Public;
|
|
|
|
|
2013-03-18 15:25:59 +00:00
|
|
|
struct Node {
|
|
|
|
explicit Node(int startPos, QQuickTextNode* node)
|
|
|
|
: m_startPos(startPos), m_node(node), m_dirty(false) { }
|
|
|
|
QQuickTextNode* textNode() const { return m_node; }
|
|
|
|
void moveStartPos(int delta) { Q_ASSERT(m_startPos + delta > 0); m_startPos += delta; }
|
|
|
|
int startPos() const { return m_startPos; }
|
|
|
|
void setDirty() { m_dirty = true; }
|
|
|
|
bool dirty() const { return m_dirty; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
int m_startPos;
|
|
|
|
QQuickTextNode* m_node;
|
|
|
|
bool m_dirty;
|
|
|
|
};
|
2013-03-25 18:58:46 +00:00
|
|
|
typedef QList<Node*>::iterator TextNodeIterator;
|
2013-03-18 15:25:59 +00:00
|
|
|
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickTextEditPrivate()
|
2012-02-21 03:31:19 +00:00
|
|
|
: color(QRgb(0xFF000000)), selectionColor(QRgb(0xFF000080)), selectedTextColor(QRgb(0xFFFFFFFF))
|
2012-07-10 01:30:53 +00:00
|
|
|
, textMargin(0.0), xoff(0), yoff(0), font(sourceFont), cursorComponent(0), cursorItem(0), document(0), control(0)
|
2013-07-01 16:33:19 +00:00
|
|
|
, quickDocument(0), lastSelectionStart(0), lastSelectionEnd(0), lineCount(0)
|
2012-02-21 03:31:19 +00:00
|
|
|
, hAlign(QQuickTextEdit::AlignLeft), vAlign(QQuickTextEdit::AlignTop)
|
|
|
|
, format(QQuickTextEdit::PlainText), wrapMode(QQuickTextEdit::NoWrap)
|
2012-07-04 12:56:38 +00:00
|
|
|
, renderType(QQuickTextEdit::QtRendering)
|
2012-04-24 13:46:27 +00:00
|
|
|
, contentDirection(Qt::LayoutDirectionAuto)
|
2012-11-22 17:47:45 +00:00
|
|
|
, mouseSelectionMode(QQuickTextEdit::SelectCharacters)
|
|
|
|
#ifndef QT_NO_IM
|
|
|
|
, inputMethodHints(Qt::ImhNone)
|
|
|
|
#endif
|
2012-02-21 03:31:19 +00:00
|
|
|
, updateType(UpdatePaintNode)
|
2013-03-18 15:25:59 +00:00
|
|
|
, dirty(false), richText(false), cursorVisible(false), cursorPending(false)
|
2012-02-21 03:31:19 +00:00
|
|
|
, focusOnPress(true), persistentSelection(false), requireImplicitWidth(false)
|
|
|
|
, selectByMouse(false), canPaste(false), canPasteValid(false), hAlignImplicit(true)
|
2013-03-01 14:26:54 +00:00
|
|
|
, textCached(true), inLayout(false), selectByKeyboard(false), selectByKeyboardSet(false)
|
2013-03-18 15:25:59 +00:00
|
|
|
, hadSelection(false)
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-01-16 06:40:13 +00:00
|
|
|
static QQuickTextEditPrivate *get(QQuickTextEdit *item) {
|
|
|
|
return static_cast<QQuickTextEditPrivate *>(QObjectPrivate::get(item)); }
|
|
|
|
|
2011-04-27 12:13:26 +00:00
|
|
|
void init();
|
|
|
|
|
|
|
|
void updateDefaultTextOption();
|
|
|
|
void relayoutDocument();
|
|
|
|
bool determineHorizontalAlignment();
|
2011-10-14 08:51:42 +00:00
|
|
|
bool setHAlign(QQuickTextEdit::HAlignment, bool forceAlign = false);
|
2011-04-27 12:13:26 +00:00
|
|
|
void mirrorChange();
|
|
|
|
qreal getImplicitWidth() const;
|
2012-04-24 13:46:27 +00:00
|
|
|
Qt::LayoutDirection textDirection(const QString &text) const;
|
2013-04-22 16:14:55 +00:00
|
|
|
bool isLinkHoveredConnected();
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2012-05-04 06:07:32 +00:00
|
|
|
void setNativeCursorEnabled(bool enabled) { control->setCursorWidth(enabled ? 1 : 0); }
|
2013-03-04 20:26:13 +00:00
|
|
|
void handleFocusEvent(QFocusEvent *event);
|
2013-03-25 18:58:46 +00:00
|
|
|
void addCurrentTextNodeToRoot(QSGTransformNode *, QQuickTextNode*, TextNodeIterator&, int startPos);
|
|
|
|
QQuickTextNode* createTextNode();
|
2012-05-04 06:07:32 +00:00
|
|
|
|
2013-02-27 11:53:23 +00:00
|
|
|
#ifndef QT_NO_IM
|
|
|
|
Qt::InputMethodHints effectiveInputMethodHints() const;
|
|
|
|
#endif
|
|
|
|
|
2012-02-21 03:31:19 +00:00
|
|
|
QColor color;
|
|
|
|
QColor selectionColor;
|
|
|
|
QColor selectedTextColor;
|
|
|
|
|
2012-02-23 04:11:48 +00:00
|
|
|
QSizeF contentSize;
|
2012-02-21 03:31:19 +00:00
|
|
|
|
|
|
|
qreal textMargin;
|
2012-07-10 01:30:53 +00:00
|
|
|
qreal xoff;
|
2012-02-23 04:11:48 +00:00
|
|
|
qreal yoff;
|
2012-02-21 03:31:19 +00:00
|
|
|
|
2011-04-27 12:13:26 +00:00
|
|
|
QString text;
|
2012-01-17 00:42:26 +00:00
|
|
|
QUrl baseUrl;
|
2011-04-27 12:13:26 +00:00
|
|
|
QFont sourceFont;
|
2012-02-21 03:31:19 +00:00
|
|
|
QFont font;
|
|
|
|
|
2012-03-05 01:39:24 +00:00
|
|
|
QQmlComponent* cursorComponent;
|
2012-05-04 06:07:32 +00:00
|
|
|
QQuickItem* cursorItem;
|
2012-02-21 03:31:19 +00:00
|
|
|
QQuickTextDocumentWithImageResources *document;
|
|
|
|
QQuickTextControl *control;
|
2013-02-15 17:25:47 +00:00
|
|
|
QQuickTextDocument *quickDocument;
|
2013-03-18 15:25:59 +00:00
|
|
|
QList<Node*> textNodeMap;
|
2012-02-21 03:31:19 +00:00
|
|
|
|
|
|
|
int lastSelectionStart;
|
|
|
|
int lastSelectionEnd;
|
|
|
|
int lineCount;
|
|
|
|
|
|
|
|
enum UpdateType {
|
|
|
|
UpdateNone,
|
|
|
|
UpdateOnlyPreprocess,
|
|
|
|
UpdatePaintNode
|
|
|
|
};
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickTextEdit::HAlignment hAlign;
|
|
|
|
QQuickTextEdit::VAlignment vAlign;
|
2012-02-21 03:31:19 +00:00
|
|
|
QQuickTextEdit::TextFormat format;
|
|
|
|
QQuickTextEdit::WrapMode wrapMode;
|
2012-07-04 12:56:38 +00:00
|
|
|
QQuickTextEdit::RenderType renderType;
|
2012-04-24 13:46:27 +00:00
|
|
|
Qt::LayoutDirection contentDirection;
|
2012-02-21 03:31:19 +00:00
|
|
|
QQuickTextEdit::SelectionMode mouseSelectionMode;
|
2012-11-22 17:47:45 +00:00
|
|
|
#ifndef QT_NO_IM
|
2012-02-21 03:31:19 +00:00
|
|
|
Qt::InputMethodHints inputMethodHints;
|
2012-11-22 17:47:45 +00:00
|
|
|
#endif
|
2012-02-21 03:31:19 +00:00
|
|
|
UpdateType updateType;
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
bool dirty : 1;
|
|
|
|
bool richText : 1;
|
|
|
|
bool cursorVisible : 1;
|
2012-05-04 06:07:32 +00:00
|
|
|
bool cursorPending : 1;
|
2011-04-27 12:13:26 +00:00
|
|
|
bool focusOnPress : 1;
|
|
|
|
bool persistentSelection : 1;
|
|
|
|
bool requireImplicitWidth:1;
|
|
|
|
bool selectByMouse:1;
|
|
|
|
bool canPaste:1;
|
2011-12-20 07:21:55 +00:00
|
|
|
bool canPasteValid:1;
|
2011-04-27 12:13:26 +00:00
|
|
|
bool hAlignImplicit:1;
|
2012-01-11 01:00:36 +00:00
|
|
|
bool textCached:1;
|
2012-03-22 02:04:16 +00:00
|
|
|
bool inLayout:1;
|
2013-03-01 14:26:54 +00:00
|
|
|
bool selectByKeyboard:1;
|
|
|
|
bool selectByKeyboardSet:1;
|
2013-03-18 15:25:59 +00:00
|
|
|
bool hadSelection : 1;
|
2011-04-27 12:13:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
#endif // QQUICKTEXTEDIT_P_P_H
|