Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 45 additions & 2 deletions plugins/dde-dock/bluetooth/quickpanelwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@

#include "quickpanelwidget.h"

#include <DFontSizeManager>

Check warning on line 8 in plugins/dde-dock/bluetooth/quickpanelwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DFontSizeManager> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <DStyle>

Check warning on line 9 in plugins/dde-dock/bluetooth/quickpanelwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DStyle> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <DGuiApplicationHelper>

Check warning on line 10 in plugins/dde-dock/bluetooth/quickpanelwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DGuiApplicationHelper> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <QHBoxLayout>

Check warning on line 12 in plugins/dde-dock/bluetooth/quickpanelwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QHBoxLayout> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QLabel>

Check warning on line 13 in plugins/dde-dock/bluetooth/quickpanelwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QLabel> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QMouseEvent>

Check warning on line 14 in plugins/dde-dock/bluetooth/quickpanelwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QMouseEvent> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QEnterEvent>

Check warning on line 15 in plugins/dde-dock/bluetooth/quickpanelwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QEnterEvent> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QPainter>

Check warning on line 16 in plugins/dde-dock/bluetooth/quickpanelwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QPainter> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QPainterPath>

Check warning on line 17 in plugins/dde-dock/bluetooth/quickpanelwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QPainterPath> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <DToolTip>

Check warning on line 18 in plugins/dde-dock/bluetooth/quickpanelwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DToolTip> not found. Please note: Cppcheck does not need standard library headers to get proper results.

DGUI_USE_NAMESPACE
DWIDGET_USE_NAMESPACE
Expand All @@ -25,9 +27,17 @@
public:
QuickButton(QWidget *parent = nullptr)
: DFloatingButton(parent)
, m_parentHover(false)
{
}

void setParentHover(bool hover) {
if (m_parentHover == hover)
return;
m_parentHover = hover;
update();
}

protected:
void initStyleOption(DStyleOptionButton *option) const override
{
Expand All @@ -43,10 +53,10 @@
bgColor.setHslF(bgColor.hslHueF(), bgColor.hslSaturationF(), bgColor.lightnessF() * 1.1);
}
} else {
textColor.setAlphaF(1);
textColor.setAlphaF(m_parentHover ? 1.0 : 0.7);
if (!option->state.testFlag(QStyle::State_Raised)) { // press
bgColor.setAlphaF(0.2);
} else if (option->state.testFlag(QStyle::State_MouseOver)) { // hover
} else if (option->state.testFlag(QStyle::State_MouseOver) || m_parentHover) { // hover
bgColor.setAlphaF(0.15);
} else { // normal
bgColor.setAlphaF(0.1);
Expand All @@ -58,6 +68,9 @@
option->state.setFlag(QStyle::State_Sunken, false);
option->state.setFlag(QStyle::State_Raised, true);
}

private:
bool m_parentHover;
};

QuickPanelWidget::QuickPanelWidget(QWidget *parent)
Expand All @@ -66,6 +79,7 @@
, m_nameLabel(new DLabel(this))
, m_stateLabel(new DLabel(this))
, m_expandLabel(new DIconButton(this))
, m_hover(false)
{
initUi();
initConnection();
Expand Down Expand Up @@ -172,3 +186,32 @@
{
connect(m_iconWidget, &DFloatingButton::clicked, this, &QuickPanelWidget::iconClicked);
}

void QuickPanelWidget::enterEvent(QEnterEvent *event)
{
m_hover = true;
m_iconWidget->setParentHover(true);
updateTextColor(true);
QWidget::enterEvent(event);
}

void QuickPanelWidget::leaveEvent(QEvent *event)
{
m_hover = false;
m_iconWidget->setParentHover(false);
updateTextColor(false);
QWidget::leaveEvent(event);
}

void QuickPanelWidget::updateTextColor(bool hover)
{
bool isLight = DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType;
QColor color = isLight ? QColor(0, 0, 0) : QColor(255, 255, 255);
color.setAlphaF(hover ? 1.0 : 0.7);

QPalette pa = m_nameLabel->palette();
pa.setColor(QPalette::BrightText, color);
pa.setColor(QPalette::WindowText, color);
m_nameLabel->setPalette(pa);
m_stateLabel->setPalette(pa);
}
4 changes: 4 additions & 0 deletions plugins/dde-dock/bluetooth/quickpanelwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,21 @@ public Q_SLOTS:
protected:
void mousePressEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
void enterEvent(QEnterEvent *event) override;
void leaveEvent(QEvent *event) override;

private:
void initUi();
void initConnection();
void updateTextColor(bool hover);

private:
QuickButton *m_iconWidget;
Dtk::Widget::DLabel *m_nameLabel;
Dtk::Widget::DLabel *m_stateLabel;
Dtk::Widget::DIconButton *m_expandLabel;
QPoint m_clickPoint;
bool m_hover;
};

