diff --git a/plugins/sound/CMakeLists.txt b/plugins/sound/CMakeLists.txt index 89e473191..822bade30 100644 --- a/plugins/sound/CMakeLists.txt +++ b/plugins/sound/CMakeLists.txt @@ -18,16 +18,14 @@ file(GLOB_RECURSE SRCS "*.h" "../../frame/qtdbusextended/*.cpp") find_package(PkgConfig REQUIRED) -find_package(Qt5Widgets REQUIRED) -find_package(Qt5Svg REQUIRED) -find_package(Qt5DBus REQUIRED) +find_package(Qt5 REQUIRED COMPONENTS Concurrent DBus Svg Widgets) find_package(DtkWidget REQUIRED) pkg_check_modules(XCB_LIBS REQUIRED IMPORTED_TARGET xcursor) pkg_check_modules(QGSettings REQUIRED IMPORTED_TARGET gsettings-qt) add_definitions("${QT_DEFINITIONS} -DQT_PLUGIN") -add_library(${PLUGIN_NAME} SHARED ${SRCS} resources/sound.qrc) +add_library(${PLUGIN_NAME} SHARED ${SRCS}) set_target_properties(${PLUGIN_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ../quick-trays) target_include_directories(${PLUGIN_NAME} PUBLIC ${DtkWidget_INCLUDE_DIRS} ./dbusinterface @@ -43,6 +41,7 @@ target_link_libraries(${PLUGIN_NAME} PRIVATE ${DtkWidget_LIBRARIES} PkgConfig::QGSettings PkgConfig::XCB_LIBS + Qt5::Concurrent Qt5::Widgets Qt5::DBus Qt5::Svg) diff --git a/plugins/sound/componments/volumeslider.cpp b/plugins/sound/componments/volumeslider.cpp deleted file mode 100644 index 484d67a70..000000000 --- a/plugins/sound/componments/volumeslider.cpp +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd. -// SPDX-FileCopyrightText: 2018 - 2023 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: LGPL-3.0-or-later - -#include "volumeslider.h" - -#include -#include -#include - -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(); -} diff --git a/plugins/sound/componments/volumeslider.h b/plugins/sound/componments/volumeslider.h deleted file mode 100644 index 1808454b8..000000000 --- a/plugins/sound/componments/volumeslider.h +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd. -// SPDX-FileCopyrightText: 2018 - 2023 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: LGPL-3.0-or-later - -#ifndef VOLUMESLIDER_H -#define VOLUMESLIDER_H - -#include -#include - -class VolumeSlider : public DTK_WIDGET_NAMESPACE::DSlider -{ - Q_OBJECT - -public: - explicit VolumeSlider(QWidget *parent = 0); - - void setValue(const int value); - -signals: - void requestPlaySoundEffect() const; - -protected: - void mousePressEvent(QMouseEvent *e) override; - void mouseMoveEvent(QMouseEvent *e) override; - void mouseReleaseEvent(QMouseEvent *e) override; - void wheelEvent(QWheelEvent *e) override; - -private slots: - void onTimeout(); - -private: - bool m_pressed; - QTimer *m_timer; -}; - -#endif // VOLUMESLIDER_H diff --git a/plugins/sound/resources/audio-volume-000-muted.svg b/plugins/sound/resources/audio-volume-000-muted.svg deleted file mode 100644 index dd16003e2..000000000 --- a/plugins/sound/resources/audio-volume-000-muted.svg +++ /dev/null @@ -1,229 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/plugins/sound/resources/audio-volume-000.svg b/plugins/sound/resources/audio-volume-000.svg deleted file mode 100644 index 64b805970..000000000 --- a/plugins/sound/resources/audio-volume-000.svg +++ /dev/null @@ -1,228 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/plugins/sound/resources/audio-volume-010-muted.svg b/plugins/sound/resources/audio-volume-010-muted.svg deleted file mode 100644 index d774d19d6..000000000 --- a/plugins/sound/resources/audio-volume-010-muted.svg +++ /dev/null @@ -1,234 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/plugins/sound/resources/audio-volume-010.svg b/plugins/sound/resources/audio-volume-010.svg deleted file mode 100644 index 13593f8ce..000000000 --- a/plugins/sound/resources/audio-volume-010.svg +++ /dev/null @@ -1,231 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/plugins/sound/resources/audio-volume-020-muted.svg b/plugins/sound/resources/audio-volume-020-muted.svg deleted file mode 100644 index ea71466d4..000000000 --- a/plugins/sound/resources/audio-volume-020-muted.svg +++ /dev/null @@ -1,235 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/plugins/sound/resources/audio-volume-020.svg b/plugins/sound/resources/audio-volume-020.svg deleted file mode 100644 index ce4a62d22..000000000 --- a/plugins/sound/resources/audio-volume-020.svg +++ /dev/null @@ -1,231 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/plugins/sound/resources/audio-volume-030-muted.svg b/plugins/sound/resources/audio-volume-030-muted.svg deleted file mode 100644 index be1323131..000000000 --- a/plugins/sound/resources/audio-volume-030-muted.svg +++ /dev/null @@ -1,235 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/plugins/sound/resources/audio-volume-030.svg b/plugins/sound/resources/audio-volume-030.svg deleted file mode 100644 index dd78054bb..000000000 --- a/plugins/sound/resources/audio-volume-030.svg +++ /dev/null @@ -1,231 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/plugins/sound/resources/audio-volume-040-muted.svg b/plugins/sound/resources/audio-volume-040-muted.svg deleted file mode 100644 index 315d7b97c..000000000 --- a/plugins/sound/resources/audio-volume-040-muted.svg +++ /dev/null @@ -1,237 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/plugins/sound/resources/audio-volume-040.svg b/plugins/sound/resources/audio-volume-040.svg deleted file mode 100644 index c9f08ac19..000000000 --- a/plugins/sound/resources/audio-volume-040.svg +++ /dev/null @@ -1,232 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/plugins/sound/resources/audio-volume-050-muted.svg b/plugins/sound/resources/audio-volume-050-muted.svg deleted file mode 100644 index 77ce8a7f0..000000000 --- a/plugins/sound/resources/audio-volume-050-muted.svg +++ /dev/null @@ -1,237 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/plugins/sound/resources/audio-volume-050.svg b/plugins/sound/resources/audio-volume-050.svg deleted file mode 100644 index 9ed242e98..000000000 --- a/plugins/sound/resources/audio-volume-050.svg +++ /dev/null @@ -1,232 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/plugins/sound/resources/audio-volume-060-muted.svg b/plugins/sound/resources/audio-volume-060-muted.svg deleted file mode 100644 index 5f916a2f6..000000000 --- a/plugins/sound/resources/audio-volume-060-muted.svg +++ /dev/null @@ -1,237 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/plugins/sound/resources/audio-volume-060.svg b/plugins/sound/resources/audio-volume-060.svg deleted file mode 100644 index e58e1cbff..000000000 --- a/plugins/sound/resources/audio-volume-060.svg +++ /dev/null @@ -1,232 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/plugins/sound/resources/audio-volume-070-muted.svg b/plugins/sound/resources/audio-volume-070-muted.svg deleted file mode 100644 index 88fca2805..000000000 --- a/plugins/sound/resources/audio-volume-070-muted.svg +++ /dev/null @@ -1,238 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/plugins/sound/resources/audio-volume-070.svg b/plugins/sound/resources/audio-volume-070.svg deleted file mode 100644 index d8a12995e..000000000 --- a/plugins/sound/resources/audio-volume-070.svg +++ /dev/null @@ -1,233 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/plugins/sound/resources/audio-volume-080-muted.svg b/plugins/sound/resources/audio-volume-080-muted.svg deleted file mode 100644 index 331da1405..000000000 --- a/plugins/sound/resources/audio-volume-080-muted.svg +++ /dev/null @@ -1,239 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/plugins/sound/resources/audio-volume-080.svg b/plugins/sound/resources/audio-volume-080.svg deleted file mode 100644 index b001da319..000000000 --- a/plugins/sound/resources/audio-volume-080.svg +++ /dev/null @@ -1,233 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/plugins/sound/resources/audio-volume-090-muted.svg b/plugins/sound/resources/audio-volume-090-muted.svg deleted file mode 100644 index 450c29257..000000000 --- a/plugins/sound/resources/audio-volume-090-muted.svg +++ /dev/null @@ -1,238 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/plugins/sound/resources/audio-volume-090.svg b/plugins/sound/resources/audio-volume-090.svg deleted file mode 100644 index 697d88d8b..000000000 --- a/plugins/sound/resources/audio-volume-090.svg +++ /dev/null @@ -1,231 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/plugins/sound/resources/audio-volume-100-muted.svg b/plugins/sound/resources/audio-volume-100-muted.svg deleted file mode 100644 index 23bcfe62c..000000000 --- a/plugins/sound/resources/audio-volume-100-muted.svg +++ /dev/null @@ -1,227 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/plugins/sound/resources/audio-volume-100.svg b/plugins/sound/resources/audio-volume-100.svg deleted file mode 100644 index ebfbadc38..000000000 --- a/plugins/sound/resources/audio-volume-100.svg +++ /dev/null @@ -1,220 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/plugins/sound/resources/audio-volume-high-symbolic-dark.svg b/plugins/sound/resources/audio-volume-high-symbolic-dark.svg deleted file mode 100644 index 4d4091a65..000000000 --- a/plugins/sound/resources/audio-volume-high-symbolic-dark.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/plugins/sound/resources/audio-volume-high-symbolic.svg b/plugins/sound/resources/audio-volume-high-symbolic.svg deleted file mode 100644 index 81e42bb50..000000000 --- a/plugins/sound/resources/audio-volume-high-symbolic.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/plugins/sound/resources/audio-volume-low-symbolic-dark.svg b/plugins/sound/resources/audio-volume-low-symbolic-dark.svg deleted file mode 100644 index 2a1451bd7..000000000 --- a/plugins/sound/resources/audio-volume-low-symbolic-dark.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/plugins/sound/resources/audio-volume-low-symbolic.svg b/plugins/sound/resources/audio-volume-low-symbolic.svg deleted file mode 100644 index 67caf09c3..000000000 --- a/plugins/sound/resources/audio-volume-low-symbolic.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/plugins/sound/resources/audio-volume-medium-symbolic-dark.svg b/plugins/sound/resources/audio-volume-medium-symbolic-dark.svg deleted file mode 100644 index aa30f960f..000000000 --- a/plugins/sound/resources/audio-volume-medium-symbolic-dark.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/plugins/sound/resources/audio-volume-medium-symbolic.svg b/plugins/sound/resources/audio-volume-medium-symbolic.svg deleted file mode 100644 index 1558aff33..000000000 --- a/plugins/sound/resources/audio-volume-medium-symbolic.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/plugins/sound/resources/audio-volume-muted-symbolic-dark.svg b/plugins/sound/resources/audio-volume-muted-symbolic-dark.svg deleted file mode 100644 index 1b62397ef..000000000 --- a/plugins/sound/resources/audio-volume-muted-symbolic-dark.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/plugins/sound/resources/audio-volume-muted-symbolic.svg b/plugins/sound/resources/audio-volume-muted-symbolic.svg deleted file mode 100644 index be87cfead..000000000 --- a/plugins/sound/resources/audio-volume-muted-symbolic.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/plugins/sound/resources/broadcast.svg b/plugins/sound/resources/broadcast.svg deleted file mode 100644 index f45b1ae57..000000000 --- a/plugins/sound/resources/broadcast.svg +++ /dev/null @@ -1,15 +0,0 @@ - - - ICON / MenuItem / Broadcast - - - - - - - - - - - - \ No newline at end of file diff --git a/plugins/sound/resources/slider_bg.png b/plugins/sound/resources/slider_bg.png deleted file mode 100644 index 7f0c61205..000000000 Binary files a/plugins/sound/resources/slider_bg.png and /dev/null differ diff --git a/plugins/sound/resources/slider_handle.svg b/plugins/sound/resources/slider_handle.svg deleted file mode 100644 index 8bdd442e2..000000000 --- a/plugins/sound/resources/slider_handle.svg +++ /dev/null @@ -1,37 +0,0 @@ - - - - slider_handle - Created with Sketch. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/plugins/sound/resources/sound.qrc b/plugins/sound/resources/sound.qrc deleted file mode 100644 index a081de4e3..000000000 --- a/plugins/sound/resources/sound.qrc +++ /dev/null @@ -1,38 +0,0 @@ - - - - - audio-volume-000-muted.svg - audio-volume-000.svg - audio-volume-010-muted.svg - audio-volume-010.svg - audio-volume-020-muted.svg - audio-volume-020.svg - audio-volume-030-muted.svg - audio-volume-030.svg - audio-volume-040-muted.svg - audio-volume-040.svg - audio-volume-050-muted.svg - audio-volume-050.svg - audio-volume-060-muted.svg - audio-volume-060.svg - audio-volume-070-muted.svg - audio-volume-070.svg - audio-volume-080-muted.svg - audio-volume-080.svg - audio-volume-090-muted.svg - audio-volume-090.svg - audio-volume-100-muted.svg - audio-volume-100.svg - audio-volume-high-symbolic.svg - audio-volume-low-symbolic.svg - audio-volume-medium-symbolic.svg - audio-volume-muted-symbolic.svg - slider_bg.png - slider_handle.svg - audio-volume-muted-symbolic-dark.svg - audio-volume-low-symbolic-dark.svg - audio-volume-medium-symbolic-dark.svg - audio-volume-high-symbolic-dark.svg - - diff --git a/plugins/sound/soundaccessible.h b/plugins/sound/soundaccessible.h index ffaa163ff..2393cc066 100644 --- a/plugins/sound/soundaccessible.h +++ b/plugins/sound/soundaccessible.h @@ -6,22 +6,10 @@ #define SOUNDACCESSIBLE_H #include "accessibledefine.h" -#include "sounditem.h" -#include "soundapplet.h" -#include "./componments/volumeslider.h" - -SET_BUTTON_ACCESSIBLE(SoundItem, "plugin-sounditem") -SET_FORM_ACCESSIBLE(SoundApplet, "soundapplet") -SET_SLIDER_ACCESSIBLE(VolumeSlider, "volumeslider") - QAccessibleInterface *soundAccessibleFactory(const QString &classname, QObject *object) { QAccessibleInterface *interface = nullptr; - USE_ACCESSIBLE(classname, SoundItem) - ELSE_USE_ACCESSIBLE(classname, SoundApplet) - ELSE_USE_ACCESSIBLE(classname, VolumeSlider); - return interface; } diff --git a/plugins/sound/soundapplet.cpp b/plugins/sound/soundapplet.cpp deleted file mode 100644 index 9f1bdb16f..000000000 --- a/plugins/sound/soundapplet.cpp +++ /dev/null @@ -1,630 +0,0 @@ -// Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd. -// SPDX-FileCopyrightText: 2018 - 2023 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: LGPL-3.0-or-later - -#include "soundapplet.h" -#include "sounddeviceport.h" -#include "util/horizontalseperator.h" -#include "../widgets/tipswidget.h" -#include "../frame/util/imageutil.h" -#include "util/utils.h" - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#define SEPARATOR_HEIGHT 2 -#define WIDTH 260 -#define MAX_HEIGHT 300 -#define ICON_SIZE 24 -#define ITEM_HEIGHT 24 -#define ITEM_SPACING 5 -#define DEVICE_SPACING 10 -#define SLIDER_HIGHT 70 -#define TITLE_HEIGHT 46 -#define GSETTING_SOUND_OUTPUT_SLIDER "soundOutputSlider" - -DWIDGET_USE_NAMESPACE -DGUI_USE_NAMESPACE -using namespace Dock; - -SoundApplet::SoundApplet(QWidget *parent) - : QScrollArea(parent) - , m_centralWidget(new QWidget(this)) - , m_volumeIconMin(new QLabel(this)) - , m_volumeIconMax(new QLabel(this)) - , m_volumeSlider(new VolumeSlider(this)) - , m_soundShow(new QLabel(this)) - , m_deviceLabel(new QLabel(this)) - , m_seperator(new HorizontalSeperator(this)) - , m_secondSeperator(new HorizontalSeperator(this)) - , m_audioInter(new DBusAudio("org.deepin.dde.Audio1", "/org/deepin/dde/Audio1", QDBusConnection::sessionBus(), this)) - , m_defSinkInter(nullptr) - , m_listView(new DListView(this)) - , m_model(new QStandardItemModel(m_listView)) - , m_deviceInfo("") - , m_lastPort(nullptr) - , m_gsettings(Utils::ModuleSettingsPtr("sound", QByteArray(), this)) -{ - initUi(); - - m_volumeIconMin->installEventFilter(this); -} - -void SoundApplet::initUi() -{ - m_listView->setFrameShape(QFrame::NoFrame); - m_listView->setEditTriggers(DListView::NoEditTriggers); - m_listView->setSelectionMode(QAbstractItemView::NoSelection); - m_listView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - m_listView->setBackgroundType(DStyledItemDelegate::NoBackground); - m_listView->setItemRadius(0); - m_listView->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents); - m_listView->setFixedHeight(0); - m_listView->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); - m_listView->setModel(m_model); - - m_centralWidget->setAccessibleName("volumn-centralwidget"); - m_volumeIconMin->setAccessibleName("volume-button"); - m_volumeIconMax->setAccessibleName("volume-iconmax"); - m_volumeSlider->setAccessibleName("volume-slider"); - m_soundShow->setAccessibleName("volume-soundtips"); - horizontalScrollBar()->setAccessibleName("volume-horizontalscrollbar"); - verticalScrollBar()->setAccessibleName("volume-verticalscrollbar"); - - m_volumeIconMin->setFixedSize(ICON_SIZE, ICON_SIZE); - m_volumeIconMax->setFixedSize(ICON_SIZE, ICON_SIZE); - - m_soundShow->setText(QString("%1%").arg(0)); - m_soundShow->setFixedHeight(TITLE_HEIGHT); - m_soundShow->setForegroundRole(QPalette::BrightText); - DFontSizeManager::instance()->bind(m_soundShow, DFontSizeManager::T8, QFont::Medium); - - m_deviceLabel->setText(tr("Device")); - m_deviceLabel->setFixedHeight(TITLE_HEIGHT); - m_deviceLabel->setForegroundRole(QPalette::BrightText); - DFontSizeManager::instance()->bind(m_deviceLabel, DFontSizeManager::T4, QFont::Medium); - - m_volumeSlider->setFixedHeight(SLIDER_HIGHT); - m_volumeSlider->setMinimum(0); - m_volumeSlider->setMaximum(m_audioInter->maxUIVolume() * 100.0f); - - // 标题部分 - QHBoxLayout *deviceLayout = new QHBoxLayout; - deviceLayout->setSpacing(0); - deviceLayout->setMargin(0); - deviceLayout->setContentsMargins(20, 0, 10, 0); - deviceLayout->addWidget(m_deviceLabel, 0, Qt::AlignLeft); - deviceLayout->addWidget(m_soundShow, 0, Qt::AlignRight); - - BackgroundWidget *deviceWidget = new BackgroundWidget(this); - deviceWidget->setLayout(deviceLayout); - - // 音量滑动条 - QHBoxLayout *volumeCtrlLayout = new QHBoxLayout; - volumeCtrlLayout->setSpacing(0); - volumeCtrlLayout->setMargin(0); - volumeCtrlLayout->setContentsMargins(12, 0, 12, 0); - volumeCtrlLayout->addWidget(m_volumeIconMin); - volumeCtrlLayout->addWidget(m_volumeSlider); - volumeCtrlLayout->addWidget(m_volumeIconMax); - - BackgroundWidget *volumnWidget = new BackgroundWidget(this); - volumnWidget->setLayout(volumeCtrlLayout); - - m_centralLayout = new QVBoxLayout(this); - m_centralLayout->setContentsMargins(0, 0, 0, 0); - m_centralLayout->setMargin(0); - m_centralLayout->setSpacing(0); - m_centralLayout->addWidget(deviceWidget); - m_centralLayout->addWidget(m_seperator); - m_centralLayout->addWidget(volumnWidget); - // 需要判断是否有声音端口 - m_centralLayout->addWidget(m_secondSeperator); - - m_centralLayout->addWidget(m_listView); - m_centralWidget->setLayout(m_centralLayout); - m_centralWidget->setFixedWidth(WIDTH); - m_centralWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); - - setFixedWidth(WIDTH); - setWidget(m_centralWidget); - setContentsMargins(0, 0, 0, 0); - setFrameShape(QFrame::NoFrame); - setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - m_centralWidget->setAutoFillBackground(false); - viewport()->setAutoFillBackground(false); - m_listView->setItemDelegate(new DStyledItemDelegate(m_listView)); - - m_secondSeperator->setVisible(m_model->rowCount() > 1); - - updateVolumeSliderStatus(Utils::SettingValue("com.deepin.dde.dock.module.sound", QByteArray(), "Enabled").toString()); - connect(m_gsettings, &QGSettings::changed, [ = ] (const QString &key) { - if (key == GSETTING_SOUND_OUTPUT_SLIDER) { - updateVolumeSliderStatus(m_gsettings->get(GSETTING_SOUND_OUTPUT_SLIDER).toString()); - } - }); - connect(qApp, &QGuiApplication::fontChanged, this, &SoundApplet::updateListHeight); - connect(m_volumeSlider, &VolumeSlider::valueChanged, this, &SoundApplet::volumeSliderValueChanged); - connect(m_audioInter, &DBusAudio::DefaultSinkChanged, this, &SoundApplet::onDefaultSinkChanged); - connect(m_audioInter, &DBusAudio::IncreaseVolumeChanged, this, &SoundApplet::increaseVolumeChanged); - connect(m_audioInter, &DBusAudio::PortEnabledChanged, [this](uint cardId, QString portId) { - portEnableChange(cardId, portId); - });; - connect(m_listView, &DListView::clicked, this, [this](const QModelIndex & idx) { - const SoundDevicePort *port = m_listView->model()->data(idx, Qt::WhatsThisPropertyRole).value(); - if (port) { - m_audioInter->SetPort(port->cardId(), port->id(), int(port->direction())); - //手动勾选时启用设备 - m_audioInter->SetPortEnabled(port->cardId(), port->id(), true); - } - - }); - connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, &SoundApplet::refreshIcon); - connect(qApp, &DApplication::iconThemeChanged, this, &SoundApplet::refreshIcon); - QDBusConnection::sessionBus().connect("org.deepin.dde.Audio1", "/org/deepin/dde/Audio1", "org.freedesktop.DBus.Properties" - ,"PropertiesChanged", "sa{sv}as", this, SLOT(haldleDbusSignal(QDBusMessage))); - - QMetaObject::invokeMethod(this, "onDefaultSinkChanged", Qt::QueuedConnection); - - refreshIcon(); - - updateCradsInfo(); -} - -int SoundApplet::volumeValue() const -{ - return m_volumeSlider->value(); -} - -int SoundApplet::maxVolumeValue() const -{ - return m_volumeSlider->maximum(); -} - -VolumeSlider *SoundApplet::mainSlider() -{ - return m_volumeSlider; -} - -void SoundApplet::onDefaultSinkChanged() -{ - //防止手动切换设备,与后端交互时,获取到多个信号,设备切换多次,造成混乱 - QThread::msleep(200); - - if (m_defSinkInter) { - delete m_defSinkInter; - m_defSinkInter = nullptr; - } - - const QDBusObjectPath defSinkPath = m_audioInter->defaultSink(); - m_defSinkInter = new DBusSink("org.deepin.dde.Audio1", defSinkPath.path(), QDBusConnection::sessionBus(), this); - - connect(m_defSinkInter, &DBusSink::VolumeChanged, this, &SoundApplet::onVolumeChanged); - connect(m_defSinkInter, &DBusSink::MuteChanged, this, [ = ] { - onVolumeChanged(m_defSinkInter->volume() * 100); - }); - - QString portId = m_defSinkInter->activePort().name; - uint cardId = m_defSinkInter->card(); - //最后一个设备会被移除,但是当在控制中心选中此设备后需要添加,并勾选 - if (!m_lastPort.isNull() && m_lastPort->cardId() == cardId && m_lastPort->id() == portId) { - startAddPort(m_lastPort); - } - activePort(portId,cardId); - - //无声卡状态下,会有伪sink设备,显示音量为0 - onVolumeChanged(findPort(portId, cardId) != nullptr ? m_defSinkInter->volume() * 100 : 0); - emit defaultSinkChanged(m_defSinkInter); -} - -void SoundApplet::onVolumeChanged(double volume) -{ - m_volumeSlider->setValue(std::min(150, qRound(volume * 100.0))); - m_soundShow->setText(QString::number(volume * 100) + '%'); - emit volumeChanged(m_volumeSlider->value()); - refreshIcon(); -} - -void SoundApplet::volumeSliderValueChanged() -{ - m_defSinkInter->SetVolume(m_volumeSlider->value() / 100.0f, true); - if (m_defSinkInter->mute()) - m_defSinkInter->SetMuteQueued(false); -} - -void SoundApplet::cardsChanged(const QString &cards) -{ - QMap tmpCardIds; - - QJsonDocument doc = QJsonDocument::fromJson(cards.toUtf8()); - QJsonArray jCards = doc.array(); - for (QJsonValue cV : jCards) { - QJsonObject jCard = cV.toObject(); - const uint cardId = jCard["Id"].toInt(); - const QString cardName = jCard["Name"].toString(); - QJsonArray jPorts = jCard["Ports"].toArray(); - - QStringList tmpPorts; - - for (QJsonValue pV : jPorts) { - QJsonObject jPort = pV.toObject(); - const double portAvai = jPort["Available"].toDouble(); - if (portAvai == 2 || portAvai == 0 ) { // 0 Unknow 1 Not available 2 Available - const QString portId = jPort["Name"].toString(); - const QString portName = jPort["Description"].toString(); - - SoundDevicePort *port = findPort(portId, cardId); - const bool include = port != nullptr; - if (!include) { port = new SoundDevicePort(m_model); } - - port->setId(portId); - port->setName(portName); - port->setDirection(SoundDevicePort::Direction(jPort["Direction"].toDouble())); - port->setCardId(cardId); - port->setCardName(cardName); - - if (!include) { - startAddPort(port); - } - - tmpPorts << portId; - } - } - tmpCardIds.insert(cardId, tmpPorts); - } - - onDefaultSinkChanged();//重新获取切换的设备信息 - enableDevice(existActiveOutputDevice()); - - for (SoundDevicePort *port : m_ports) { - //只要有一个设备在控制中心被禁用后,在任务栏声音设备列表中该设备会被移除, - if (!m_audioInter->IsPortEnabled(port->cardId(), port->id())) { - removeDisabledDevice(port->id(), port->cardId()); - } - //判断端口是否在最新的设备列表中 - if (tmpCardIds.contains(port->cardId())) { - if (!tmpCardIds[port->cardId()].contains(port->id())) { - startRemovePort(port->id(), port->cardId()); - } - } - else { - startRemovePort(port->id(), port->cardId()); - } - } - //当只有一个设备剩余时,该设备也需要移除 - removeLastDevice(); - updateListHeight(); -} - -void SoundApplet::increaseVolumeChanged() -{ - // 触发VolumeSlider::valueChanged - m_volumeSlider->setMaximum(m_audioInter->maxUIVolume() * 100.0f); - - // onDefaultSinkChanged()比increaseVolumeChanged()先执行,设置完最大值后需要重新设置当前值 - if (m_defSinkInter) { - // 规避因开启声音增强,声音值超过100后,关闭声音增强后读取到数据为旧数据的问题 - if (m_audioInter->increaseVolume()) - m_volumeSlider->setValue(std::min(150, qRound(m_defSinkInter->volume() * 100.0))); - } -} - -void SoundApplet::refreshIcon() -{ - if (!m_defSinkInter) - return; - - const bool mute = existActiveOutputDevice() ? m_defSinkInter->mute() : true; - - QString volumeString; - - if (mute) { - volumeString = "muted"; - } else { - volumeString = "off"; - } - - QString iconLeft = QString("audio-volume-%1-symbolic").arg(volumeString); - QString iconRight = QString("audio-volume-high-symbolic"); - - if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType) { - iconLeft.append("-dark"); - iconRight.append("-dark"); - } - - const auto ratio = devicePixelRatioF(); - QPixmap ret = ImageUtil::loadSvg(iconRight, ":/", ICON_SIZE, ratio); - m_volumeIconMax->setPixmap(ret); - - ret = ImageUtil::loadSvg(iconLeft, ":/", ICON_SIZE, ratio); - m_volumeIconMin->setPixmap(ret); -} - -/** - * @brief SoundApplet::startAddPort 添加端口前判断 - * @param port 端口 - */ -void SoundApplet::startAddPort(SoundDevicePort *port) -{ - if (!containsPort(port) && port->direction() == SoundDevicePort::Out) { - m_ports.append(port); - addPort(port); - } -} - -/** - * @brief SoundApplet::startRemovePort 移除端口前判断 - * @param portId 端口 - * @param cardId 声卡 - */ -void SoundApplet::startRemovePort(const QString &portId, const uint &cardId) -{ - SoundDevicePort *port = findPort(portId, cardId); - if (port) { - m_ports.removeOne(port); - port->deleteLater(); - removePort(portId, cardId); - } -} - -bool SoundApplet::containsPort(const SoundDevicePort *port) -{ - return findPort(port->id(), port->cardId()) != nullptr; -} - -SoundDevicePort *SoundApplet::findPort(const QString &portId, const uint &cardId) const -{ - auto it = std::find_if(m_ports.begin(), m_ports.end(), [ = ] (SoundDevicePort *p) { - return (p->id() == portId && p->cardId() == cardId); - }); - - if (it != m_ports.end()) { - return *it; - } - - return nullptr; -} - -void SoundApplet::addPort(const SoundDevicePort *port) -{ - DStandardItem *pi = new DStandardItem; - QString deviceName = port->name() + "(" + port->cardName() + ")"; - pi->setText(deviceName); - pi->setTextColorRole(QPalette::BrightText); - pi->setData(QVariant::fromValue(port), Qt::WhatsThisPropertyRole); - - connect(port, &SoundDevicePort::nameChanged, this, [ = ](const QString &str) { - QString devName = str + "(" + port->cardName() + ")"; - pi->setText(devName); - }); - connect(port, &SoundDevicePort::cardNameChanged, this, [ = ](const QString &str) { - QString devName = port->name() + "(" + str + ")"; - pi->setText(devName); - }); - connect(port, &SoundDevicePort::isActiveChanged, this, [ = ](bool isActive) { - pi->setCheckState(isActive ? Qt::CheckState::Checked : Qt::CheckState::Unchecked); - }); - - if (port->isActive()) { - pi->setCheckState(Qt::CheckState::Checked); - } - - m_model->appendRow(pi); - m_model->sort(0); - m_secondSeperator->setVisible(m_model->rowCount() > 1); - updateListHeight(); -} - -void SoundApplet::removePort(const QString &portId, const uint &cardId) -{ - auto rmFunc = [ = ](QStandardItemModel * model) { - for (int i = 0; i < model->rowCount();) { - auto item = model->item(i); - auto port = item->data(Qt::WhatsThisPropertyRole).value(); - if (port->id() == portId && cardId == port->cardId()) { - model->removeRow(i); - break; - } else { - ++i; - } - } - }; - - rmFunc(m_model); - m_secondSeperator->setVisible(m_model->rowCount() > 1); - updateListHeight(); -} - -/** - * @brief SoundApplet::activePort 激活某一指定端口 - * @param portId 端口 - * @param cardId 声卡 - */ -void SoundApplet::activePort(const QString &portId, const uint &cardId) -{ - for (SoundDevicePort *it : m_ports) { - if (it->id() == portId && it->cardId() == cardId) { - it->setIsActive(true); - enableDevice(true); - } - else { - it->setIsActive(false); - } - } -} - -void SoundApplet::updateCradsInfo() -{ - QString info = m_audioInter->property("CardsWithoutUnavailable").toString(); - if(m_deviceInfo != info){ - cardsChanged(info); - m_deviceInfo = info; - } -} - -void SoundApplet::enableDevice(bool flag) -{ - QString status = m_gsettings ? m_gsettings->get(GSETTING_SOUND_OUTPUT_SLIDER).toString() : "Enabled"; - if ("Disabled" == status ) { - m_volumeSlider->setEnabled(false); - } else if ("Enabled" == status) { - m_volumeSlider->setEnabled(flag); - } - m_volumeIconMin->setEnabled(flag); - m_soundShow->setEnabled(flag); - m_volumeIconMax->setEnabled(flag); - m_deviceLabel->setEnabled(flag); -} - -void SoundApplet::disableAllDevice() -{ - for (SoundDevicePort *port : m_ports) { - port->setIsActive(false); - } -} - -/** - * @brief SoundApplet::removeLastDevice - * 移除最后一个设备 - */ -void SoundApplet::removeLastDevice() -{ - if (m_ports.count() == 1 && m_ports.at(0)) { - m_lastPort = new SoundDevicePort(m_model); - m_lastPort->setId(m_ports.at(0)->id()); - m_lastPort->setName(m_ports.at(0)->name()); - m_lastPort->setDirection(m_ports.at(0)->direction()); - m_lastPort->setCardId(m_ports.at(0)->cardId()); - m_lastPort->setCardName(m_ports.at(0)->cardName()); - startRemovePort(m_ports.at(0)->id(), m_ports.at(0)->cardId()); - qDebug() << "remove last output device"; - } -} - -/** - * @brief SoundApplet::removeDisabledDevice 移除禁用设备 - * @param portId - * @param cardId - */ -void SoundApplet::removeDisabledDevice(QString portId, unsigned int cardId) -{ - startRemovePort(portId, cardId); - if (m_defSinkInter->activePort().name == portId && m_defSinkInter->card() == cardId) { - enableDevice(false); - disableAllDevice(); - } - qDebug() << "remove disabled output device"; -} - -void SoundApplet::updateVolumeSliderStatus(const QString &status) -{ - bool flag = true; - if ("Enabled" == status) { - flag = true; - } else if ("Disabled" == status) { - flag = false; - } - m_volumeSlider->setEnabled(flag); - m_volumeIconMin->setEnabled(flag); - m_volumeIconMax->setEnabled(flag); - - flag = "Hiden" != status; - m_volumeSlider->setVisible(flag); - m_volumeIconMin->setVisible(flag); - m_volumeIconMax->setVisible(flag); -} - -/** 判断是否存在未禁用的声音输出设备 - * @brief SoundApplet::existActiveOutputDevice - * @return 存在返回true,否则返回false - */ -bool SoundApplet::existActiveOutputDevice() -{ - QString info = m_audioInter->property("CardsWithoutUnavailable").toString(); - - QJsonDocument doc = QJsonDocument::fromJson(info.toUtf8()); - QJsonArray jCards = doc.array(); - for (QJsonValue cV : jCards) { - QJsonObject jCard = cV.toObject(); - QJsonArray jPorts = jCard["Ports"].toArray(); - - for (QJsonValue pV : jPorts) { - QJsonObject jPort = pV.toObject(); - if (jPort["Direction"].toInt() == 1 && jPort["Enabled"].toBool()) - return true; - } - } - - return false; -} - -bool SoundApplet::eventFilter(QObject *watcher, QEvent *event) -{ - // 当控制中心禁用所有输出设备时,静音按钮置灰,其他情况正常. - if (watcher == m_volumeIconMin && event->type() == QEvent::MouseButtonRelease) { - if (!existActiveOutputDevice()) { - m_volumeIconMin->setEnabled(false); - } else { - m_volumeIconMin->setEnabled(true); - m_defSinkInter->SetMuteQueued(!m_defSinkInter->mute()); - } - } - return false; -} - -void SoundApplet::haldleDbusSignal(const QDBusMessage &msg) -{ - Q_UNUSED(msg) - - updateCradsInfo(); -} - -void SoundApplet::updateListHeight() -{ - //设备数多于10个时显示滚动条,固定高度 - int count = m_model->rowCount() == 1 ? 0 : m_model->rowCount(); - - if (m_model->rowCount() > 10) { - count = 10; - m_listView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); - } else { - m_listView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - } - - int visualHeight = 0; - for (int i = 0; i < count; i++) - visualHeight += m_listView->visualRect(m_model->index(i, 0)).height(); - - int listMargin = m_listView->contentsMargins().top() + m_listView->contentsMargins().bottom(); - //显示声音设备列表高度 = 设备的高度 + 间隔 + 边距 - int viewHeight = visualHeight + m_listView->spacing() * (count - 1) + listMargin; - // 设备信息高度 = 设备标签 + 分隔线 + 滚动条 + 间隔 - int labelHeight = m_deviceLabel->height() > m_soundShow->height() ? m_deviceLabel->height() : m_soundShow->height(); - int infoHeight = labelHeight + m_seperator->height() * 2 + m_volumeSlider->height(); - int margain = m_centralLayout->contentsMargins().top() + m_centralLayout->contentsMargins().bottom(); - //整个界面高度 = 显示声音设备列表高度 + 设备信息高度 + 边距 - int totalHeight = viewHeight + infoHeight + margain; - //加上分割线占用的高度,否则显示界面高度不够显示,会造成音频列表item最后一项比其它项的高度小 - m_listView->setFixedHeight(viewHeight); - setFixedHeight(totalHeight); - m_centralWidget->setFixedHeight(totalHeight); -} - -void SoundApplet::portEnableChange(unsigned int cardId, QString portId) -{ - Q_UNUSED(cardId) - Q_UNUSED(portId) - m_deviceInfo = ""; - updateCradsInfo(); -} diff --git a/plugins/sound/soundapplet.h b/plugins/sound/soundapplet.h deleted file mode 100644 index 0db10616b..000000000 --- a/plugins/sound/soundapplet.h +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd. -// SPDX-FileCopyrightText: 2018 - 2023 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: LGPL-3.0-or-later - -#ifndef SOUNDAPPLET_H -#define SOUNDAPPLET_H - -#include "componments/volumeslider.h" - -#include "org_deepin_dde_audio1.h" -#include "org_deepin_dde_audio1_sink.h" - -#include -#include -#include - -#include -#include -#include -#include - -DWIDGET_USE_NAMESPACE - -using DBusAudio = org::deepin::dde::Audio1; -using DBusSink = org::deepin::dde::audio1::Sink; -using DTK_NAMESPACE::Gui::DGuiApplicationHelper; - -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 (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::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 m_ports; - QString m_deviceInfo; - QPointer m_lastPort;//最后一个因为只有一个设备而被直接移除的设备 - const QGSettings *m_gsettings; -}; - -#endif // SOUNDAPPLET_H diff --git a/plugins/sound/sounddeviceswidget.cpp b/plugins/sound/sounddeviceswidget.cpp index 13b47781b..ce321972b 100644 --- a/plugins/sound/sounddeviceswidget.cpp +++ b/plugins/sound/sounddeviceswidget.cpp @@ -4,16 +4,17 @@ // SPDX-License-Identifier: LGPL-3.0-or-later #include "sounddeviceswidget.h" +#include "constants.h" #include "imageutil.h" #include "slidercontainer.h" #include "sounddeviceport.h" +#include "../widgets/tipswidget.h" #include #include #include #include #include -#include #include #include @@ -22,13 +23,16 @@ #include #include #include +#include +#include +#include DWIDGET_USE_NAMESPACE #define HEADERHEIGHT 30 #define ITEMSPACE 16 -#define ROWSPACE 10 -#define DESCRIPTIONHEIGHT 15 +#define ROWSPACE 5 +#define DESCRIPTIONHEIGHT 20 #define SLIDERHEIGHT 36 #define AUDIOPORT 0 @@ -40,10 +44,13 @@ enum ItemRole { SortRole, }; +using namespace Dock; + SoundDevicesWidget::SoundDevicesWidget(QWidget *parent) : QWidget(parent) - , m_sliderParent(new QWidget(this)) - , m_sliderContainer(new SliderContainer(m_sliderParent)) + , m_tipsLabel(new TipsWidget(this)) + , m_titleLabel(new QLabel(tr("Sound"), this)) + , m_sliderContainer(new SliderContainer(this)) , m_descriptionLabel(new QLabel(tr("Output Device"), this)) , m_deviceList(new DListView(this)) , m_soundInter(new DBusAudio("org.deepin.dde.Audio1", "/org/deepin/dde/Audio1", QDBusConnection::sessionBus(), this)) @@ -66,14 +73,14 @@ SoundDevicesWidget::~SoundDevicesWidget() bool SoundDevicesWidget::eventFilter(QObject *watcher, QEvent *event) { - if ((watcher == m_sliderParent) && (event->type() == QEvent::Paint)) { - QPainter painter(m_sliderParent); + if ((watcher == m_sliderContainer) && (event->type() == QEvent::Paint)) { + QPainter painter(m_sliderContainer); painter.setRenderHint(QPainter::Antialiasing); // 抗锯齿 painter.setPen(Qt::NoPen); - DPalette dpa = DPaletteHelper::instance()->palette(m_sliderParent); - painter.setBrush(dpa.brush(DPalette::ColorRole::Midlight)); - painter.drawRoundedRect(m_sliderParent->rect(), 10, 10); + QStandardItem *item = m_model->item(m_model->rowCount() - 1); + painter.setBrush(item->background()); + painter.drawRoundedRect(m_sliderContainer->rect(), 10, 10); } return QWidget::eventFilter(watcher, event); @@ -81,31 +88,33 @@ bool SoundDevicesWidget::eventFilter(QObject *watcher, QEvent *event) void SoundDevicesWidget::initUi() { + m_tipsLabel->setAccessibleName("soundtips"); + m_tipsLabel->setVisible(false); + QVBoxLayout *layout = new QVBoxLayout(this); layout->setContentsMargins(10, 0, 10, 0); - layout->setSpacing(6); - m_sliderParent->setFixedHeight(SLIDERHEIGHT); + m_titleLabel->setFixedHeight(HEADERHEIGHT); + m_titleLabel->setAlignment(Qt::AlignCenter); - QHBoxLayout *sliderLayout = new QHBoxLayout(m_sliderParent); - sliderLayout->setContentsMargins(11, 0, 11, 0); - sliderLayout->setSpacing(0); - - QPixmap leftPixmap = ImageUtil::loadSvg(leftIcon(), QSize(24, 24)); + QPixmap leftPixmap = QIcon::fromTheme(QString("audio-volume-%1-symbolic").arg(m_sinkInter->mute() ? "muted" : "off")).pixmap(18, 18); m_sliderContainer->setIcon(SliderContainer::IconPosition::LeftIcon, leftPixmap, QSize(), 5); - QPixmap rightPixmap = ImageUtil::loadSvg(rightIcon(), QSize(24, 24)); + QPixmap rightPixmap = QIcon::fromTheme("audio-volume-high-symbolic").pixmap(18, 18); m_sliderContainer->setIcon(SliderContainer::IconPosition::RightIcon, rightPixmap, QSize(), 7); SliderProxyStyle *proxy = new SliderProxyStyle(SliderProxyStyle::Normal); m_sliderContainer->setSliderProxyStyle(proxy); m_sliderContainer->setRange(0, std::round(m_soundInter->maxUIVolume() * 100.00)); m_sliderContainer->setPageStep(2); - sliderLayout->addWidget(m_sliderContainer); - QHBoxLayout *topLayout = new QHBoxLayout(this); - topLayout->setContentsMargins(0, 0, 0, 0); + QVBoxLayout *topLayout = new QVBoxLayout(this); + + topLayout->setContentsMargins(7, 0, 7, 0); topLayout->setSpacing(0); - topLayout->addWidget(m_sliderParent); + + topLayout->addWidget(m_titleLabel); + topLayout->addWidget(m_sliderContainer); + m_descriptionLabel->setMargin(5); layout->addLayout(topLayout); layout->addWidget(m_descriptionLabel); @@ -118,21 +127,22 @@ void SoundDevicesWidget::initUi() m_deviceList->horizontalScrollBar()->setVisible(false); m_deviceList->setBackgroundType(DStyledItemDelegate::BackgroundType::RoundedBackground); m_deviceList->setOrientation(QListView::Flow::TopToBottom, false); - layout->addWidget(m_deviceList); m_deviceList->setSpacing(ROWSPACE); + layout->addWidget(m_deviceList); + m_model->setSortRole(SortRole); - m_descriptionLabel->setFixedHeight(DESCRIPTIONHEIGHT); // 增加音量设置 DStandardItem *settingItem = new DStandardItem; settingItem->setText(tr("Sound settings")); - settingItem->setFlags(Qt::NoItemFlags); + settingItem->setTextColorRole(QPalette::BrightText); + settingItem->setFlags(settingItem->flags() & ~Qt::ItemIsEditable & ~Qt::ItemIsSelectable); settingItem->setCheckable(Qt::Unchecked); settingItem->setData(AUDIOSETTING, ItemTypeRole); m_model->appendRow(settingItem); - m_sliderParent->installEventFilter(this); + m_sliderContainer->installEventFilter(this); } void SoundDevicesWidget::onAudioDevicesChanged() @@ -196,17 +206,19 @@ void SoundDevicesWidget::initConnection() connect(m_sinkInter, &DBusSink::VolumeChanged, this, [ = ](double value) { m_sliderContainer->updateSliderValue(value * 100); }); connect(m_sinkInter, &DBusSink::MuteChanged, this, [ = ] { m_sliderContainer->updateSliderValue(m_sinkInter->volume() * 100); }); connect(m_soundInter, &DBusAudio::DefaultSinkChanged, this, &SoundDevicesWidget::onDefaultSinkChanged); - connect(m_deviceList->selectionModel(), &QItemSelectionModel::currentChanged, this, &SoundDevicesWidget::onSelectIndexChanged); + connect(m_deviceList, &DListView::clicked, this, &SoundDevicesWidget::onSelectIndexChanged); connect(m_soundInter, &DBusAudio::PortEnabledChanged, this, &SoundDevicesWidget::onAudioDevicesChanged); connect(m_soundInter, &DBusAudio::CardsWithoutUnavailableChanged, this, &SoundDevicesWidget::onAudioDevicesChanged); connect(m_soundInter, &DBusAudio::MaxUIVolumeChanged, this, [ = ] (double maxValue) { m_sliderContainer->setRange(0, std::round(maxValue * 100.00)); + emit iconChanged(); }); connect(m_sliderContainer, &SliderContainer::sliderValueChanged, this, [ this ](int value) { m_sinkInter->SetVolume(value * 0.01, true); if (m_sinkInter->mute()) { m_sinkInter->SetMuteQueued(false); } + emit iconChanged(); }); } @@ -239,12 +251,15 @@ void SoundDevicesWidget::addPort(const SoundDevicePort *port) { DStandardItem *portItem = new DStandardItem; QString deviceName = port->name(); - portItem->setIcon(QIcon(soundIconFile())); + // TODO: get right icon + portItem->setIcon(QIcon()); portItem->setText(deviceName); + portItem->setFlags(portItem->flags() & ~Qt::ItemIsSelectable); portItem->setTextColorRole(QPalette::BrightText); portItem->setData(QVariant::fromValue(port), DeviceObjRole); portItem->setData(AUDIOPORT, ItemTypeRole); portItem->setToolTip(port->cardName()); + static QBrush oldBackGroundStyle = portItem->background(); connect(port, &SoundDevicePort::nameChanged, this, [ = ](const QString &str) { portItem->setText(str); @@ -254,6 +269,11 @@ void SoundDevicesWidget::addPort(const SoundDevicePort *port) }); connect(port, &SoundDevicePort::isActiveChanged, this, [ = ](bool isActive) { portItem->setCheckState(isActive ? Qt::CheckState::Checked : Qt::CheckState::Unchecked); + if (isActive) { + portItem->setBackground(DPaletteHelper::instance()->palette(this).highlight()); + } else { + portItem->setBackground(oldBackGroundStyle); + } }); if (port->isActive()) { @@ -326,32 +346,6 @@ void SoundDevicesWidget::deviceEnabled(bool enable) Q_EMIT enableChanged(enable); } -QString SoundDevicesWidget::leftIcon() -{ - QString iconLeft = QString(":/icons/resources/audio-volume-%1").arg(m_sinkInter->mute() ? "muted" : "low"); - if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType) - iconLeft.append("-dark"); - - return iconLeft; -} - -QString SoundDevicesWidget::rightIcon() -{ - QString iconRight = QString(":/icons/resources/audio-volume-high"); - if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType) - iconRight.append("-dark"); - - return iconRight; -} - -const QString SoundDevicesWidget::soundIconFile() const -{ - if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType) - return QString(":/icons/resources/ICON_Device_Laptop_dark.svg"); - - return QString(":/icons/resources/ICON_Device_Laptop.svg"); -} - void SoundDevicesWidget::resizeHeight() { int deviceListHeight = 0; @@ -431,10 +425,12 @@ void SoundDevicesWidget::onSelectIndexChanged(const QModelIndex &index) } } else { // 如果是点击声音设置,则打开控制中心的声音模块 - DDBusSender().service("org.deepin.dde.ControlCenter1") + QtConcurrent::run([=] { + DDBusSender().service("org.deepin.dde.ControlCenter1") .path("/org/deepin/dde/ControlCenter1") .interface("org.deepin.dde.ControlCenter1") .method("ShowPage").arg(QString("sound")).call(); + }); emit requestHide(); } } @@ -443,8 +439,15 @@ void SoundDevicesWidget::onDefaultSinkChanged(const QDBusObjectPath &value) { delete m_sinkInter; m_sinkInter = new DBusSink("org.deepin.dde.Audio1", m_soundInter->defaultSink().path(), QDBusConnection::sessionBus(), this); - connect(m_sinkInter, &DBusSink::VolumeChanged, this, [ = ](double value) { m_sliderContainer->updateSliderValue(value * 100); }); - connect(m_sinkInter, &DBusSink::MuteChanged, this, [ = ] { m_sliderContainer->updateSliderValue(m_sinkInter->volume() * 100); }); + connect(m_sinkInter, &DBusSink::VolumeChanged, this, [ = ](double value) { + m_sliderContainer->updateSliderValue(value * 100); + emit iconChanged(); + }); + + connect(m_sinkInter, &DBusSink::MuteChanged, this, [ = ] { + m_sliderContainer->updateSliderValue(m_sinkInter->volume() * 100); + emit iconChanged(); + }); QString portId = m_sinkInter->activePort().name; uint cardId = m_sinkInter->card(); @@ -466,4 +469,48 @@ void SoundDevicesWidget::onDefaultSinkChanged(const QDBusObjectPath &value) resetVolumeInfo(); m_deviceList->update(); + emit iconChanged(); +} + +QWidget* SoundDevicesWidget::tipsWidget() +{ + if (m_sinkInter) + refreshTips(std::min(150, qRound(m_sinkInter->volume() * 100.0)), true); + + m_tipsLabel->resize(m_tipsLabel->sizeHint().width() + 10, + m_tipsLabel->sizeHint().height()); + + return m_tipsLabel; +} + +void SoundDevicesWidget::refreshTips(const int volume, const bool force) +{ + if (!force && !m_tipsLabel->isVisible()) + return; + + m_tipsLabel->setText(QString(tr("Volume %1").arg(QString::number(volume) + '%'))); +} + +QPixmap SoundDevicesWidget::pixmap(DGuiApplicationHelper::ColorType colorType, int iconWidth, int iconHeight) const +{ + const double volmue = m_sinkInter->volume(); + const bool mute = m_sinkInter->mute(); + const double maxVolmue = m_soundInter->maxUIVolume(); + + QPixmap leftPixmap = QIcon::fromTheme(QString("audio-volume-%1-symbolic").arg(m_sinkInter->mute() ? "muted" : "off")).pixmap(18, 18); + m_sliderContainer->setIcon(SliderContainer::IconPosition::LeftIcon, leftPixmap, QSize(), 5); + + QString volumeString; + if (mute) + volumeString = "muted"; + else if (0.0 == volmue) + volumeString = "off"; + else if (volmue > maxVolmue * 2 / 3) + volumeString = "high"; + else if (volmue > maxVolmue * 1 / 3) + volumeString = "medium"; + else + volumeString = "low";; + + return QIcon::fromTheme(QString("audio-volume-%1-symbolic").arg(volumeString)).pixmap(iconWidth, iconHeight); } diff --git a/plugins/sound/sounddeviceswidget.h b/plugins/sound/sounddeviceswidget.h index 3a7bdf566..4e97a07b8 100644 --- a/plugins/sound/sounddeviceswidget.h +++ b/plugins/sound/sounddeviceswidget.h @@ -12,10 +12,14 @@ #include #include +#include namespace Dtk { namespace Widget { class DListView; } } using namespace Dtk::Widget; +namespace Dock { +class TipsWidget; +} class SliderContainer; class QStandardItemModel; @@ -35,9 +39,14 @@ public: explicit SoundDevicesWidget(QWidget *parent = nullptr); ~SoundDevicesWidget() override; + QWidget* tipsWidget(); + QPixmap pixmap() const; + QPixmap pixmap(DGuiApplicationHelper::ColorType colorType, int iconWidth, int iconHeight) const; + Q_SIGNALS: void enableChanged(bool); void requestHide(); + void iconChanged(); protected: bool eventFilter(QObject *watcher, QEvent *event) override; @@ -45,9 +54,6 @@ protected: private: void initUi(); void initConnection(); - QString leftIcon(); - QString rightIcon(); - const QString soundIconFile() const; void resizeHeight(); @@ -67,13 +73,17 @@ private: void deviceEnabled(bool enable); + + void refreshTips(const int volume, const bool force); + private Q_SLOTS: void onSelectIndexChanged(const QModelIndex &index); void onDefaultSinkChanged(const QDBusObjectPath & value); void onAudioDevicesChanged(); private: - QWidget *m_sliderParent; + Dock::TipsWidget *m_tipsLabel; + QLabel *m_titleLabel; SliderContainer *m_sliderContainer; QLabel *m_descriptionLabel; DListView *m_deviceList; diff --git a/plugins/sound/sounditem.cpp b/plugins/sound/sounditem.cpp deleted file mode 100644 index ee8a38f72..000000000 --- a/plugins/sound/sounditem.cpp +++ /dev/null @@ -1,286 +0,0 @@ -// Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd. -// SPDX-FileCopyrightText: 2018 - 2023 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: LGPL-3.0-or-later - -#include "sounditem.h" -#include "constants.h" -#include "../widgets/tipswidget.h" -#include "../frame/util/imageutil.h" -#include "../frame/util/utils.h" - -#include -#include -#include - -#include -#include -#include -#include -#include - -DWIDGET_USE_NAMESPACE -DGUI_USE_NAMESPACE - -// menu actions -#define MUTE "mute" -#define SETTINGS "settings" - -using namespace Dock; - -SoundItem::SoundItem(QWidget *parent) - : QWidget(parent) - , m_tipsLabel(new TipsWidget(this)) - , m_applet(new SoundApplet) - , m_sinkInter(nullptr) -{ - m_tipsLabel->setAccessibleName("soundtips"); - m_tipsLabel->setVisible(false); - - m_applet->setVisible(false); - - connect(m_applet.get(), &SoundApplet::defaultSinkChanged, this, &SoundItem::sinkChanged); - connect(m_applet.get(), &SoundApplet::volumeChanged, this, &SoundItem::refresh, Qt::QueuedConnection); - - connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, [ = ] { - refreshIcon(); - }); -} - -QWidget *SoundItem::tipsWidget() -{ - if (m_sinkInter) - refreshTips(std::min(150, qRound(m_sinkInter->volume() * 100.0)), true); - else - refreshTips(m_applet->volumeValue(), true); - - m_tipsLabel->resize(m_tipsLabel->sizeHint().width() + 10, - m_tipsLabel->sizeHint().height()); - - return m_tipsLabel; -} - -QWidget *SoundItem::popupApplet() -{ - return m_applet.get(); -} - -const QString SoundItem::contextMenu() -{ - QList items; - items.reserve(2); - - QMap open; - open["itemId"] = MUTE; - - // 如果没有可用输出设备,直接显示静音菜单不可用 - if (!m_applet->existActiveOutputDevice()) { - open["itemText"] = tr("Unmute"); - open["isActive"] = false; - } else if (m_sinkInter->mute()) { - open["itemText"] = tr("Unmute"); - open["isActive"] = true; - } else { - open["itemText"] = tr("Mute"); - open["isActive"] = true; - } - items.push_back(open); - - if (!QFile::exists(ICBC_CONF_FILE)) { - QMap settings; - settings["itemId"] = SETTINGS; - settings["itemText"] = tr("Sound settings"); - settings["isActive"] = true; - items.push_back(settings); -#ifdef QT_DEBUG - qInfo() << "----------icbc sound setting."; -#endif - } - - QMap menu; - menu["items"] = items; - menu["checkableMenu"] = false; - menu["singleCheck"] = false; - - return QJsonDocument::fromVariant(menu).toJson(); -} - -void SoundItem::invokeMenuItem(const QString menuId, const bool checked) -{ - Q_UNUSED(checked); - - if (menuId == MUTE) - m_sinkInter->SetMuteQueued(!m_sinkInter->mute()); - else if (menuId == SETTINGS) - DDBusSender() - .service("org.deepin.dde.ControlCenter1") - .interface("org.deepin.dde.ControlCenter1") - .path("/org/deepin/dde/ControlCenter1") - .method(QString("ShowPage")) - .arg(QString("sound")) - .call(); -} - -void SoundItem::resizeEvent(QResizeEvent *e) -{ - QWidget::resizeEvent(e); - - const Dock::Position position = qApp->property(PROP_POSITION).value(); - // 保持横纵比 - if (position == Dock::Bottom || position == Dock::Top) { - setMaximumWidth(height()); - setMaximumHeight(QWIDGETSIZE_MAX); - } else { - setMaximumHeight(width()); - setMaximumWidth(QWIDGETSIZE_MAX); - } - - refreshIcon(); -} - -void SoundItem::wheelEvent(QWheelEvent *e) -{ - QWheelEvent *event = new QWheelEvent(e->position(), e->globalPosition(), e->pixelDelta(), e->angleDelta(), - e->buttons(), e->modifiers(), e->phase(), e->inverted()); - qApp->postEvent(m_applet->mainSlider(), event); - - e->accept(); -} - -void SoundItem::paintEvent(QPaintEvent *e) -{ - QWidget::paintEvent(e); - - QPainter painter(this); - const QRectF &rf = QRectF(rect()); - const QRectF &rfp = QRectF(m_iconPixmap.rect()); - painter.drawPixmap(rf.center() - rfp.center() / m_iconPixmap.devicePixelRatioF(), m_iconPixmap); -} - -void SoundItem::refresh(const int volume) -{ - refreshIcon(); - refreshTips(volume, false); -} - -void SoundItem::refreshIcon() -{ - if (!m_sinkInter) - return; - - const double volmue = m_applet->volumeValue(); - const double maxVolmue = m_applet->maxVolumeValue(); - const bool mute = m_applet->existActiveOutputDevice() ? (m_sinkInter && m_sinkInter->mute()) : true; - const Dock::DisplayMode displayMode = Dock::DisplayMode::Efficient; - - QString iconString; - if (displayMode == Dock::Fashion) { - QString volumeString; - if (volmue >= 1000) - volumeString = "100"; - else - volumeString = QString("0") + ('0' + int(volmue / 100)) + "0"; - - iconString = "audio-volume-" + volumeString; - - if (mute) - iconString += "-muted"; - } else { - QString volumeString; - if (mute) - volumeString = "muted"; - else if (int(volmue) == 0) - volumeString = "off"; - else if (volmue / maxVolmue > double(2) / 3) - volumeString = "high"; - else if (volmue / maxVolmue > double(1) / 3) - volumeString = "medium"; - else - volumeString = "low"; - - iconString = QString("audio-volume-%1-symbolic").arg(volumeString); - } - - const auto ratio = devicePixelRatioF(); - int iconSize = PLUGIN_ICON_MAX_SIZE; - if (height() <= PLUGIN_BACKGROUND_MIN_SIZE && DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType) - iconString.append(PLUGIN_MIN_ICON_NAME); - - m_iconPixmap = ImageUtil::loadSvg(iconString, ":/", iconSize, ratio); - - update(); - - emit iconChanged(); -} - -void SoundItem::refreshTips(const int volume, const bool force) -{ - if (!force && !m_tipsLabel->isVisible()) - return; - - const bool mute = m_applet->existActiveOutputDevice() ? (m_sinkInter && m_sinkInter->mute()) : true; - if (mute) { - m_tipsLabel->setText(QString(tr("Mute"))); - } else { - m_tipsLabel->setText(QString(tr("Volume %1").arg(QString::number(volume) + '%'))); - } -} - -QPixmap SoundItem::pixmap() const -{ - return m_iconPixmap; -} - -QPixmap SoundItem::pixmap(DGuiApplicationHelper::ColorType colorType, int iconWidth, int iconHeight) const -{ - const Dock::DisplayMode displayMode = Dock::DisplayMode::Efficient; - - const double volmue = m_applet->volumeValue(); - const double maxVolmue = m_applet->maxVolumeValue(); - const bool mute = m_applet->existActiveOutputDevice() ? (m_sinkInter && m_sinkInter->mute()) : true; - - QString iconString; - if (displayMode == Dock::Fashion) { - QString volumeString; - if (volmue >= 1000) - volumeString = "100"; - else - volumeString = QString("0") + ('0' + int(volmue / 100)) + "0"; - - iconString = "audio-volume-" + volumeString; - - if (mute) - iconString += "-muted"; - } else { - QString volumeString; - if (mute) - volumeString = "muted"; - else if (int(volmue) == 0) - volumeString = "off"; - else if (volmue / maxVolmue > double(2) / 3) - volumeString = "high"; - else if (volmue / maxVolmue > double(1) / 3) - volumeString = "medium"; - else - volumeString = "low"; - - iconString = QString("audio-volume-%1-symbolic").arg(volumeString); - } - - if (colorType == DGuiApplicationHelper::LightType) - iconString.append(PLUGIN_MIN_ICON_NAME); - - iconString.append(".svg"); - - return ImageUtil::loadSvg(":/" + iconString, QSize(iconWidth, iconHeight)); -} - -void SoundItem::sinkChanged(DBusSink *sink) -{ - m_sinkInter = sink; - - if (m_sinkInter) - refresh(std::min(150, qRound(m_sinkInter->volume() * 100.0))); - else - refresh(m_applet->volumeValue()); -} diff --git a/plugins/sound/sounditem.h b/plugins/sound/sounditem.h deleted file mode 100644 index 49996e9fa..000000000 --- a/plugins/sound/sounditem.h +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd. -// SPDX-FileCopyrightText: 2018 - 2023 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: LGPL-3.0-or-later - -#ifndef SOUNDITEM_H -#define SOUNDITEM_H - -#include "soundapplet.h" -#include "org_deepin_dde_audio1_sink.h" - -#include -#include - -#define SOUND_KEY "sound-item-key" - -using DBusSink = org::deepin::dde::audio1::Sink; - -namespace Dock { -class TipsWidget; -} -class SoundItem : public QWidget -{ - Q_OBJECT - -public: - explicit SoundItem(QWidget *parent = 0); - - QWidget *tipsWidget(); - QWidget *popupApplet(); - - const QString contextMenu(); - void invokeMenuItem(const QString menuId, const bool checked); - - void refreshIcon(); - void refreshTips(const int volume, const bool force = false); - QPixmap pixmap() const; - QPixmap pixmap(DGuiApplicationHelper::ColorType colorType, int iconWidth, int iconHeight) const; - -signals: - void requestContextMenu() const; - void iconChanged() const; - -protected: - void resizeEvent(QResizeEvent *e); - void wheelEvent(QWheelEvent *e); - void paintEvent(QPaintEvent *e); - -private slots: - void sinkChanged(DBusSink *sink); - void refresh(const int volume); - -private: - Dock::TipsWidget *m_tipsLabel; - QScopedPointer m_applet; - DBusSink *m_sinkInter; - QPixmap m_iconPixmap; -}; - -#endif // SOUNDITEM_H diff --git a/plugins/sound/soundplugin.cpp b/plugins/sound/soundplugin.cpp index a7ba73484..b4eb6b18d 100644 --- a/plugins/sound/soundplugin.cpp +++ b/plugins/sound/soundplugin.cpp @@ -2,7 +2,6 @@ // SPDX-FileCopyrightText: 2018 - 2023 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: LGPL-3.0-or-later - #include "soundplugin.h" #include "soundaccessible.h" #include "soundwidget.h" @@ -14,11 +13,12 @@ #include #define STATE_KEY "enable" +#define SOUND_KEY "sound-item-key" SoundPlugin::SoundPlugin(QObject *parent) : QObject(parent) - , m_soundItem(nullptr) , m_soundWidget(nullptr) + , m_soundDeviceWidget(nullptr) { QAccessible::installFactory(soundAccessibleFactory); } @@ -37,10 +37,8 @@ void SoundPlugin::init(PluginProxyInterface *proxyInter) { m_proxyInter = proxyInter; - if (m_soundItem) - return; + if (m_soundWidget) return; - m_soundItem.reset(new SoundItem); m_soundWidget.reset(new SoundWidget); m_soundWidget->setFixedHeight(60); @@ -58,7 +56,7 @@ void SoundPlugin::init(PluginProxyInterface *proxyInter) m_proxyInter->requestSetAppletVisible(this, QUICK_ITEM_KEY, false); }); - connect(m_soundItem.data(), &SoundItem::iconChanged, this, [=] { + connect(m_soundDeviceWidget.data(), &SoundDevicesWidget::iconChanged, this, [=] { m_proxyInter->updateDockInfo(this, DockPart::QuickPanel); m_proxyInter->updateDockInfo(this, DockPart::QuickShow); m_proxyInter->itemUpdate(this, SOUND_KEY); @@ -79,9 +77,6 @@ bool SoundPlugin::pluginIsDisable() QWidget *SoundPlugin::itemWidget(const QString &itemKey) { - if (itemKey == SOUND_KEY) - return m_soundItem.data(); - if (itemKey == QUICK_ITEM_KEY) return m_soundWidget.data(); @@ -91,29 +86,19 @@ QWidget *SoundPlugin::itemWidget(const QString &itemKey) QWidget *SoundPlugin::itemTipsWidget(const QString &itemKey) { if (itemKey == SOUND_KEY) - return m_soundItem->tipsWidget(); + return m_soundDeviceWidget->tipsWidget(); return nullptr; } QWidget *SoundPlugin::itemPopupApplet(const QString &itemKey) { - if (itemKey == SOUND_KEY) - return m_soundItem->popupApplet(); - if (itemKey == QUICK_ITEM_KEY) return m_soundDeviceWidget.data(); return nullptr; } -void SoundPlugin::invokedMenuItem(const QString &itemKey, const QString &menuId, const bool checked) -{ - if (itemKey == SOUND_KEY) { - m_soundItem->invokeMenuItem(menuId, checked); - } -} - int SoundPlugin::itemSortKey(const QString &itemKey) { const QString key = QString("pos_%1_%2").arg(itemKey).arg(Dock::Efficient); @@ -128,13 +113,6 @@ void SoundPlugin::setSortKey(const QString &itemKey, const int order) m_proxyInter->saveValue(this, key, order); } -void SoundPlugin::refreshIcon(const QString &itemKey) -{ - if (itemKey == SOUND_KEY) { - m_soundItem->refreshIcon(); - } -} - void SoundPlugin::pluginSettingsChanged() { refreshPluginItemsVisible(); @@ -144,9 +122,9 @@ QIcon SoundPlugin::icon(const DockPart &dockPart, DGuiApplicationHelper::ColorTy { switch (dockPart) { case DockPart::QuickShow: - return m_soundItem->pixmap(themeType, 18, 16); + return m_soundDeviceWidget->pixmap(themeType, 18, 16); case DockPart::DCCSetting: - return m_soundItem->pixmap(themeType, 18, 18); + return m_soundDeviceWidget->pixmap(themeType, 18, 18); default: break; } diff --git a/plugins/sound/soundplugin.h b/plugins/sound/soundplugin.h index 9d3006dc8..a703b17d1 100644 --- a/plugins/sound/soundplugin.h +++ b/plugins/sound/soundplugin.h @@ -7,7 +7,6 @@ #define SOUNDPLUGIN_H #include "pluginsiteminterface.h" -#include "sounditem.h" class SoundWidget; class SoundDevicesWidget; @@ -30,10 +29,8 @@ public: QWidget *itemWidget(const QString &itemKey) override; QWidget *itemTipsWidget(const QString &itemKey) override; QWidget *itemPopupApplet(const QString &itemKey) override; - void invokedMenuItem(const QString &itemKey, const QString &menuId, const bool checked) override; int itemSortKey(const QString &itemKey) override; void setSortKey(const QString &itemKey, const int order) override; - void refreshIcon(const QString &itemKey) override; void pluginSettingsChanged() override; QIcon icon(const DockPart &dockPart, DGuiApplicationHelper::ColorType themeType) override; PluginMode status() const override; @@ -44,7 +41,6 @@ private: void refreshPluginItemsVisible(); private: - QScopedPointer m_soundItem; QScopedPointer m_soundWidget; QScopedPointer m_soundDeviceWidget; };