-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapvisualizer.h
More file actions
99 lines (78 loc) · 2.74 KB
/
mapvisualizer.h
File metadata and controls
99 lines (78 loc) · 2.74 KB
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
#ifndef MAPVISUALIZER_H
#define MAPVISUALIZER_H
#include <QWidget>
#include <QPainter>
#include <QMouseEvent>
#include <QPoint>
#include <memory>
#include <QApplication>
#include <QPalette>
#include "mapgraph.h"
const double sqrt3 = sqrt(3);
// Theme enum for light/dark mode
enum class AppTheme {
Light,
Dark
};
class MapVisualizer : public QWidget {
Q_OBJECT
public:
// Singleton
static MapVisualizer* instance(){static auto* instance = new MapVisualizer(nullptr);; return instance; }
explicit MapVisualizer(QWidget *parent = nullptr);
~MapVisualizer() override;
void setMapGraph();
void clearSelectionPoints();
void reset();
void resetZoom();
// Theme management
void setTheme(AppTheme theme);
void toggleTheme();
[[nodiscard]] AppTheme getCurrentTheme() const { return currentTheme; }
// Getters for selected points
[[nodiscard]] QPointF getStartPoint() const { return startPoint; }
[[nodiscard]] QPointF getEndPoint() const { return endPoint; }
// Setters for points
void setStartPoint(const double x, const double y) { startPoint = QPointF(x, y); hasStartPoint = true; update(); }
void setEndPoint(const double x, const double y) { endPoint = QPointF(x, y); hasEndPoint = true; update(); }
// Coordinate transformation
[[nodiscard]] QPointF transformCoordinates(double x, double y) const;
[[nodiscard]] QPointF inverseTransformCoordinates(int pixelX, int pixelY) const;
signals:
void startPointSelected(double x, double y);
void endPointSelected(double x, double y);
void pointsSelected(double startX, double startY, double endX, double endY);
protected:
void paintEvent(QPaintEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
//Mouse Wheel Zooming In/Out////////////////////////////////////////////////////
void wheelEvent(QWheelEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
private:
double scaleFactor = 1.0; // Zoom level, default = 100%
QPoint lastMousePos;
QPointF offset; // Offset for panning
bool isPanning = false;
bool hasStartPoint, hasEndPoint;
QPointF startPoint;
QPointF endPoint;
// Drawing parameters
int nodeDiameter;
int pathThickness;
QColor edgeColor;
QColor pathColor;
QColor startPointColor;
QColor endPointColor;
QColor backgroundColor;
// Theme management
AppTheme currentTheme;
void updateThemeColors();
// Coordinate transformation
QRectF graphBounds;
void calculateGraphBounds();
// Keep scaled content within view
void clampView();
Q_DISABLE_COPY(MapVisualizer);
};
#endif // MAPVISUALIZER_H