mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-02 15:45:21 +00:00
feat: keyboard交互调整 (#717)
keyboard的显示方式和其他托盘颜色格格不入,修改成统一风格; 浅色模式且任务栏高度最小时显示黑色,其他情况显示白色; Log: keyboard交互调整 Change-Id: I6c56d9cb08872caac7b3614bb0117e5a5427a17d
This commit is contained in:
parent
d24d69d41e
commit
4abc8ae385
@ -3,13 +3,17 @@
|
||||
// SPDX-License-Identifier: LGPL-3.0-or-later
|
||||
|
||||
#include "indicatortraywidget.h"
|
||||
#include "constants.h"
|
||||
#include "util/utils.h"
|
||||
|
||||
#include <QLabel>
|
||||
#include <QBoxLayout>
|
||||
#include <QResizeEvent>
|
||||
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusInterface>
|
||||
#include <DGuiApplicationHelper>
|
||||
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)
|
||||
|
@ -27,6 +27,7 @@ public:
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *event) override;
|
||||
void updateLabelColor();
|
||||
|
||||
public Q_SLOTS:
|
||||
Q_SCRIPTABLE void setPixmapData(const QByteArray &data);
|
||||
|
Loading…
x
Reference in New Issue
Block a user