#endif // QUICKPANELWIDGET_H
16 changes: 13 additions & 3 deletions plugins/dde-dock/common/commoniconbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ CommonIconButton::CommonIconButton(QWidget *parent)
, m_refreshTimer(nullptr)
, m_clickable(false)
, m_hover(false)
, m_parentHover(false)
, m_state(Default)
, m_lightThemeColor(Qt::black)
, m_darkThemeColor(Qt::white)
, m_lightThemeColor(QColor(0, 0, 0, 178))
, m_darkThemeColor(QColor(255, 255, 255, 178))
, m_activeState(false)
Comment on lines -20 to 22

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (broader_impact): Changing the default m_lightThemeColor and m_darkThemeColor to 70% alpha does not affect buttons initialized through the string overload of setIcon, because that overload ends with update() rather than updatePalette(). Those callers retain the inherited opaque WindowText palette and do not receive the new normal-state opacity.

Triggers: When a CommonIconButton is configured with setIcon(const QString &, const QString &, const QString &) and is not later updated through a path that calls updatePalette().

Suggested fix: Call updatePalette() from the string overload after selecting the icon.

, m_hoverEnable(true)
, m_iconSize(QSize())
Expand Down Expand Up @@ -87,6 +88,9 @@ void CommonIconButton::updatePalette()
if (m_lightThemeColor.isValid() && m_darkThemeColor.isValid()) {
if (!m_activeState) {
QColor color = DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType ? m_lightThemeColor : m_darkThemeColor;
if (m_hover || m_parentHover) {
color.setAlpha(255);
}
auto pa = palette();
pa.setColor(QPalette::WindowText, color);
setPalette(pa);
Expand All @@ -113,6 +117,12 @@ void CommonIconButton::setHoverEnable(bool enable)
m_hoverEnable = enable;
}

void CommonIconButton::setParentHover(bool hover)
{
m_parentHover = hover;
updatePalette();
}

void CommonIconButton::setIcon(const QString &icon, const QString &fallback, const QString &suffix)
{
if (!m_fileMapping.contains(Default)) {
Expand Down Expand Up @@ -162,7 +172,7 @@ bool CommonIconButton::event(QEvent *e)
case QEvent::Leave:
case QEvent::Enter:
m_hover = e->type() == QEvent::Enter;
update();
updatePalette();
break;
default:
break;
Expand Down
2 changes: 2 additions & 0 deletions plugins/dde-dock/common/commoniconbutton.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class CommonIconButton : public QWidget
void setHoverEnable(bool enable);
void setIconSize(const QSize &size);
void setAllEnabled(bool enable);
void setParentHover(bool hover);

void startRotate();
void stopRotate();
Expand Down Expand Up @@ -64,6 +65,7 @@ public Q_SLOTS:
QPoint m_pressPos;
bool m_clickable;
bool m_hover;
bool m_parentHover;
QMap<State, QPair<QString, QString>> m_fileMapping;
State m_state;
QColor m_lightThemeColor;
Expand Down
4 changes: 3 additions & 1 deletion plugins/dde-dock/common/jumpsettingbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void JumpSettingButton::initUI()

void JumpSettingButton::setIcon(const QIcon &icon)
{
m_iconButton->setIcon(icon, Qt::black, Qt::white);
m_iconButton->setIcon(icon, QColor(0, 0, 0, 178), QColor(255, 255, 255, 178));
}

void JumpSettingButton::setDescription(const QString& description)
Expand All @@ -78,6 +78,7 @@ bool JumpSettingButton::event(QEvent* e)
case QEvent::Leave:
case QEvent::Enter:
m_hover = e->type() == QEvent::Enter;
m_iconButton->setParentHover(m_hover);
update();
break;
case QEvent::Hide:
Expand All @@ -101,6 +102,7 @@ void JumpSettingButton::paintEvent(QPaintEvent* e)
bgColor = palette.color(QPalette::Active, QPalette::Highlight);
} else {
textColor = palette.brightText().color();
textColor.setAlphaF(0.7);
bgColor = palette.brightText().color();
bgColor.setAlphaF(0.05);
}
Expand Down
1 change: 1 addition & 0 deletions plugins/dde-dock/common/pluginitemdelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ void PluginItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
}
} else {
textColor = boption.dpalette.brightText().color();
textColor.setAlphaF(0.7);
bgColor = boption.dpalette.brightText().color();
bgColor.setAlphaF(0.05);
}
Expand Down
35 changes: 34 additions & 1 deletion plugins/dde-dock/common/singlequickpanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "singlequickpanel.h"

#include <QVBoxLayout>
#include <QEnterEvent>
#include <QMargins>

