aboutsummaryrefslogtreecommitdiff
path: root/src/views/mtexteditview_p.h
blob: 7ba46b21a9129dc45ad9f0f44a81899217f426d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/***************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (directui@nokia.com)
**
** This file is part of libmeegotouch.
**
** If you have questions regarding the use of this file, please contact
** Nokia at directui@nokia.com.
**
** This library is free software; you can redistribute it and/or
** modify it 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.
**
****************************************************************************/

#ifndef MTEXTEDITVIEW_P_H
#define MTEXTEDITVIEW_P_H

#include <QObject>
#include <QTextCharFormat>
#include <QAbstractTextDocumentLayout>
#include <QPointer>

#include "mtexteditview.h"

class MTextEdit;
class MTextMagnifier;
class QGraphicsSceneMouseEvent;
class QColor;
class QTextDocument;
class QTimer;
class QTimeLine;
class MInfoBanner;

//! \internal
class MTextEditViewPrivate : public QObject
{
    Q_OBJECT
    Q_DECLARE_PUBLIC(MTextEditView)

public:
    MTextEditViewPrivate(MTextEdit *controller, MTextEditView *q);
    virtual ~MTextEditViewPrivate();

    int cursorPosition(QGraphicsSceneMouseEvent *event);
    int cursorPosition(const QPointF &point, Qt::HitTestAccuracy accuracy = Qt::FuzzyHit);

    QTextDocument *document() const;
    QTextDocument *promptDocument() const;
    void checkScroll();
    void setMouseTarget(const QPointF &point);

    // returns a paint context for drawing. Includes selection formatting
    QAbstractTextDocumentLayout::PaintContext paintContext() const;

    qreal cursorX() const;

    void initMaskedDocument();

    QTextDocument *activeDocument() const;

    qreal heightForWidth(qreal width) const;

protected slots:
    void scrolling();
    void hideUnmaskedText();
    void checkSize();
    void handleDocumentUpdate(int position, int charsRemoved, int charsAdded);
    void handleDocumentSizeChange(const QSizeF &newSize);
    void playTextFieldSelectionFeedback();
    void updateMagnifierPosition();

private:
    void scrollingTestAndStart(QGraphicsSceneMouseEvent *event);
    void checkStartOfSelection(QGraphicsSceneMouseEvent *event);
    void startSelection(QGraphicsSceneMouseEvent *event);
    void updateSelection(const QPointF &pos);
    void updateSelection(QGraphicsSceneMouseEvent *event);

    //! Returns a rectangle covering preedit text in item space
    QRect preeditRectangle() const;

    //! Returns a rectangle of the cursor
    QRect cursorRect() const;

protected:
    MTextEditView *q_ptr;

    MTextEdit *controller;

    bool focused;

    QTextDocument *maskedTextDocument;
    QTextDocument *promptTextDocument;

    int unmaskPosition; // position where unmask in masked mode starts
    int unmaskLength; // lenght of unmasked text

    // styling
    qreal selectionThreshold;
    QChar maskCharacter; // what characters are replaced with in masked mode
    QTextCharFormat selectionFormat;

    qreal hscroll; // horizontal offset of text
    qreal vscroll; // vertical offset

    int scrollSpeedVertical;
    int scrollSpeedHorizontal;

    QTimer *longPressTimer;
    QTimer *scrollTimer;
    QTimer *maskTimer;

    bool selecting; // separate from controller mode because the selection there doesn't tell
    // this view initiated the selection by mouse press
    bool ignoreSelection;
    int startCursorPos;

    qreal documentHeight;
    QPointF mouseTarget; // known mouse position inside widget

    bool inAutoSelectionClick;

    MInfoBanner *infoBanner;

    bool editActive; // true if editing started and having focus

    QTimer *hideInfoBannerTimer;

    QScopedPointer<MTextMagnifier> magnifier;

#ifdef UNIT_TEST
    friend class Ut_MTextEditView;
    friend class Ut_MTextEdit;
#endif
};
//! \internal_end

#endif