aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/scxmleditor/common/navigator.cpp
blob: 39a76dcbd7b9536eee4adbe21a6ebe3503e5672a (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
// 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

#include "navigator.h"
#include "graphicsscene.h"
#include "graphicsview.h"
#include "navigatorgraphicsview.h"
#include "navigatorslider.h"
#include "sizegrip.h"

#include <utils/utilsicons.h>

#include <QLabel>
#include <QResizeEvent>
#include <QToolBar>
#include <QToolButton>

using namespace ScxmlEditor::Common;

Navigator::Navigator(QWidget *parent)
    : MovableFrame(parent)
{
    createUi();
    connect(m_closeButton, &QToolButton::clicked, this, &Navigator::hideFrame);
}

void Navigator::setCurrentView(GraphicsView *view)
{
    if (m_currentView) {
        m_currentView->disconnect(m_navigatorView);
        m_navigatorView->disconnect(m_currentView);
        m_currentView->disconnect(m_navigatorSlider);
        m_navigatorSlider->disconnect(m_currentView);
    }

    m_currentView = view;

    if (m_currentView) {
        connect(m_currentView.data(), &GraphicsView::viewChanged, m_navigatorView, &NavigatorGraphicsView::setMainViewPolygon);
        connect(m_currentView.data(), &GraphicsView::zoomPercentChanged, m_navigatorSlider, &NavigatorSlider::setSliderValue);

        connect(m_navigatorSlider, &NavigatorSlider::valueChanged, m_currentView.data(), &GraphicsView::zoomTo);
        connect(m_navigatorView, &NavigatorGraphicsView::moveMainViewTo, m_currentView.data(), &GraphicsView::moveToPoint);
        connect(m_navigatorView, &NavigatorGraphicsView::zoomIn, m_currentView.data(), &GraphicsView::zoomIn);
        connect(m_navigatorView, &NavigatorGraphicsView::zoomOut, m_currentView.data(), &GraphicsView::zoomOut);
    }
}

void Navigator::setCurrentScene(ScxmlEditor::PluginInterface::GraphicsScene *scene)
{
    m_navigatorView->setGraphicsScene(scene);
}

void Navigator::resizeEvent(QResizeEvent *e)
{
    MovableFrame::resizeEvent(e);
    m_sizeGrip->move(e->size().width() - m_sizeGrip->width(), e->size().height() - m_sizeGrip->height());
}

void Navigator::createUi()
{
    auto titleLabel = new QLabel(tr("Navigator"));
    titleLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);

    m_closeButton = new QToolButton;
    m_closeButton->setIcon(Utils::Icons::CLOSE_TOOLBAR.icon());

    auto titleToolBar = new QToolBar;
    titleToolBar->addWidget(titleLabel);
    titleToolBar->addWidget(m_closeButton);

    m_navigatorView = new NavigatorGraphicsView;
    m_navigatorSlider = new NavigatorSlider;

    setLayout(new QVBoxLayout);
    layout()->setSpacing(0);
    layout()->setContentsMargins(0, 0, 0, 0);
    layout()->addWidget(titleToolBar);
    layout()->addWidget(m_navigatorView);
    layout()->addWidget(m_navigatorSlider);

    m_sizeGrip = new SizeGrip(this);
    m_sizeGrip->setGeometry(0, 0, 18, 18);

    setAutoFillBackground(true);
    setMinimumSize(300, 200);
    setGeometry(x(), y(), 400, 300);
}