Skip to content

Commit

Permalink
refactor(tier4_state_rviz_plugin): add button background colors
Browse files Browse the repository at this point in the history
Signed-off-by: KhalilSelyan <[email protected]>
  • Loading branch information
M. Fatih Cırıt committed Sep 12, 2024
1 parent c44343b commit 95dff2f
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 26 deletions.
67 changes: 53 additions & 14 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,7 @@ 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);
// 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 @@ -560,18 +560,26 @@ void AutowareStatePanel::onRoute(const RouteState::ConstSharedPtr msg)

if (msg->state == RouteState::SET) {
activateButton(clear_route_button_ptr_);
clear_route_button_ptr_->updateStyle(

Check warning on line 563 in common/tier4_state_rviz_plugin/src/autoware_state_panel.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/autoware_state_panel.cpp#L563

Added line #L563 was not covered by tests
"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_highest.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.surface_container_high.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.surface_container_high.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.surface_container_highest.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.on_surface.c_str()));

Check warning on line 571 in common/tier4_state_rviz_plugin/src/autoware_state_panel.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/autoware_state_panel.cpp#L565-L571

Added lines #L565 - L571 were not covered by tests
} 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_);
clear_route_button_ptr_->updateStyle(

Check warning on line 574 in common/tier4_state_rviz_plugin/src/autoware_state_panel.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/autoware_state_panel.cpp#L574

Added line #L574 was not covered by tests
"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_highest.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.surface_container_high.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.surface_container_high.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.surface_container_highest.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.on_surface.c_str()));

Check warning on line 582 in common/tier4_state_rviz_plugin/src/autoware_state_panel.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Code Duplication

The module contains 4 functions with similar structure: AutowareStatePanel::makeLocalizationGroup,AutowareStatePanel::makeMotionGroup,AutowareStatePanel::onMotion,AutowareStatePanel::onRoute. Avoid duplicated, aka copy-pasted, code inside the module. More duplication lowers the code health.

Check warning on line 582 in common/tier4_state_rviz_plugin/src/autoware_state_panel.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/autoware_state_panel.cpp#L576-L582

Added lines #L576 - L582 were not covered by tests
}
}

Expand Down Expand Up @@ -608,6 +616,15 @@ void AutowareStatePanel::onLocalization(const LocalizationInitializationState::C

localization_icon->updateStyle(state, bgColor);
localization_label_ptr_->setText(localization_state);
init_by_gnss_button_ptr_->updateStyle(

Check warning on line 619 in common/tier4_state_rviz_plugin/src/autoware_state_panel.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/autoware_state_panel.cpp#L619

Added line #L619 was not covered by tests
"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_highest.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.surface_container_high.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.surface_container_high.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.surface_container_high.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.on_surface.c_str()));

Check warning on line 627 in common/tier4_state_rviz_plugin/src/autoware_state_panel.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/autoware_state_panel.cpp#L621-L627

Added lines #L621 - L627 were not covered by tests
}

void AutowareStatePanel::onMotion(const MotionState::ConstSharedPtr msg)
Expand Down Expand Up @@ -646,8 +663,26 @@ void AutowareStatePanel::onMotion(const MotionState::ConstSharedPtr msg)

if (msg->state == MotionState::STARTING) {
activateButton(accept_start_button_ptr_);
accept_start_button_ptr_->updateStyle(

Check warning on line 666 in common/tier4_state_rviz_plugin/src/autoware_state_panel.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/autoware_state_panel.cpp#L666

Added line #L666 was not covered by tests
"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_highest.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.surface_container_high.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.surface_container_high.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.surface_container_highest.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.on_surface.c_str()));

Check warning on line 674 in common/tier4_state_rviz_plugin/src/autoware_state_panel.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/autoware_state_panel.cpp#L668-L674

Added lines #L668 - L674 were not covered by tests
} else {
deactivateButton(accept_start_button_ptr_);
accept_start_button_ptr_->updateStyle(

Check warning on line 677 in common/tier4_state_rviz_plugin/src/autoware_state_panel.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/autoware_state_panel.cpp#L677

Added line #L677 was not covered by tests
"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_highest.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.surface_container_high.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.surface_container_high.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.surface_container_highest.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.on_surface.c_str()));

Check warning on line 685 in common/tier4_state_rviz_plugin/src/autoware_state_panel.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/autoware_state_panel.cpp#L679-L685

Added lines #L679 - L685 were not covered by tests
}
}

Expand Down Expand Up @@ -748,14 +783,18 @@ void AutowareStatePanel::onEmergencyStatus(
QColor(autoware::state_rviz_plugin::colors::default_colors.error_container.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.on_error.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.on_error.c_str()),
QColor(autoware::state_rviz_plugin::colors::default_colors.error_container.c_str()),

Check warning on line 788 in common/tier4_state_rviz_plugin/src/autoware_state_panel.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/autoware_state_panel.cpp#L786-L788

Added lines #L786 - L788 were not covered by tests
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()),

Check warning on line 797 in common/tier4_state_rviz_plugin/src/autoware_state_panel.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/autoware_state_panel.cpp#L794-L797

Added lines #L794 - L797 were not covered by tests
QColor(autoware::state_rviz_plugin::colors::default_colors.surface_tint.c_str()));
}
}
Expand Down
45 changes: 38 additions & 7 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)

