chore: 删除多余的文件

删除已经移到插件中的文件

Log:
Influence: 无
Task: https://pms.uniontech.com/task-view-222353.html
Change-Id: Ie4373902170defacebb9f6652b1b21121980ad18
This commit is contained in:
donghualin 2023-01-10 21:42:10 +08:00
parent e7dbbb0140
commit 0c414397e1
15 changed files with 0 additions and 1662 deletions

View File

@ -19,7 +19,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "quicksettingcontroller.h"
#include "quicksettingitem.h"
#include "pluginsitem.h"
#include "pluginmanagerinterface.h"

View File

@ -1,97 +0,0 @@
/*
* 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 "fullquickitem.h"
#include "pluginsiteminterface.h"
FullQuickItem::FullQuickItem(PluginsItemInterface *const pluginInter, QWidget *parent)
: QuickSettingItem(pluginInter, parent)
, m_centerWidget(pluginInter->itemWidget(QUICK_ITEM_KEY))
, m_centerParentWidget(nullptr)
, m_effectWidget(new DBlurEffectWidget(this))
{
initUi();
QMetaObject::invokeMethod(this, &FullQuickItem::resizeSelf, Qt::QueuedConnection);
}
FullQuickItem::~FullQuickItem()
{
if (m_centerWidget)
m_centerWidget->setParent(nullptr);
}
void FullQuickItem::updateShow()
{
if (m_centerWidget)
m_centerWidget->update();
}
void FullQuickItem::detachPlugin()
{
if (m_centerWidget)
m_centerWidget->setParent(m_centerParentWidget);
}
QuickSettingItem::QuickSettingType FullQuickItem::type() const
{
return QuickSettingItem::QuickSettingType::Full;
}
bool FullQuickItem::eventFilter(QObject *obj, QEvent *event)
{
if (obj == m_centerWidget && event->type() == QEvent::Resize)
resizeSelf();
return QuickSettingItem::eventFilter(obj, event);
}
void FullQuickItem::initUi()
{
m_effectWidget->setMaskColor(QColor(239, 240, 245));
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 FullQuickItem::resizeSelf()
{
if (!m_centerWidget)
return;
m_effectWidget->setFixedHeight(m_centerWidget->height());
setFixedHeight(m_centerWidget->height());
}

View File

@ -1,51 +0,0 @@
/*
* 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/>.
*/
#ifndef FULLQUICKITEM_H
#define FULLQUICKITEM_H
#include "quicksettingitem.h"
class FullQuickItem : public QuickSettingItem
{
Q_OBJECT
public:
FullQuickItem(PluginsItemInterface *const pluginInter, QWidget *parent = nullptr);
~FullQuickItem() override;
void updateShow() override;
void detachPlugin() override;
QuickSettingType type() const override;
protected:
bool eventFilter(QObject *obj, QEvent *event) override;
private:
void initUi();
void resizeSelf();
private:
QWidget *m_centerWidget;
QWidget *m_centerParentWidget;
DBlurEffectWidget *m_effectWidget;
};
#endif // FULLQUICKITEM_H

View File

