|
8 | 8 | class CursorTileRect : public QGraphicsItem |
9 | 9 | { |
10 | 10 | public: |
11 | | - CursorTileRect(bool *enabled, QRgb color); |
12 | | - QRectF boundingRect() const override |
13 | | - { |
14 | | - int width = this->width; |
15 | | - int height = this->height; |
16 | | - if (this->singleTileMode) { |
17 | | - width = 16; |
18 | | - height = 16; |
19 | | - } else if (!this->rightClickSelectionAnchored && this->smartPathMode && this->selectionHeight == 3 && this->selectionWidth == 3) { |
20 | | - width = 32; |
21 | | - height = 32; |
22 | | - } |
| 11 | + CursorTileRect(const QSize &tileSize, const QRgb &color, QGraphicsItem *parent = nullptr); |
| 12 | + |
| 13 | + QSize size() const; |
| 14 | + |
| 15 | + QRectF boundingRect() const override { |
| 16 | + auto s = size(); |
23 | 17 | qreal penWidth = 4; |
24 | 18 | return QRectF(-penWidth, |
25 | 19 | -penWidth, |
26 | | - width + penWidth * 2, |
27 | | - height + penWidth * 2); |
| 20 | + s.width() + penWidth * 2, |
| 21 | + s.height() + penWidth * 2); |
28 | 22 | } |
29 | 23 |
|
30 | | - void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override |
31 | | - { |
32 | | - if (!(*enabled)) return; |
33 | | - int width = this->width; |
34 | | - int height = this->height; |
35 | | - if (this->singleTileMode) { |
36 | | - width = 16; |
37 | | - height = 16; |
38 | | - } else if (this->smartPathInEffect()) { |
39 | | - width = 32; |
40 | | - height = 32; |
41 | | - } |
42 | | - |
43 | | - painter->setPen(this->color); |
44 | | - painter->drawRect(x() - 1, y() - 1, width + 2, height + 2); |
| 24 | + void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override { |
| 25 | + if (!isVisible()) return; |
| 26 | + auto rect = QRectF(pos(), size()); |
| 27 | + painter->setPen(m_color); |
| 28 | + painter->drawRect(rect + QMargins(1,1,1,1)); // Fill |
45 | 29 | painter->setPen(QColor(0, 0, 0)); |
46 | | - painter->drawRect(x() - 2, y() - 2, width + 4, height + 4); |
47 | | - painter->drawRect(x(), y(), width, height); |
| 30 | + painter->drawRect(rect + QMargins(2,2,2,2)); // Outer border |
| 31 | + painter->drawRect(rect); // Inner border |
48 | 32 | } |
| 33 | + |
49 | 34 | void initAnchor(int coordX, int coordY); |
50 | 35 | void stopAnchor(); |
51 | 36 | void initRightClickSelectionAnchor(int coordX, int coordY); |
52 | 37 | void stopRightClickSelectionAnchor(); |
53 | 38 |
|
54 | | - void setSmartPathMode(bool enable) { this->smartPathMode = enable; } |
55 | | - bool getSmartPathMode() const { return this->smartPathMode; } |
56 | | - |
57 | | - void setStraightPathMode(bool enable) { this->straightPathMode = enable; } |
58 | | - bool getStraightPathMode() const { return this->straightPathMode; } |
| 39 | + void setSmartPathMode(bool enable) { m_smartPathMode = enable; } |
| 40 | + bool getSmartPathMode() const { return m_smartPathMode; } |
59 | 41 |
|
60 | | - void setSingleTileMode(bool enable) { this->singleTileMode = enable; } |
61 | | - bool getSingleTileMode() const { return this->singleTileMode; } |
| 42 | + void setSingleTileMode(bool enable) { m_singleTileMode = enable; } |
| 43 | + bool getSingleTileMode() const { return m_singleTileMode; } |
62 | 44 |
|
63 | 45 | void updateLocation(int x, int y); |
64 | 46 | void updateSelectionSize(int width, int height); |
65 | | - void setActive(bool active); |
66 | | - bool getActive(); |
67 | | - bool *enabled; |
| 47 | + |
68 | 48 | private: |
69 | | - bool active; |
70 | | - int width; |
71 | | - int height; |
72 | | - bool anchored; |
73 | | - bool rightClickSelectionAnchored; |
74 | | - bool smartPathMode; |
75 | | - bool straightPathMode; |
76 | | - bool singleTileMode; |
77 | | - int anchorCoordX; |
78 | | - int anchorCoordY; |
79 | | - int selectionWidth; |
80 | | - int selectionHeight; |
81 | | - QRgb color; |
82 | | - bool smartPathInEffect(); |
| 49 | + const QSize m_tileSize; |
| 50 | + QSize m_selectionSize; |
| 51 | + QPoint m_anchorCoord; |
| 52 | + QRgb m_color; |
| 53 | + |
| 54 | + bool m_anchored = false; |
| 55 | + bool m_rightClickSelectionAnchored = false; |
| 56 | + bool m_smartPathMode = false; |
| 57 | + bool m_singleTileMode = false; |
| 58 | + |
| 59 | + bool smartPathInEffect() const; |
83 | 60 | }; |
84 | 61 |
|
85 | 62 |
|
|
0 commit comments