Check warning on line 21 in common/tier4_state_rviz_plugin/src/custom_button.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/custom_button.cpp#L21

Added line #L21 was not covered by tests
: 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;

Check notice on line 77 in common/tier4_state_rviz_plugin/src/custom_button.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

ℹ Getting worse: Excess Number of Function Arguments

CustomElevatedButton::updateStyle increases from 6 to 8 arguments, threshold = 4. This function has too many arguments, indicating a lack of encapsulation. Avoid adding more arguments.

Check warning on line 77 in common/tier4_state_rviz_plugin/src/custom_button.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/custom_button.cpp#L76-L77

Added lines #L76 - L77 were not covered by tests
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;

Check warning on line 100 in common/tier4_state_rviz_plugin/src/custom_button.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/custom_button.cpp#L100

Added line #L100 was not covered by tests
} else if (isChecked) {
buttonColor = checkedColor;

Check warning on line 102 in common/tier4_state_rviz_plugin/src/custom_button.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/custom_button.cpp#L102

Added line #L102 was not covered by tests
} else if (isHovered) {
buttonColor = hoverColor;

Check warning on line 104 in common/tier4_state_rviz_plugin/src/custom_button.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/custom_button.cpp#L104

Added line #L104 was not covered by tests
} else {
buttonColor = backgroundColor;

Check warning on line 106 in common/tier4_state_rviz_plugin/src/custom_button.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/custom_button.cpp#L106

Added line #L106 was not covered by tests
}
}

int cornerRadius = height() / 2; // Making the corner radius proportional to the height
Expand All @@ -101,8 +113,7 @@ 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.setBrush(disabledBgColor);

Check warning on line 116 in common/tier4_state_rviz_plugin/src/custom_button.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/custom_button.cpp#L116

Added line #L116 was not covered by tests
painter.setOpacity(0.12);
} else {
painter.setBrush(buttonColor);
Expand Down Expand Up @@ -131,3 +142,23 @@ void CustomElevatedButton::leaveEvent(QEvent * event)
update();
QPushButton::leaveEvent(event);
}

void CustomElevatedButton::mousePressEvent(QMouseEvent * event)

Check warning on line 146 in common/tier4_state_rviz_plugin/src/custom_button.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/custom_button.cpp#L146

Added line #L146 was not covered by tests
{
isPressed = true;
update();
QPushButton::mousePressEvent(event);

Check warning on line 150 in common/tier4_state_rviz_plugin/src/custom_button.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/custom_button.cpp#L148-L150

Added lines #L148 - L150 were not covered by tests
}

void CustomElevatedButton::mouseReleaseEvent(QMouseEvent * event)

Check warning on line 153 in common/tier4_state_rviz_plugin/src/custom_button.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/custom_button.cpp#L153

Added line #L153 was not covered by tests
{
isPressed = false;
update();
QPushButton::mouseReleaseEvent(event);

Check warning on line 157 in common/tier4_state_rviz_plugin/src/custom_button.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/custom_button.cpp#L155-L157

Added lines #L155 - L157 were not covered by tests
}