@ -1,278 +0,0 @@
/*
* 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 "multiquickitem.h"
#include "pluginsiteminterface.h"
#include <DFontSizeManager>
#include <DGuiApplicationHelper>
#include <DPaletteHelper>
#define BGSIZE 36
#define ICONWIDTH 24
#define ICONHEIGHT 24
static QSize expandSize = QSize(20, 20);
MultiQuickItem::MultiQuickItem(PluginsItemInterface *const pluginInter, QWidget *parent)
: QuickSettingItem(pluginInter, parent)
, m_iconWidget(nullptr)
, m_nameLabel(nullptr)
, m_stateLabel(nullptr)
, m_itemWidgetParent(nullptr)
{
initUi();
}
MultiQuickItem::~MultiQuickItem()
{
QWidget *itemWidget = pluginItem()->itemWidget(QUICK_ITEM_KEY);
if (itemWidget)
itemWidget->setParent(nullptr);
}
void MultiQuickItem::updateShow()
{
if (m_iconWidget && m_nameLabel && m_stateLabel) {
m_iconWidget->update();
m_nameLabel->setText(QFontMetrics(m_nameLabel->font()).elidedText(pluginItem()->pluginDisplayName(), Qt::TextElideMode::ElideRight, m_nameLabel->width()));
m_stateLabel->setText(QFontMetrics(m_stateLabel->font()).elidedText(pluginItem()->description(), Qt::TextElideMode::ElideRight, m_stateLabel->width()));
} else {
QWidget *itemWidget = pluginItem()->itemWidget(QUICK_ITEM_KEY);
if (itemWidget) {
// 如果插件没有返回图标的显示则获取插件的itemWidget
itemWidget->update();
}
}
}
void MultiQuickItem::detachPlugin()
{
QWidget *itemWidget = pluginItem()->itemWidget(QUICK_ITEM_KEY);
if (itemWidget && itemWidget->parentWidget() == this)
itemWidget->setParent(m_itemWidgetParent);
}
QuickSettingItem::QuickSettingType MultiQuickItem::type() const
{
return QuickSettingItem::QuickSettingType::Multi;
}
bool MultiQuickItem::eventFilter(QObject *obj, QEvent *event)
{
if (m_iconWidget) {
if (event->type() == QEvent::MouseButtonRelease) {
if (obj->objectName() == "expandLabel") {
// 如果是鼠标的按下事件
QWidget *widget = pluginItem()->itemPopupApplet(QUICK_ITEM_KEY);
if (!widget)
return QuickSettingItem::eventFilter(obj, event);
Q_EMIT requestShowChildWidget(widget);
} else if (obj == this) {
QStringList commandArgumend = pluginItem()->itemCommand(itemKey()).split(" ");
if (commandArgumend.size() > 0) {
QString command = commandArgumend.first();
commandArgumend.removeFirst();
QProcess::startDetached(command, commandArgumend);
}
}
} else if (event->type() == QEvent::Resize) {
QLabel *labelWidget = qobject_cast<QLabel *>(obj);
if (!labelWidget)
return QuickSettingItem::eventFilter(obj, event);
if (labelWidget == m_nameLabel) {
labelWidget->setText(QFontMetrics(labelWidget->font()).elidedText(pluginItem()->pluginDisplayName(), Qt::TextElideMode::ElideRight, labelWidget->width()));
} else if (labelWidget == m_stateLabel) {
labelWidget->setText(QFontMetrics(labelWidget->font()).elidedText(pluginItem()->description(), Qt::TextElideMode::ElideRight, labelWidget->width()));
}
}
}
return QuickSettingItem::eventFilter(obj, event);
}
void MultiQuickItem::initUi()
{
QWidget *itemWidget = pluginItem()->itemWidget(QUICK_ITEM_KEY);
if (pluginItem()->icon(DockPart::QuickPanel).isNull() && itemWidget) {
m_itemWidgetParent = itemWidget->parentWidget();
// 如果插件没有返回图标的显示则获取插件的itemWidget
QHBoxLayout *mainLayout = new QHBoxLayout(this);
itemWidget->setVisible(true);
itemWidget->setParent(this);
mainLayout->setContentsMargins(0, 0, 0, 0);
mainLayout->addWidget(itemWidget);
} else {
// 如果插件获取到插件区域的图标,则让其按照图标来组合显示
// 如果是占用两排的插件则用横向Layout
QHBoxLayout *mainLayout = new QHBoxLayout(this);
mainLayout->setContentsMargins(10, 0, 10, 0);
mainLayout->setSpacing(0);
mainLayout->addStretch(10);
mainLayout->setAlignment(Qt::AlignCenter);
// 添加图标
QWidget *iconWidgetParent = new QWidget(this);
QVBoxLayout *iconLayout = new QVBoxLayout(iconWidgetParent);
iconLayout->setContentsMargins(0, 0, 0, 0);
iconLayout->setSpacing(0);
iconLayout->setAlignment(Qt::AlignCenter);
m_iconWidget = new QuickIconWidget(pluginItem(), itemKey(), iconWidgetParent);
m_iconWidget->setFixedSize(BGSIZE, BGSIZE);
iconLayout->addWidget(m_iconWidget);
mainLayout->addWidget(iconWidgetParent);
mainLayout->addSpacing(10);
// 添加中间的名称部分
QWidget *textWidget = new QWidget(this);
m_nameLabel = new QLabel(textWidget);
m_stateLabel = new QLabel(textWidget);
m_nameLabel->setObjectName("nameLabel");
m_stateLabel->setObjectName("stateLabel");
// 设置图标和文字的属性
QFont nameFont = DFontSizeManager::instance()->t6();
nameFont.setBold(true);
QPalette pe;
pe.setColor(QPalette::WindowText, Qt::black);
m_nameLabel->setPalette(pe);
m_stateLabel->setPalette(pe);
m_nameLabel->setFont(nameFont);
m_stateLabel->setFont(DFontSizeManager::instance()->t10());
m_nameLabel->setText(pluginItem()->pluginDisplayName());
m_stateLabel->setText(pluginItem()->description());
m_nameLabel->installEventFilter(this);
m_stateLabel->installEventFilter(this);
QVBoxLayout *textLayout = new QVBoxLayout(textWidget);
textLayout->setContentsMargins(0, 0, 0, 0);
textLayout->setSpacing(0);
textLayout->addWidget(m_nameLabel);
textLayout->addWidget(m_stateLabel);
textLayout->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
mainLayout->addWidget(textWidget);
// 添加右侧的展开按钮
QWidget *expandWidgetParent = new QWidget(this);
QVBoxLayout *expandLayout = new QVBoxLayout(expandWidgetParent);
expandLayout->setSpacing(0);
QLabel *expandLabel = new QLabel(expandWidgetParent);
expandLabel->setObjectName("expandLabel");
expandLabel->setPixmap(QPixmap(expandFileName()));
expandLabel->setFixedSize(expandSize);
expandLabel->setAutoFillBackground(true);
expandLabel->installEventFilter(this);
expandLayout->addWidget(expandLabel);
pe.setBrush(QPalette::Window, Qt::transparent);
expandLabel->setPalette(pe);
mainLayout->addWidget(expandWidgetParent);
}
}
QString MultiQuickItem::expandFileName() const
{
if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType)
return QString(":/icons/resources/arrow-right-dark.svg");
return QString(":/icons/resources/arrow-right.svg");
}
/**
* @brief QuickIconWidget::QuickIconWidget
* @param pluginInter
* @param parent
* widget
*/
QuickIconWidget::QuickIconWidget(PluginsItemInterface *pluginInter, const QString &itemKey, QWidget *parent)
: QWidget(parent)
, m_pluginInter(pluginInter)
, m_itemKey(itemKey)
{
}
void QuickIconWidget::paintEvent(QPaintEvent *event)
{
QPixmap pixmapIcon = pluginIcon();
if (pixmapIcon.isNull())
return QWidget::paintEvent(event);
pixmapIcon = pluginIcon(true);
QPainter painter(this);
painter.setRenderHint(QPainter::RenderHint::Antialiasing);
painter.setPen(foregroundColor());
DPalette dpa = DPaletteHelper::instance()->palette(this);
QPainter pa(&pixmapIcon);
pa.setCompositionMode(QPainter::CompositionMode_SourceIn);
pa.fillRect(pixmapIcon.rect(), painter.pen().brush());
// 如果是主图标,则显示阴影背景
painter.save();
painter.setPen(Qt::NoPen);
painter.setBrush(dpa.brush(DPalette::ColorRole::Midlight));
painter.drawEllipse(rect());
painter.restore();
QRect rctIcon((rect().width() - pixmapIcon.width()) / 2, (rect().height() - pixmapIcon.height()) / 2, pixmapIcon.width(), pixmapIcon.height());
painter.drawPixmap(rctIcon, pixmapIcon);
}
QColor QuickIconWidget::foregroundColor() const
{
DPalette dpa = DPaletteHelper::instance()->palette(this);
// 此处的颜色是临时获取的,后期需要和设计师确认,改成正规的颜色
if (m_pluginInter->status() == PluginsItemInterface::PluginMode::Active)
return dpa.color(DPalette::ColorGroup::Active, DPalette::ColorRole::Text);
if (m_pluginInter->status() == PluginsItemInterface::PluginMode::Deactive)
return dpa.color(DPalette::ColorGroup::Disabled, DPalette::ColorRole::Text);
return dpa.color(DPalette::ColorGroup::Normal, DPalette::ColorRole::Text);
}
QPixmap QuickIconWidget::pluginIcon(bool contailGrab) const
{
QIcon icon = m_pluginInter->icon(DockPart::QuickPanel);
if (icon.isNull() && contailGrab) {
// 如果图标为空就使用itemWidget的截图作为它的图标这种一般是适用于老版本插件或者没有实现v23接口的插件
QWidget *itemWidget = m_pluginInter->itemWidget(m_itemKey);
if (itemWidget) {
itemWidget->setFixedSize(ICONWIDTH, ICONHEIGHT);
return itemWidget->grab();
}
return QPixmap();
}
// 获取icon接口返回的图标
int pixmapWidth = width();
int pixmapHeight = height();
QList<QSize> iconSizes = icon.availableSizes();
if (iconSizes.size() > 0) {
QSize size = iconSizes[0];
if (size.isValid() && !size.isEmpty() && !size.isNull()) {
pixmapWidth = size.width();
pixmapHeight = size.height();
}
}
return icon.pixmap(pixmapWidth, pixmapHeight);
}

