summaryrefslogtreecommitdiffstats
path: root/src/declarative/canvas/qsimplecanvasitem.h
blob: cab8492b6667748c7b4d5de2d06c8a11a4189019 (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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Qt Software Information (qt-info@nokia.com)
**
** This file is part of the QtDeclarative module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the either Technology Preview License Agreement or the
** Beta Release License Agreement.
**
** GNU Lesser General Public License Usage
** 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.
**
** In addition, as a special exception, Nokia gives you certain
** additional rights. These rights are described in the Nokia Qt LGPL
** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
** package.
**
** GNU General Public License Usage
** 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at qt-sales@nokia.com.
** $QT_END_LICENSE$
**
****************************************************************************/

#ifndef QSIMPLECANVASITEM_H
#define QSIMPLECANVASITEM_H

#include <QtDeclarative/qfxglobal.h>
#include <QtDeclarative/qmldebuggerstatus.h>
#include <QtDeclarative/qsimplecanvas.h>
#include <QtCore/qobject.h>
#include <QtGui/qgraphicsitem.h>
class QPainter;

QT_BEGIN_HEADER

QT_BEGIN_NAMESPACE

QT_MODULE(Declarative)
class QRect;
class QSimpleCanvas;
class QMouseEvent;
class QKeyEvent;
class QSimpleCanvasItemPrivate;
class QSimpleCanvasLayer;
class QPointF;
class QRectF;
class QGraphicsSceneHoverEvent;
class QSimpleCanvasFilter;
class GLTexture;
class QGLShaderProgram;

class Q_DECLARATIVE_EXPORT QSimpleCanvasItem : public QObject
{
    Q_OBJECT
    Q_CAST_INTERFACES(QGraphicsItem)
    Q_CAST_INTERFACES(QmlDebuggerStatus)
    Q_DECLARE_PRIVATE(QSimpleCanvasItem)
    Q_ENUMS(TransformOrigin)
    Q_PROPERTY(TransformOrigin transformOrigin READ transformOrigin WRITE setTransformOrigin);

public:
    enum ClipType { NoClip = 0x00,
                    ClipToHeight = 0x01, 
                    ClipToWidth = 0x02, 
                    ClipToRect = 0x03 };
    enum Option { NoOption = 0x00000000,
                  MouseFilter = 0x00000001,
                  ChildMouseFilter = 0x00000002,
                  HoverEvents = 0x00000004,
                  MouseEvents = 0x00000008,
                  HasContents = 0x00000010,
                  SimpleItem = 0x00000020,
                  IsFocusPanel = 0x00000040,
                  IsFocusRealm = 0x00000080,
                  AcceptsInputMethods = 0x00000100};
    Q_DECLARE_FLAGS(Options, Option);

    QSimpleCanvasItem(QSimpleCanvasItem *parent=0);
    virtual ~QSimpleCanvasItem();
    operator QGraphicsItem *();
    operator QmlDebuggerStatus *();

    bool clip() const;
    void setClip(bool);
    ClipType clipType() const;
    void setClipType(ClipType);

    Options options() const;
    void setOptions(Options, bool set = true);

    Qt::MouseButtons acceptedMouseButtons() const;
    void setAcceptedMouseButtons(Qt::MouseButtons buttons);

    qreal x() const;
    qreal y() const;
    qreal z() const;
    QPointF pos() const;
    void setX(qreal);
    void setY(qreal);
    virtual void setZ(qreal);
    void setPos(const QPointF &);

    qreal width() const;
    void setWidth(qreal);
    void setImplicitWidth(qreal);
    bool widthValid() const;
    qreal height() const;
    void setHeight(qreal);
    void setImplicitHeight(qreal);
    bool heightValid() const;

    QPointF scenePos() const;

    enum TransformOrigin {
        TopLeft, TopCenter, TopRight,
        MiddleLeft, Center, MiddleRight,
        BottomLeft, BottomCenter, BottomRight 
    };
    TransformOrigin transformOrigin() const;
    void setTransformOrigin(TransformOrigin);
    QPointF transformOriginPoint() const;


    qreal scale() const;
    virtual void setScale(qreal);

    enum Flip { NoFlip = 0, 
                VerticalFlip = 0x01, 
                HorizontalFlip = 0x02, 
                VerticalAndHorizontalFlip = 0x03 };
    Flip flip() const;
    void setFlip(Flip);

    qreal visible() const;
    virtual void setVisible(qreal);
    bool isVisible() const;

    QSimpleCanvas *canvas() const;

    QSimpleCanvasItem *parent() const;
    void setParent(QSimpleCanvasItem *);
    void stackUnder(QSimpleCanvasItem *);
    void stackOver(QSimpleCanvasItem *);
    void stackAt(int idx);
    int indexForChild(QSimpleCanvasItem *);

    QRect itemBoundingRect();

    class GLPainter 
    {
    public:
        GLPainter(QSimpleCanvasItem *i) : item(i), activeOpacity(1) {}
        QSimpleCanvasItem *item;
        QSimpleCanvas::Matrix activeTransform;
        qreal activeOpacity;
        QRect sceneClipRect;

        QGLShaderProgram *useTextureShader();
        QGLShaderProgram *useColorShader(const QColor &);
        void  drawImage(const QPointF &, const GLTexture &);
        void  drawImage(const QRectF &, const GLTexture &);
    private:
        GLPainter(const GLPainter &);
        GLPainter &operator=(const GLPainter &);
    };


    QRectF boundingRect() const;
    virtual void paintContents(QPainter &);
    virtual void paintGLContents(GLPainter &);
    virtual uint glSimpleItemData(float *vertices, float *texVertices,
                                  GLTexture **texture, uint count);

    void update();

    virtual QSimpleCanvasLayer *layer();

    bool hasChildren() const;
    const QList<QSimpleCanvasItem *> &children() const;

    QPointF mapFromScene(const QPointF &) const;
    QRectF mapFromScene(const QRectF &) const;
    QPointF mapToScene(const QPointF &) const;
    QRectF mapToScene(const QRectF &) const;

    QSimpleCanvas::Matrix transform() const;
    void setTransform(const QSimpleCanvas::Matrix &);

    QSimpleCanvasFilter *filter() const;
    void setFilter(QSimpleCanvasFilter *);

    QSimpleCanvasItem *mouseGrabberItem() const;
    void ungrabMouse();
    void grabMouse();

    virtual bool isFocusable() const;
    void setFocusable(bool);
    virtual bool hasFocus() const;
    void setFocus(bool);
    bool activeFocusPanel() const;
    void setActiveFocusPanel(bool);

    bool hasActiveFocus() const;

    QSimpleCanvasItem *findFirstFocusChild() const;
    QSimpleCanvasItem *findLastFocusChild() const;
    static QSimpleCanvasItem *findPrevFocus(QSimpleCanvasItem *item);
    static QSimpleCanvasItem *findNextFocus(QSimpleCanvasItem *item);

    GLBasicShaders *basicShaders() const;
  
    static QImage string(const QString &, const QColor & = Qt::black, const QFont & = QFont());

protected:
    virtual void geometryChanged(const QRectF &newGeometry, 
                                 const QRectF &oldGeometry);
    virtual void addChild(QSimpleCanvasItem *);
    virtual void remChild(QSimpleCanvasItem *);
    virtual void canvasChanged();
    virtual void childrenChanged();
    virtual void parentChanged(QSimpleCanvasItem *, QSimpleCanvasItem *);
    virtual void focusChanged(bool);
    virtual void activeFocusChanged(bool);
    virtual bool eventFilter(QObject *, QEvent *);

public:
    // Events
    virtual bool mouseFilter(QGraphicsSceneMouseEvent *);
    virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
    virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
    virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
    virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *);
    virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *);
    virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
    virtual void mouseUngrabEvent();
    virtual void keyPressEvent(QKeyEvent *event);
    virtual void keyReleaseEvent(QKeyEvent *event);
    virtual void focusOutEvent(QFocusEvent *e);
    virtual void focusInEvent(QFocusEvent *e);
    virtual void activePanelInEvent();
    virtual void activePanelOutEvent();
    virtual void inputMethodEvent(QInputMethodEvent* event);
    virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;

