aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/qmldesigner/components/formeditor/formeditorgraphicsview.h
blob: 7ea7536fe11202927a6000f626b7dabe4dbaaa69 (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
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
#pragma once

#include <QGraphicsView>

namespace QmlDesigner {

class FormEditorGraphicsView : public QGraphicsView
{
    Q_OBJECT

signals:
    void zoomChanged(double zoom);
    void zoomIn();
    void zoomOut();

public:
    explicit FormEditorGraphicsView(QWidget *parent = nullptr);

    void setRootItemRect(const QRectF &rect);
    QRectF rootItemRect() const;

    void activateCheckboardBackground();
    void activateColoredBackground(const QColor &color);
    void drawBackground(QPainter *painter, const QRectF &rect) override;

    void setZoomFactor(double zoom);
    void frame(const QRectF &bbox);

protected:
    bool eventFilter(QObject *watched, QEvent *event) override;
    void wheelEvent(QWheelEvent *event) override;
    void mousePressEvent(QMouseEvent *event) override;
    void mouseReleaseEvent(QMouseEvent *event) override;
    void keyPressEvent(QKeyEvent *event) override;
    void keyReleaseEvent(QKeyEvent *event) override;

private:
    enum Panning { NotStarted, MouseWheelStarted, SpaceKeyStarted };

    void startPanning(QEvent *event);
    void stopPanning(QEvent *event);

    Panning m_isPanning = Panning::NotStarted;
    QPoint m_panningStartPosition;
    QRectF m_rootItemRect;
};

} // namespace QmlDesigner