View File

@ -1,78 +0,0 @@
/*
* 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/>.
*/
#ifndef MULTIQUICKITEM_H
#define MULTIQUICKITEM_H
#include <quicksettingitem.h>
class QuickIconWidget;
class QWidget;
class MultiQuickItem : public QuickSettingItem
{
Q_OBJECT
public:
MultiQuickItem(PluginsItemInterface *const pluginInter, QWidget *parent = nullptr);
~MultiQuickItem() override;
void updateShow() override;
void detachPlugin() override;
QuickSettingType type() const override;
protected:
bool eventFilter(QObject *obj, QEvent *event) override;
private:
void initUi();
QString expandFileName() const;
private:
QuickIconWidget *m_iconWidget;
QLabel *m_nameLabel;
QLabel *m_stateLabel;
QWidget *m_itemWidgetParent;
};
/**
* @brief The QuickIconWidget class
* Widget
*/
class QuickIconWidget : public QWidget
{
Q_OBJECT
public:
explicit QuickIconWidget(PluginsItemInterface *pluginInter, const QString &itemKey, QWidget *parent = Q_NULLPTR);
protected:
void paintEvent(QPaintEvent *event) override;
private:
QColor foregroundColor() const;
QPixmap pluginIcon(bool contailGrab = false) const;
private:
PluginsItemInterface *m_pluginInter;
QString m_itemKey;
};
#endif // MULTIQUICKITEM_H

View File