void CustomElevatedButton::setChecked(bool checked)

Check warning on line 160 in common/tier4_state_rviz_plugin/src/custom_button.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/custom_button.cpp#L160

Added line #L160 was not covered by tests
{
isChecked = checked;
update();

Check warning on line 163 in common/tier4_state_rviz_plugin/src/custom_button.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/custom_button.cpp#L162-L163

Added lines #L162 - L163 were not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ void CustomSegmentedButtonItem::paintEvent(QPaintEvent *)
QColor buttonColor;
if (isDisabled) {
buttonColor = disabledBgColor;
} else if (isPressed) {
buttonColor = pressedColor;

Check notice on line 96 in common/tier4_state_rviz_plugin/src/custom_segmented_button_item.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

ℹ Getting worse: Complex Method

CustomSegmentedButtonItem::paintEvent increases in cyclomatic complexity from 14 to 15, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.

Check warning on line 96 in common/tier4_state_rviz_plugin/src/custom_segmented_button_item.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/custom_segmented_button_item.cpp#L96

Added line #L96 was not covered by tests
} else if (isHovered && !isChecked() && isCheckable()) {
buttonColor = hoverColor;
} else if (isActivated) {
Expand Down Expand Up @@ -177,3 +179,21 @@ void CustomSegmentedButtonItem::leaveEvent(QEvent * event)
}
QPushButton::leaveEvent(event);
}

void CustomSegmentedButtonItem::mousePressEvent(QMouseEvent * event)

Check warning on line 183 in common/tier4_state_rviz_plugin/src/custom_segmented_button_item.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/custom_segmented_button_item.cpp#L183

Added line #L183 was not covered by tests
{
if (event->button() == Qt::LeftButton && !isDisabled) {
isPressed = true;
update();

Check warning on line 187 in common/tier4_state_rviz_plugin/src/custom_segmented_button_item.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/custom_segmented_button_item.cpp#L186-L187

Added lines #L186 - L187 were not covered by tests
}
QPushButton::mousePressEvent(event);

Check warning on line 189 in common/tier4_state_rviz_plugin/src/custom_segmented_button_item.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/custom_segmented_button_item.cpp#L189

Added line #L189 was not covered by tests
}

void CustomSegmentedButtonItem::mouseReleaseEvent(QMouseEvent * event)

Check warning on line 192 in common/tier4_state_rviz_plugin/src/custom_segmented_button_item.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/custom_segmented_button_item.cpp#L192

Added line #L192 was not covered by tests
{
if (event->button() == Qt::LeftButton && !isDisabled) {
isPressed = false;
update();

Check warning on line 196 in common/tier4_state_rviz_plugin/src/custom_segmented_button_item.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/custom_segmented_button_item.cpp#L195-L196

Added lines #L195 - L196 were not covered by tests
}
QPushButton::mouseReleaseEvent(event);

Check warning on line 198 in common/tier4_state_rviz_plugin/src/custom_segmented_button_item.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/custom_segmented_button_item.cpp#L198

Added line #L198 was not covered by tests
}
35 changes: 33 additions & 2 deletions common/tier4_state_rviz_plugin/src/custom_toggle_switch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,31 @@ void CustomToggleSwitch::paintEvent(QPaintEvent *)
QColor(autoware::state_rviz_plugin::colors::default_colors.outline.c_str());
QColor checkedIndicatorColor =
QColor(autoware::state_rviz_plugin::colors::default_colors.on_primary.c_str());
QColor indicatorColor = isChecked ? checkedIndicatorColor : uncheckedIndicatorColor;

QColor uncheckedHoverIndicatorColor =
QColor(autoware::state_rviz_plugin::colors::default_colors.surface.c_str());

Check warning on line 49 in common/tier4_state_rviz_plugin/src/custom_toggle_switch.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/custom_toggle_switch.cpp#L49

Added line #L49 was not covered by tests
QColor checkedHoverIndicatorColor =
QColor(autoware::state_rviz_plugin::colors::default_colors.primary_container.c_str());

Check warning on line 51 in common/tier4_state_rviz_plugin/src/custom_toggle_switch.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/custom_toggle_switch.cpp#L51

