@@ -55,50 +55,60 @@ void TrafficDisplay::drawTrafficLightIndicator(QPainter & painter, const QRectF
55
55
painter.setRenderHint (QPainter::Antialiasing, true );
56
56
painter.setRenderHint (QPainter::SmoothPixmapTransform, true );
57
57
58
+ // #C2C2C2
59
+ painter.setPen (QPen (gray, 2 , Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
60
+ painter.setBrush (QBrush (gray, Qt::SolidPattern));
58
61
// Define the area for the circle (background)
59
62
QRectF circleRect = backgroundRect;
60
63
circleRect.setWidth (backgroundRect.width () / 2 - 20 );
61
64
circleRect.setHeight (backgroundRect.height () - 20 );
62
65
circleRect.moveTopRight (QPointF (backgroundRect.right () - 10 , backgroundRect.top () + 10 ));
63
66
64
- painter.setBrush (QBrush (gray));
65
- painter.drawEllipse (circleRect.center (), 30 , 30 );
66
-
67
- // Define the area for the traffic light image (should be smaller or positioned within the circle)
68
- QRectF imageRect =
69
- circleRect.adjusted (15 , 15 , -15 , -15 ); // Adjusting the rectangle to make the image smaller
70
-
71
- QImage scaled_traffic_image = traffic_light_image_.scaled (
72
- imageRect.size ().toSize (), Qt::KeepAspectRatio, Qt::SmoothTransformation);
67
+ painter.drawEllipse (circleRect);
73
68
74
69
if (current_traffic_.signals .size () > 0 ) {
75
70
switch (current_traffic_.signals [0 ].elements [0 ].color ) {
76
71
case 1 :
77
72
painter.setBrush (QBrush (red));
78
- painter.drawEllipse (circleRect. center (), 30 , 30 );
73
+ painter.drawEllipse (circleRect);
79
74
break ;
80
75
case 2 :
81
76
painter.setBrush (QBrush (yellow));
82
- painter.drawEllipse (circleRect. center (), 30 , 30 );
77
+ painter.drawEllipse (circleRect);
83
78
break ;
84
79
case 3 :
85
80
painter.setBrush (QBrush (green));
86
- painter.drawEllipse (circleRect. center (), 30 , 30 );
81
+ painter.drawEllipse (circleRect);
87
82
break ;
88
83
case 4 :
89
84
painter.setBrush (QBrush (gray));
90
- painter.drawEllipse (circleRect. center (), 30 , 30 );
85
+ painter.drawEllipse (circleRect);
91
86
break ;
92
87
default :
93
88
painter.setBrush (QBrush (gray));
94
- painter.drawEllipse (circleRect. center (), 30 , 30 );
89
+ painter.drawEllipse (circleRect);
95
90
break ;
96
91
}
97
92
}
98
- // make the image thicker
99
- painter.setPen (QPen (Qt::black, 2 , Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
100
93
101
- painter.drawImage (imageRect, scaled_traffic_image);
94
+ // Scaling factor (e.g., 1.5 for 150% size)
95
+ qreal scaleFactor = 1.25 ;
96
+
97
+ // Calculate the scaled size
98
+ QSize scaledSize = traffic_light_image_.size () * scaleFactor;
99
+
100
+ // Ensure the scaled image is still within the circle bounds or adjust scaleFactor accordingly
101
+
102
+ // Calculate the centered rectangle for the scaled image
103
+ QRectF scaledImageRect (0 , 0 , scaledSize.width (), scaledSize.height ());
104
+ scaledImageRect.moveCenter (circleRect.center ());
105
+
106
+ // Scale the image to the new size
107
+ QImage scaledTrafficImage =
108
+ traffic_light_image_.scaled (scaledSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
109
+
110
+ // Draw the scaled and centered image
111
+ painter.drawImage (scaledImageRect.topLeft (), scaledTrafficImage);
102
112
}
103
113
104
114
QImage TrafficDisplay::coloredImage (const QImage & source, const QColor & color)
0 commit comments