aboutsummaryrefslogtreecommitdiff
path: root/src/views/mtexteditview.h
blob: 0feec8c7e6f22f8f7c37cc4fef1d1055f40695b1 (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
/***************************************************************************
**
** 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_H
#define MTEXTEDITVIEW_H

#include "mwidgetview.h"
#include <mtexteditmodel.h>
#include <mtexteditstyle.h>

class MTextEdit;
class MTextEditViewPrivate;


/*!
* \class MTextEditView
* \brief Standard view for MTextEdit widget
*/
class M_VIEWS_EXPORT MTextEditView : public MWidgetView
{
    Q_OBJECT
    M_VIEW(MTextEditModel, MTextEditStyle)

public:
    /*!
     * \brief Constructor
     * \param controller MTextEdit widget which this view shows
     */
    MTextEditView(MTextEdit *controller);

    /*!
     * \brief Destructor
     */
    virtual ~MTextEditView();

    //! \reimp
    virtual QRectF boundingRect() const;
    virtual void resizeEvent(QGraphicsSceneResizeEvent *event);
    virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
    //! \reimp_end

protected:
    //! \reimp
    virtual void drawContents(QPainter *painter, const QStyleOptionGraphicsItem *option) const;
    virtual void applyStyle();
    virtual void setupModel();
    virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
    virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
    virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
    virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
    virtual void changeEvent(QEvent *event);
    virtual void cancelEvent(MCancelEvent *event);
    //! \reimp_end

    //! \brief Notifies this and possibly derived views about the need for redraw.
    virtual void doUpdate();

    //! \brief Gets the last mouse position.
    const QPointF &mouseTarget() const;

    //! \brief Updates cursor position based on mouse \a event.
    //! \param event Event that contains the mouse position, buttons, etc.
    //! \param updateSelection Tells whether or not to update text selection.
    //! If false, only cursor moves without selecting any text.
    void updateCursorPosition(QGraphicsSceneMouseEvent *event, bool updateSelection);

    /*!
     * \brief Returns cursor position from a mouse position
     * \param hitPoint mouse position
     * \return cursor position as characters from start of document
     */
    int cursorPosition(const QPointF &hitPoint);

protected Q_SLOTS:
    /*!
     * \brief Set view focused
     */
    void setFocused(Qt::FocusReason reason);

    /*!
     * \brief Remove focus from view
     */
    void removeFocus(Qt::FocusReason reason);

    //! \reimp
    virtual void updateData(const QList<const char *> &modifications);
    //! \reimp_end

    /*!
     * \brief Show informational banner about failed text paste
     */
    virtual void informPasteFailed();

    //! \brief Handler for long press event.
    virtual void handleLongPress();

    //! \brief Hide informational banner about failed text paste
    void hideInfoBanner();

private:
    Q_DISABLE_COPY(MTextEditView)
    Q_DECLARE_PRIVATE(MTextEditView)

    MTextEditViewPrivate *const d_ptr;

#ifdef UNIT_TEST
    friend class Ut_MTextEditView;
    friend class Ut_MTextEdit;
#endif
};

#endif