Skip to content

Commit

Permalink
correction of sizing/positionning of items in overlay + use color val…
Browse files Browse the repository at this point in the history
…ues from main widget

Signed-off-by: KhalilSelyan <[email protected]>
  • Loading branch information
KhalilSelyan committed May 22, 2024
1 parent 8f9c9c9 commit 518caf4
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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);

Expand All @@ -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));

Check warning on line 140 in common/autoware_overlay_rviz_plugin/autoware_overlay_rviz_plugin/src/speed_limit_display.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Excess Number of Function Arguments

SpeedLimitDisplay::drawSpeedLimitIndicator has 7 arguments, threshold = 4. This function has too many arguments, indicating a lack of encapsulation. Avoid adding more arguments.

// Draw the text in the center of the circle
painter.drawText(innerCircleRect, Qt::AlignCenter, text);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down

0 comments on commit 518caf4

Please sign in to comment.