From 669e51d5aceaebf527ae0563a470097937076dc2 Mon Sep 17 00:00:00 2001 From: kobayu858 Date: Mon, 26 Aug 2024 13:26:10 +0900 Subject: [PATCH 01/13] fix:unusedFunction Signed-off-by: kobayu858 --- .../src/custom_button.cpp | 49 +-------- .../src/custom_container.cpp | 31 +----- .../src/custom_icon_label.cpp | 29 ------ .../src/custom_label.cpp | 26 ----- .../src/custom_segmented_button.cpp | 21 +--- .../src/custom_segmented_button_item.cpp | 99 +------------------ .../src/custom_slider.cpp | 82 --------------- .../src/custom_toggle_switch.cpp | 40 -------- .../src/include/custom_button.hpp | 2 - .../src/include/custom_container.hpp | 4 - .../src/include/custom_icon_label.hpp | 2 - .../src/include/custom_label.hpp | 2 - .../src/include/custom_segmented_button.hpp | 4 - .../include/custom_segmented_button_item.hpp | 4 - .../src/include/custom_slider.hpp | 2 - .../src/include/custom_toggle_switch.hpp | 1 - 16 files changed, 7 insertions(+), 391 deletions(-) diff --git a/common/tier4_state_rviz_plugin/src/custom_button.cpp b/common/tier4_state_rviz_plugin/src/custom_button.cpp index 0ef2628577135..6b5b069e27b39 100644 --- a/common/tier4_state_rviz_plugin/src/custom_button.cpp +++ b/common/tier4_state_rviz_plugin/src/custom_button.cpp @@ -53,11 +53,7 @@ QSize CustomElevatedButton::sizeHint() const return QSize(width, height); } -QSize CustomElevatedButton::minimumSizeHint() const -{ - return sizeHint(); -} - +// cppcheck-suppress unusedFunction void CustomElevatedButton::updateStyle( const QString & text, const QColor & bgColor, const QColor & textColor, const QColor & hoverColor, const QColor & disabledBgColor, const QColor & disabledTextColor) @@ -71,49 +67,6 @@ void CustomElevatedButton::updateStyle( update(); // Force repaint } -void CustomElevatedButton::paintEvent(QPaintEvent *) -{ - QPainter painter(this); - painter.setRenderHint(QPainter::Antialiasing); - - QStyleOption opt; - opt.initFrom(this); - QRect r = rect(); - - QColor buttonColor; - QColor currentTextColor = textColor; - if (!isEnabled()) { - buttonColor = disabledBgColor; - currentTextColor = disabledTextColor; - } else if (isHovered) { - buttonColor = hoverColor; - } else { - buttonColor = backgroundColor; - } - - int cornerRadius = height() / 2; // Making the corner radius proportional to the height - - // Draw button background - 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); - } 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()); -} - void CustomElevatedButton::enterEvent(QEvent * event) { isHovered = true; diff --git a/common/tier4_state_rviz_plugin/src/custom_container.cpp b/common/tier4_state_rviz_plugin/src/custom_container.cpp index 0b0aa1ccd6ed5..01bab2a7754f2 100644 --- a/common/tier4_state_rviz_plugin/src/custom_container.cpp +++ b/common/tier4_state_rviz_plugin/src/custom_container.cpp @@ -26,17 +26,7 @@ CustomContainer::CustomContainer(QWidget * parent) : QFrame(parent), cornerRadiu setLayout(layout); } -void CustomContainer::setCornerRadius(int radius) -{ - cornerRadius = radius; - update(); -} - -int CustomContainer::getCornerRadius() const -{ - return cornerRadius; -} - +// cppcheck-suppress unusedFunction QGridLayout * CustomContainer::getLayout() const { return layout; // Provide access to the layout @@ -49,22 +39,3 @@ QSize CustomContainer::sizeHint() const int height = size.height() + 20; // Adding padding return QSize(width, height); } - -QSize CustomContainer::minimumSizeHint() const -{ - return sizeHint(); -} - -void CustomContainer::paintEvent(QPaintEvent *) -{ - QPainter painter(this); - painter.setRenderHint(QPainter::Antialiasing); - - // Draw background - QPainterPath path; - path.addRoundedRect(rect(), height() / 2, height() / 2); // Use height for rounded corners - painter.setPen(Qt::NoPen); - painter.setBrush(QColor( - autoware::state_rviz_plugin::colors::default_colors.surface.c_str())); // Background color - painter.drawPath(path); -} diff --git a/common/tier4_state_rviz_plugin/src/custom_icon_label.cpp b/common/tier4_state_rviz_plugin/src/custom_icon_label.cpp index 6e4d32d40f7fb..0ab73ae0ffd85 100644 --- a/common/tier4_state_rviz_plugin/src/custom_icon_label.cpp +++ b/common/tier4_state_rviz_plugin/src/custom_icon_label.cpp @@ -49,32 +49,3 @@ QSize CustomIconLabel::sizeHint() const int size = qMax(icon.width(), icon.height()) + 20; // Adding padding return QSize(size, size); } - -QSize CustomIconLabel::minimumSizeHint() const -{ - return sizeHint(); -} - -void CustomIconLabel::paintEvent(QPaintEvent *) -{ - QPainter painter(this); - painter.setRenderHint(QPainter::Antialiasing); - - int diameter = qMin(width(), height()); - int radius = diameter / 2; - - // Draw background circle - QPainterPath path; - path.addEllipse(width() / 2 - radius, height() / 2 - radius, diameter, diameter); - painter.setPen(Qt::NoPen); - painter.setBrush(backgroundColor); - painter.drawPath(path); - - // Draw icon in the center - if (!icon.isNull()) { - QSize iconSize = icon.size().scaled(diameter * 0.6, diameter * 0.6, Qt::KeepAspectRatio); - QPoint iconPos((width() - iconSize.width()) / 2, (height() - iconSize.height()) / 2); - painter.drawPixmap( - iconPos, icon.scaled(iconSize, Qt::KeepAspectRatio, Qt::SmoothTransformation)); - } -} diff --git a/common/tier4_state_rviz_plugin/src/custom_label.cpp b/common/tier4_state_rviz_plugin/src/custom_label.cpp index 1f96fc0d45095..76ef9d0349810 100644 --- a/common/tier4_state_rviz_plugin/src/custom_label.cpp +++ b/common/tier4_state_rviz_plugin/src/custom_label.cpp @@ -46,32 +46,6 @@ QSize CustomLabel::sizeHint() const return QSize(width, height); } -QSize CustomLabel::minimumSizeHint() const -{ - return sizeHint(); -} - -void CustomLabel::paintEvent(QPaintEvent *) -{ - QPainter painter(this); - painter.setRenderHint(QPainter::Antialiasing); - - int cornerRadius = height() / 2; // Making the corner radius proportional to the height - - // Draw background - QPainterPath path; - path.addRoundedRect(rect().adjusted(1, 1, -1, -1), cornerRadius, cornerRadius); - - painter.setPen(Qt::NoPen); - painter.setBrush(backgroundColor); - - painter.drawPath(path); - - // Set text color and draw text - painter.setPen(textColor); - painter.drawText(rect(), Qt::AlignCenter, text()); -} - void CustomLabel::updateStyle( const QString & text, const QColor & bg_color, const QColor & text_color) { diff --git a/common/tier4_state_rviz_plugin/src/custom_segmented_button.cpp b/common/tier4_state_rviz_plugin/src/custom_segmented_button.cpp index 8063bdc0fbc28..65f4f83be91f4 100644 --- a/common/tier4_state_rviz_plugin/src/custom_segmented_button.cpp +++ b/common/tier4_state_rviz_plugin/src/custom_segmented_button.cpp @@ -40,6 +40,7 @@ CustomSegmentedButtonItem * CustomSegmentedButton::addButton(const QString & tex return button; } +// cppcheck-suppress unusedFunction QButtonGroup * CustomSegmentedButton::getButtonGroup() const { return buttonGroup; @@ -53,23 +54,3 @@ QSize CustomSegmentedButton::sizeHint() const // layout->count() * (layout->itemAt(0)->widget()->width()), // layout->itemAt(0)->widget()->height() + 10); } - -QSize CustomSegmentedButton::minimumSizeHint() const -{ - return sizeHint(); -} - -void CustomSegmentedButton::paintEvent(QPaintEvent *) -{ - QPainter painter(this); - painter.setRenderHint(QPainter::Antialiasing); - - // Draw background - QPainterPath path; - path.addRoundedRect(rect(), height() / 2, height() / 2); - - painter.setPen(Qt::NoPen); - painter.setBrush( - QColor(autoware::state_rviz_plugin::colors::default_colors.surface_container_low.c_str())); - painter.drawPath(path); -} diff --git a/common/tier4_state_rviz_plugin/src/custom_segmented_button_item.cpp b/common/tier4_state_rviz_plugin/src/custom_segmented_button_item.cpp index f2d15260c4e41..fb46eca1606f6 100644 --- a/common/tier4_state_rviz_plugin/src/custom_segmented_button_item.cpp +++ b/common/tier4_state_rviz_plugin/src/custom_segmented_button_item.cpp @@ -32,17 +32,6 @@ CustomSegmentedButtonItem::CustomSegmentedButtonItem(const QString & text, QWidg setCursor(Qt::PointingHandCursor); } -void CustomSegmentedButtonItem::setColors( - const QColor & bg, const QColor & checkedBg, const QColor & activeText, - const QColor & inactiveText) -{ - bgColor = bg; - checkedBgColor = checkedBg; - activeTextColor = activeText; - inactiveTextColor = inactiveText; - update(); -} - // void CustomSegmentedButtonItem::updateSize() // { // QFontMetrics fm(font()); @@ -51,12 +40,14 @@ void CustomSegmentedButtonItem::setColors( // setFixedSize(width, height); // } +// cppcheck-suppress unusedFunction void CustomSegmentedButtonItem::setHovered(bool hovered) { isHovered = hovered; updateCheckableState(); } +// cppcheck-suppress unusedFunction void CustomSegmentedButtonItem::setCheckableButton(bool checkable) { setCheckable(checkable); @@ -71,102 +62,20 @@ void CustomSegmentedButtonItem::updateCheckableState() update(); } +// cppcheck-suppress unusedFunction void CustomSegmentedButtonItem::setDisabledButton(bool disabled) { isDisabled = disabled; updateCheckableState(); } +// cppcheck-suppress unusedFunction void CustomSegmentedButtonItem::setActivated(bool activated) { isActivated = activated; update(); } -void CustomSegmentedButtonItem::paintEvent(QPaintEvent *) -{ - QPainter painter(this); - painter.setRenderHint(QPainter::Antialiasing); - - // Adjust opacity for disabled state - if (isDisabled) { - painter.setOpacity(0.3); - } else { - painter.setOpacity(1.0); - } - - // Determine the button's color based on its state - QColor buttonColor; - if (isDisabled) { - buttonColor = disabledBgColor; - } else if (isHovered && !isChecked() && isCheckable()) { - buttonColor = hoverColor; - } else if (isActivated) { - buttonColor = checkedBgColor; - } else { - buttonColor = isChecked() ? checkedBgColor : bgColor; - } - - // Determine if this is the first or last button - bool isFirstButton = false; - bool isLastButton = false; - - QHBoxLayout * parentLayout = qobject_cast(parentWidget()->layout()); - if (parentLayout) { - int index = parentLayout->indexOf(this); - isFirstButton = (index == 0); - isLastButton = (index == parentLayout->count() - 1); - } - - // Draw button background - - QRect buttonRect = rect().adjusted(0, 1, 0, -1); - - if (isFirstButton) { - buttonRect.setLeft(buttonRect.left() + 1); - } - if (isLastButton) { - buttonRect.setRight(buttonRect.right() - 1); - } - - QPainterPath path; - double radius = (height() - 2) / 2; - - path.setFillRule(Qt::WindingFill); - if (isFirstButton) { - path.addRoundedRect(buttonRect, radius, radius); - path.addRect(QRect( - (buttonRect.left() + buttonRect.width() - radius), - buttonRect.top() + buttonRect.height() - radius, radius, - radius)); // Bottom Right - path.addRect(QRect( - (buttonRect.left() + buttonRect.width() - radius), buttonRect.top(), radius, - radius)); // Top Right - } else if (isLastButton) { - path.addRoundedRect(buttonRect, radius, radius); - path.addRect(QRect( - (buttonRect.left()), buttonRect.top() + buttonRect.height() - radius, radius, - radius)); // Bottom left - path.addRect(QRect((buttonRect.left()), buttonRect.top(), radius, - radius)); // Top Left - } else { - path.addRect(buttonRect); - } - painter.fillPath(path, buttonColor); - - // Draw button border - QPen pen(QColor(autoware::state_rviz_plugin::colors::default_colors.outline.c_str()), 1); - pen.setJoinStyle(Qt::RoundJoin); - pen.setCapStyle(Qt::RoundCap); - painter.setPen(pen); - painter.drawPath(path.simplified()); - - // Draw button text - QColor textColor = (isChecked() ? activeTextColor : inactiveTextColor); - painter.setPen(textColor); - painter.drawText(rect(), Qt::AlignCenter, text()); -} - void CustomSegmentedButtonItem::enterEvent(QEvent * event) { if (isCheckable()) { diff --git a/common/tier4_state_rviz_plugin/src/custom_slider.cpp b/common/tier4_state_rviz_plugin/src/custom_slider.cpp index cf3f7c3d4638f..9f3c75bc0bfe6 100644 --- a/common/tier4_state_rviz_plugin/src/custom_slider.cpp +++ b/common/tier4_state_rviz_plugin/src/custom_slider.cpp @@ -18,85 +18,3 @@ CustomSlider::CustomSlider(Qt::Orientation orientation, QWidget * parent) { setMinimumHeight(40); // Ensure there's enough space for the custom track } - -void CustomSlider::paintEvent(QPaintEvent *) -{ - QPainter painter(this); - painter.setRenderHint(QPainter::Antialiasing); - painter.setPen(Qt::NoPen); - - // Initialize style option - QStyleOptionSlider opt; - initStyleOption(&opt); - - QRect grooveRect = - style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderGroove, this); - int centerY = grooveRect.center().y(); - QRect handleRect = - style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, this); - - int value = this->value(); - int minValue = this->minimum(); - int maxValue = this->maximum(); - - int trackThickness = 14; - int gap = 8; - - QRect beforeRect( - grooveRect.x(), centerY - trackThickness / 2, handleRect.center().x() - grooveRect.x() - gap, - trackThickness); - - QRect afterRect( - handleRect.center().x() + gap, centerY - trackThickness / 2, - grooveRect.right() - handleRect.center().x() - gap, trackThickness); - - QColor inactiveTrackColor( - autoware::state_rviz_plugin::colors::default_colors.primary_container.c_str()); - QColor activeTrackColor(autoware::state_rviz_plugin::colors::default_colors.primary.c_str()); - QColor handleColor(autoware::state_rviz_plugin::colors::default_colors.primary.c_str()); - - // only draw the active track if the value is more than the gap from the minimum - if (value > minValue + gap / 2) { - QPainterPath beforePath; - beforePath.moveTo(beforeRect.left(), centerY + trackThickness / 2); // Start from bottom-left - beforePath.quadTo( - beforeRect.left(), centerY - trackThickness / 2, beforeRect.left() + trackThickness * 0.5, - centerY - trackThickness / 2); - beforePath.lineTo(beforeRect.right() - trackThickness * 0.1, centerY - trackThickness / 2); - beforePath.quadTo( - beforeRect.right(), centerY - trackThickness / 2, beforeRect.right(), centerY); - beforePath.quadTo( - beforeRect.right(), centerY + trackThickness / 2, beforeRect.right() - trackThickness * 0.1, - centerY + trackThickness / 2); - beforePath.lineTo(beforeRect.left() + trackThickness * 0.5, centerY + trackThickness / 2); - beforePath.quadTo(beforeRect.left(), centerY + trackThickness / 2, beforeRect.left(), centerY); - painter.fillPath(beforePath, activeTrackColor); - } - - if (value < maxValue - gap / 2) { - QPainterPath afterPath; - afterPath.moveTo(afterRect.left(), centerY + trackThickness / 2); - afterPath.quadTo( - afterRect.left(), centerY - trackThickness / 2, afterRect.left() + trackThickness * 0.1, - centerY - trackThickness / 2); - afterPath.lineTo(afterRect.right() - trackThickness * 0.5, centerY - trackThickness / 2); - afterPath.quadTo(afterRect.right(), centerY - trackThickness / 2, afterRect.right(), centerY); - afterPath.quadTo( - afterRect.right(), centerY + trackThickness / 2, afterRect.right() - trackThickness * 0.5, - centerY + trackThickness / 2); - afterPath.lineTo(afterRect.left() + trackThickness * 0.1, centerY + trackThickness / 2); - afterPath.quadTo(afterRect.left(), centerY + trackThickness / 2, afterRect.left(), centerY); - painter.fillPath(afterPath, inactiveTrackColor); - } - - painter.setBrush(handleColor); - int handleLineHeight = 30; - int handleLineWidth = 4; - int handleLineRadius = 2; - QRect handleLineRect( - handleRect.center().x() - handleLineWidth / 2, centerY - handleLineHeight / 2, handleLineWidth, - handleLineHeight); - QPainterPath handlePath; - handlePath.addRoundedRect(handleLineRect, handleLineRadius, handleLineRadius); - painter.fillPath(handlePath, handleColor); -} diff --git a/common/tier4_state_rviz_plugin/src/custom_toggle_switch.cpp b/common/tier4_state_rviz_plugin/src/custom_toggle_switch.cpp index 3b58ded626439..336d767f3159f 100644 --- a/common/tier4_state_rviz_plugin/src/custom_toggle_switch.cpp +++ b/common/tier4_state_rviz_plugin/src/custom_toggle_switch.cpp @@ -30,46 +30,6 @@ QSize CustomToggleSwitch::sizeHint() const return QSize(50, 30); // Preferred size of the toggle switch } -void CustomToggleSwitch::paintEvent(QPaintEvent *) -{ - QPainter p(this); - p.setRenderHint(QPainter::Antialiasing); - - int margin = 2; - int circleRadius = height() / 2 - margin * 2; - QRect r = rect().adjusted(margin, margin, -margin, -margin); - bool isChecked = this->isChecked(); - - QColor uncheckedIndicatorColor = - 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 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; - - QRect borderR = r.adjusted(-margin, -margin, margin, margin); - p.setBrush(bgColor); - p.setPen(Qt::NoPen); - p.drawRoundedRect(borderR, circleRadius + 4, circleRadius + 4); - - p.setBrush(bgColor); - p.setPen(Qt::NoPen); - p.drawRoundedRect(r, circleRadius + 4, circleRadius + 4); - - int minX = r.left() + margin * 2; - int maxX = r.right() - circleRadius * 2 - margin; - int circleX = isChecked ? maxX : minX; - QRect circleRect(circleX, r.top() + margin, circleRadius * 2, circleRadius * 2); - p.setBrush(indicatorColor); - p.drawEllipse(circleRect); -} - void CustomToggleSwitch::mouseReleaseEvent(QMouseEvent * event) { if (event->button() == Qt::LeftButton) { diff --git a/common/tier4_state_rviz_plugin/src/include/custom_button.hpp b/common/tier4_state_rviz_plugin/src/include/custom_button.hpp index b10663ce09933..3e10c65c33264 100644 --- a/common/tier4_state_rviz_plugin/src/include/custom_button.hpp +++ b/common/tier4_state_rviz_plugin/src/include/custom_button.hpp @@ -47,11 +47,9 @@ class CustomElevatedButton : public QPushButton const QColor & hoverColor, const QColor & disabledBgColor, const QColor & disabledTextColor); protected: - void paintEvent(QPaintEvent * event) override; void enterEvent(QEvent * event) override; void leaveEvent(QEvent * event) override; QSize sizeHint() const override; - QSize minimumSizeHint() const override; private: QColor backgroundColor = diff --git a/common/tier4_state_rviz_plugin/src/include/custom_container.hpp b/common/tier4_state_rviz_plugin/src/include/custom_container.hpp index 5142b409ebc88..3a7207f0a1940 100644 --- a/common/tier4_state_rviz_plugin/src/include/custom_container.hpp +++ b/common/tier4_state_rviz_plugin/src/include/custom_container.hpp @@ -31,18 +31,14 @@ class CustomContainer : public QFrame // Methods to set dimensions and corner radius void setContainerHeight(int height); void setContainerWidth(int width); - void setCornerRadius(int radius); // Getters int getContainerHeight() const; int getContainerWidth() const; - int getCornerRadius() const; QGridLayout * getLayout() const; // Add a method to access the layout protected: - void paintEvent(QPaintEvent * event) override; QSize sizeHint() const override; - QSize minimumSizeHint() const override; private: QGridLayout * layout; diff --git a/common/tier4_state_rviz_plugin/src/include/custom_icon_label.hpp b/common/tier4_state_rviz_plugin/src/include/custom_icon_label.hpp index 1b3ab9c8e0c6c..d1f486bb4cad7 100644 --- a/common/tier4_state_rviz_plugin/src/include/custom_icon_label.hpp +++ b/common/tier4_state_rviz_plugin/src/include/custom_icon_label.hpp @@ -39,9 +39,7 @@ class CustomIconLabel : public QLabel void updateStyle(IconState state, const QColor & bgColor); protected: - void paintEvent(QPaintEvent * event) override; QSize sizeHint() const override; - QSize minimumSizeHint() const override; private: void loadIcons(); diff --git a/common/tier4_state_rviz_plugin/src/include/custom_label.hpp b/common/tier4_state_rviz_plugin/src/include/custom_label.hpp index a328c4de56e3d..6cb8152294653 100644 --- a/common/tier4_state_rviz_plugin/src/include/custom_label.hpp +++ b/common/tier4_state_rviz_plugin/src/include/custom_label.hpp @@ -33,9 +33,7 @@ class CustomLabel : public QLabel QColor(autoware::state_rviz_plugin::colors::default_colors.on_surface.c_str())); protected: - void paintEvent(QPaintEvent * event) override; QSize sizeHint() const override; - QSize minimumSizeHint() const override; private: QColor backgroundColor = diff --git a/common/tier4_state_rviz_plugin/src/include/custom_segmented_button.hpp b/common/tier4_state_rviz_plugin/src/include/custom_segmented_button.hpp index c6c589d31b8d4..e9f7cd7d1756f 100644 --- a/common/tier4_state_rviz_plugin/src/include/custom_segmented_button.hpp +++ b/common/tier4_state_rviz_plugin/src/include/custom_segmented_button.hpp @@ -37,14 +37,10 @@ class CustomSegmentedButton : public QWidget QButtonGroup * getButtonGroup() const; QSize sizeHint() const override; - QSize minimumSizeHint() const override; Q_SIGNALS: void buttonClicked(int id); -protected: - void paintEvent(QPaintEvent * event) override; - private: QButtonGroup * buttonGroup; QHBoxLayout * layout; diff --git a/common/tier4_state_rviz_plugin/src/include/custom_segmented_button_item.hpp b/common/tier4_state_rviz_plugin/src/include/custom_segmented_button_item.hpp index 33eb9fe16aa31..f454da30825c3 100644 --- a/common/tier4_state_rviz_plugin/src/include/custom_segmented_button_item.hpp +++ b/common/tier4_state_rviz_plugin/src/include/custom_segmented_button_item.hpp @@ -30,16 +30,12 @@ class CustomSegmentedButtonItem : public QPushButton public: explicit CustomSegmentedButtonItem(const QString & text, QWidget * parent = nullptr); - void setColors( - const QColor & bg, const QColor & checkedBg, const QColor & activeText, - const QColor & inactiveText); void setActivated(bool activated); void setCheckableButton(bool checkable); void setDisabledButton(bool disabled); void setHovered(bool hovered); protected: - void paintEvent(QPaintEvent * event) override; void enterEvent(QEvent * event) override; void leaveEvent(QEvent * event) override; diff --git a/common/tier4_state_rviz_plugin/src/include/custom_slider.hpp b/common/tier4_state_rviz_plugin/src/include/custom_slider.hpp index f0dc9f12aedfe..268d3dfc7f079 100644 --- a/common/tier4_state_rviz_plugin/src/include/custom_slider.hpp +++ b/common/tier4_state_rviz_plugin/src/include/custom_slider.hpp @@ -28,8 +28,6 @@ class CustomSlider : public QSlider public: explicit CustomSlider(Qt::Orientation orientation, QWidget * parent = nullptr); -protected: - void paintEvent(QPaintEvent * event) override; }; #endif // CUSTOM_SLIDER_HPP_ diff --git a/common/tier4_state_rviz_plugin/src/include/custom_toggle_switch.hpp b/common/tier4_state_rviz_plugin/src/include/custom_toggle_switch.hpp index 107d45af8c3f3..e22cb8d98bc41 100644 --- a/common/tier4_state_rviz_plugin/src/include/custom_toggle_switch.hpp +++ b/common/tier4_state_rviz_plugin/src/include/custom_toggle_switch.hpp @@ -30,7 +30,6 @@ class CustomToggleSwitch : public QCheckBox void setCheckedState(bool state); protected: - void paintEvent(QPaintEvent * event) override; void mouseReleaseEvent(QMouseEvent * event) override; private: From 2ab1f172f6dbb94de719de0fff468dc1fd7e15c5 Mon Sep 17 00:00:00 2001 From: kobayu858 Date: Mon, 26 Aug 2024 13:32:54 +0900 Subject: [PATCH 02/13] fix:clang format Signed-off-by: kobayu858 --- common/tier4_state_rviz_plugin/src/include/custom_slider.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/common/tier4_state_rviz_plugin/src/include/custom_slider.hpp b/common/tier4_state_rviz_plugin/src/include/custom_slider.hpp index 268d3dfc7f079..b494b437b4790 100644 --- a/common/tier4_state_rviz_plugin/src/include/custom_slider.hpp +++ b/common/tier4_state_rviz_plugin/src/include/custom_slider.hpp @@ -27,7 +27,6 @@ class CustomSlider : public QSlider public: explicit CustomSlider(Qt::Orientation orientation, QWidget * parent = nullptr); - }; #endif // CUSTOM_SLIDER_HPP_ From 8f399e947a3e079fa16ae8157f3f0a9d658df0f3 Mon Sep 17 00:00:00 2001 From: kobayu858 Date: Tue, 27 Aug 2024 16:11:23 +0900 Subject: [PATCH 03/13] fix:revert custom button Signed-off-by: kobayu858 --- .../src/custom_button.cpp | 50 +++++++++++++++++++ .../src/include/custom_button.hpp | 2 + 2 files changed, 52 insertions(+) diff --git a/common/tier4_state_rviz_plugin/src/custom_button.cpp b/common/tier4_state_rviz_plugin/src/custom_button.cpp index 6b5b069e27b39..26d9d699038d8 100644 --- a/common/tier4_state_rviz_plugin/src/custom_button.cpp +++ b/common/tier4_state_rviz_plugin/src/custom_button.cpp @@ -53,6 +53,12 @@ QSize CustomElevatedButton::sizeHint() const return QSize(width, height); } +// cppcheck-suppress unusedFunction +QSize CustomElevatedButton::minimumSizeHint() const +{ + return sizeHint(); +} + // cppcheck-suppress unusedFunction void CustomElevatedButton::updateStyle( const QString & text, const QColor & bgColor, const QColor & textColor, const QColor & hoverColor, @@ -67,6 +73,50 @@ void CustomElevatedButton::updateStyle( update(); // Force repaint } +// cppcheck-suppress unusedFunction +void CustomElevatedButton::paintEvent(QPaintEvent *) +{ + QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing); + + QStyleOption opt; + opt.initFrom(this); + QRect r = rect(); + + QColor buttonColor; + QColor currentTextColor = textColor; + if (!isEnabled()) { + buttonColor = disabledBgColor; + currentTextColor = disabledTextColor; + } else if (isHovered) { + buttonColor = hoverColor; + } else { + buttonColor = backgroundColor; + } + + int cornerRadius = height() / 2; // Making the corner radius proportional to the height + + // Draw button background + 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); + } 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()); +} + void CustomElevatedButton::enterEvent(QEvent * event) { isHovered = true; diff --git a/common/tier4_state_rviz_plugin/src/include/custom_button.hpp b/common/tier4_state_rviz_plugin/src/include/custom_button.hpp index 3e10c65c33264..b10663ce09933 100644 --- a/common/tier4_state_rviz_plugin/src/include/custom_button.hpp +++ b/common/tier4_state_rviz_plugin/src/include/custom_button.hpp @@ -47,9 +47,11 @@ class CustomElevatedButton : public QPushButton const QColor & hoverColor, const QColor & disabledBgColor, const QColor & disabledTextColor); protected: + void paintEvent(QPaintEvent * event) override; void enterEvent(QEvent * event) override; void leaveEvent(QEvent * event) override; QSize sizeHint() const override; + QSize minimumSizeHint() const override; private: QColor backgroundColor = From 35aa25896672c9e6e490102ec5aea0aaaa97ab10 Mon Sep 17 00:00:00 2001 From: kobayu858 Date: Tue, 27 Aug 2024 16:33:28 +0900 Subject: [PATCH 04/13] fix:revert custom container Signed-off-by: kobayu858 --- .../src/custom_container.cpp | 20 +++++++++++++++++++ .../src/include/custom_container.hpp | 4 ++++ 2 files changed, 24 insertions(+) diff --git a/common/tier4_state_rviz_plugin/src/custom_container.cpp b/common/tier4_state_rviz_plugin/src/custom_container.cpp index 01bab2a7754f2..7504e2374c528 100644 --- a/common/tier4_state_rviz_plugin/src/custom_container.cpp +++ b/common/tier4_state_rviz_plugin/src/custom_container.cpp @@ -39,3 +39,23 @@ QSize CustomContainer::sizeHint() const int height = size.height() + 20; // Adding padding return QSize(width, height); } + +// cppcheck-suppress unusedFunction +QSize CustomContainer::minimumSizeHint() const +{ + return sizeHint(); +} + +void CustomContainer::paintEvent(QPaintEvent *) +{ + QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing); + + // Draw background + QPainterPath path; + path.addRoundedRect(rect(), height() / 2, height() / 2); // Use height for rounded corners + painter.setPen(Qt::NoPen); + painter.setBrush(QColor( + autoware::state_rviz_plugin::colors::default_colors.surface.c_str())); // Background color + painter.drawPath(path); +} \ No newline at end of file diff --git a/common/tier4_state_rviz_plugin/src/include/custom_container.hpp b/common/tier4_state_rviz_plugin/src/include/custom_container.hpp index 3a7207f0a1940..5142b409ebc88 100644 --- a/common/tier4_state_rviz_plugin/src/include/custom_container.hpp +++ b/common/tier4_state_rviz_plugin/src/include/custom_container.hpp @@ -31,14 +31,18 @@ class CustomContainer : public QFrame // Methods to set dimensions and corner radius void setContainerHeight(int height); void setContainerWidth(int width); + void setCornerRadius(int radius); // Getters int getContainerHeight() const; int getContainerWidth() const; + int getCornerRadius() const; QGridLayout * getLayout() const; // Add a method to access the layout protected: + void paintEvent(QPaintEvent * event) override; QSize sizeHint() const override; + QSize minimumSizeHint() const override; private: QGridLayout * layout; From e9a1b337455c85f0a0766d6db61721ec98968378 Mon Sep 17 00:00:00 2001 From: kobayu858 Date: Tue, 27 Aug 2024 16:37:24 +0900 Subject: [PATCH 05/13] fix:revert custom icon label Signed-off-by: kobayu858 --- .../src/custom_icon_label.cpp | 31 +++++++++++++++++++ .../src/include/custom_icon_label.hpp | 2 ++ 2 files changed, 33 insertions(+) diff --git a/common/tier4_state_rviz_plugin/src/custom_icon_label.cpp b/common/tier4_state_rviz_plugin/src/custom_icon_label.cpp index 0ab73ae0ffd85..526693832c102 100644 --- a/common/tier4_state_rviz_plugin/src/custom_icon_label.cpp +++ b/common/tier4_state_rviz_plugin/src/custom_icon_label.cpp @@ -49,3 +49,34 @@ QSize CustomIconLabel::sizeHint() const int size = qMax(icon.width(), icon.height()) + 20; // Adding padding return QSize(size, size); } + +// cppcheck-suppress unusedFunction +QSize CustomIconLabel::minimumSizeHint() const +{ + return sizeHint(); +} + +// cppcheck-suppress unusedFunction +void CustomIconLabel::paintEvent(QPaintEvent *) +{ + QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing); + + int diameter = qMin(width(), height()); + int radius = diameter / 2; + + // Draw background circle + QPainterPath path; + path.addEllipse(width() / 2 - radius, height() / 2 - radius, diameter, diameter); + painter.setPen(Qt::NoPen); + painter.setBrush(backgroundColor); + painter.drawPath(path); + + // Draw icon in the center + if (!icon.isNull()) { + QSize iconSize = icon.size().scaled(diameter * 0.6, diameter * 0.6, Qt::KeepAspectRatio); + QPoint iconPos((width() - iconSize.width()) / 2, (height() - iconSize.height()) / 2); + painter.drawPixmap( + iconPos, icon.scaled(iconSize, Qt::KeepAspectRatio, Qt::SmoothTransformation)); + } +} \ No newline at end of file diff --git a/common/tier4_state_rviz_plugin/src/include/custom_icon_label.hpp b/common/tier4_state_rviz_plugin/src/include/custom_icon_label.hpp index d1f486bb4cad7..1b3ab9c8e0c6c 100644 --- a/common/tier4_state_rviz_plugin/src/include/custom_icon_label.hpp +++ b/common/tier4_state_rviz_plugin/src/include/custom_icon_label.hpp @@ -39,7 +39,9 @@ class CustomIconLabel : public QLabel void updateStyle(IconState state, const QColor & bgColor); protected: + void paintEvent(QPaintEvent * event) override; QSize sizeHint() const override; + QSize minimumSizeHint() const override; private: void loadIcons(); From 8d01097fb69a05e4e5f7d103f87afbf40f21e1b4 Mon Sep 17 00:00:00 2001 From: kobayu858 Date: Tue, 27 Aug 2024 16:40:20 +0900 Subject: [PATCH 06/13] fix:revert custom label Signed-off-by: kobayu858 --- .../src/custom_label.cpp | 29 +++++++++++++++++++ .../src/include/custom_label.hpp | 2 ++ 2 files changed, 31 insertions(+) diff --git a/common/tier4_state_rviz_plugin/src/custom_label.cpp b/common/tier4_state_rviz_plugin/src/custom_label.cpp index 76ef9d0349810..36f578cd0da83 100644 --- a/common/tier4_state_rviz_plugin/src/custom_label.cpp +++ b/common/tier4_state_rviz_plugin/src/custom_label.cpp @@ -46,6 +46,34 @@ QSize CustomLabel::sizeHint() const return QSize(width, height); } +// cppcheck-suppress unusedFunction +QSize CustomLabel::minimumSizeHint() const +{ + return sizeHint(); +} + +// cppcheck-suppress unusedFunction +void CustomLabel::paintEvent(QPaintEvent *) +{ + QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing); + + int cornerRadius = height() / 2; // Making the corner radius proportional to the height + + // Draw background + QPainterPath path; + path.addRoundedRect(rect().adjusted(1, 1, -1, -1), cornerRadius, cornerRadius); + + painter.setPen(Qt::NoPen); + painter.setBrush(backgroundColor); + + painter.drawPath(path); + + // Set text color and draw text + painter.setPen(textColor); + painter.drawText(rect(), Qt::AlignCenter, text()); +} + void CustomLabel::updateStyle( const QString & text, const QColor & bg_color, const QColor & text_color) { @@ -54,3 +82,4 @@ void CustomLabel::updateStyle( textColor = text_color; update(); // Force repaint } + diff --git a/common/tier4_state_rviz_plugin/src/include/custom_label.hpp b/common/tier4_state_rviz_plugin/src/include/custom_label.hpp index 6cb8152294653..a328c4de56e3d 100644 --- a/common/tier4_state_rviz_plugin/src/include/custom_label.hpp +++ b/common/tier4_state_rviz_plugin/src/include/custom_label.hpp @@ -33,7 +33,9 @@ class CustomLabel : public QLabel QColor(autoware::state_rviz_plugin::colors::default_colors.on_surface.c_str())); protected: + void paintEvent(QPaintEvent * event) override; QSize sizeHint() const override; + QSize minimumSizeHint() const override; private: QColor backgroundColor = From 9242131084ce0f46f03db4f7658983d8e0827f1e Mon Sep 17 00:00:00 2001 From: kobayu858 Date: Tue, 27 Aug 2024 16:41:58 +0900 Subject: [PATCH 07/13] fix:revert custom segment button Signed-off-by: kobayu858 --- .../src/custom_segmented_button.cpp | 22 +++++++++++++++++++ .../src/include/custom_segmented_button.hpp | 4 ++++ 2 files changed, 26 insertions(+) diff --git a/common/tier4_state_rviz_plugin/src/custom_segmented_button.cpp b/common/tier4_state_rviz_plugin/src/custom_segmented_button.cpp index 65f4f83be91f4..b5f2d522b45f9 100644 --- a/common/tier4_state_rviz_plugin/src/custom_segmented_button.cpp +++ b/common/tier4_state_rviz_plugin/src/custom_segmented_button.cpp @@ -54,3 +54,25 @@ QSize CustomSegmentedButton::sizeHint() const // layout->count() * (layout->itemAt(0)->widget()->width()), // layout->itemAt(0)->widget()->height() + 10); } + +// cppcheck-suppress unusedFunction +QSize CustomSegmentedButton::minimumSizeHint() const +{ + return sizeHint(); +} + +// cppcheck-suppress unusedFunction +void CustomSegmentedButton::paintEvent(QPaintEvent *) +{ + QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing); + + // Draw background + QPainterPath path; + path.addRoundedRect(rect(), height() / 2, height() / 2); + + painter.setPen(Qt::NoPen); + painter.setBrush( + QColor(autoware::state_rviz_plugin::colors::default_colors.surface_container_low.c_str())); + painter.drawPath(path); +} \ No newline at end of file diff --git a/common/tier4_state_rviz_plugin/src/include/custom_segmented_button.hpp b/common/tier4_state_rviz_plugin/src/include/custom_segmented_button.hpp index e9f7cd7d1756f..c6c589d31b8d4 100644 --- a/common/tier4_state_rviz_plugin/src/include/custom_segmented_button.hpp +++ b/common/tier4_state_rviz_plugin/src/include/custom_segmented_button.hpp @@ -37,10 +37,14 @@ class CustomSegmentedButton : public QWidget QButtonGroup * getButtonGroup() const; QSize sizeHint() const override; + QSize minimumSizeHint() const override; Q_SIGNALS: void buttonClicked(int id); +protected: + void paintEvent(QPaintEvent * event) override; + private: QButtonGroup * buttonGroup; QHBoxLayout * layout; From a5ed6451720289519a416bd0dd28b6dd1d6df9a3 Mon Sep 17 00:00:00 2001 From: kobayu858 Date: Tue, 27 Aug 2024 16:43:51 +0900 Subject: [PATCH 08/13] fix:revert custom slider Signed-off-by: kobayu858 --- .../src/custom_slider.cpp | 83 +++++++++++++++++++ .../src/include/custom_slider.hpp | 3 + 2 files changed, 86 insertions(+) diff --git a/common/tier4_state_rviz_plugin/src/custom_slider.cpp b/common/tier4_state_rviz_plugin/src/custom_slider.cpp index 9f3c75bc0bfe6..efc596e252c2c 100644 --- a/common/tier4_state_rviz_plugin/src/custom_slider.cpp +++ b/common/tier4_state_rviz_plugin/src/custom_slider.cpp @@ -18,3 +18,86 @@ CustomSlider::CustomSlider(Qt::Orientation orientation, QWidget * parent) { setMinimumHeight(40); // Ensure there's enough space for the custom track } + +// cppcheck-suppress unusedFunction +void CustomSlider::paintEvent(QPaintEvent *) +{ + QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing); + painter.setPen(Qt::NoPen); + + // Initialize style option + QStyleOptionSlider opt; + initStyleOption(&opt); + + QRect grooveRect = + style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderGroove, this); + int centerY = grooveRect.center().y(); + QRect handleRect = + style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, this); + + int value = this->value(); + int minValue = this->minimum(); + int maxValue = this->maximum(); + + int trackThickness = 14; + int gap = 8; + + QRect beforeRect( + grooveRect.x(), centerY - trackThickness / 2, handleRect.center().x() - grooveRect.x() - gap, + trackThickness); + + QRect afterRect( + handleRect.center().x() + gap, centerY - trackThickness / 2, + grooveRect.right() - handleRect.center().x() - gap, trackThickness); + + QColor inactiveTrackColor( + autoware::state_rviz_plugin::colors::default_colors.primary_container.c_str()); + QColor activeTrackColor(autoware::state_rviz_plugin::colors::default_colors.primary.c_str()); + QColor handleColor(autoware::state_rviz_plugin::colors::default_colors.primary.c_str()); + + // only draw the active track if the value is more than the gap from the minimum + if (value > minValue + gap / 2) { + QPainterPath beforePath; + beforePath.moveTo(beforeRect.left(), centerY + trackThickness / 2); // Start from bottom-left + beforePath.quadTo( + beforeRect.left(), centerY - trackThickness / 2, beforeRect.left() + trackThickness * 0.5, + centerY - trackThickness / 2); + beforePath.lineTo(beforeRect.right() - trackThickness * 0.1, centerY - trackThickness / 2); + beforePath.quadTo( + beforeRect.right(), centerY - trackThickness / 2, beforeRect.right(), centerY); + beforePath.quadTo( + beforeRect.right(), centerY + trackThickness / 2, beforeRect.right() - trackThickness * 0.1, + centerY + trackThickness / 2); + beforePath.lineTo(beforeRect.left() + trackThickness * 0.5, centerY + trackThickness / 2); + beforePath.quadTo(beforeRect.left(), centerY + trackThickness / 2, beforeRect.left(), centerY); + painter.fillPath(beforePath, activeTrackColor); + } + + if (value < maxValue - gap / 2) { + QPainterPath afterPath; + afterPath.moveTo(afterRect.left(), centerY + trackThickness / 2); + afterPath.quadTo( + afterRect.left(), centerY - trackThickness / 2, afterRect.left() + trackThickness * 0.1, + centerY - trackThickness / 2); + afterPath.lineTo(afterRect.right() - trackThickness * 0.5, centerY - trackThickness / 2); + afterPath.quadTo(afterRect.right(), centerY - trackThickness / 2, afterRect.right(), centerY); + afterPath.quadTo( + afterRect.right(), centerY + trackThickness / 2, afterRect.right() - trackThickness * 0.5, + centerY + trackThickness / 2); + afterPath.lineTo(afterRect.left() + trackThickness * 0.1, centerY + trackThickness / 2); + afterPath.quadTo(afterRect.left(), centerY + trackThickness / 2, afterRect.left(), centerY); + painter.fillPath(afterPath, inactiveTrackColor); + } + + painter.setBrush(handleColor); + int handleLineHeight = 30; + int handleLineWidth = 4; + int handleLineRadius = 2; + QRect handleLineRect( + handleRect.center().x() - handleLineWidth / 2, centerY - handleLineHeight / 2, handleLineWidth, + handleLineHeight); + QPainterPath handlePath; + handlePath.addRoundedRect(handleLineRect, handleLineRadius, handleLineRadius); + painter.fillPath(handlePath, handleColor); +} \ No newline at end of file diff --git a/common/tier4_state_rviz_plugin/src/include/custom_slider.hpp b/common/tier4_state_rviz_plugin/src/include/custom_slider.hpp index b494b437b4790..f0dc9f12aedfe 100644 --- a/common/tier4_state_rviz_plugin/src/include/custom_slider.hpp +++ b/common/tier4_state_rviz_plugin/src/include/custom_slider.hpp @@ -27,6 +27,9 @@ class CustomSlider : public QSlider public: explicit CustomSlider(Qt::Orientation orientation, QWidget * parent = nullptr); + +protected: + void paintEvent(QPaintEvent * event) override; }; #endif // CUSTOM_SLIDER_HPP_ From f3542ec69da854016ad2f44b75de8574dc0e3f75 Mon Sep 17 00:00:00 2001 From: kobayu858 Date: Tue, 27 Aug 2024 16:44:56 +0900 Subject: [PATCH 09/13] fix:revert custom toggle switch Signed-off-by: kobayu858 --- .../src/custom_toggle_switch.cpp | 41 +++++++++++++++++++ .../src/include/custom_toggle_switch.hpp | 1 + 2 files changed, 42 insertions(+) diff --git a/common/tier4_state_rviz_plugin/src/custom_toggle_switch.cpp b/common/tier4_state_rviz_plugin/src/custom_toggle_switch.cpp index 336d767f3159f..b171fa554cd01 100644 --- a/common/tier4_state_rviz_plugin/src/custom_toggle_switch.cpp +++ b/common/tier4_state_rviz_plugin/src/custom_toggle_switch.cpp @@ -30,6 +30,47 @@ QSize CustomToggleSwitch::sizeHint() const return QSize(50, 30); // Preferred size of the toggle switch } +// cppcheck-suppress unusedFunction +void CustomToggleSwitch::paintEvent(QPaintEvent *) +{ + QPainter p(this); + p.setRenderHint(QPainter::Antialiasing); + + int margin = 2; + int circleRadius = height() / 2 - margin * 2; + QRect r = rect().adjusted(margin, margin, -margin, -margin); + bool isChecked = this->isChecked(); + + QColor uncheckedIndicatorColor = + 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 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; + + QRect borderR = r.adjusted(-margin, -margin, margin, margin); + p.setBrush(bgColor); + p.setPen(Qt::NoPen); + p.drawRoundedRect(borderR, circleRadius + 4, circleRadius + 4); + + p.setBrush(bgColor); + p.setPen(Qt::NoPen); + p.drawRoundedRect(r, circleRadius + 4, circleRadius + 4); + + int minX = r.left() + margin * 2; + int maxX = r.right() - circleRadius * 2 - margin; + int circleX = isChecked ? maxX : minX; + QRect circleRect(circleX, r.top() + margin, circleRadius * 2, circleRadius * 2); + p.setBrush(indicatorColor); + p.drawEllipse(circleRect); +} + void CustomToggleSwitch::mouseReleaseEvent(QMouseEvent * event) { if (event->button() == Qt::LeftButton) { diff --git a/common/tier4_state_rviz_plugin/src/include/custom_toggle_switch.hpp b/common/tier4_state_rviz_plugin/src/include/custom_toggle_switch.hpp index e22cb8d98bc41..107d45af8c3f3 100644 --- a/common/tier4_state_rviz_plugin/src/include/custom_toggle_switch.hpp +++ b/common/tier4_state_rviz_plugin/src/include/custom_toggle_switch.hpp @@ -30,6 +30,7 @@ class CustomToggleSwitch : public QCheckBox void setCheckedState(bool state); protected: + void paintEvent(QPaintEvent * event) override; void mouseReleaseEvent(QMouseEvent * event) override; private: From 468da6d28169557e3934cababe0884d43aa65128 Mon Sep 17 00:00:00 2001 From: kobayu858 Date: Tue, 27 Aug 2024 16:46:18 +0900 Subject: [PATCH 10/13] fix:revert custom label Signed-off-by: kobayu858 --- common/tier4_state_rviz_plugin/src/custom_label.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/common/tier4_state_rviz_plugin/src/custom_label.cpp b/common/tier4_state_rviz_plugin/src/custom_label.cpp index 36f578cd0da83..59df84138b890 100644 --- a/common/tier4_state_rviz_plugin/src/custom_label.cpp +++ b/common/tier4_state_rviz_plugin/src/custom_label.cpp @@ -82,4 +82,3 @@ void CustomLabel::updateStyle( textColor = text_color; update(); // Force repaint } - From ccd581506d4aed3e082b68eab5d987590a99cef8 Mon Sep 17 00:00:00 2001 From: kobayu858 Date: Tue, 27 Aug 2024 16:48:07 +0900 Subject: [PATCH 11/13] fix:add blank line Signed-off-by: kobayu858 --- common/tier4_state_rviz_plugin/src/custom_container.cpp | 2 +- common/tier4_state_rviz_plugin/src/custom_icon_label.cpp | 2 +- common/tier4_state_rviz_plugin/src/custom_segmented_button.cpp | 2 +- common/tier4_state_rviz_plugin/src/custom_slider.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/common/tier4_state_rviz_plugin/src/custom_container.cpp b/common/tier4_state_rviz_plugin/src/custom_container.cpp index 7504e2374c528..c82ca685ca9ba 100644 --- a/common/tier4_state_rviz_plugin/src/custom_container.cpp +++ b/common/tier4_state_rviz_plugin/src/custom_container.cpp @@ -58,4 +58,4 @@ void CustomContainer::paintEvent(QPaintEvent *) painter.setBrush(QColor( autoware::state_rviz_plugin::colors::default_colors.surface.c_str())); // Background color painter.drawPath(path); -} \ No newline at end of file +} diff --git a/common/tier4_state_rviz_plugin/src/custom_icon_label.cpp b/common/tier4_state_rviz_plugin/src/custom_icon_label.cpp index 526693832c102..28458d7c79d71 100644 --- a/common/tier4_state_rviz_plugin/src/custom_icon_label.cpp +++ b/common/tier4_state_rviz_plugin/src/custom_icon_label.cpp @@ -79,4 +79,4 @@ void CustomIconLabel::paintEvent(QPaintEvent *) painter.drawPixmap( iconPos, icon.scaled(iconSize, Qt::KeepAspectRatio, Qt::SmoothTransformation)); } -} \ No newline at end of file +} diff --git a/common/tier4_state_rviz_plugin/src/custom_segmented_button.cpp b/common/tier4_state_rviz_plugin/src/custom_segmented_button.cpp index b5f2d522b45f9..3f93df006415e 100644 --- a/common/tier4_state_rviz_plugin/src/custom_segmented_button.cpp +++ b/common/tier4_state_rviz_plugin/src/custom_segmented_button.cpp @@ -75,4 +75,4 @@ void CustomSegmentedButton::paintEvent(QPaintEvent *) painter.setBrush( QColor(autoware::state_rviz_plugin::colors::default_colors.surface_container_low.c_str())); painter.drawPath(path); -} \ No newline at end of file +} diff --git a/common/tier4_state_rviz_plugin/src/custom_slider.cpp b/common/tier4_state_rviz_plugin/src/custom_slider.cpp index efc596e252c2c..16dfda19a87bf 100644 --- a/common/tier4_state_rviz_plugin/src/custom_slider.cpp +++ b/common/tier4_state_rviz_plugin/src/custom_slider.cpp @@ -100,4 +100,4 @@ void CustomSlider::paintEvent(QPaintEvent *) QPainterPath handlePath; handlePath.addRoundedRect(handleLineRect, handleLineRadius, handleLineRadius); painter.fillPath(handlePath, handleColor); -} \ No newline at end of file +} From 84d383498adb5cb87728b741908916fe4146def1 Mon Sep 17 00:00:00 2001 From: kobayu858 Date: Tue, 27 Aug 2024 17:02:51 +0900 Subject: [PATCH 12/13] fix:revert custom botton item Signed-off-by: kobayu858 --- .../src/custom_segmented_button_item.cpp | 85 +++++++++++++++++++ .../include/custom_segmented_button_item.hpp | 4 + 2 files changed, 89 insertions(+) diff --git a/common/tier4_state_rviz_plugin/src/custom_segmented_button_item.cpp b/common/tier4_state_rviz_plugin/src/custom_segmented_button_item.cpp index fb46eca1606f6..3c671c988f936 100644 --- a/common/tier4_state_rviz_plugin/src/custom_segmented_button_item.cpp +++ b/common/tier4_state_rviz_plugin/src/custom_segmented_button_item.cpp @@ -76,6 +76,91 @@ void CustomSegmentedButtonItem::setActivated(bool activated) update(); } +// cppcheck-suppress unusedFunction +void CustomSegmentedButtonItem::paintEvent(QPaintEvent *) +{ + QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing); + + // Adjust opacity for disabled state + if (isDisabled) { + painter.setOpacity(0.3); + } else { + painter.setOpacity(1.0); + } + + // Determine the button's color based on its state + QColor buttonColor; + if (isDisabled) { + buttonColor = disabledBgColor; + } else if (isHovered && !isChecked() && isCheckable()) { + buttonColor = hoverColor; + } else if (isActivated) { + buttonColor = checkedBgColor; + } else { + buttonColor = isChecked() ? checkedBgColor : bgColor; + } + + // Determine if this is the first or last button + bool isFirstButton = false; + bool isLastButton = false; + + QHBoxLayout * parentLayout = qobject_cast(parentWidget()->layout()); + if (parentLayout) { + int index = parentLayout->indexOf(this); + isFirstButton = (index == 0); + isLastButton = (index == parentLayout->count() - 1); + } + + // Draw button background + + QRect buttonRect = rect().adjusted(0, 1, 0, -1); + + if (isFirstButton) { + buttonRect.setLeft(buttonRect.left() + 1); + } + if (isLastButton) { + buttonRect.setRight(buttonRect.right() - 1); + } + + QPainterPath path; + double radius = (height() - 2) / 2; + + path.setFillRule(Qt::WindingFill); + if (isFirstButton) { + path.addRoundedRect(buttonRect, radius, radius); + path.addRect(QRect( + (buttonRect.left() + buttonRect.width() - radius), + buttonRect.top() + buttonRect.height() - radius, radius, + radius)); // Bottom Right + path.addRect(QRect( + (buttonRect.left() + buttonRect.width() - radius), buttonRect.top(), radius, + radius)); // Top Right + } else if (isLastButton) { + path.addRoundedRect(buttonRect, radius, radius); + path.addRect(QRect( + (buttonRect.left()), buttonRect.top() + buttonRect.height() - radius, radius, + radius)); // Bottom left + path.addRect(QRect((buttonRect.left()), buttonRect.top(), radius, + radius)); // Top Left + } else { + path.addRect(buttonRect); + } + painter.fillPath(path, buttonColor); + + // Draw button border + QPen pen(QColor(autoware::state_rviz_plugin::colors::default_colors.outline.c_str()), 1); + pen.setJoinStyle(Qt::RoundJoin); + pen.setCapStyle(Qt::RoundCap); + painter.setPen(pen); + painter.drawPath(path.simplified()); + + // Draw button text + QColor textColor = (isChecked() ? activeTextColor : inactiveTextColor); + painter.setPen(textColor); + painter.drawText(rect(), Qt::AlignCenter, text()); +} + void CustomSegmentedButtonItem::enterEvent(QEvent * event) { if (isCheckable()) { diff --git a/common/tier4_state_rviz_plugin/src/include/custom_segmented_button_item.hpp b/common/tier4_state_rviz_plugin/src/include/custom_segmented_button_item.hpp index f454da30825c3..33eb9fe16aa31 100644 --- a/common/tier4_state_rviz_plugin/src/include/custom_segmented_button_item.hpp +++ b/common/tier4_state_rviz_plugin/src/include/custom_segmented_button_item.hpp @@ -30,12 +30,16 @@ class CustomSegmentedButtonItem : public QPushButton public: explicit CustomSegmentedButtonItem(const QString & text, QWidget * parent = nullptr); + void setColors( + const QColor & bg, const QColor & checkedBg, const QColor & activeText, + const QColor & inactiveText); void setActivated(bool activated); void setCheckableButton(bool checkable); void setDisabledButton(bool disabled); void setHovered(bool hovered); protected: + void paintEvent(QPaintEvent * event) override; void enterEvent(QEvent * event) override; void leaveEvent(QEvent * event) override; From 476aa0e48a2c130ca0a61d963d83e9b05ef45a59 Mon Sep 17 00:00:00 2001 From: kobayu858 Date: Wed, 28 Aug 2024 10:29:36 +0900 Subject: [PATCH 13/13] fix:remove declaration Signed-off-by: kobayu858 --- .../tier4_state_rviz_plugin/src/include/custom_container.hpp | 2 -- .../src/include/custom_segmented_button_item.hpp | 3 --- 2 files changed, 5 deletions(-) diff --git a/common/tier4_state_rviz_plugin/src/include/custom_container.hpp b/common/tier4_state_rviz_plugin/src/include/custom_container.hpp index 5142b409ebc88..ef81ef2417d52 100644 --- a/common/tier4_state_rviz_plugin/src/include/custom_container.hpp +++ b/common/tier4_state_rviz_plugin/src/include/custom_container.hpp @@ -31,12 +31,10 @@ class CustomContainer : public QFrame // Methods to set dimensions and corner radius void setContainerHeight(int height); void setContainerWidth(int width); - void setCornerRadius(int radius); // Getters int getContainerHeight() const; int getContainerWidth() const; - int getCornerRadius() const; QGridLayout * getLayout() const; // Add a method to access the layout protected: diff --git a/common/tier4_state_rviz_plugin/src/include/custom_segmented_button_item.hpp b/common/tier4_state_rviz_plugin/src/include/custom_segmented_button_item.hpp index 33eb9fe16aa31..ee6f48e285975 100644 --- a/common/tier4_state_rviz_plugin/src/include/custom_segmented_button_item.hpp +++ b/common/tier4_state_rviz_plugin/src/include/custom_segmented_button_item.hpp @@ -30,9 +30,6 @@ class CustomSegmentedButtonItem : public QPushButton public: explicit CustomSegmentedButtonItem(const QString & text, QWidget * parent = nullptr); - void setColors( - const QColor & bg, const QColor & checkedBg, const QColor & activeText, - const QColor & inactiveText); void setActivated(bool activated); void setCheckableButton(bool checkable); void setDisabledButton(bool disabled);