dde-dock/plugins/sound/componments/volumeslider.cpp
donghualin cf376ebb3f style: 消除编译警告信息
将代码中的过期的不建议使用的函数或类替换成建议使用的函数或类

Log: 消除编译警告
Influence: 无
Task: https://pms.uniontech.com/task-view-96831.html
Change-Id: Ie42a3eed97013adb047105bcf75e07ff8e0277a0
2022-11-04 06:29:16 +00:00

94 lines
2.3 KiB
C++

/*
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
*
* Author: sbw <sbw@sbw.so>
*
* Maintainer: sbw <sbw@sbw.so>
*
* 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 "volumeslider.h"
#include <QMouseEvent>
#include <QDebug>
#include <QTimer>
VolumeSlider::VolumeSlider(QWidget *parent)
: DSlider(Qt::Horizontal, parent),
m_pressed(false),
m_timer(new QTimer(this))
{
setPageStep(50);
m_timer->setInterval(100);
connect(m_timer, &QTimer::timeout, this, &VolumeSlider::onTimeout);
}
void VolumeSlider::setValue(const int value)
{
if (m_pressed)
return;
blockSignals(true);
DSlider::setValue(value);
blockSignals(false);
}
void VolumeSlider::mousePressEvent(QMouseEvent *e)
{
if (e->button() == Qt::LeftButton)
{
if (!rect().contains(e->pos()))
return;
m_pressed = true;
DSlider::setValue(maximum() * e->x() / rect().width());
}
}
void VolumeSlider::mouseMoveEvent(QMouseEvent *e)
{
const int value = minimum() + (double((maximum()) - minimum()) * e->x() / rect().width());
const int normalized = std::max(std::min(maximum(), value), 0);
DSlider::setValue(normalized);
blockSignals(true);
emit valueChanged(normalized);
blockSignals(false);
}
void VolumeSlider::mouseReleaseEvent(QMouseEvent *e)
{
if (e->button() == Qt::LeftButton) {
m_pressed = false;
emit requestPlaySoundEffect();
}
}
void VolumeSlider::wheelEvent(QWheelEvent *e)
{
e->accept();
m_timer->start();
DSlider::setValue(value() + (e->angleDelta().y() > 0 ? 2 : -2));
}
void VolumeSlider::onTimeout()
{
m_timer->stop();
emit requestPlaySoundEffect();
}