@ -1,194 +0,0 @@
/*
* 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 "singlequickitem.h"
#include "pluginsiteminterface.h"
#include <DFontSizeManager>
#include <DGuiApplicationHelper>
#define ICONHEIGHT 24
#define ICONWIDTH 24
#define TEXTHEIGHT 11
SingleQuickItem::SingleQuickItem(PluginsItemInterface *const pluginInter, QWidget *parent)
: QuickSettingItem(pluginInter, parent)
, m_itemParentWidget(nullptr)
{
initUi();
}
SingleQuickItem::~SingleQuickItem()
{
}
QuickSettingItem::QuickSettingType SingleQuickItem::type() const
{
return QuickSettingItem::QuickSettingType::Single;
}
void SingleQuickItem::mouseReleaseEvent(QMouseEvent *event)
{
Q_UNUSED(event);
QStringList commandArgument = pluginItem()->itemCommand(itemKey()).split(" ");
if (commandArgument.size() > 0) {
QString command = commandArgument.first();
commandArgument.removeFirst();
QProcess::startDetached(command, commandArgument);
}
}
void SingleQuickItem::resizeEvent(QResizeEvent *event)
{
updateShow();
QuickSettingItem::resizeEvent(event);
}
void SingleQuickItem::initUi()
{
QWidget *topWidget = iconWidget(this);
QVBoxLayout *layout = new QVBoxLayout(this);
layout->addWidget(topWidget);
installEventFilter(this);
}
QWidget *SingleQuickItem::iconWidget(QWidget *parent)
{
// 显示图标的窗体
QWidget *widget = new QWidget(parent);
bool childIsEmpty = true;
QIcon icon = pluginItem()->icon(DockPart::QuickPanel);
if (icon.isNull()) {
// 如果图标为空则将获取itemWidget作为它的显示
QWidget *itemWidget = pluginItem()->itemWidget(QUICK_ITEM_KEY);
if (itemWidget) {
m_itemParentWidget = itemWidget->parentWidget();
QHBoxLayout *layout = new QHBoxLayout(widget);
layout->setContentsMargins(0, 0, 0 ,0);
itemWidget->setParent(widget);
layout->addWidget(itemWidget);
itemWidget->setVisible(true);
childIsEmpty = false;
}
}
if (childIsEmpty) {
// 如果没有子窗体,则需要添加下方的文字
QVBoxLayout *layout = new QVBoxLayout(widget);
layout->setAlignment(Qt::AlignVCenter);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
QLabel *imageLabel = new QLabel(widget);
imageLabel->setObjectName("imageLabel");
imageLabel->setFixedHeight(ICONHEIGHT);
imageLabel->setAlignment(Qt::AlignCenter);
QLabel *labelText = new QLabel(widget);
labelText->setObjectName("textLabel");
labelText->setFixedHeight(TEXTHEIGHT);
updatePluginName(labelText);
labelText->setAlignment(Qt::AlignCenter);
labelText->setFont(DFontSizeManager::instance()->t10());
layout->addWidget(imageLabel);
layout->addSpacing(7);
layout->addWidget(labelText);
}
setProperty("paint", childIsEmpty);
return widget;
}
QPixmap SingleQuickItem::pixmap() const
{
// 如果快捷面板区域的图标为空那么就获取itemWidget的截图
QIcon icon = pluginItem()->icon(DockPart::QuickPanel);
if (icon.isNull())
return QPixmap();
int pixmapWidth = width();
int pixmapHeight = height();
QList<QSize> iconSizes = icon.availableSizes();
if (iconSizes.size() > 0) {
QSize size = iconSizes[0];
if (size.isValid() && !size.isEmpty() && !size.isNull()) {
pixmapWidth = size.width();
pixmapHeight = size.height();
}
}
return icon.pixmap(pixmapWidth / qApp->devicePixelRatio(), pixmapHeight / qApp->devicePixelRatio());
}
QLabel *SingleQuickItem::findChildLabel(QWidget *parent, const QString &childObjectName) const
{
QList<QObject *> childrends = parent->children();
for (QObject *child : childrends) {
QWidget *widget = qobject_cast<QWidget *>(child);
if (!widget)
continue;
QLabel *label = qobject_cast<QLabel *>(child);
if (label && widget->objectName() == childObjectName)
return label;
label = findChildLabel(widget, childObjectName);
if (label)
return label;
}
return nullptr;
}
void SingleQuickItem::updatePluginName(QLabel *textLabel)
{
if (!textLabel)
return;
QString text = pluginItem()->description();
if (text.isEmpty())
text = pluginItem()->pluginDisplayName();
QFontMetrics ftm(textLabel->font());
text = ftm.elidedText(text, Qt::TextElideMode::ElideRight, textLabel->width());
textLabel->setText(text);
}
void SingleQuickItem::updateShow()
{
if (property("paint").toBool()) {
QLabel *imageLabel = findChildLabel(this, "imageLabel");
if (imageLabel) {
// 更新图像
imageLabel->setPixmap(pixmap());
}
updatePluginName(findChildLabel(this, "textLabel"));
} else {
QWidget *itemWidget = pluginItem()->itemWidget(QUICK_ITEM_KEY);
if (itemWidget)
itemWidget->update();
}
}
void SingleQuickItem::detachPlugin()
{
QWidget *itemWidget = pluginItem()->itemWidget(QUICK_ITEM_KEY);
if (itemWidget && !property("paint").toBool())
itemWidget->setParent(m_itemParentWidget);
}

View File

@ -1,53 +0,0 @@
/*
* 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/>.
*/
#ifndef SINGLEQUICKITEM_H
#define SINGLEQUICKITEM_H
#include <quicksettingitem.h>
class SingleQuickItem : public QuickSettingItem
{
Q_OBJECT
public:
SingleQuickItem(PluginsItemInterface *const pluginInter, QWidget *parent = nullptr);
~SingleQuickItem() override;
QuickSettingType type() const override;
void updateShow() override;
void detachPlugin() override;
protected:
void mouseReleaseEvent(QMouseEvent *event) override;
void resizeEvent(QResizeEvent *event) override;
private:
void initUi();
QWidget *iconWidget(QWidget *parent);
QPixmap pixmap() const;
QLabel *findChildLabel(QWidget *parent, const QString &childObjectName) const;
void updatePluginName(QLabel *textLabel);
private:
QWidget *m_itemParentWidget;
};
#endif // SINGLEQUICKITEM_H

View File