private:
    friend class QSimpleCanvas;
    friend class QSimpleCanvasPrivate;
    friend class QSimpleCanvasRootLayer;
    friend class QSimpleCanvasItem::GLPainter;
    friend class QSimpleCanvasFilter;
    friend class QGraphicsQSimpleCanvasItem;
    friend class QSimpleGraphicsItem;
    friend class CanvasEGLWidget;
    friend class QSimpleCanvasFilterPrivate;

public:
    QSimpleCanvasItem(QSimpleCanvasItemPrivate &dd, QSimpleCanvasItem *parent);
};

Q_DECLARE_OPERATORS_FOR_FLAGS(QSimpleCanvasItem::Options);

class QSimpleCanvasLayer : public QSimpleCanvasItem
{
public:
    QSimpleCanvasLayer(QSimpleCanvasItem *parent);

    virtual void addChild(QSimpleCanvasItem *);
    virtual void addDirty(QSimpleCanvasItem *);
    virtual void remDirty(QSimpleCanvasItem *);
    virtual QSimpleCanvasLayer *layer();

private:
    friend class QSimpleCanvas;
    friend class QSimpleCanvasRootLayer;
    QSimpleCanvasLayer();
};



#endif // _GFXCANVASITEM_H_


QT_END_NAMESPACE

QT_END_HEADER