Skip to content

Commit

Permalink
style: update state panel plugin (#8846)
Browse files Browse the repository at this point in the history
Signed-off-by: KhalilSelyan <[email protected]>
Signed-off-by: M. Fatih Cırıt <[email protected]>
  • Loading branch information
KhalilSelyan authored Sep 17, 2024
1 parent e8e9e89 commit 28a389b
Show file tree
Hide file tree
Showing 10 changed files with 249 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ void SpeedLimitDisplay::drawSpeedLimitIndicator(
painter.setRenderHint(QPainter::Antialiasing, true);
QColor colorFromHSV;
colorFromHSV.setHsv(bg_color.hue(), bg_color.saturation(), bg_color.value());
colorFromHSV.setAlphaF(bg_alpha);
painter.setBrush(colorFromHSV);
painter.drawEllipse(innerCircleRect);

Expand Down
64 changes: 48 additions & 16 deletions common/tier4_state_rviz_plugin/src/autoware_state_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,6 @@ QVBoxLayout * AutowareStatePanel::makeVelocityLimitGroup()
CustomSlider * pub_velocity_limit_slider_ = new CustomSlider(Qt::Horizontal);
pub_velocity_limit_slider_->setRange(0, 100);
pub_velocity_limit_slider_->setValue(0);
pub_velocity_limit_slider_->setMaximumWidth(300);

connect(pub_velocity_limit_slider_, &QSlider::sliderPressed, this, [this]() {
sliderIsDragging = true; // User starts dragging the handle
Expand Down Expand Up @@ -455,7 +454,13 @@ QVBoxLayout * AutowareStatePanel::makeVelocityLimitGroup()
connect(emergency_button_ptr_, SIGNAL(clicked()), this, SLOT(onClickEmergencyButton()));
auto * utility_layout = new QVBoxLayout;
auto * velocity_limit_layout = new QHBoxLayout;
QLabel * velocity_limit_label = new QLabel("km/h");
auto * velocity_limit_label = new QLabel("km/h");

QFontMetrics fm(velocity_limit_value_label_->font());
int width = fm.horizontalAdvance("999");

// Set the fixed width for the label
velocity_limit_value_label_->setFixedWidth(width);

velocity_limit_layout->addWidget(pub_velocity_limit_slider_);
velocity_limit_layout->addSpacing(5);
Expand Down Expand Up @@ -558,19 +563,20 @@ void AutowareStatePanel::onRoute(const RouteState::ConstSharedPtr msg)
routing_icon->updateStyle(state, bgColor);
routing_label_ptr_->setText(route_state);

clear_route_button_ptr_->updateStyle(
"Clear Route",
QColor(autoware::state_rviz_plugin::colors::default_colors.surface_container_low.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.primary.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.surface_container_low_hover.c_str()),
QColor(
autoware::state_rviz_plugin::colors::default_colors.surface_container_low_pressed.c_str()),
QColor(
autoware::state_rviz_plugin::colors::default_colors.surface_container_low_pressed.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.disabled_button_bg.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.disabled_button_text.c_str()));
if (msg->state == RouteState::SET) {
activateButton(clear_route_button_ptr_);
} else {
clear_route_button_ptr_->setStyleSheet(
QString("QPushButton {"
"background-color: %1;color: %2;"
"border: 2px solid %3;"
"font-weight: bold;"
"}")
.arg(autoware::state_rviz_plugin::colors::default_colors.surface_container_highest.c_str())
.arg(autoware::state_rviz_plugin::colors::default_colors.outline.c_str())
.arg(
autoware::state_rviz_plugin::colors::default_colors.surface_container_highest.c_str()));
deactivateButton(clear_route_button_ptr_);
}
}
Expand Down Expand Up @@ -608,6 +614,17 @@ void AutowareStatePanel::onLocalization(const LocalizationInitializationState::C

localization_icon->updateStyle(state, bgColor);
localization_label_ptr_->setText(localization_state);
init_by_gnss_button_ptr_->updateStyle(
"Initialize with GNSS",
QColor(autoware::state_rviz_plugin::colors::default_colors.surface_container_low.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.primary.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.surface_container_low_hover.c_str()),
QColor(
autoware::state_rviz_plugin::colors::default_colors.surface_container_low_pressed.c_str()),
QColor(
autoware::state_rviz_plugin::colors::default_colors.surface_container_low_pressed.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.disabled_button_bg.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.disabled_button_text.c_str()));
}

void AutowareStatePanel::onMotion(const MotionState::ConstSharedPtr msg)
Expand Down Expand Up @@ -644,6 +661,17 @@ void AutowareStatePanel::onMotion(const MotionState::ConstSharedPtr msg)
motion_icon->updateStyle(state, bgColor);
motion_label_ptr_->setText(motion_state);

accept_start_button_ptr_->updateStyle(
"Accept Start",
QColor(autoware::state_rviz_plugin::colors::default_colors.surface_container_low.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.primary.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.surface_container_low_hover.c_str()),
QColor(
autoware::state_rviz_plugin::colors::default_colors.surface_container_low_pressed.c_str()),
QColor(
autoware::state_rviz_plugin::colors::default_colors.surface_container_low_pressed.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.disabled_button_bg.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.disabled_button_text.c_str()));
if (msg->state == MotionState::STARTING) {
activateButton(accept_start_button_ptr_);
} else {
Expand Down Expand Up @@ -746,16 +774,20 @@ void AutowareStatePanel::onEmergencyStatus(
emergency_button_ptr_->updateStyle(
"Clear Emergency",
QColor(autoware::state_rviz_plugin::colors::default_colors.error_container.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.error.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.on_error_container.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.on_error.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.on_error_container.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.error_press.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.error_press.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.error_container.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.error_container.c_str()));
} else {
emergency_button_ptr_->updateStyle(
"Set Emergency", QColor(autoware::state_rviz_plugin::colors::default_colors.primary.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.on_primary.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.on_primary_container.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.on_primary.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.hover_button_bg.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.pressed_button_bg.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.checked_button_bg.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.error_container.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.surface_tint.c_str()));
}
}
Expand Down
49 changes: 38 additions & 11 deletions common/tier4_state_rviz_plugin/src/custom_button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@

CustomElevatedButton::CustomElevatedButton(
const QString & text, const QColor & bgColor, const QColor & textColor, const QColor & hoverColor,
const QColor & disabledBgColor, const QColor & disabledTextColor, QWidget * parent)
const QColor & pressedColor, const QColor & checkedColor, const QColor & disabledBgColor,
const QColor & disabledTextColor, QWidget * parent)
: QPushButton(text, parent),
backgroundColor(bgColor),
textColor(textColor),
hoverColor(hoverColor),
pressedColor(pressedColor),
checkedColor(checkedColor),
disabledBgColor(disabledBgColor),
disabledTextColor(disabledTextColor)
{
Expand Down Expand Up @@ -63,12 +66,15 @@ QSize CustomElevatedButton::minimumSizeHint() const
// cppcheck-suppress unusedFunction
void CustomElevatedButton::updateStyle(
const QString & text, const QColor & bgColor, const QColor & textColor, const QColor & hoverColor,
const QColor & disabledBgColor, const QColor & disabledTextColor)
const QColor & pressedColor, const QColor & checkedColor, const QColor & disabledBgColor,
const QColor & disabledTextColor)
{
setText(text);
backgroundColor = bgColor;
this->textColor = textColor;
this->hoverColor = hoverColor;
this->pressedColor = pressedColor;
this->checkedColor = checkedColor;
this->disabledBgColor = disabledBgColor;
this->disabledTextColor = disabledTextColor;
update(); // Force repaint
Expand All @@ -89,10 +95,16 @@ void CustomElevatedButton::paintEvent(QPaintEvent *)
if (!isEnabled()) {
buttonColor = disabledBgColor;
currentTextColor = disabledTextColor;
} else if (isHovered) {
buttonColor = hoverColor;
} else {
buttonColor = backgroundColor;
if (isPressed) {
buttonColor = pressedColor;
} else if (isChecked) {
buttonColor = checkedColor;
} else if (isHovered) {
buttonColor = hoverColor;
} else {
buttonColor = backgroundColor;
}
}

int cornerRadius = height() / 2; // Making the corner radius proportional to the height
Expand All @@ -101,19 +113,14 @@ void CustomElevatedButton::paintEvent(QPaintEvent *)
QPainterPath backgroundPath;
backgroundPath.addRoundedRect(r, cornerRadius, cornerRadius);
if (!isEnabled()) {
painter.setBrush(
QColor(autoware::state_rviz_plugin::colors::default_colors.on_surface.c_str()));
painter.setOpacity(0.12);
painter.setBrush(disabledBgColor);
} else {
painter.setBrush(buttonColor);
}
painter.setPen(Qt::NoPen);
painter.drawPath(backgroundPath);

// Draw button text
if (!isEnabled()) {
painter.setOpacity(0.38);
}
painter.setPen(currentTextColor);
painter.drawText(r, Qt::AlignCenter, text());
}
Expand All @@ -131,3 +138,23 @@ void CustomElevatedButton::leaveEvent(QEvent * event)
update();
QPushButton::leaveEvent(event);
}

void CustomElevatedButton::mousePressEvent(QMouseEvent * event)
{
isPressed = true;
update();
QPushButton::mousePressEvent(event);
}

void CustomElevatedButton::mouseReleaseEvent(QMouseEvent * event)
{
isPressed = false;
update();
QPushButton::mouseReleaseEvent(event);
}

void CustomElevatedButton::setChecked(bool checked)
{
isChecked = checked;
update();
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,21 @@

CustomSegmentedButtonItem::CustomSegmentedButtonItem(const QString & text, QWidget * parent)
: QPushButton(text, parent),
bgColor(
QColor(autoware::state_rviz_plugin::colors::default_colors.surface_container_low.c_str())),
bgColor(QColor(autoware::state_rviz_plugin::colors::default_colors.surface.c_str())),
checkedBgColor(
QColor(autoware::state_rviz_plugin::colors::default_colors.secondary_container.c_str())),
QColor(autoware::state_rviz_plugin::colors::default_colors.on_secondary_fixed_variant.c_str())),
hoverColor(autoware::state_rviz_plugin::colors::default_colors.on_surface_hover_bg.c_str()),
pressedColor(autoware::state_rviz_plugin::colors::default_colors.on_surface_pressed_bg.c_str()),
inactiveTextColor(QColor(autoware::state_rviz_plugin::colors::default_colors.on_surface.c_str())),
activeTextColor(
QColor(autoware::state_rviz_plugin::colors::default_colors.on_secondary_container.c_str())),
disabledBgColor(autoware::state_rviz_plugin::colors::default_colors.surface.c_str()),
disabledTextColor(
autoware::state_rviz_plugin::colors::default_colors.on_surface_disabled.c_str()),
isHovered(false),
isActivated(false),
isDisabled(false)

isDisabled(false),
isPressed(false)
{
setCheckable(true);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
Expand Down Expand Up @@ -92,6 +96,8 @@ void CustomSegmentedButtonItem::paintEvent(QPaintEvent *)
QColor buttonColor;
if (isDisabled) {
buttonColor = disabledBgColor;
} else if (isPressed) {
buttonColor = pressedColor;
} else if (isHovered && !isChecked() && isCheckable()) {
buttonColor = hoverColor;
} else if (isActivated) {
Expand Down Expand Up @@ -177,3 +183,21 @@ void CustomSegmentedButtonItem::leaveEvent(QEvent * event)
}
QPushButton::leaveEvent(event);
}

void CustomSegmentedButtonItem::mousePressEvent(QMouseEvent * event)
{
if (event->button() == Qt::LeftButton && !isDisabled) {
isPressed = true;
update();
}
QPushButton::mousePressEvent(event);
}

void CustomSegmentedButtonItem::mouseReleaseEvent(QMouseEvent * event)
{
if (event->button() == Qt::LeftButton && !isDisabled) {
isPressed = false;
update();
}
QPushButton::mouseReleaseEvent(event);
}
Loading

0 comments on commit 28a389b

Please sign in to comment.