#include <DFontSizeManager>
Expand All @@ -20,6 +21,7 @@ SignalQuickPanel::SignalQuickPanel(QWidget *parent)
, m_icon(new CommonIconButton(this))
, m_description(new DLabel(this))
, m_active(false)
, m_hover(false)
{
initUI();
connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, &SignalQuickPanel::refreshBg);
Expand Down Expand Up @@ -52,7 +54,7 @@ void SignalQuickPanel::initUI()

void SignalQuickPanel::setIcon(const QIcon &icon)
{
m_icon->setIcon(icon, Qt::black, Qt::white);
m_icon->setIcon(icon, QColor(0, 0, 0, 178), QColor(255, 255, 255, 178));
}

void SignalQuickPanel::setDescription(const QString &description)
Expand Down Expand Up @@ -81,5 +83,36 @@ void SignalQuickPanel::mouseReleaseEvent(QMouseEvent *event)
void SignalQuickPanel::refreshBg()
{
m_description->setForegroundRole(m_icon->activeState() ? QPalette::Highlight : QPalette::NoRole);
updateTextColor();
update();
}

void SignalQuickPanel::enterEvent(QEnterEvent *event)
{
m_hover = true;
m_icon->setParentHover(true);
updateTextColor();
QWidget::enterEvent(event);
}

void SignalQuickPanel::leaveEvent(QEvent *event)
{
m_hover = false;
m_icon->setParentHover(false);
updateTextColor();
QWidget::leaveEvent(event);
}

void SignalQuickPanel::updateTextColor()
{
if (m_active)
return;

bool isLight = DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType;
QColor color = isLight ? QColor(0, 0, 0) : QColor(255, 255, 255);
color.setAlphaF(m_hover ? 1.0 : 0.7);

QPalette pa = m_description->palette();
pa.setColor(QPalette::WindowText, color);
m_description->setPalette(pa);
}
4 changes: 4 additions & 0 deletions plugins/dde-dock/common/singlequickpanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ class SignalQuickPanel : public QWidget

protected:
void mouseReleaseEvent(QMouseEvent *event) override;
void enterEvent(QEnterEvent *event) override;
void leaveEvent(QEvent *event) override;

private:
void initUI();
void updateTextColor();

private slots:
void refreshBg();
Expand All @@ -48,6 +51,7 @@ private slots:
CommonIconButton *m_icon;
DLabel *m_description;
bool m_active;
bool m_hover;
};

#endif
36 changes: 34 additions & 2 deletions plugins/dde-dock/eye-comfort-mode/quickpanelwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@

#include <DFontSizeManager>
#include <DStyle>
#include <DGuiApplicationHelper>

#include <QHBoxLayout>
#include <QLabel>
#include <QMouseEvent>
#include <QEnterEvent>
#include <QPainter>
#include <QPainterPath>
#include <DToolTip>
Expand All @@ -36,10 +38,10 @@ void QuickButton::initStyleOption(DStyleOptionButton *option) const
bgColor.setHslF(bgColor.hslHueF(), bgColor.hslSaturationF(), bgColor.lightnessF() * 1.1);
}
} else {
textColor.setAlphaF(1);
textColor.setAlphaF(m_parentHover ? 1.0 : 0.7);
if (!option->state.testFlag(QStyle::State_Raised)) { // press
bgColor.setAlphaF(0.2);
} else if (option->state.testFlag(QStyle::State_MouseOver)) { // hover
} else if (option->state.testFlag(QStyle::State_MouseOver) || m_parentHover) { // hover
bgColor.setAlphaF(0.15);
} else { // normal
bgColor.setAlphaF(0.1);
Expand All @@ -64,6 +66,7 @@ QuickPanelWidget::QuickPanelWidget(QWidget *parent)
, m_nameLabel(new DLabel(this))
, m_stateLabel(new DLabel(this))
, m_expandLabel(new DIconButton(this))
, m_hover(false)
{
initUi();
initConnection();
Expand Down Expand Up @@ -174,3 +177,32 @@ void QuickPanelWidget::initConnection()
{
connect(m_iconWidget, &DFloatingButton::clicked, this, &QuickPanelWidget::iconClicked);
}

void QuickPanelWidget::enterEvent(QEnterEvent *event)
{
m_hover = true;
m_iconWidget->setParentHover(true);
updateTextColor(true);
QWidget::enterEvent(event);
}

void QuickPanelWidget::leaveEvent(QEvent *event)
{
m_hover = false;
m_iconWidget->setParentHover(false);
updateTextColor(false);
QWidget::leaveEvent(event);
}

void QuickPanelWidget::updateTextColor(bool hover)
{
bool isLight = DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType;
QColor color = isLight ? QColor(0, 0, 0) : QColor(255, 255, 255);
color.setAlphaF(hover ? 1.0 : 0.7);

QPalette pa = m_nameLabel->palette();
pa.setColor(QPalette::BrightText, color);
pa.setColor(QPalette::WindowText, color);
m_nameLabel->setPalette(pa);
m_stateLabel->setPalette(pa);
}
Loading
Loading