mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-03 00:15:21 +00:00

将加载插件的流程和快捷面板的功能移动到单独的插件中,精简任务栏的代码 Log: Influence: 加载插件 Task: https://pms.uniontech.com/task-view-222353.html Change-Id: I9b2fbe4f32c852f6a3535daab87c63741bd8914a
106 lines
2.9 KiB
C++
106 lines
2.9 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 "linequickitem.h"
|
|
#include "pluginsiteminterface.h"
|
|
|
|
#include <DBlurEffectWidget>
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
DWIDGET_USE_NAMESPACE
|
|
|
|
LineQuickItem::LineQuickItem(PluginsItemInterface *const pluginInter, const QString &itemKey, QWidget *parent)
|
|
: QuickSettingItem(pluginInter, itemKey, parent)
|
|
, m_centerWidget(pluginInter->itemWidget(QUICK_ITEM_KEY))
|
|
, m_centerParentWidget(nullptr)
|
|
, m_effectWidget(new DBlurEffectWidget(this))
|
|
{
|
|
initUi();
|
|
QMetaObject::invokeMethod(this, &LineQuickItem::resizeSelf, Qt::QueuedConnection);
|
|
}
|
|
|
|
LineQuickItem::~LineQuickItem()
|
|
{
|
|
if (m_centerWidget)
|
|
m_centerWidget->setParent(nullptr);
|
|
}
|
|
|
|
void LineQuickItem::doUpdate()
|
|
{
|
|
if (m_centerWidget)
|
|
m_centerWidget->update();
|
|
}
|
|
|
|
void LineQuickItem::detachPlugin()
|
|
{
|
|
if (m_centerWidget)
|
|
m_centerWidget->setParent(m_centerParentWidget);
|
|
}
|
|
|
|
QuickSettingItem::QuickItemStyle LineQuickItem::type() const
|
|
{
|
|
return QuickSettingItem::QuickItemStyle::Line;
|
|
}
|
|
|
|
bool LineQuickItem::eventFilter(QObject *obj, QEvent *event)
|
|
{
|
|
if (obj == m_centerWidget && event->type() == QEvent::Resize)
|
|
resizeSelf();
|
|
|
|
return QuickSettingItem::eventFilter(obj, event);
|
|
}
|
|
|
|
void LineQuickItem::initUi()
|
|
{
|
|
QColor maskColor(Qt::white);
|
|
maskColor.setAlphaF(0.8);
|
|
m_effectWidget->setMaskColor(maskColor);
|
|
m_effectWidget->setBlurRectXRadius(8);
|
|
m_effectWidget->setBlurRectYRadius(8);
|
|
|
|
// 如果图标不为空
|
|
if (!m_centerWidget)
|
|
return;
|
|
|
|
m_centerWidget->setVisible(true);
|
|
m_centerParentWidget = m_centerWidget->parentWidget();
|
|
|
|
QHBoxLayout *layout = new QHBoxLayout(m_effectWidget);
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
|
layout->setAlignment(Qt::AlignHCenter);
|
|
layout->addWidget(m_centerWidget);
|
|
|
|
QHBoxLayout *mainLayout = new QHBoxLayout(this);
|
|
mainLayout->setContentsMargins(0, 0, 0, 0);
|
|
mainLayout->addWidget(m_effectWidget);
|
|
|
|
m_centerWidget->installEventFilter(this);
|
|
}
|
|
|
|
void LineQuickItem::resizeSelf()
|
|
{
|
|
if (!m_centerWidget)
|
|
return;
|
|
|
|
m_effectWidget->setFixedHeight(m_centerWidget->height());
|
|
setFixedHeight(m_centerWidget->height());
|
|
}
|