From 518caf413f776e5db8cdd3b984654cc760a22169 Mon Sep 17 00:00:00 2001 From: KhalilSelyan Date: Wed, 22 May 2024 11:27:58 +0300 Subject: [PATCH] correction of sizing/positionning of items in overlay + use color values from main widget Signed-off-by: KhalilSelyan --- .../include/gear_display.hpp | 4 +- .../include/speed_display.hpp | 3 +- .../include/speed_limit_display.hpp | 6 ++- .../src/gear_display.cpp | 7 ++-- .../src/speed_display.cpp | 5 ++- .../src/speed_limit_display.cpp | 38 +++++++++---------- .../src/traffic_display.cpp | 2 +- 7 files changed, 34 insertions(+), 31 deletions(-) diff --git a/common/autoware_overlay_rviz_plugin/autoware_overlay_rviz_plugin/include/gear_display.hpp b/common/autoware_overlay_rviz_plugin/autoware_overlay_rviz_plugin/include/gear_display.hpp index 3fe473d5d5123..4041625c6401d 100644 --- a/common/autoware_overlay_rviz_plugin/autoware_overlay_rviz_plugin/include/gear_display.hpp +++ b/common/autoware_overlay_rviz_plugin/autoware_overlay_rviz_plugin/include/gear_display.hpp @@ -36,7 +36,9 @@ class GearDisplay { public: GearDisplay(); - void drawGearIndicator(QPainter & painter, const QRectF & backgroundRect); + void drawGearIndicator( + QPainter & painter, const QRectF & backgroundRect, const QColor & color, + const QColor & bg_color); void updateGearData(const autoware_auto_vehicle_msgs::msg::GearReport::ConstSharedPtr & msg); private: diff --git a/common/autoware_overlay_rviz_plugin/autoware_overlay_rviz_plugin/include/speed_display.hpp b/common/autoware_overlay_rviz_plugin/autoware_overlay_rviz_plugin/include/speed_display.hpp index 0669028dba3b2..0e691aad7da32 100644 --- a/common/autoware_overlay_rviz_plugin/autoware_overlay_rviz_plugin/include/speed_display.hpp +++ b/common/autoware_overlay_rviz_plugin/autoware_overlay_rviz_plugin/include/speed_display.hpp @@ -36,12 +36,11 @@ class SpeedDisplay { public: SpeedDisplay(); - void drawSpeedDisplay(QPainter & painter, const QRectF & backgroundRect); + void drawSpeedDisplay(QPainter & painter, const QRectF & backgroundRect, const QColor & color); void updateSpeedData(const autoware_auto_vehicle_msgs::msg::VelocityReport::ConstSharedPtr & msg); private: float current_speed_; // Internal variable to store current speed - QColor gray = QColor(194, 194, 194); }; } // namespace autoware_overlay_rviz_plugin diff --git a/common/autoware_overlay_rviz_plugin/autoware_overlay_rviz_plugin/include/speed_limit_display.hpp b/common/autoware_overlay_rviz_plugin/autoware_overlay_rviz_plugin/include/speed_limit_display.hpp index b59f4acf380db..a5ad7e5502c20 100644 --- a/common/autoware_overlay_rviz_plugin/autoware_overlay_rviz_plugin/include/speed_limit_display.hpp +++ b/common/autoware_overlay_rviz_plugin/autoware_overlay_rviz_plugin/include/speed_limit_display.hpp @@ -37,14 +37,16 @@ class SpeedLimitDisplay { public: SpeedLimitDisplay(); - void drawSpeedLimitIndicator(QPainter & painter, const QRectF & backgroundRect); + void drawSpeedLimitIndicator( + QPainter & painter, const QRectF & backgroundRect, const QColor & color, + const QColor & light_color, const QColor & dark_color, const QColor & bg_color, + const float bg_alpha); void updateSpeedLimitData(const tier4_planning_msgs::msg::VelocityLimit::ConstSharedPtr msg); void updateSpeedData(const autoware_auto_vehicle_msgs::msg::VelocityReport::ConstSharedPtr & msg); private: float current_limit; // Internal variable to store current gear float current_speed_; // Internal variable to store current speed - QColor gray = QColor(194, 194, 194); }; } // namespace autoware_overlay_rviz_plugin diff --git a/common/autoware_overlay_rviz_plugin/autoware_overlay_rviz_plugin/src/gear_display.cpp b/common/autoware_overlay_rviz_plugin/autoware_overlay_rviz_plugin/src/gear_display.cpp index 825c7c1620e2c..d8bff4d51c212 100644 --- a/common/autoware_overlay_rviz_plugin/autoware_overlay_rviz_plugin/src/gear_display.cpp +++ b/common/autoware_overlay_rviz_plugin/autoware_overlay_rviz_plugin/src/gear_display.cpp @@ -55,7 +55,8 @@ void GearDisplay::updateGearData( current_gear_ = msg->report; // Assuming msg->report contains the gear information } -void GearDisplay::drawGearIndicator(QPainter & painter, const QRectF & backgroundRect) +void GearDisplay::drawGearIndicator( + QPainter & painter, const QRectF & backgroundRect, const QColor & color, const QColor & bg_color) { // we deal with the different gears here std::string gearString; @@ -91,9 +92,9 @@ void GearDisplay::drawGearIndicator(QPainter & painter, const QRectF & backgroun double gearX = backgroundRect.left() + 54; double gearY = backgroundRect.height() / 2 - gearBoxSize / 2; QRect gearRect(gearX, gearY, gearBoxSize, gearBoxSize); - painter.setBrush(gray); + painter.setBrush(color); painter.drawRoundedRect(gearRect, 10, 10); - painter.setPen(Qt::black); + painter.setPen(bg_color); painter.drawText(gearRect, Qt::AlignCenter, QString::fromStdString(gearString)); } diff --git a/common/autoware_overlay_rviz_plugin/autoware_overlay_rviz_plugin/src/speed_display.cpp b/common/autoware_overlay_rviz_plugin/autoware_overlay_rviz_plugin/src/speed_display.cpp index 5c5342259005b..b73fc28abd140 100644 --- a/common/autoware_overlay_rviz_plugin/autoware_overlay_rviz_plugin/src/speed_display.cpp +++ b/common/autoware_overlay_rviz_plugin/autoware_overlay_rviz_plugin/src/speed_display.cpp @@ -76,7 +76,8 @@ void SpeedDisplay::updateSpeedData( // } // } -void SpeedDisplay::drawSpeedDisplay(QPainter & painter, const QRectF & backgroundRect) +void SpeedDisplay::drawSpeedDisplay( + QPainter & painter, const QRectF & backgroundRect, const QColor & color) { QFont referenceFont("Quicksand", 80, QFont::Bold); painter.setFont(referenceFont); @@ -96,7 +97,7 @@ void SpeedDisplay::drawSpeedDisplay(QPainter & painter, const QRectF & backgroun QPointF speedPos( backgroundRect.center().x() - speedNumberRect.width() / 2, backgroundRect.center().y() + speedNumberRect.bottom()); - painter.setPen(gray); + painter.setPen(color); painter.drawText(speedPos, speedNumber); QFont unitFont("Quicksand", 8, QFont::DemiBold); diff --git a/common/autoware_overlay_rviz_plugin/autoware_overlay_rviz_plugin/src/speed_limit_display.cpp b/common/autoware_overlay_rviz_plugin/autoware_overlay_rviz_plugin/src/speed_limit_display.cpp index 4c83b4a73c0c2..49d8b7a2f18d9 100644 --- a/common/autoware_overlay_rviz_plugin/autoware_overlay_rviz_plugin/src/speed_limit_display.cpp +++ b/common/autoware_overlay_rviz_plugin/autoware_overlay_rviz_plugin/src/speed_limit_display.cpp @@ -68,41 +68,40 @@ void SpeedLimitDisplay::updateSpeedData( } } -void SpeedLimitDisplay::drawSpeedLimitIndicator(QPainter & painter, const QRectF & backgroundRect) +void SpeedLimitDisplay::drawSpeedLimitIndicator( + QPainter & painter, const QRectF & backgroundRect, const QColor & color, + const QColor & light_color, const QColor & dark_color, const QColor & bg_color, + const float bg_alpha) { // Enable Antialiasing for smoother drawing painter.setRenderHint(QPainter::Antialiasing, true); painter.setRenderHint(QPainter::SmoothPixmapTransform, true); - const double color_s_min = 0.4; - const double color_s_max = 0.8; - QColor colorMin; - colorMin.setHsvF(0.0, color_s_min, 1.0); - QColor colorMax; - colorMax.setHsvF(0.0, color_s_max, 1.0); - - QColor borderColor = colorMin; + QColor borderColor = light_color; if (current_limit > 0.0) { double speed_to_limit_ratio = current_speed_ / current_limit; const double speed_to_limit_ratio_min = 0.6; const double speed_to_limit_ratio_max = 0.9; if (speed_to_limit_ratio >= speed_to_limit_ratio_max) { - borderColor = colorMax; + borderColor = dark_color; } else if (speed_to_limit_ratio > speed_to_limit_ratio_min) { double interpolation_factor = (speed_to_limit_ratio - speed_to_limit_ratio_min) / (speed_to_limit_ratio_max - speed_to_limit_ratio_min); - // Interpolate between colorMin and colorMax - double saturation = color_s_min + (color_s_max - color_s_min) * interpolation_factor; - - borderColor.setHsvF(0.0, saturation, 1.0); + // Interpolate between light_color and dark_color + int red = light_color.red() + (dark_color.red() - light_color.red()) * interpolation_factor; + int green = + light_color.green() + (dark_color.green() - light_color.green()) * interpolation_factor; + int blue = + light_color.blue() + (dark_color.blue() - light_color.blue()) * interpolation_factor; + borderColor = QColor(red, green, blue); } } // Define the area for the outer circle QRectF outerCircleRect = QRectF(45, 45, 45, 45); - outerCircleRect.moveTopRight( - QPointF(backgroundRect.right() - 44, backgroundRect.top() + outerCircleRect.height() / 2 + 5)); + outerCircleRect.moveTopRight(QPointF( + backgroundRect.right() - 44, backgroundRect.height() / 2 - outerCircleRect.height() / 2)); // Now use borderColor for drawing painter.setPen(QPen(borderColor, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); @@ -120,8 +119,8 @@ void SpeedLimitDisplay::drawSpeedLimitIndicator(QPainter & painter, const QRectF painter.setRenderHint(QPainter::Antialiasing, true); QColor colorFromHSV; - colorFromHSV.setHsv(0, 0, 29); // Hue, Saturation, Value - colorFromHSV.setAlphaF(0.60); // Transparency + colorFromHSV.setHsv(bg_color.hue(), bg_color.saturation(), bg_color.value()); + colorFromHSV.setAlphaF(bg_alpha); painter.setBrush(colorFromHSV); painter.drawEllipse(innerCircleRect); @@ -138,8 +137,7 @@ void SpeedLimitDisplay::drawSpeedLimitIndicator(QPainter & painter, const QRectF QFont font = QFont("Quicksand", 16, QFont::Bold); painter.setFont(font); - // #C2C2C2 - painter.setPen(QPen(gray, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); + painter.setPen(QPen(color, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); // Draw the text in the center of the circle painter.drawText(innerCircleRect, Qt::AlignCenter, text); diff --git a/common/autoware_overlay_rviz_plugin/autoware_overlay_rviz_plugin/src/traffic_display.cpp b/common/autoware_overlay_rviz_plugin/autoware_overlay_rviz_plugin/src/traffic_display.cpp index f6d232709a333..9996714c0e692 100644 --- a/common/autoware_overlay_rviz_plugin/autoware_overlay_rviz_plugin/src/traffic_display.cpp +++ b/common/autoware_overlay_rviz_plugin/autoware_overlay_rviz_plugin/src/traffic_display.cpp @@ -65,7 +65,7 @@ void TrafficDisplay::drawTrafficLightIndicator(QPainter & painter, const QRectF QRectF circleRect = QRectF(50, 50, 50, 50); circleRect.moveTopRight(QPointF( backgroundRect.right() - circleRect.width() - 75, - backgroundRect.top() + circleRect.height() / 2)); + backgroundRect.height() / 2 - circleRect.height() / 2)); painter.drawEllipse(circleRect); if (!current_traffic_.elements.empty()) {