Added line #L51 was not covered by tests

QColor indicatorColor = isChecked
? (isHovered ? checkedHoverIndicatorColor : checkedIndicatorColor)
: (isHovered ? uncheckedHoverIndicatorColor : uncheckedIndicatorColor);

Check warning on line 55 in common/tier4_state_rviz_plugin/src/custom_toggle_switch.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/custom_toggle_switch.cpp#L54-L55

Added lines #L54 - L55 were not covered by tests

QColor uncheckedBgColor =
QColor(autoware::state_rviz_plugin::colors::default_colors.surface_container_highest.c_str());
QColor checkedBgColor =
QColor(autoware::state_rviz_plugin::colors::default_colors.primary.c_str());

QColor bgColor = isChecked ? checkedBgColor : uncheckedBgColor;
QColor uncheckedHoverBgColor =
QColor(autoware::state_rviz_plugin::colors::default_colors.disabled_elevated_button_bg.c_str());

Check warning on line 63 in common/tier4_state_rviz_plugin/src/custom_toggle_switch.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/custom_toggle_switch.cpp#L63

Added line #L63 was not covered by tests

QColor bgColor =
isChecked ? checkedBgColor : (isHovered ? uncheckedHoverBgColor : uncheckedBgColor);

Check warning on line 66 in common/tier4_state_rviz_plugin/src/custom_toggle_switch.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/custom_toggle_switch.cpp#L66

Added line #L66 was not covered by tests

// Surface color with 12% opacity for the hover circle
QColor hoverCircleColor =
QColor(autoware::state_rviz_plugin::colors::default_colors.surface.c_str());
hoverCircleColor.setAlpha(255 * 0.12); // 12% opacity

Check warning on line 71 in common/tier4_state_rviz_plugin/src/custom_toggle_switch.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/custom_toggle_switch.cpp#L70-L71

Added lines #L70 - L71 were not covered by tests

QRect borderR = r.adjusted(-margin, -margin, margin, margin);
p.setBrush(bgColor);
Expand Down Expand Up @@ -85,3 +102,17 @@ void CustomToggleSwitch::setCheckedState(bool state)
blockSignalsGuard = false;
update(); // Force repaint
}

void CustomToggleSwitch::enterEvent(QEvent * event)

Check warning on line 106 in common/tier4_state_rviz_plugin/src/custom_toggle_switch.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/custom_toggle_switch.cpp#L106

Added line #L106 was not covered by tests
{
isHovered = true;
update();
QCheckBox::enterEvent(event);

Check warning on line 110 in common/tier4_state_rviz_plugin/src/custom_toggle_switch.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/custom_toggle_switch.cpp#L108-L110

Added lines #L108 - L110 were not covered by tests
}

void CustomToggleSwitch::leaveEvent(QEvent * event)

Check warning on line 113 in common/tier4_state_rviz_plugin/src/custom_toggle_switch.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/custom_toggle_switch.cpp#L113

Added line #L113 was not covered by tests
{
isHovered = false;
update();
QCheckBox::leaveEvent(event);

Check warning on line 117 in common/tier4_state_rviz_plugin/src/custom_toggle_switch.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_state_rviz_plugin/src/custom_toggle_switch.cpp#L115-L117

Added lines #L115 - L117 were not covered by tests
}
19 changes: 17 additions & 2 deletions common/tier4_state_rviz_plugin/src/include/custom_button.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,33 +37,48 @@ class CustomElevatedButton : public QPushButton
QColor(autoware::state_rviz_plugin::colors::default_colors.primary.c_str()),
const QColor & hoverColor =
QColor(autoware::state_rviz_plugin::colors::default_colors.surface_container_highest.c_str()),
const QColor & pressedColor =
QColor(autoware::state_rviz_plugin::colors::default_colors.surface_container_highest.c_str()),
const QColor & checkedColor =
QColor(autoware::state_rviz_plugin::colors::default_colors.surface_container_highest.c_str()),
const QColor & disabledBgColor =
QColor(autoware::state_rviz_plugin::colors::default_colors.surface_container_high.c_str()),
const QColor & disabledTextColor =
QColor(autoware::state_rviz_plugin::colors::default_colors.on_surface_variant.c_str()),
QWidget * parent = nullptr);
void updateStyle(
const QString & text, const QColor & bgColor, const QColor & textColor,
const QColor & hoverColor, const QColor & disabledBgColor, const QColor & disabledTextColor);
const QColor & hoverColor, const QColor & pressedColor, const QColor & checkedColor,
const QColor & disabledBgColor, const QColor & disabledTextColor);

