diff --git a/plugins/tray/indicatortraywidget.cpp b/plugins/tray/indicatortraywidget.cpp index f35a2c9a8..9cfcf7961 100644 --- a/plugins/tray/indicatortraywidget.cpp +++ b/plugins/tray/indicatortraywidget.cpp @@ -3,13 +3,17 @@ // SPDX-License-Identifier: LGPL-3.0-or-later #include "indicatortraywidget.h" +#include "constants.h" #include "util/utils.h" #include #include +#include #include #include +#include +DGUI_USE_NAMESPACE IndicatorTrayWidget::IndicatorTrayWidget(const QString &indicatorName, QWidget *parent, Qt::WindowFlags f) : AbstractTrayWidget(parent, f) @@ -22,12 +26,6 @@ IndicatorTrayWidget::IndicatorTrayWidget(const QString &indicatorName, QWidget * auto layout = new QVBoxLayout(this); layout->setContentsMargins(0, 0, 0, 0); m_label = new QLabel(this); - - QPalette p = m_label->palette(); - p.setColor(QPalette::Foreground, Qt::white); - p.setColor(QPalette::Background, Qt::transparent); - m_label->setPalette(p); - m_label->setAttribute(Qt::WA_TranslucentBackground); layout->addWidget(m_label, 0, Qt::AlignCenter); @@ -49,6 +47,9 @@ IndicatorTrayWidget::IndicatorTrayWidget(const QString &indicatorName, QWidget * connect(m_gsettings, &QGSettings::changed, this, &IndicatorTrayWidget::onGSettingsChanged); } + + updateLabelColor(); + connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, &IndicatorTrayWidget::updateLabelColor); } IndicatorTrayWidget::~IndicatorTrayWidget() @@ -73,26 +74,30 @@ void IndicatorTrayWidget::sendClick(uint8_t buttonIndex, int x, int y) void IndicatorTrayWidget::enableLabel(bool enable) { - QPalette p = m_label->palette(); - if (!enable) { - m_enableClick = false; - p.setColor(QPalette::Disabled, QPalette::Foreground, Qt::lightGray); - p.setColor(QPalette::Disabled, QPalette::Background, Qt::transparent); - m_label->setEnabled(enable); - } else { - m_enableClick = true; - p.setColor(QPalette::Normal, QPalette::BrightText, Qt::white); - p.setColor(QPalette::Normal, QPalette::Background, Qt::transparent); - m_label->setEnabled(enable); - } - - m_label->setPalette(p); - m_label->update(); + m_enableClick = enable; + m_label->setEnabled(enable); + updateLabelColor(); } void IndicatorTrayWidget::resizeEvent(QResizeEvent *event) { - return QWidget::resizeEvent(event); + QWidget::resizeEvent(event); + + if (event->size().height() <= PLUGIN_BACKGROUND_MIN_SIZE || event->oldSize().height() <= PLUGIN_BACKGROUND_MIN_SIZE) + updateLabelColor(); +} + +void IndicatorTrayWidget::updateLabelColor() +{ + QPalette p = m_label->palette(); + p.setColor(QPalette::Foreground, m_label->isEnabled() ? Qt::white : Qt::lightGray); + + if (height() <= PLUGIN_BACKGROUND_MIN_SIZE && DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType) { + p.setColor(QPalette::Foreground, m_label->isEnabled() ? Qt::black : Qt::darkGray); + } + + m_label->setPalette(p); + m_label->update(); } void IndicatorTrayWidget::setPixmapData(const QByteArray &data) diff --git a/plugins/tray/indicatortraywidget.h b/plugins/tray/indicatortraywidget.h index 4831cbdaa..8f1e6cd31 100644 --- a/plugins/tray/indicatortraywidget.h +++ b/plugins/tray/indicatortraywidget.h @@ -27,6 +27,7 @@ public: protected: void resizeEvent(QResizeEvent *event) override; + void updateLabelColor(); public Q_SLOTS: Q_SCRIPTABLE void setPixmapData(const QByteArray &data);