dde-dock/plugins/sound/soundapplet.h
donghualin ec092bb980 fix: 修复任务栏插件音量设备显示错误的问题
音量设备解析错误,没有和控制中心保持一致,参照之前的音量的解析逻辑重新来显示音量的功能即可

Log:
Influence: 从任务栏打开音量,进入音量的详情页面,观察是否和控制中心一致
Bug: https://pms.uniontech.com/bug-view-165853.html
Change-Id: I39a6b0664ac2adc40f2ea523d8e0693426640ae5
2022-11-24 09:53:05 +00:00

145 lines
4.1 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/>.
*/
#ifndef SOUNDAPPLET_H
#define SOUNDAPPLET_H
#include "componments/volumeslider.h"
#include "org_deepin_daemon_audio.h"
#include "org_deepin_daemon_audio_sink.h"
#include <DIconButton>
#include <DListView>
#include <DApplicationHelper>
#include <QScrollArea>
#include <QVBoxLayout>
#include <QLabel>
#include <QSlider>
DWIDGET_USE_NAMESPACE
using DBusAudio = org::deepin::daemon::Audio1;
using DBusSink = org::deepin::daemon::audio1::Sink;
class HorizontalSeperator;
class QGSettings;
class SoundDevicePort;
namespace Dock {
class TipsWidget;
}
class BackgroundWidget : public QWidget
{
public:
explicit BackgroundWidget(QWidget *parent = nullptr)
: QWidget(parent) {}
protected:
void paintEvent(QPaintEvent *event)
{
QPainter painter(this);
painter.setPen(Qt::NoPen);
if (DApplicationHelper::instance()->themeType() == DApplicationHelper::LightType) {
painter.setBrush(QColor(0, 0, 0, 0.03 * 255));
} else {
painter.setBrush(QColor(255, 255, 255, 0.03 * 255));
}
painter.drawRect(rect());
return QWidget::paintEvent(event);
}
};
class SoundApplet : public QScrollArea
{
Q_OBJECT
public:
explicit SoundApplet(QWidget *parent = 0);
int volumeValue() const;
int maxVolumeValue() const;
VolumeSlider *mainSlider();
void startAddPort(SoundDevicePort *port);
void startRemovePort(const QString &portId, const uint &cardId);
bool containsPort(const SoundDevicePort *port);
SoundDevicePort *findPort(const QString &portId, const uint &cardId) const;
void setUnchecked(DStandardItem *pi);
void initUi();
bool existActiveOutputDevice();
signals:
void volumeChanged(const int value) const;
void defaultSinkChanged(DBusSink *sink) const;
private slots:
void onDefaultSinkChanged();
void onVolumeChanged(double volume);
void volumeSliderValueChanged();
void increaseVolumeChanged();
void cardsChanged(const QString &cards);
void removePort(const QString &portId, const uint &cardId);
void addPort(const SoundDevicePort *port);
void activePort(const QString &portId,const uint &cardId);
void haldleDbusSignal(const QDBusMessage &msg);
void updateListHeight();
void portEnableChange(unsigned int cardId, QString portId);
private:
void refreshIcon();
void updateCradsInfo();
void enableDevice(bool flag);
void disableAllDevice();//禁用所有设备
void removeLastDevice();//移除最后一个设备
void removeDisabledDevice(QString portId, unsigned int cardId);
void updateVolumeSliderStatus(const QString &status);
protected:
bool eventFilter(QObject *watcher, QEvent *event) override;
private:
QWidget *m_centralWidget;
QLabel *m_volumeIconMin;
QLabel *m_volumeIconMax;
VolumeSlider *m_volumeSlider;
QLabel *m_soundShow;
QLabel *m_deviceLabel;
QVBoxLayout *m_centralLayout;
HorizontalSeperator *m_seperator;
HorizontalSeperator *m_secondSeperator;
DBusAudio *m_audioInter;
DBusSink *m_defSinkInter;
DTK_WIDGET_NAMESPACE::DListView *m_listView;
QStandardItemModel *m_model;
QList<SoundDevicePort *> m_ports;
QString m_deviceInfo;
QPointer<SoundDevicePort> m_lastPort;//最后一个因为只有一个设备而被直接移除的设备
const QGSettings *m_gsettings;
};
#endif // SOUNDAPPLET_H