SILICON
Loading...
Searching...
No Matches
diagramView.hpp
Go to the documentation of this file.
1/*
2 Copyright (c) 2026. Giulio Cocconi
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#pragma once
19
20#include <algorithm>
21
22#include <QGraphicsView>
23#include <QWheelEvent>
24
26
27
28namespace SILICON::ui {
29class DiagramView : public QGraphicsView {
30 Q_OBJECT
31public:
32 explicit DiagramView(QWidget* parent = nullptr);
33 void setScene(DiagramScene* scene);
34
35protected:
36 void wheelEvent(QWheelEvent* event) override;
37
38public slots:
40 void zoomIn();
42 void zoomOut();
48 void zoomToRect(const QRectF& rect);
50 void centerCircuit();
52
53private:
54 static constexpr int MIN_ZOOM_LEVEL = 60;
55 static constexpr int MAX_ZOOM_LEVEL = 200;
56 int zoomLevel = 100;
58
59 bool zoom(int level);
60 void updateZoom();
61};
62
63} // namespace SILICON::ui
Graphics scene for the circuit diagram editor.
DiagramView(QWidget *parent=nullptr)
static constexpr int MAX_ZOOM_LEVEL
void modeChanged(InteractionMode mode)
void zoomOut()
Decreases the circuit zoom by one step.
void setScene(DiagramScene *scene)
void zoomIn()
Increases the circuit zoom by one step.
static constexpr int MIN_ZOOM_LEVEL
void zoomToRect(const QRectF &rect)
Centers a scene rectangle and fits it within the existing zoom limits.
void wheelEvent(QWheelEvent *event) override
void centerCircuit()
Pans the viewport so the circuit's bounds are centered.
DiagramScene::InteractionMode InteractionMode
Alias for DiagramScene::InteractionMode.