@@ -68,41 +68,40 @@ void SpeedLimitDisplay::updateSpeedData(
68
68
}
69
69
}
70
70
71
- void SpeedLimitDisplay::drawSpeedLimitIndicator (QPainter & painter, const QRectF & backgroundRect)
71
+ void SpeedLimitDisplay::drawSpeedLimitIndicator (
72
+ QPainter & painter, const QRectF & backgroundRect, const QColor & color,
73
+ const QColor & light_color, const QColor & dark_color, const QColor & bg_color,
74
+ const float bg_alpha)
72
75
{
73
76
// Enable Antialiasing for smoother drawing
74
77
painter.setRenderHint (QPainter::Antialiasing, true );
75
78
painter.setRenderHint (QPainter::SmoothPixmapTransform, true );
76
79
77
- const double color_s_min = 0.4 ;
78
- const double color_s_max = 0.8 ;
79
- QColor colorMin;
80
- colorMin.setHsvF (0.0 , color_s_min, 1.0 );
81
- QColor colorMax;
82
- colorMax.setHsvF (0.0 , color_s_max, 1.0 );
83
-
84
- QColor borderColor = colorMin;
80
+ QColor borderColor = light_color;
85
81
if (current_limit > 0.0 ) {
86
82
double speed_to_limit_ratio = current_speed_ / current_limit;
87
83
const double speed_to_limit_ratio_min = 0.6 ;
88
84
const double speed_to_limit_ratio_max = 0.9 ;
89
85
90
86
if (speed_to_limit_ratio >= speed_to_limit_ratio_max) {
91
- borderColor = colorMax ;
87
+ borderColor = dark_color ;
92
88
} else if (speed_to_limit_ratio > speed_to_limit_ratio_min) {
93
89
double interpolation_factor = (speed_to_limit_ratio - speed_to_limit_ratio_min) /
94
90
(speed_to_limit_ratio_max - speed_to_limit_ratio_min);
95
- // Interpolate between colorMin and colorMax
96
- double saturation = color_s_min + (color_s_max - color_s_min) * interpolation_factor;
97
-
98
- borderColor.setHsvF (0.0 , saturation, 1.0 );
91
+ // Interpolate between light_color and dark_color
92
+ int red = light_color.red () + (dark_color.red () - light_color.red ()) * interpolation_factor;
93
+ int green =
94
+ light_color.green () + (dark_color.green () - light_color.green ()) * interpolation_factor;
95
+ int blue =
96
+ light_color.blue () + (dark_color.blue () - light_color.blue ()) * interpolation_factor;
97
+ borderColor = QColor (red, green, blue);
99
98
}
100
99
}
101
100
102
101
// Define the area for the outer circle
103
102
QRectF outerCircleRect = QRectF (45 , 45 , 45 , 45 );
104
- outerCircleRect.moveTopRight (
105
- QPointF ( backgroundRect.right () - 44 , backgroundRect.top () + outerCircleRect.height () / 2 + 5 ));
103
+ outerCircleRect.moveTopRight (QPointF (
104
+ backgroundRect.right () - 44 , backgroundRect.height () / 2 - outerCircleRect.height () / 2 ));
106
105
107
106
// Now use borderColor for drawing
108
107
painter.setPen (QPen (borderColor, 2 , Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
@@ -120,8 +119,8 @@ void SpeedLimitDisplay::drawSpeedLimitIndicator(QPainter & painter, const QRectF
120
119
121
120
painter.setRenderHint (QPainter::Antialiasing, true );
122
121
QColor colorFromHSV;
123
- colorFromHSV.setHsv (0 , 0 , 29 ); // Hue, Saturation, Value
124
- colorFromHSV.setAlphaF (0.60 ); // Transparency
122
+ colorFromHSV.setHsv (bg_color. hue (), bg_color. saturation (), bg_color. value ());
123
+ colorFromHSV.setAlphaF (bg_alpha);
125
124
painter.setBrush (colorFromHSV);
126
125
painter.drawEllipse (innerCircleRect);
127
126
@@ -138,8 +137,7 @@ void SpeedLimitDisplay::drawSpeedLimitIndicator(QPainter & painter, const QRectF
138
137
QFont font = QFont (" Quicksand" , 16 , QFont::Bold);
139
138
140
139
painter.setFont (font);
141
- // #C2C2C2
142
- painter.setPen (QPen (gray, 2 , Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
140
+ painter.setPen (QPen (color, 2 , Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
143
141
144
142
// Draw the text in the center of the circle
145
143
painter.drawText (innerCircleRect, Qt::AlignCenter, text);
0 commit comments