protected:
void paintEvent(QPaintEvent * event) override;
void enterEvent(QEvent * event) override;
void leaveEvent(QEvent * event) override;
void mousePressEvent(QMouseEvent * event) override;
void mouseReleaseEvent(QMouseEvent * event) override;
QSize sizeHint() const override;
QSize minimumSizeHint() const override;
// set checked state
void setChecked(bool checked);

private:
QColor backgroundColor =
QColor(autoware::state_rviz_plugin::colors::default_colors.surface_container_low.c_str());
QColor textColor = QColor(autoware::state_rviz_plugin::colors::default_colors.primary.c_str());
QColor hoverColor =
QColor(autoware::state_rviz_plugin::colors::default_colors.surface_container_highest.c_str());
QColor(autoware::state_rviz_plugin::colors::default_colors.hover_button_bg.c_str());
QColor pressedColor =
QColor(autoware::state_rviz_plugin::colors::default_colors.pressed_button_bg.c_str());
QColor checkedColor =
QColor(autoware::state_rviz_plugin::colors::default_colors.checked_button_bg.c_str());
QColor disabledBgColor =
QColor(autoware::state_rviz_plugin::colors::default_colors.disabled_elevated_button_bg.c_str());
QColor disabledTextColor =
QColor(autoware::state_rviz_plugin::colors::default_colors.on_surface.c_str());
bool isHovered = false;
bool isPressed = false;
bool isChecked = false;
};

#endif // CUSTOM_BUTTON_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <QColor>
#include <QHBoxLayout>
#include <QMouseEvent>
#include <QPainter>
#include <QPainterPath>
#include <QPushButton>
Expand All @@ -39,6 +40,8 @@ class CustomSegmentedButtonItem : public QPushButton
void paintEvent(QPaintEvent * event) override;
void enterEvent(QEvent * event) override;
void leaveEvent(QEvent * event) override;
void mousePressEvent(QMouseEvent * event) override;
void mouseReleaseEvent(QMouseEvent * event) override;

private:
void updateCheckableState();
Expand All @@ -47,6 +50,8 @@ class CustomSegmentedButtonItem : public QPushButton
QColor checkedBgColor;
QColor hoverColor =
QColor(autoware::state_rviz_plugin::colors::default_colors.surface_container_highest.c_str());
QColor pressedColor =
QColor(autoware::state_rviz_plugin::colors::default_colors.surface_container_high.c_str());
QColor inactiveTextColor;
QColor activeTextColor;
QColor disabledBgColor =
Expand All @@ -56,6 +61,7 @@ class CustomSegmentedButtonItem : public QPushButton
bool isHovered = false;
bool isActivated = false;
bool isDisabled = false;
bool isPressed = false;
};

#endif // CUSTOM_SEGMENTED_BUTTON_ITEM_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ class CustomToggleSwitch : public QCheckBox
protected:
void paintEvent(QPaintEvent * event) override;
void mouseReleaseEvent(QMouseEvent * event) override;
void enterEvent(QEvent * event) override;
void leaveEvent(QEvent * event) override;

private:
bool blockSignalsGuard = false; // Guard variable to block signals during updates
bool blockSignalsGuard = false;
bool isHovered = false;
};

#endif // CUSTOM_TOGGLE_SWITCH_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ struct MaterialColors
std::string warning = "#EEF08B";
std::string info = "#8BD0F0";
std::string danger = "#F08B8B";

std::string enabled_button_bg = "#8BD0F0";
std::string hover_button_bg = "#84c2e6";
std::string pressed_button_bg = "#699BB8";
std::string checked_button_bg = "#699BB8";
std::string disabled_button_bg = "#292d30";
};

inline MaterialColors default_colors;
Expand Down

0 comments on commit 95dff2f

Please sign in to comment.