-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraphics_items.h
More file actions
68 lines (54 loc) · 2.23 KB
/
Copy pathgraphics_items.h
File metadata and controls
68 lines (54 loc) · 2.23 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
#ifndef GRAPHICS_ITEMS_H
#define GRAPHICS_ITEMS_H
#include <QGraphicsEllipseItem>
#include <QGraphicsLineItem>
#include <QGraphicsSceneHoverEvent>
#include <QGraphicsSimpleTextItem>
#include <QPen>
#include <QBrush>
#include <QList>
class GraphEdge;
class MainWindow; // Предварительное объявление главного окна
class GraphNode : public QGraphicsEllipseItem {
public:
// Теперь передаём указатель на MainWindow
GraphNode(int id, double radius, MainWindow* window, QGraphicsItem* parent = nullptr);
void addEdge(GraphEdge* edge);
int getId() const { return nodeId; }
void updateNodeSize(double newRadius);
void setNormalizedPos(const QPointF& pos) { normPos = pos; }
QPointF getNormalizedPos() const { return normPos; }
// Управление подсветкой
void setCustomSelected(bool selected);
void setNodeInPath(bool inPath);
bool isCustomSelect() const { return isCustomSelected; }
protected:
void hoverEnterEvent(QGraphicsSceneHoverEvent* event) override;
void hoverLeaveEvent(QGraphicsSceneHoverEvent* event) override;
QVariant itemChange(GraphicsItemChange change, const QVariant& value) override;
// Перехватываем клик мыши
void mousePressEvent(QGraphicsSceneMouseEvent* event) override;
private:
void centerText();
void updateAppearance(bool isHovered = false); // Метод управления цветом
int nodeId;
QList<GraphEdge*> edgeList;
QBrush defaultBrush;
QBrush hoverBrush;
QGraphicsSimpleTextItem* textItem;
QPointF normPos;
MainWindow* mainWindow; // Сохраняем указатель на главное окно
bool isCustomSelected = false; // Выбрана ли как Старт/Финиш
bool isPartOfPath = false; // Входит ли в кратчайший путь
};
class GraphEdge : public QGraphicsLineItem {
public:
GraphEdge(GraphNode* source, GraphNode* dest, QGraphicsItem* parent = nullptr);
void adjust();
// Метод для подсветки ребра пути
void setHighlighted(bool highlighted);
private:
GraphNode* sourceNode;
GraphNode* destNode;
};
#endif // GRAPHICS_ITEMS_H