@ -1,107 +0,0 @@
/*
* 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 "quicksettingitem.h"
#include "pluginsiteminterface.h"
#include "imageutil.h"
#include "quicksettingcontroller.h"
#include <DGuiApplicationHelper>
#include <DFontSizeManager>
#include <DPaletteHelper>
#include <QIcon>
#include <QPainterPath>
#include <QPushButton>
#include <QFontMetrics>
#include <QPainterPath>
#include <QBitmap>
#define ICONWIDTH 24
#define ICONHEIGHT 24
#define ICONSPACE 10
#define RADIUS 8
#define FONTSIZE 10
#define BGWIDTH 128
#define BGSIZE 36
#define MARGINLEFTSPACE 10
#define OPENICONSIZE 12
#define MARGINRIGHTSPACE 9
QuickSettingItem::QuickSettingItem(PluginsItemInterface *const pluginInter, QWidget *parent)
: DockItem(parent)
, m_pluginInter(pluginInter)
, m_itemKey(QuickSettingController::instance()->itemKey(pluginInter))
{
setAcceptDrops(true);
this->installEventFilter(this);
}
QuickSettingItem::~QuickSettingItem()
{
}
PluginsItemInterface *QuickSettingItem::pluginItem() const
{
return m_pluginInter;
}
DockItem::ItemType QuickSettingItem::itemType() const
{
return DockItem::QuickSettingPlugin;
}
const QPixmap QuickSettingItem::dragPixmap()
{
return grab();
}
const QString QuickSettingItem::itemKey() const
{
return m_itemKey;
}
void QuickSettingItem::paintEvent(QPaintEvent *e)
{
QWidget::paintEvent(e);
QPainter painter(this);
painter.setRenderHint(QPainter::RenderHint::Antialiasing);
painter.setPen(foregroundColor());
QPainterPath path;
path.addRoundedRect(rect(), RADIUS, RADIUS);
painter.setClipPath(path);
// 绘制背景色
DPalette dpa = DPaletteHelper::instance()->palette(this);
painter.fillRect(rect(), Qt::white);
}
QColor QuickSettingItem::foregroundColor() const
{
DPalette dpa = DPaletteHelper::instance()->palette(this);
// 此处的颜色是临时获取的,后期需要和设计师确认,改成正规的颜色
if (m_pluginInter->status() == PluginsItemInterface::PluginMode::Active)
return dpa.color(DPalette::ColorGroup::Active, DPalette::ColorRole::Text);
if (m_pluginInter->status() == PluginsItemInterface::PluginMode::Deactive)
return dpa.color(DPalette::ColorGroup::Disabled, DPalette::ColorRole::Text);
return dpa.color(DPalette::ColorGroup::Normal, DPalette::ColorRole::Text);
}

View File

@ -1,64 +0,0 @@
/*
* 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/>.
*/
#ifndef QUICKSETTINGITEM_H
#define QUICKSETTINGITEM_H
#include "dockitem.h"
class PluginsItemInterface;
class QuickIconWidget;
class QuickSettingItem : public DockItem
{
Q_OBJECT
public:
enum class QuickSettingType {
Single = 1, // 插件的UI显示单列
Multi = 2, // 插件的UI显示双列例如网络和蓝牙等
Full = 4 // 插件的UI整行显示例如声音亮度、音乐播放等
};
public:
QuickSettingItem(PluginsItemInterface *const pluginInter, QWidget *parent = nullptr);
~QuickSettingItem() override;
PluginsItemInterface *pluginItem() const;
ItemType itemType() const override;
virtual const QPixmap dragPixmap();
virtual void updateShow() {}
virtual void detachPlugin() {}
const QString itemKey() const;
virtual QuickSettingType type() const = 0;
Q_SIGNALS:
void requestShowChildWidget(QWidget *);
protected:
void paintEvent(QPaintEvent *e) override;
QColor foregroundColor() const;
private:
PluginsItemInterface *m_pluginInter;
QString m_itemKey;
};
#endif // QUICKSETTINGITEM_H

View File

