mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00

1.增加license 2.修复bug 3.UI调整 Log: 优化任务栏代码 Influence: v23任务栏 Task: https://pms.uniontech.com/task-view-112073.html Change-Id: Ic66428699f6060d8b0baefa3dbc2d3603d320242
100 lines
2.8 KiB
C++
100 lines
2.8 KiB
C++
/*
|
|
* Copyright (C) 2022 ~ 2022 Deepin Technology Co., Ltd.
|
|
*
|
|
* Author: donghualin <donghualin@uniontech.com>
|
|
*
|
|
* Maintainer: donghualin <donghualin@uniontech.com>
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
#include "brightnesswidget.h"
|
|
#include "customslider.h"
|
|
#include "brightnessmodel.h"
|
|
#include "brightnessmonitorwidget.h"
|
|
|
|
#include <QHBoxLayout>
|
|
#include <QDebug>
|
|
|
|
BrightnessWidget::BrightnessWidget(QWidget *parent)
|
|
: DBlurEffectWidget(parent)
|
|
, m_slider(new CustomSlider(CustomSlider::SliderType::Normal, this))
|
|
, m_model(new BrightnessModel(this))
|
|
{
|
|
initUi();
|
|
initConenction();
|
|
}
|
|
|
|
BrightnessWidget::~BrightnessWidget()
|
|
{
|
|
}
|
|
|
|
BrightnessModel *BrightnessWidget::model()
|
|
{
|
|
return m_model;
|
|
}
|
|
|
|
void BrightnessWidget::showEvent(QShowEvent *event)
|
|
{
|
|
DBlurEffectWidget::showEvent(event);
|
|
Q_EMIT visibleChanged(true);
|
|
}
|
|
|
|
void BrightnessWidget::hideEvent(QHideEvent *event)
|
|
{
|
|
DBlurEffectWidget::hideEvent(event);
|
|
Q_EMIT visibleChanged(true);
|
|
}
|
|
|
|
void BrightnessWidget::initUi()
|
|
{
|
|
QHBoxLayout *layout = new QHBoxLayout(this);
|
|
layout->setContentsMargins(20, 0, 20, 0);
|
|
layout->addWidget(m_slider);
|
|
|
|
m_slider->setPageStep(1);
|
|
m_slider->setIconSize(QSize(24, 24));
|
|
|
|
m_slider->setLeftIcon(QIcon(":/icons/resources/brightness.svg"));
|
|
m_slider->setRightIcon(QIcon::fromTheme(":/icons/resources/ICON_Device_Laptop.svg"));
|
|
m_slider->setTickPosition(QSlider::TicksBelow);
|
|
}
|
|
|
|
void BrightnessWidget::initConenction()
|
|
{
|
|
connect(m_slider, &CustomSlider::iconClicked, this, [ this ](DSlider::SliderIcons icon, bool) {
|
|
if (icon == DSlider::SliderIcons::RightIcon)
|
|
Q_EMIT rightIconClicked();
|
|
});
|
|
|
|
connect(m_slider, &CustomSlider::valueChanged, this, [ this ](int value) {
|
|
BrightMonitor *monitor = m_model->primaryMonitor();
|
|
if (monitor)
|
|
m_model->setBrightness(monitor, value);
|
|
});
|
|
|
|
connect(m_model, &BrightnessModel::brightnessChanged, this, &BrightnessWidget::onUpdateBright);
|
|
|
|
BrightMonitor *monitor = m_model->primaryMonitor();
|
|
if (monitor)
|
|
onUpdateBright(monitor);
|
|
}
|
|
|
|
void BrightnessWidget::onUpdateBright(BrightMonitor *monitor)
|
|
{
|
|
if (!monitor->isPrimary())
|
|
return;
|
|
// 此处只显示主屏的亮度
|
|
m_slider->setValue(monitor->brihtness());
|
|
}
|