mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-03 00:15:21 +00:00
feat: 增加工具区域的使用
时尚模式下,在最近使用区域右侧增加工具区域的功能,时尚模式切换到高效模式后,高效模式依然显示原来的区域 Log: 时尚模式下增加工具区域 Influence: 时尚模式下,查看最近打开区域右侧是否显示回收站,来回切换时尚模式与高效模式,查看回收站位置是否发生变化 Task: https://pms.uniontech.com/task-view-152867.html Change-Id: Icaf77f09b737ca9473767fa876883ac0fdddb1ad
This commit is contained in:
parent
a4172e6763
commit
301e515319
@ -60,18 +60,17 @@ void DockPluginsController::itemAdded(PluginsItemInterface *const itemInter, con
|
||||
return;
|
||||
|
||||
const QJsonObject &meta = pluginLoader->metaData().value("MetaData").toObject();
|
||||
const QString &pluginApi = meta.value("api").toString();
|
||||
|
||||
PluginsItem *item = nullptr;
|
||||
if (itemInter->pluginName() == "tray") {
|
||||
item = new TrayPluginItem(itemInter, itemKey, pluginApi);
|
||||
item = new TrayPluginItem(itemInter, itemKey, meta);
|
||||
if (item->graphicsEffect()) {
|
||||
item->graphicsEffect()->setEnabled(false);
|
||||
}
|
||||
connect(static_cast<TrayPluginItem *>(item), &TrayPluginItem::trayVisableCountChanged,
|
||||
this, &DockPluginsController::trayVisableCountChanged, Qt::UniqueConnection);
|
||||
} else {
|
||||
item = new PluginsItem(itemInter, itemKey, pluginApi);
|
||||
item = new PluginsItem(itemInter, itemKey, meta);
|
||||
}
|
||||
|
||||
mPluginsMap[itemInter][itemKey] = item;
|
||||
|
256
frame/controller/toolapphelper.cpp
Normal file
256
frame/controller/toolapphelper.cpp
Normal file
@ -0,0 +1,256 @@
|
||||
/*
|
||||
* 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 "toolapphelper.h"
|
||||
#include "dockitem.h"
|
||||
#include "pluginsitem.h"
|
||||
|
||||
#include <QWidget>
|
||||
#include <QBoxLayout>
|
||||
|
||||
ToolAppHelper::ToolAppHelper(QWidget *pluginAreaWidget, QWidget *toolAreaWidget, QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_pluginAreaWidget(pluginAreaWidget)
|
||||
, m_toolAreaWidget(toolAreaWidget)
|
||||
, m_displayMode(DisplayMode::Efficient)
|
||||
, m_trashItem(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
void ToolAppHelper::setDisplayMode(DisplayMode displayMode)
|
||||
{
|
||||
m_displayMode = displayMode;
|
||||
resetPluginItems();
|
||||
updateWidgetStatus();
|
||||
}
|
||||
|
||||
void ToolAppHelper::addPluginItem(int index, DockItem *dockItem)
|
||||
{
|
||||
if (pluginInTool(dockItem))
|
||||
appendToToolArea(index, dockItem);
|
||||
else
|
||||
appendToPluginArea(index, dockItem);
|
||||
|
||||
// 将插件指针顺序保存到列表中
|
||||
if (index >= 0 && index < m_sequentPluginItems.size())
|
||||
m_sequentPluginItems.insert(index, dockItem);
|
||||
else
|
||||
m_sequentPluginItems << dockItem;
|
||||
|
||||
// 保存垃圾箱插件指针
|
||||
PluginsItem *pluginsItem = qobject_cast<PluginsItem *>(dockItem);
|
||||
if (pluginsItem && pluginsItem->pluginName() == "trash")
|
||||
m_trashItem = pluginsItem;
|
||||
|
||||
if (!toolIsVisible())
|
||||
updateWidgetStatus();
|
||||
|
||||
Q_EMIT requestUpdate();
|
||||
}
|
||||
|
||||
void ToolAppHelper::removePluginItem(DockItem *dockItem)
|
||||
{
|
||||
if (dockItem == m_trashItem)
|
||||
m_trashItem = nullptr;
|
||||
|
||||
if (!removePluginArea(dockItem))
|
||||
removeToolArea(dockItem);
|
||||
|
||||
if (m_toolAreaWidget->layout()->count() == 0 && toolIsVisible())
|
||||
updateWidgetStatus();
|
||||
|
||||
Q_EMIT requestUpdate();
|
||||
}
|
||||
|
||||
PluginsItem *ToolAppHelper::trashPlugin() const
|
||||
{
|
||||
return m_trashItem;
|
||||
}
|
||||
|
||||
bool ToolAppHelper::toolIsVisible() const
|
||||
{
|
||||
return m_toolAreaWidget->isVisible();
|
||||
}
|
||||
|
||||
void ToolAppHelper::appendToPluginArea(int index, DockItem *dockItem)
|
||||
{
|
||||
// 因为日期时间插件和其他插件的大小有异,为了方便设置边距,在插件区域布局再添加一层布局设置边距
|
||||
// 因此在处理插件图标时,需要通过两层布局判断是否为需要的插件,例如拖动插件位置等判断
|
||||
QBoxLayout *boxLayout = new QBoxLayout(QBoxLayout::LeftToRight, m_pluginAreaWidget);
|
||||
boxLayout->addWidget(dockItem, 0, Qt::AlignCenter);
|
||||
QBoxLayout *pluginLayout = static_cast<QBoxLayout *>(m_pluginAreaWidget->layout());
|
||||
pluginLayout->insertLayout(index, boxLayout, 0);
|
||||
}
|
||||
|
||||
void ToolAppHelper::appendToToolArea(int index, DockItem *dockItem)
|
||||
{
|
||||
QBoxLayout *boxLayout = static_cast<QBoxLayout *>(m_toolAreaWidget->layout());
|
||||
if (index >= 0)
|
||||
boxLayout->insertWidget(index, dockItem);
|
||||
else
|
||||
boxLayout->addWidget(dockItem);
|
||||
}
|
||||
|
||||
bool ToolAppHelper::removePluginArea(DockItem *dockItem)
|
||||
{
|
||||
bool removeResult = false;
|
||||
QBoxLayout *pluginLayout = static_cast<QBoxLayout *>(m_pluginAreaWidget->layout());
|
||||
for (int i = 0; i < pluginLayout->count(); ++i) {
|
||||
QLayoutItem *layoutItem = pluginLayout->itemAt(i);
|
||||
QLayout *boxLayout = layoutItem->layout();
|
||||
if (boxLayout && boxLayout->itemAt(0)->widget() == dockItem) {
|
||||
boxLayout->removeWidget(dockItem);
|
||||
pluginLayout->removeItem(layoutItem);
|
||||
delete layoutItem;
|
||||
layoutItem = nullptr;
|
||||
removeResult = true;
|
||||
}
|
||||
}
|
||||
|
||||
return removeResult;
|
||||
}
|
||||
|
||||
bool ToolAppHelper::removeToolArea(DockItem *dockItem)
|
||||
{
|
||||
QBoxLayout *boxLayout = static_cast<QBoxLayout *>(m_toolAreaWidget->layout());
|
||||
for (int i = 0; i < boxLayout->count(); i++) {
|
||||
if (boxLayout->itemAt(i)->widget() == dockItem) {
|
||||
boxLayout->removeWidget(dockItem);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ToolAppHelper::resetPluginItems()
|
||||
{
|
||||
if (m_displayMode == DisplayMode::Efficient) {
|
||||
// 高效模式下, 让工具区域的插件移动到插件区域显示
|
||||
QList<DockItem *> dockItems = dockItemOnWidget(true);
|
||||
for (DockItem *dockItem : dockItems) {
|
||||
// 从工具列表中移除插件, 将这些插件放入到插件区域
|
||||
removeToolArea(dockItem);
|
||||
int index = itemIndex(dockItem, false);
|
||||
appendToPluginArea(index, dockItem);
|
||||
}
|
||||
} else {
|
||||
// 时尚模式下,将插件区域对应的插件移动到工具区域
|
||||
QList<DockItem *> dockItems = dockItemOnWidget(false);
|
||||
for (DockItem *dockItem : dockItems) {
|
||||
if (!pluginInTool(dockItem))
|
||||
continue;
|
||||
|
||||
// 从插件区域中移除相关插件,并将其插入到工具区域中
|
||||
removePluginArea(dockItem);
|
||||
int index = itemIndex(dockItem, true);
|
||||
appendToToolArea(index, dockItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ToolAppHelper::updateWidgetStatus()
|
||||
{
|
||||
bool oldVisible = toolIsVisible();
|
||||
if (m_displayMode == DisplayMode::Efficient) {
|
||||
// 高效模式
|
||||
m_pluginAreaWidget->setVisible(true);
|
||||
m_toolAreaWidget->setVisible(false);
|
||||
} else {
|
||||
// 时尚模式
|
||||
m_pluginAreaWidget->setVisible(false);
|
||||
m_toolAreaWidget->setVisible(m_toolAreaWidget->layout()->count() > 0);
|
||||
}
|
||||
bool visible = toolIsVisible();
|
||||
if (oldVisible != visible)
|
||||
Q_EMIT toolVisibleChanged(visible);
|
||||
}
|
||||
|
||||
bool ToolAppHelper::pluginInTool(DockItem *dockItem) const
|
||||
{
|
||||
if (m_displayMode != DisplayMode::Fashion)
|
||||
return false;
|
||||
|
||||
PluginsItem *pluginItem = qobject_cast<PluginsItem *>(dockItem);
|
||||
if (!pluginItem)
|
||||
return false;
|
||||
|
||||
QJsonObject metaData = pluginItem->metaData();
|
||||
if (metaData.contains("tool"))
|
||||
return metaData.value("tool").toBool();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ToolAppHelper::itemIndex 返回该插件在工具区域(isTool == true)或插件区域(isTool == false)的正确位置
|
||||
* @param dockItem
|
||||
* @param isTool
|
||||
* @return
|
||||
*/
|
||||
int ToolAppHelper::itemIndex(DockItem *dockItem, bool isTool) const
|
||||
{
|
||||
int index = m_sequentPluginItems.indexOf(dockItem);
|
||||
if (index < 0 || index >= m_sequentPluginItems.size() - 1)
|
||||
return -1;
|
||||
|
||||
QList<DockItem *> dockItems = dockItemOnWidget(isTool);
|
||||
for (int i = index + 1; i < m_sequentPluginItems.size(); i++) {
|
||||
DockItem *nextItem = m_sequentPluginItems[i];
|
||||
if (dockItems.contains(nextItem)) {
|
||||
// 如果当前包含当前插入的下一个item,则直接返回下一个item的插入位置
|
||||
return dockItems.indexOf(nextItem);
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
QList<DockItem *> ToolAppHelper::dockItemOnWidget(bool isTool) const
|
||||
{
|
||||
QList<DockItem *> dockItems;
|
||||
if (isTool) {
|
||||
QLayout *layout = m_toolAreaWidget->layout();
|
||||
for (int i = 0; i < layout->count(); i++) {
|
||||
DockItem *dockItem = qobject_cast<DockItem *>(layout->itemAt(i)->widget());
|
||||
if (!dockItem)
|
||||
continue;
|
||||
|
||||
dockItems << dockItem;
|
||||
}
|
||||
} else {
|
||||
QBoxLayout *pluginLayout = static_cast<QBoxLayout *>(m_pluginAreaWidget->layout());
|
||||
for (int i = 0; i < pluginLayout->count(); ++i) {
|
||||
QLayoutItem *layoutItem = pluginLayout->itemAt(i);
|
||||
QLayout *boxLayout = layoutItem->layout();
|
||||
if (!boxLayout)
|
||||
continue;
|
||||
|
||||
DockItem *dockItem = qobject_cast<DockItem *>(boxLayout->itemAt(0)->widget());
|
||||
if (!dockItem)
|
||||
continue;
|
||||
|
||||
dockItems << dockItem;
|
||||
}
|
||||
}
|
||||
|
||||
return dockItems;
|
||||
}
|
72
frame/controller/toolapphelper.h
Normal file
72
frame/controller/toolapphelper.h
Normal file
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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 TOOLAPPHELPER_H
|
||||
#define TOOLAPPHELPER_H
|
||||
|
||||
#include "constants.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class QWidget;
|
||||
class DockItem;
|
||||
class PluginsItem;
|
||||
|
||||
using namespace Dock;
|
||||
|
||||
class ToolAppHelper : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ToolAppHelper(QWidget *pluginAreaWidget, QWidget *toolAreaWidget, QObject *parent = nullptr);
|
||||
|
||||
void setDisplayMode(DisplayMode displayMode);
|
||||
void addPluginItem(int index, DockItem *dockItem);
|
||||
void removePluginItem(DockItem *dockItem);
|
||||
PluginsItem *trashPlugin() const;
|
||||
bool toolIsVisible() const;
|
||||
|
||||
Q_SIGNALS:
|
||||
void requestUpdate();
|
||||
void toolVisibleChanged(bool);
|
||||
|
||||
private:
|
||||
void appendToPluginArea(int index, DockItem *dockItem);
|
||||
void appendToToolArea(int index, DockItem *dockItem);
|
||||
bool removePluginArea(DockItem *dockItem);
|
||||
bool removeToolArea(DockItem *dockItem);
|
||||
|
||||
void resetPluginItems();
|
||||
void updateWidgetStatus();
|
||||
bool pluginInTool(DockItem *dockItem) const;
|
||||
int itemIndex(DockItem *dockItem, bool isTool) const;
|
||||
QList<DockItem *> dockItemOnWidget(bool isTool) const;
|
||||
|
||||
private:
|
||||
QWidget *m_pluginAreaWidget;
|
||||
QWidget *m_toolAreaWidget;
|
||||
DisplayMode m_displayMode;
|
||||
PluginsItem *m_trashItem;
|
||||
QList<DockItem *> m_sequentPluginItems;
|
||||
};
|
||||
|
||||
#endif // TOOLAPPHELPER_H
|
@ -37,11 +37,11 @@
|
||||
|
||||
QPoint PluginsItem::MousePressPoint = QPoint();
|
||||
|
||||
PluginsItem::PluginsItem(PluginsItemInterface *const pluginInter, const QString &itemKey, const QString &plginApi, QWidget *parent)
|
||||
PluginsItem::PluginsItem(PluginsItemInterface *const pluginInter, const QString &itemKey, const QJsonObject &jsonData, QWidget *parent)
|
||||
: DockItem(parent)
|
||||
, m_pluginInter(pluginInter)
|
||||
, m_centralWidget(m_pluginInter->itemWidget(itemKey))
|
||||
, m_pluginApi(plginApi)
|
||||
, m_jsonData(jsonData)
|
||||
, m_itemKey(itemKey)
|
||||
, m_dragging(false)
|
||||
, m_gsettings(Utils::ModuleSettingsPtr(pluginInter->pluginName(), QByteArray(), this))
|
||||
@ -95,7 +95,7 @@ QString PluginsItem::pluginName() const
|
||||
PluginsItemInterface::PluginSizePolicy PluginsItem::pluginSizePolicy() const
|
||||
{
|
||||
// 插件版本大于 1.2.2 才能使用 PluginsItemInterface::pluginSizePolicy 函数
|
||||
if (Utils::comparePluginApi(m_pluginApi, "1.2.2") > 0) {
|
||||
if (Utils::comparePluginApi(pluginApi(), "1.2.2") > 0) {
|
||||
return m_pluginInter->pluginSizePolicy();
|
||||
} else {
|
||||
return PluginsItemInterface::System;
|
||||
@ -308,6 +308,11 @@ bool PluginsItem::checkGSettingsControl() const
|
||||
return m_gsettings ? m_gsettings->keys().contains("control") && m_gsettings->get("control").toBool() : false;
|
||||
}
|
||||
|
||||
QString PluginsItem::pluginApi() const
|
||||
{
|
||||
return m_jsonData.value("api").toString();
|
||||
}
|
||||
|
||||
void PluginsItem::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
setMaximumSize(m_centralWidget->maximumSize());
|
||||
@ -325,3 +330,8 @@ PluginsItemInterface *PluginsItem::pluginItem() const
|
||||
{
|
||||
return m_pluginInter;
|
||||
}
|
||||
|
||||
QJsonObject PluginsItem::metaData() const
|
||||
{
|
||||
return m_jsonData;
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ class PluginsItem : public DockItem
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit PluginsItem(PluginsItemInterface *const pluginInter, const QString &itemKey, const QString &plginApi, QWidget *parent = nullptr);
|
||||
explicit PluginsItem(PluginsItemInterface *const pluginInter, const QString &itemKey, const QJsonObject &jsonData, QWidget *parent = nullptr);
|
||||
~PluginsItem() override;
|
||||
|
||||
int itemSortKey() const;
|
||||
@ -53,6 +53,8 @@ public:
|
||||
|
||||
PluginsItemInterface *pluginItem() const;
|
||||
|
||||
QJsonObject metaData() const;
|
||||
|
||||
public slots:
|
||||
void refreshIcon() override;
|
||||
|
||||
@ -78,12 +80,13 @@ private:
|
||||
void startDrag();
|
||||
void mouseClicked();
|
||||
bool checkGSettingsControl() const;
|
||||
QString pluginApi() const;
|
||||
|
||||
private:
|
||||
PluginsItemInterface *const m_pluginInter;
|
||||
QWidget *m_centralWidget;
|
||||
|
||||
const QString m_pluginApi;
|
||||
QJsonObject m_jsonData;
|
||||
const QString m_itemKey;
|
||||
bool m_dragging;
|
||||
|
||||
|
@ -24,8 +24,8 @@
|
||||
|
||||
#include <QEvent>
|
||||
|
||||
TrayPluginItem::TrayPluginItem(PluginsItemInterface * const pluginInter, const QString &itemKey, const QString &pluginApi, QWidget *parent)
|
||||
: PluginsItem(pluginInter, itemKey, pluginApi, parent)
|
||||
TrayPluginItem::TrayPluginItem(PluginsItemInterface * const pluginInter, const QString &itemKey, const QJsonObject &metaData, QWidget *parent)
|
||||
: PluginsItem(pluginInter, itemKey, metaData, parent)
|
||||
{
|
||||
centralWidget()->installEventFilter(this);
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ class TrayPluginItem : public PluginsItem
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TrayPluginItem(PluginsItemInterface* const pluginInter, const QString &itemKey, const QString &pluginApi, QWidget *parent = nullptr);
|
||||
TrayPluginItem(PluginsItemInterface* const pluginInter, const QString &itemKey, const QJsonObject &metaData, QWidget *parent = nullptr);
|
||||
|
||||
inline ItemType itemType() const override {return ItemType::TrayPlugin;}
|
||||
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include "multiscreenworker.h"
|
||||
#include "displaymanager.h"
|
||||
#include "recentapphelper.h"
|
||||
#include "toolapphelper.h"
|
||||
|
||||
#include <QDrag>
|
||||
#include <QTimer>
|
||||
@ -87,6 +88,9 @@ MainPanelControl::MainPanelControl(QWidget *parent)
|
||||
, m_pluginAreaWidget(new QWidget(this))
|
||||
, m_recentAreaWidget(new QWidget(this))
|
||||
, m_recentLayout(new QBoxLayout(QBoxLayout::LeftToRight, this))
|
||||
, m_recentSpliter(new QLabel(this))
|
||||
, m_toolAreaWidget(new QWidget(this))
|
||||
, m_toolLayout(new QBoxLayout(QBoxLayout::LeftToRight, m_toolAreaWidget))
|
||||
, m_trayManagerWidget(new TrayManagerWindow(this))
|
||||
, m_pluginLayout(new QBoxLayout(QBoxLayout::LeftToRight, this))
|
||||
, m_desktopWidget(new DesktopWidget(this))
|
||||
@ -95,9 +99,9 @@ MainPanelControl::MainPanelControl(QWidget *parent)
|
||||
, m_appDragWidget(nullptr)
|
||||
, m_displayMode(Efficient)
|
||||
, m_tray(nullptr)
|
||||
, m_trashItem(nullptr)
|
||||
, m_dockScreen(nullptr)
|
||||
, m_recentHelper(new RecentAppHelper(m_appAreaSonWidget, m_recentAreaWidget, this))
|
||||
, m_toolHelper(new ToolAppHelper(m_pluginAreaWidget, m_toolAreaWidget, this))
|
||||
{
|
||||
initUI();
|
||||
initConnection();
|
||||
@ -116,6 +120,7 @@ MainPanelControl::MainPanelControl(QWidget *parent)
|
||||
m_fixedSpliter->setFixedSize(0, 0);
|
||||
m_appSpliter ->setFixedSize(0, 0);
|
||||
m_traySpliter->setFixedSize(0, 0);
|
||||
m_recentSpliter->setFixedSize(0, 0);
|
||||
}
|
||||
|
||||
void MainPanelControl::initUI()
|
||||
@ -149,6 +154,17 @@ void MainPanelControl::initUI()
|
||||
m_recentLayout->setContentsMargins(0, 0, 0, 0);
|
||||
m_mainPanelLayout->addWidget(m_recentAreaWidget);
|
||||
|
||||
m_recentSpliter->setObjectName("spliter_recent");
|
||||
m_mainPanelLayout->addWidget(m_recentSpliter);
|
||||
|
||||
/* 工具应用 */
|
||||
m_toolAreaWidget->setObjectName("toolarea");
|
||||
m_toolAreaWidget->setAccessibleName("toolarea");
|
||||
m_toolAreaWidget->setLayout(m_toolLayout);
|
||||
m_toolLayout->setSpacing(0);
|
||||
m_toolLayout->setContentsMargins(0, 0, 0, 0);
|
||||
m_mainPanelLayout->addWidget(m_toolAreaWidget);
|
||||
|
||||
/* 托盘区域 */
|
||||
m_trayAreaWidget->setObjectName("trayarea");
|
||||
m_trayAreaWidget->setLayout(m_trayAreaLayout);
|
||||
@ -179,6 +195,7 @@ void MainPanelControl::initUI()
|
||||
m_mainPanelLayout->setAlignment(m_fixedSpliter, Qt::AlignCenter);
|
||||
m_mainPanelLayout->setAlignment(m_appSpliter, Qt::AlignCenter);
|
||||
m_mainPanelLayout->setAlignment(m_traySpliter, Qt::AlignCenter);
|
||||
m_mainPanelLayout->setAlignment(m_recentSpliter, Qt::AlignCenter);
|
||||
}
|
||||
|
||||
void MainPanelControl::initConnection()
|
||||
@ -186,6 +203,8 @@ void MainPanelControl::initConnection()
|
||||
connect(m_trayManagerWidget, &TrayManagerWindow::requestUpdate, this, &MainPanelControl::onRequestUpdate);
|
||||
connect(m_recentHelper, &RecentAppHelper::requestUpdate, this, &MainPanelControl::requestUpdate);
|
||||
connect(m_recentHelper, &RecentAppHelper::recentVisibleChanged, this, &MainPanelControl::onRecentVisibleChanged);
|
||||
connect(m_toolHelper, &ToolAppHelper::requestUpdate, this, &MainPanelControl::requestUpdate);
|
||||
connect(m_toolHelper, &ToolAppHelper::toolVisibleChanged, this, &MainPanelControl::onToolVisibleChanged);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -199,6 +218,7 @@ void MainPanelControl::setDisplayMode(DisplayMode dislayMode)
|
||||
|
||||
m_displayMode = dislayMode;
|
||||
m_recentHelper->setDisplayMode(dislayMode);
|
||||
m_toolHelper->setDisplayMode(dislayMode);
|
||||
updateDisplayMode();
|
||||
}
|
||||
|
||||
@ -278,25 +298,6 @@ void MainPanelControl::addTrayAreaItem(int index, QWidget *wdg)
|
||||
m_tray->installEventFilter(this);
|
||||
}
|
||||
|
||||
/**往插件区域添加应用,保存回收站插件指针对象
|
||||
* @brief MainPanelControl::addPluginAreaItem
|
||||
* @param index 位置索引,如果为负数则插入到最后,为正则插入到指定位置
|
||||
* @param wdg 应用指针对象
|
||||
*/
|
||||
void MainPanelControl::addPluginAreaItem(int index, QWidget *wdg)
|
||||
{
|
||||
//因为日期时间插件和其他插件的大小有异,为了方便设置边距,在插件区域布局再添加一层布局设置边距
|
||||
//因此在处理插件图标时,需要通过两层布局判断是否为需要的插件,例如拖动插件位置等判断
|
||||
QBoxLayout * boxLayout = new QBoxLayout(QBoxLayout::LeftToRight, this);
|
||||
boxLayout->addWidget(wdg, 0, Qt::AlignCenter);
|
||||
m_pluginLayout->insertLayout(index, boxLayout, 0);
|
||||
|
||||
// 保存垃圾箱插件指针
|
||||
PluginsItem *pluginsItem = qobject_cast<PluginsItem *>(wdg);
|
||||
if (pluginsItem && pluginsItem->pluginName() == "trash")
|
||||
m_trashItem = pluginsItem;
|
||||
}
|
||||
|
||||
/**移除固定区域某一应用
|
||||
* @brief MainPanelControl::removeFixedAreaItem
|
||||
* @param wdg 应用指针对象
|
||||
@ -326,31 +327,6 @@ void MainPanelControl::removeTrayAreaItem(QWidget *wdg)
|
||||
m_trayAreaLayout->removeWidget(wdg);
|
||||
}
|
||||
|
||||
/**移除插件区域某一应用
|
||||
* @brief MainPanelControl::removePluginAreaItem
|
||||
* @param wdg 应用指针对象
|
||||
*/
|
||||
void MainPanelControl::removePluginAreaItem(QWidget *wdg)
|
||||
{
|
||||
// 因为日期时间插件大小和其他插件有异,为了方便设置边距,各插件中增加一层布局
|
||||
// 因此remove插件图标时,需要从多的一层布局中取widget进行判断是否需要移除的插件
|
||||
// 清空保存的垃圾箱插件指针
|
||||
PluginsItem *pluginsItem = qobject_cast<PluginsItem *>(wdg);
|
||||
if (pluginsItem && pluginsItem->pluginName() == "trash")
|
||||
m_trashItem = nullptr;
|
||||
|
||||
for (int i = 0; i < m_pluginLayout->count(); ++i) {
|
||||
QLayoutItem *layoutItem = m_pluginLayout->itemAt(i);
|
||||
QLayout *boxLayout = layoutItem->layout();
|
||||
if (boxLayout && boxLayout->itemAt(0)->widget() == wdg) {
|
||||
boxLayout->removeWidget(wdg);
|
||||
m_pluginLayout->removeItem(layoutItem);
|
||||
delete layoutItem;
|
||||
layoutItem = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainPanelControl::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
// 先通过消息循环让各部件调整好size后再计算图标大小
|
||||
@ -399,10 +375,12 @@ void MainPanelControl::updateAppAreaSonWidgetSize()
|
||||
m_appAreaSonWidget->setMaximumHeight(height());
|
||||
m_appAreaSonWidget->setMaximumWidth(m_appAreaWidget->width());
|
||||
m_recentAreaWidget->setFixedHeight(height());
|
||||
m_toolAreaWidget->setFixedHeight(height());
|
||||
} else {
|
||||
m_appAreaSonWidget->setMaximumWidth(width());
|
||||
m_appAreaSonWidget->setMaximumHeight(m_appAreaWidget->height());
|
||||
m_recentAreaWidget->setFixedWidth(width());
|
||||
m_toolAreaWidget->setFixedWidth(width());
|
||||
}
|
||||
|
||||
m_appAreaSonWidget->adjustSize();
|
||||
@ -452,7 +430,8 @@ void MainPanelControl::insertItem(int index, DockItem *item)
|
||||
addTrayAreaItem(index, item);
|
||||
break;
|
||||
case DockItem::Plugins:
|
||||
addPluginAreaItem(index, item);
|
||||
//addPluginAreaItem(index, item);
|
||||
m_toolHelper->addPluginItem(index, item);
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
@ -484,7 +463,7 @@ void MainPanelControl::removeItem(DockItem *item)
|
||||
removeTrayAreaItem(item);
|
||||
break;
|
||||
case DockItem::Plugins:
|
||||
removePluginAreaItem(item);
|
||||
m_toolHelper->removePluginItem(item);
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
@ -863,8 +842,10 @@ void MainPanelControl::startDrag(DockItem *dockItem)
|
||||
// isNeedBack 保存是否需要重置垃圾箱的AcceptDrops
|
||||
// 设置垃圾箱插件AcceptDrops false
|
||||
bool isNeedBack = false;
|
||||
if (item->itemType() == DockItem::Plugins && m_trashItem && dockItem != m_trashItem) {
|
||||
m_trashItem->centralWidget()->setAcceptDrops(false);
|
||||
PluginsItem *trashItem = m_toolHelper->trashPlugin();
|
||||
|
||||
if (item->itemType() == DockItem::Plugins && trashItem && dockItem != trashItem) {
|
||||
trashItem->centralWidget()->setAcceptDrops(false);
|
||||
isNeedBack = true;
|
||||
}
|
||||
|
||||
@ -878,7 +859,7 @@ void MainPanelControl::startDrag(DockItem *dockItem)
|
||||
|
||||
// isNeedBack是否需要设置垃圾箱插件AcceptDrops true
|
||||
if (isNeedBack)
|
||||
m_trashItem->centralWidget()->setAcceptDrops(true);
|
||||
trashItem->centralWidget()->setAcceptDrops(true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -955,6 +936,8 @@ void MainPanelControl::updateModeChange()
|
||||
m_traySpliter->setVisible(m_displayMode == DisplayMode::Efficient);
|
||||
m_pluginAreaWidget->setVisible(m_displayMode == DisplayMode::Efficient);
|
||||
m_trayManagerWidget->setVisible(m_displayMode != DisplayMode::Efficient);
|
||||
onRecentVisibleChanged(m_recentHelper->recentIsVisible());
|
||||
onToolVisibleChanged(m_toolHelper->toolIsVisible());
|
||||
if (m_tray)
|
||||
m_tray->setVisible(m_displayMode == DisplayMode::Efficient);
|
||||
}
|
||||
@ -1038,6 +1021,9 @@ QPainterPath MainPanelControl::areaPath()
|
||||
if (m_recentLayout->count() > 0)
|
||||
leftWidth += m_recentAreaWidget->width();
|
||||
|
||||
if (m_toolLayout->count() > 0)
|
||||
leftWidth += m_toolAreaWidget->width();
|
||||
|
||||
int roundHeight = height();
|
||||
path.addRoundedRect(QRect(0, 0, leftWidth, roundHeight), radius, radius);
|
||||
path.addRoundedRect(QRect(m_trayManagerWidget->x(), 0, m_trayManagerWidget->width(), roundHeight), radius, radius);
|
||||
@ -1047,6 +1033,9 @@ QPainterPath MainPanelControl::areaPath()
|
||||
if (m_recentLayout->count() > 0)
|
||||
topHeight += m_recentAreaWidget->height();
|
||||
|
||||
if (m_toolLayout->count() > 0)
|
||||
topHeight += m_toolAreaWidget->height();
|
||||
|
||||
path.addRoundedRect(QRect(0, 0, roundWidth, topHeight), radius, radius);
|
||||
path.addRoundedRect(QRect(0, m_trayManagerWidget->y(), roundWidth, m_trayManagerWidget->height()), radius, radius);
|
||||
}
|
||||
@ -1077,7 +1066,7 @@ QSize MainPanelControl::suitableSize(int screenSize, double deviceRatio) const
|
||||
// 减去右侧托盘和快捷设置还有插件区域的尺寸
|
||||
totalLength -= (((m_position == Position::Top || m_position == Position::Bottom) ? traySuitableSize.width() : traySuitableSize.height()) / ratio);
|
||||
// 需要参与计算的图标的总数
|
||||
int iconCount = m_fixedAreaLayout->count() + m_appAreaSonLayout->count() + m_recentLayout->count();
|
||||
int iconCount = m_fixedAreaLayout->count() + m_appAreaSonLayout->count() + m_recentLayout->count() + m_toolLayout->count();
|
||||
if (iconCount <= 0) {
|
||||
if (m_position == Position::Top || m_position == Position::Bottom)
|
||||
return QSize((static_cast<int>((traySuitableSize.width() + 20) / ratio)), height());
|
||||
@ -1091,7 +1080,14 @@ QSize MainPanelControl::suitableSize(int screenSize, double deviceRatio) const
|
||||
|
||||
if (m_position == Position::Top || m_position == Position::Bottom) {
|
||||
iconSize = qMin(iconSize, height());
|
||||
int panelWidth = qMin(iconSize * iconCount + static_cast<int>((m_fixedSpliter->width() + traySuitableSize.width() + 20) / ratio),
|
||||
int spliterWidth = m_fixedSpliter->isVisible() ? m_fixedSpliter->width() : 0;
|
||||
if (m_appSpliter->isVisible())
|
||||
spliterWidth += m_appSpliter->width();
|
||||
|
||||
if (m_recentSpliter->isVisible())
|
||||
spliterWidth += m_recentSpliter->isVisible();
|
||||
|
||||
int panelWidth = qMin(iconSize * iconCount + static_cast<int>((spliterWidth + traySuitableSize.width() + 20) / ratio),
|
||||
static_cast<int>(screenSize / deviceRatio));
|
||||
|
||||
return QSize(panelWidth, static_cast<int>(height() / ratio));
|
||||
@ -1099,7 +1095,14 @@ QSize MainPanelControl::suitableSize(int screenSize, double deviceRatio) const
|
||||
|
||||
iconSize = iconSize < width() ? iconSize : width();
|
||||
|
||||
int panelHeight = qMin(iconSize * iconCount + static_cast<int>((m_fixedSpliter->height() + traySuitableSize.height() + 20) / ratio),
|
||||
int spliterHeight = m_fixedSpliter->isVisible() ? m_fixedSpliter->height() : 0;
|
||||
if (m_appSpliter->isVisible())
|
||||
spliterHeight += m_appSpliter->height();
|
||||
|
||||
if (m_recentSpliter->isVisible())
|
||||
spliterHeight += m_recentSpliter->height();
|
||||
|
||||
int panelHeight = qMin(iconSize * iconCount + static_cast<int>((spliterHeight + traySuitableSize.height() + 20) / ratio),
|
||||
static_cast<int>(screenSize / deviceRatio));
|
||||
|
||||
return QSize(width(), panelHeight);
|
||||
@ -1133,6 +1136,9 @@ void MainPanelControl::paintEvent(QPaintEvent *event)
|
||||
|
||||
if (m_traySpliter->isVisible())
|
||||
painter.fillRect(m_traySpliter->geometry(), color);
|
||||
|
||||
if (m_recentSpliter->isVisible())
|
||||
painter.fillRect(m_recentSpliter->geometry(), color);
|
||||
}
|
||||
|
||||
// 获取当前屏幕的高或者宽(任务栏上下的时候获取宽,左右获取高)
|
||||
@ -1299,25 +1305,39 @@ void MainPanelControl::calcuDockIconSize(int w, int h, int traySize)
|
||||
m_fixedSpliter->setFixedSize(SPLITER_SIZE, int(w * 0.6));
|
||||
m_appSpliter->setFixedSize(SPLITER_SIZE, int(w * 0.6));
|
||||
m_traySpliter->setFixedSize(SPLITER_SIZE, int(w * 0.5));
|
||||
m_recentSpliter->setFixedSize(SPLITER_SIZE, int(w * 0.6));
|
||||
} else {
|
||||
m_fixedSpliter->setFixedSize(int(h * 0.6), SPLITER_SIZE);
|
||||
m_appSpliter->setFixedSize(int(h * 0.6), SPLITER_SIZE);
|
||||
m_traySpliter->setFixedSize(int(h * 0.5), SPLITER_SIZE);
|
||||
m_recentSpliter->setFixedSize(int(h * 0.6), SPLITER_SIZE);
|
||||
}
|
||||
|
||||
for (int i = 0; i < m_appAreaSonLayout->count(); ++i)
|
||||
m_appAreaSonLayout->itemAt(i)->widget()->setFixedSize(appItemSize, appItemSize);
|
||||
|
||||
// 时尚模式下判断是否需要显示最近打开的应用区域
|
||||
if (m_displayMode == Dock::DisplayMode::Fashion && m_recentLayout->count() > 0) {
|
||||
for (int i = 0; i < m_recentLayout->count(); ++i)
|
||||
m_recentLayout->itemAt(i)->widget()->setFixedSize(appItemSize, appItemSize);
|
||||
if (m_displayMode == Dock::DisplayMode::Fashion) {
|
||||
if (m_recentLayout->count() > 0) {
|
||||
for (int i = 0; i < m_recentLayout->count(); ++i)
|
||||
m_recentLayout->itemAt(i)->widget()->setFixedSize(appItemSize, appItemSize);
|
||||
|
||||
// 时尚模式下计算最近打开应用区域的尺寸
|
||||
if (m_position == Dock::Position::Top || m_position == Dock::Position::Bottom)
|
||||
m_recentAreaWidget->setFixedWidth(appItemSize * m_recentLayout->count());
|
||||
else
|
||||
m_recentAreaWidget->setFixedHeight(appItemSize * m_recentLayout->count());
|
||||
// 时尚模式下计算最近打开应用区域的尺寸
|
||||
if (m_position == Dock::Position::Top || m_position == Dock::Position::Bottom)
|
||||
m_recentAreaWidget->setFixedWidth(appItemSize * m_recentLayout->count());
|
||||
else
|
||||
m_recentAreaWidget->setFixedHeight(appItemSize * m_recentLayout->count());
|
||||
}
|
||||
|
||||
if (m_toolLayout->count() > 0) {
|
||||
for (int i = 0; i < m_toolLayout->count(); i++)
|
||||
m_toolLayout->itemAt(i)->widget()->setFixedSize(appItemSize, appItemSize);
|
||||
|
||||
if (m_position == Dock::Position::Top || m_position == Dock::Position::Bottom)
|
||||
m_toolAreaWidget->setFixedWidth(appItemSize * m_toolLayout->count());
|
||||
else
|
||||
m_toolAreaWidget->setFixedHeight(appItemSize * m_toolLayout->count());
|
||||
}
|
||||
}
|
||||
|
||||
if (m_tray)
|
||||
@ -1329,32 +1349,34 @@ void MainPanelControl::calcuDockIconSize(int w, int h, int traySize)
|
||||
// 三方插件
|
||||
for (int i = 0; i < m_pluginLayout->count(); ++ i) {
|
||||
QLayout *layout = m_pluginLayout->itemAt(i)->layout();
|
||||
if (layout && layout->itemAt(0)) {
|
||||
PluginsItem *pItem = static_cast<PluginsItem *>(layout->itemAt(0)->widget());
|
||||
if (pItem) {
|
||||
if (pItem->sizeHint().height() == -1) {
|
||||
pItem->setFixedSize(traySize, traySize);
|
||||
} else if (pItem->sizeHint().height() > height()) {
|
||||
pItem->resize(pItem->width(), height());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!layout || !layout->itemAt(0))
|
||||
continue;
|
||||
|
||||
PluginsItem *pItem = static_cast<PluginsItem *>(layout->itemAt(0)->widget());
|
||||
if (!pItem)
|
||||
continue;
|
||||
|
||||
if (pItem->sizeHint().height() == -1)
|
||||
pItem->setFixedSize(traySize, traySize);
|
||||
else if (pItem->sizeHint().height() > height())
|
||||
pItem->resize(pItem->width(), height());
|
||||
}
|
||||
} else {
|
||||
// 三方插件
|
||||
for (int i = 0; i < m_pluginLayout->count(); ++ i) {
|
||||
for (int i = 0; i < m_pluginLayout->count(); i++) {
|
||||
QLayout *layout = m_pluginLayout->itemAt(i)->layout();
|
||||
if (layout) {
|
||||
PluginsItem *pItem = static_cast<PluginsItem *>(layout->itemAt(0)->widget());
|
||||
qInfo() << pItem->pluginItem()->pluginDisplayName();
|
||||
if (pItem) {
|
||||
if (pItem->sizeHint().width() == -1) {
|
||||
pItem->setFixedSize(traySize, traySize);
|
||||
} else if (pItem->sizeHint().width() > width()) {
|
||||
pItem->resize(width(), pItem->height());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!layout || !layout->itemAt(0))
|
||||
continue;
|
||||
|
||||
PluginsItem *pItem = static_cast<PluginsItem *>(layout->itemAt(0)->widget());
|
||||
qInfo() << pItem->pluginItem()->pluginDisplayName();
|
||||
if (!pItem)
|
||||
continue;
|
||||
|
||||
if (pItem->sizeHint().width() == -1)
|
||||
pItem->setFixedSize(traySize, traySize);
|
||||
else if (pItem->sizeHint().width() > width())
|
||||
pItem->resize(width(), pItem->height());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1376,8 +1398,8 @@ void MainPanelControl::calcuDockIconSize(int w, int h, int traySize)
|
||||
m_appAreaSonLayout->setContentsMargins(appLeftAndRightMargin, appTopAndBottomMargin, appLeftAndRightMargin, appTopAndBottomMargin);
|
||||
m_trayAreaLayout->setContentsMargins(trayLeftAndRightMargin, trayTopAndBottomMargin, trayLeftAndRightMargin, trayTopAndBottomMargin);
|
||||
|
||||
//因为日期时间插件大小和其他插件大小有异,需要单独设置各插件的边距
|
||||
//而不对日期时间插件设置边距
|
||||
// 因为日期时间插件大小和其他插件大小有异,需要单独设置各插件的边距
|
||||
// 而不对日期时间插件设置边距
|
||||
for (int i = 0; i < m_pluginLayout->count(); ++ i) {
|
||||
QLayout *layout = m_pluginLayout->itemAt(i)->layout();
|
||||
if (layout && layout->itemAt(0)) {
|
||||
@ -1403,6 +1425,11 @@ void MainPanelControl::onRecentVisibleChanged(bool visible)
|
||||
m_appSpliter->setVisible(visible);
|
||||
}
|
||||
|
||||
void MainPanelControl::onToolVisibleChanged(bool visible)
|
||||
{
|
||||
m_recentSpliter->setVisible(visible);
|
||||
}
|
||||
|
||||
/**时尚模式没有‘显示桌面’区域
|
||||
* @brief MainPanelControl::resizeDesktopWidget
|
||||
*/
|
||||
|
@ -41,6 +41,7 @@ class DesktopWidget;
|
||||
class TrayManagerWindow;
|
||||
class DockScreen;
|
||||
class RecentAppHelper;
|
||||
class ToolAppHelper;
|
||||
|
||||
class MainPanelControl : public QWidget
|
||||
{
|
||||
@ -82,8 +83,6 @@ private:
|
||||
void removeAppAreaItem(QWidget *wdg);
|
||||
void addTrayAreaItem(int index, QWidget *wdg);
|
||||
void removeTrayAreaItem(QWidget *wdg);
|
||||
void addPluginAreaItem(int index, QWidget *wdg);
|
||||
void removePluginAreaItem(QWidget *wdg);
|
||||
int getScreenSize() const;
|
||||
|
||||
// 拖拽相关
|
||||
@ -101,6 +100,7 @@ private:
|
||||
private Q_SLOTS:
|
||||
void onRequestUpdate();
|
||||
void onRecentVisibleChanged(bool visible);
|
||||
void onToolVisibleChanged(bool visible);
|
||||
|
||||
protected:
|
||||
void dragMoveEvent(QDragMoveEvent *e) override;
|
||||
@ -129,6 +129,9 @@ private:
|
||||
QWidget *m_pluginAreaWidget; // 插件区域
|
||||
QWidget *m_recentAreaWidget; // 最近打开应用
|
||||
QBoxLayout *m_recentLayout;
|
||||
QLabel *m_recentSpliter; // 最近打开应用区域分割线
|
||||
QWidget *m_toolAreaWidget; // 工具区域
|
||||
QBoxLayout *m_toolLayout; // 工具区域布局
|
||||
|
||||
TrayManagerWindow *m_trayManagerWidget;
|
||||
QBoxLayout *m_pluginLayout; // 插件区域布局
|
||||
@ -143,9 +146,9 @@ private:
|
||||
TrayPluginItem *m_tray;
|
||||
int m_dragIndex = -1; // 记录应用区域被拖拽图标的位置
|
||||
|
||||
PluginsItem *m_trashItem; // 垃圾箱插件(需要特殊处理一下)
|
||||
DockScreen *m_dockScreen;
|
||||
RecentAppHelper *m_recentHelper;
|
||||
ToolAppHelper *m_toolHelper;
|
||||
};
|
||||
|
||||
#endif // MAINPANELCONTROL_H
|
||||
|
@ -1,3 +1,4 @@
|
||||
{
|
||||
"api": "2.0.0"
|
||||
"api": "2.0.0",
|
||||
"tool": true
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user