Skip to content

Commit

Permalink
chore: update mission details display with customizable background an…
Browse files Browse the repository at this point in the history
…d text colors

Signed-off-by: KhalilSelyan <[email protected]>
  • Loading branch information
KhalilSelyan committed May 22, 2024
1 parent 518caf4 commit 2add231
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ private Q_SLOTS:
rviz_common::properties::IntProperty * property_height_;
rviz_common::properties::IntProperty * property_right_;
rviz_common::properties::IntProperty * property_top_;
rviz_common::properties::ColorProperty * property_bg_color_;
rviz_common::properties::FloatProperty * property_bg_alpha_;
rviz_common::properties::ColorProperty * property_text_color_;
std::unique_ptr<rviz_common::properties::RosTopicProperty>
remaining_distance_time_topic_property_;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,15 @@ class RemainingDistanceTimeDisplay
{
public:
RemainingDistanceTimeDisplay();
void drawRemainingDistanceTimeDisplay(QPainter & painter, const QRectF & backgroundRect);
void drawRemainingDistanceTimeDisplay(
QPainter & painter, const QRectF & backgroundRect, const QColor & text_color);
void updateRemainingDistanceTimeData(
const autoware_internal_msgs::msg::MissionRemainingDistanceTime::ConstSharedPtr & msg);

private:
double remaining_distance_; // Internal variable to store remaining distance
double remaining_time_; // Internal variable to store remaining time

QColor gray = QColor(194, 194, 194);

QImage icon_dist_;
QImage icon_dist_scaled_;
QImage icon_time_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ MissionDetailsDisplay::MissionDetailsDisplay()
"Right", 10, "Margin from the right border", this, SLOT(update_size()));
property_top_ = new rviz_common::properties::IntProperty(
"Top", 10, "Margin from the top border", this, SLOT(update_size()));
property_bg_alpha_ = new rviz_common::properties::FloatProperty(
"Background Alpha", 0.3, "Background Alpha", this, SLOT(update_size()));
property_bg_color_ = new rviz_common::properties::ColorProperty(
"Background Color", QColor(0, 0, 0), "Background Color", this, SLOT(update_size()));
property_text_color_ = new rviz_common::properties::ColorProperty(
"Text Color", QColor(194, 194, 194), "Text Color", this, SLOT(update_size()));

// Initialize the component displays
remaining_distance_time_display_ = std::make_unique<RemainingDistanceTimeDisplay>();
Expand Down Expand Up @@ -154,7 +160,8 @@ void MissionDetailsDisplay::draw_widget(QImage & hud)
draw_rounded_rect(painter, backgroundRect);

if (remaining_distance_time_display_) {
remaining_distance_time_display_->drawRemainingDistanceTimeDisplay(painter, backgroundRect);
remaining_distance_time_display_->drawRemainingDistanceTimeDisplay(
painter, backgroundRect, property_text_color_->getColor());
}

painter.end();
Expand All @@ -164,8 +171,10 @@ void MissionDetailsDisplay::draw_rounded_rect(QPainter & painter, const QRectF &
{
painter.setRenderHint(QPainter::Antialiasing, true);
QColor colorFromHSV;
colorFromHSV.setHsv(0, 0, 29);
colorFromHSV.setAlphaF(0.60);
colorFromHSV.setHsv(
property_bg_color_->getColor().hue(), property_bg_color_->getColor().saturation(),
property_bg_color_->getColor().value());
colorFromHSV.setAlphaF(property_bg_alpha_->getFloat());

painter.setBrush(colorFromHSV);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void RemainingDistanceTimeDisplay::updateRemainingDistanceTimeData(
}

void RemainingDistanceTimeDisplay::drawRemainingDistanceTimeDisplay(
QPainter & painter, const QRectF & backgroundRect)
QPainter & painter, const QRectF & backgroundRect, const QColor & text_color)
{
const QFont font("Quicksand", 15, QFont::Bold);
painter.setFont(font);
Expand Down Expand Up @@ -107,7 +107,7 @@ void RemainingDistanceTimeDisplay::drawRemainingDistanceTimeDisplay(
QRectF rect_text_unit(
rect.topRight().x() - unit_width, rect.topRight().y(), unit_width, rect.height());

painter.setPen(gray);
painter.setPen(text_color);
painter.drawText(rect_text_unit, Qt::AlignLeft | Qt::AlignVCenter, str_unit);

// place the value text
Expand Down

0 comments on commit 2add231

Please sign in to comment.