@ -1,213 +0,0 @@
/*
* 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 "pluginadapter.h"
#include <QWidget>
#define ICONWIDTH 24
#define ICONHEIGHT 24
PluginAdapter::PluginAdapter(PluginsItemInterface_V20 *pluginInter, QPluginLoader *pluginLoader)
: m_pluginInter(pluginInter)
, m_pluginLoader(pluginLoader)
{
}
PluginAdapter::~PluginAdapter()
{
delete m_pluginInter;
}
const QString PluginAdapter::pluginName() const
{
return m_pluginInter->pluginName();
}
const QString PluginAdapter::pluginDisplayName() const
{
return m_pluginInter->pluginDisplayName();
}
void PluginAdapter::init(PluginProxyInterface *proxyInter)
{
m_pluginInter->init(proxyInter);
}
QWidget *PluginAdapter::itemWidget(const QString &itemKey)
{
return m_pluginInter->itemWidget(itemKey);
}
QWidget *PluginAdapter::itemTipsWidget(const QString &itemKey)
{
return m_pluginInter->itemTipsWidget(itemKey);
}
QWidget *PluginAdapter::itemPopupApplet(const QString &itemKey)
{
return m_pluginInter->itemPopupApplet(itemKey);
}
const QString PluginAdapter::itemCommand(const QString &itemKey)
{
return m_pluginInter->itemCommand(itemKey);
}
const QString PluginAdapter::itemContextMenu(const QString &itemKey)
{
return m_pluginInter->itemContextMenu(itemKey);
}
void PluginAdapter::invokedMenuItem(const QString &itemKey, const QString &menuId, const bool checked)
{
m_pluginInter->invokedMenuItem(itemKey, menuId, checked);
}
int PluginAdapter::itemSortKey(const QString &itemKey)
{
return m_pluginInter->itemSortKey(itemKey);
}
void PluginAdapter::setSortKey(const QString &itemKey, const int order)
{
m_pluginInter->setSortKey(itemKey, order);
}
bool PluginAdapter::itemAllowContainer(const QString &itemKey)
{
return m_pluginInter->itemAllowContainer(itemKey);
}
bool PluginAdapter::itemIsInContainer(const QString &itemKey)
{
return m_pluginInter->itemIsInContainer(itemKey);
}
void PluginAdapter::setItemIsInContainer(const QString &itemKey, const bool container)
{
m_pluginInter->setItemIsInContainer(itemKey, container);
}
bool PluginAdapter::pluginIsAllowDisable()
{
return m_pluginInter->pluginIsAllowDisable();
}
bool PluginAdapter::pluginIsDisable()
{
return m_pluginInter->pluginIsDisable();
}
void PluginAdapter::pluginStateSwitched()
{
m_pluginInter->pluginStateSwitched();
}
void PluginAdapter::displayModeChanged(const Dock::DisplayMode displayMode)
{
m_pluginInter->displayModeChanged(displayMode);
}
void PluginAdapter::positionChanged(const Dock::Position position)
{
m_pluginInter->positionChanged(position);
}
void PluginAdapter::refreshIcon(const QString &itemKey)
{
m_pluginInter->refreshIcon(itemKey);
}
void PluginAdapter::pluginSettingsChanged()
{
m_pluginInter->pluginSettingsChanged();
}
PluginsItemInterface::PluginType PluginAdapter::type()
{
switch (m_pluginInter->type()) {
case PluginsItemInterface_V20::PluginType::Fixed:
return PluginsItemInterface::PluginType::Fixed;
case PluginsItemInterface_V20::PluginType::Normal:
return PluginsItemInterface::PluginType::Normal;
}
return PluginsItemInterface::PluginType::Normal;
}
PluginsItemInterface::PluginSizePolicy PluginAdapter::pluginSizePolicy() const
{
switch (m_pluginInter->pluginSizePolicy()) {
case PluginsItemInterface_V20::PluginSizePolicy::Custom:
return PluginsItemInterface::PluginSizePolicy::Custom;
case PluginsItemInterface_V20::PluginSizePolicy::System:
return PluginsItemInterface::PluginSizePolicy::System;
}
return PluginsItemInterface::PluginSizePolicy::Custom;
}
QIcon PluginAdapter::icon(const DockPart &dockPart, DGuiApplicationHelper::ColorType themeType)
{
QWidget *itemWidget = m_pluginInter->itemWidget(m_itemKey);
if (!itemWidget)
return QIcon();
switch (dockPart) {
case DockPart::QuickPanel:
case DockPart::SystemPanel: {
// 如果是托盘插件则让他返回空图标直接将QWidget展示
if (m_pluginLoader->fileName().contains(TRAY_PATH))
return QIcon();
// 如果图标为空就使用itemWidget的截图作为它的图标这种一般是适用于老版本插件或者没有实现v23接口的插件
QSize oldSize = itemWidget->size();
itemWidget->setFixedSize(ICONWIDTH / qApp->devicePixelRatio(), ICONHEIGHT / qApp->devicePixelRatio());
QPixmap pixmap = itemWidget->grab();
itemWidget->setFixedSize(oldSize);
return pixmap;
}
default: break;
}
return QIcon();
}
PluginsItemInterface::PluginMode PluginAdapter::status() const
{
return PluginMode::Active;
}
QString PluginAdapter::description() const
{
return m_pluginInter->pluginDisplayName();
}
PluginFlags PluginAdapter::flags() const
{
if (m_pluginLoader->fileName().contains(TRAY_PATH))
return PluginFlag::Type_Tray | PluginFlag::Attribute_CanDrag | PluginFlag::Attribute_CanInsert;
return PluginsItemInterface::flags();
}
void PluginAdapter::setItemKey(const QString &itemKey)
{
m_itemKey = itemKey;
}

View File

@ -1,81 +0,0 @@
/*
* 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/>.
*/
#ifndef PLUGINADAPTER_H
#define PLUGINADAPTER_H
#include "pluginsiteminterface.h"
#include "pluginsiteminterface_v20.h"
#include <QObject>
/** 适配器当加载到v20插件的时候通过该接口来转成v23接口的插件
* @brief The PluginAdapter class
*/
class PluginAdapter : public QObject, public PluginsItemInterface
{
Q_OBJECT
Q_INTERFACES(PluginsItemInterface)
public:
PluginAdapter(PluginsItemInterface_V20 *pluginInter, QPluginLoader *pluginLoader);
~PluginAdapter();
const QString pluginName() const override;
const QString pluginDisplayName() const override;
void init(PluginProxyInterface *proxyInter) override;
QWidget *itemWidget(const QString &itemKey) override;
QWidget *itemTipsWidget(const QString &itemKey) override;
QWidget *itemPopupApplet(const QString &itemKey) override;
const QString itemCommand(const QString &itemKey) override;
const QString itemContextMenu(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;
bool itemAllowContainer(const QString &itemKey) override;
bool itemIsInContainer(const QString &itemKey) override;
void setItemIsInContainer(const QString &itemKey, const bool container) override;
bool pluginIsAllowDisable() override;
bool pluginIsDisable() override;
void pluginStateSwitched() override;
void displayModeChanged(const Dock::DisplayMode displayMode) override;
void positionChanged(const Dock::Position position) override;
void refreshIcon(const QString &itemKey) override;
void pluginSettingsChanged() override;
PluginType type() override;
PluginSizePolicy pluginSizePolicy() const override;
QIcon icon(const DockPart &dockPart, DGuiApplicationHelper::ColorType themeType) override;
PluginMode status() const override;
QString description() const override;
PluginFlags flags() const override;
void setItemKey(const QString &itemKey);
private:
PluginsItemInterface_V20 *m_pluginInter;
QString m_itemKey;
QPluginLoader *m_pluginLoader;
};
#endif // PLUGINADAPTER_H

View File

@ -1,261 +0,0 @@
/*
* Copyright (C) 2011 ~ 2018 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/>.
*/
#ifndef PLUGINSITEMINTERFACE_V20_H
#define PLUGINSITEMINTERFACE_V20_H
#include "pluginproxyinterface.h"
#include <QIcon>
#include <QtCore>
///
/// \brief The PluginsItemInterface_V20 class
/// the dock plugins item interface, all dock plugins should
/// inheirt this class and override all pure virtual function.
///
class PluginsItemInterface_V20
{
public:
enum PluginType {
Normal,
Fixed
};
/**
* @brief Plugin size policy
*/
enum PluginSizePolicy {
System = 1 << 0, // Follow the system
Custom = 1 << 1 // The custom
};
///
/// \brief ~PluginsItemInterface_V20
/// DON'T try to delete m_proxyInter.
///
virtual ~PluginsItemInterface_V20() {}
///
/// \brief pluginName
/// tell dock the unique plugin id
/// \return
///
virtual const QString pluginName() const = 0;
virtual const QString pluginDisplayName() const { return QString(); }
///
/// \brief init
/// init your plugins, you need to save proxyInter to m_proxyInter
/// member variable. but you shouldn't free this pointer.
/// \param proxyInter
/// DON'T try to delete this pointer.
///
virtual void init(PluginProxyInterface *proxyInter) = 0;
///
/// \brief itemWidget
/// your plugin item widget, each item should have a unique key.
/// \param itemKey
/// your widget' unqiue key.
/// \return
///
virtual QWidget *itemWidget(const QString &itemKey) = 0;
///
/// \brief itemTipsWidget
/// override this function if your item want to have a tips.
/// the tips will shown when user hover your item.
/// nullptr will be ignored.
/// \param itemKey
/// \return
///
virtual QWidget *itemTipsWidget(const QString &itemKey) {Q_UNUSED(itemKey); return nullptr;}
///
/// \brief itemPopupApplet
/// override this function if your item wants to have an popup applet.
/// the popup applet will shown when user click your item.
///
/// Tips:
/// dock should receive mouse press/release event to check user mouse operate,
/// if your item filter mouse event, this function will not be called.
/// so if you override mouse event and want to use popup applet, you
/// should pass event to your parent use QWidget::someEvent(e);
/// \param itemKey
/// \return
///
virtual QWidget *itemPopupApplet(const QString &itemKey) {Q_UNUSED(itemKey); return nullptr;}
///
/// \brief itemCommand
/// execute spec command when user clicked your item.
/// ensure your command do not get user input.
///
/// empty string will be ignored.
/// \param itemKey
/// \return
///
virtual const QString itemCommand(const QString &itemKey) {Q_UNUSED(itemKey); return QString();}
///
/// \brief itemContextMenu
/// context menu is shown when RequestPopupMenu called.
/// \param itemKey
/// \return
///
virtual const QString itemContextMenu(const QString &itemKey) {Q_UNUSED(itemKey); return QString();}
///
/// \brief invokedMenuItem
/// call if context menu item is clicked
/// \param itemKey
/// \param itemId
/// menu item id
/// \param checked
///
virtual void invokedMenuItem(const QString &itemKey, const QString &menuId, const bool checked) {Q_UNUSED(itemKey); Q_UNUSED(menuId); Q_UNUSED(checked);}
///
/// \brief itemSortKey
/// tell dock where your item wants to put on.
///
/// this index is start from 1 and
/// 0 for left side
/// -1 for right side
/// \param itemKey
/// \return
///
virtual int itemSortKey(const QString &itemKey) {Q_UNUSED(itemKey); return 1;}
///
/// \brief setSortKey
/// save your item new position
/// sort key will be changed when plugins order
/// changed(by user drag-drop)
/// \param itemKey
/// \param order
///
virtual void setSortKey(const QString &itemKey, const int order) {Q_UNUSED(itemKey); Q_UNUSED(order);}
///
/// \brief itemAllowContainer
/// tell dock is your item allow to move into container
///
/// if your item placed into container, popup tips and popup
/// applet will be disabled.
/// \param itemKey
/// \return
///
virtual bool itemAllowContainer(const QString &itemKey) {Q_UNUSED(itemKey); return false;}
///
/// \brief itemIsInContainer
/// tell dock your item is in container, this function
/// called at item init and if your item enable container.
/// \param itemKey
/// \return
///
virtual bool itemIsInContainer(const QString &itemKey) {Q_UNUSED(itemKey); return false;}
///
/// \brief setItemIsInContainer
/// save your item new state.
/// this function called when user drag out your item from
/// container or user drop item into container(if your item
/// allow drop into container).
/// \param itemKey
/// \param container
///
virtual void setItemIsInContainer(const QString &itemKey, const bool container) {Q_UNUSED(itemKey); Q_UNUSED(container);}
virtual bool pluginIsAllowDisable() { return false; }
virtual bool pluginIsDisable() { return false; }
virtual void pluginStateSwitched() {}
///
/// \brief displayModeChanged
/// override this function to receive display mode changed signal
/// \param displayMode
///
virtual void displayModeChanged(const Dock::DisplayMode displayMode) {Q_UNUSED(displayMode);}
///
/// \brief positionChanged
/// override this function to receive dock position changed signal
/// \param position
///
virtual void positionChanged(const Dock::Position position) {Q_UNUSED(position);}
///
/// \brief refreshIcon
/// refresh item icon, its triggered when system icon theme changed.
/// \param itemKey
/// item key
///
virtual void refreshIcon(const QString &itemKey) { Q_UNUSED(itemKey); }
///
/// \brief displayMode
/// get current dock display mode
/// \return
///
inline Dock::DisplayMode displayMode() const
{
return qApp->property(PROP_DISPLAY_MODE).value<Dock::DisplayMode>();
}
///
/// \brief position
/// get current dock position
/// \return
///
inline Dock::Position position() const
{
return qApp->property(PROP_POSITION).value<Dock::Position>();
}
///
/// \brief settingsChanged
/// override this function to receive plugin settings changed signal(DeepinSync)
///
virtual void pluginSettingsChanged() {}
///
/// \brief type
/// default plugin add dock right,fixed plugin add to dock fixed area
///
virtual PluginType type() { return Normal; }
///
/// \brief plugin size policy
/// default plugin size policy
///
virtual PluginSizePolicy pluginSizePolicy() const { return System; }
protected:
///
/// \brief m_proxyInter
/// NEVER delete this object.
///
PluginProxyInterface *m_proxyInter = nullptr;
};
QT_BEGIN_NAMESPACE
#define ModuleInterfaceV20_iid "com.deepin.dock.PluginsItemInterface"
Q_DECLARE_INTERFACE(PluginsItemInterface_V20, ModuleInterfaceV20_iid)
QT_END_NAMESPACE
#endif // PLUGINSITEMINTERFACE_H

View File

@ -1,121 +0,0 @@
/*
* 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 "pluginchildpage.h"
#include <QLabel>
#include <QVBoxLayout>
#include <QEvent>
PluginChildPage::PluginChildPage(QWidget *parent)
: QWidget(parent)
, m_headerWidget(new QWidget(this))
, m_back(new QLabel(m_headerWidget))
, m_title(new QLabel(m_headerWidget))
, m_container(new QWidget(this))
, m_topWidget(nullptr)
, m_containerLayout(new QVBoxLayout(m_container))
, m_isBack(false)
{
initUi();
m_back->installEventFilter(this);
}
PluginChildPage::~PluginChildPage()
{
}
void PluginChildPage::pushWidget(QWidget *widget)
{
// 首先将界面其他的窗体移除
for (int i = m_containerLayout->count() - 1; i >= 0; i--) {
QLayoutItem *item = m_containerLayout->itemAt(i);
item->widget()->removeEventFilter(this);
item->widget()->hide();
m_containerLayout->removeItem(item);
}
m_topWidget = widget;
widget->installEventFilter(this);
m_containerLayout->addWidget(widget);
widget->show();
m_isBack = false;
QMetaObject::invokeMethod(this, &PluginChildPage::resetHeight, Qt::QueuedConnection);
}
void PluginChildPage::setTitle(const QString &text)
{
m_title->setText(text);
}
void PluginChildPage::setCanBack(bool canBack)
{
m_back->setVisible(canBack);
}
bool PluginChildPage::isBack()
{
return m_isBack;
}
void PluginChildPage::initUi()
{
m_back->setFixedWidth(24);
m_title->setAlignment(Qt::AlignCenter);
QHBoxLayout *headerLayout = new QHBoxLayout(m_headerWidget);
headerLayout->setContentsMargins(11, 12, 24 + 11, 12);
headerLayout->setSpacing(0);
headerLayout->addWidget(m_back);
headerLayout->addWidget(m_title);
m_headerWidget->setFixedHeight(48);
QVBoxLayout *mainLayout = new QVBoxLayout(this);
mainLayout->setContentsMargins(0, 0, 0, 0);
mainLayout->setSpacing(0);
mainLayout->addWidget(m_headerWidget);
mainLayout->addWidget(m_container);
m_containerLayout->setContentsMargins(11, 0, 11, 0);
m_containerLayout->setSpacing(0);
}
bool PluginChildPage::eventFilter(QObject *watched, QEvent *event)
{
if (watched == m_back && event->type() == QEvent::MouseButtonRelease) {
m_isBack = true;
Q_EMIT back();
return true;
}
if (watched == m_topWidget) {
if (event->type() == QEvent::Hide) {
Q_EMIT closeSelf();
return true;
}
if (event->type() == QEvent::Resize)
resetHeight();
}
return QWidget::eventFilter(watched, event);
}
void PluginChildPage::resetHeight()
{
QMargins m = m_containerLayout->contentsMargins();
m_container->setFixedHeight(m.top() + m.bottom() + m_topWidget->height());
setFixedHeight(m_headerWidget->height() + m_container->height());
}

View File

@ -1,62 +0,0 @@
/*
* 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/>.
*/
#ifndef PLUGINCHILDPAGE_H
#define PLUGINCHILDPAGE_H
#include <QWidget>
class QLabel;
class QVBoxLayout;
class PluginChildPage : public QWidget
{
Q_OBJECT
public:
explicit PluginChildPage(QWidget *parent);
~PluginChildPage() override;
void pushWidget(QWidget *widget);
void setTitle(const QString &text);
void setCanBack(bool canBack);
bool isBack();
Q_SIGNALS:
void back();
void closeSelf();
protected:
bool eventFilter(QObject *watched, QEvent *event) override;
private:
void initUi();
void resetHeight();
private:
QWidget *m_headerWidget;
QLabel *m_back;
QLabel *m_title;
QWidget *m_container;
QWidget *m_topWidget;
QVBoxLayout *m_containerLayout;
bool m_isBack;
};
#endif // PLUGINCHILDPAGE_H

View File

@ -20,7 +20,6 @@
*/
#include "quickpluginwindow.h"
#include "quicksettingcontroller.h"
#include "quicksettingitem.h"
#include "pluginsiteminterface.h"
#include "appdrag.h"
#include "quickpluginmodel.h"