mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-02 15:45:21 +00:00
fix: 点击插件弹出自己的列表
1、删除已经移到插件中的文件 2、点击插件图标,弹出当前插件对应的列表 Log: Influence: 点击插件,观察是否弹出插件自己对应的列表,如果没有弹出列表,则触发这个插件的功能 Task: https://pms.uniontech.com/task-view-222353.html Change-Id: Ia8797ccbe630d56d79ab9138d5aa982b66f74c57
This commit is contained in:
parent
bc840d233d
commit
e7dbbb0140
@ -21,9 +21,6 @@
|
||||
#include "quicksettingitem.h"
|
||||
#include "pluginsiteminterface.h"
|
||||
#include "imageutil.h"
|
||||
#include "multiquickitem.h"
|
||||
#include "singlequickitem.h"
|
||||
#include "fullquickitem.h"
|
||||
#include "quicksettingcontroller.h"
|
||||
|
||||
#include <DGuiApplicationHelper>
|
||||
@ -108,21 +105,3 @@ QColor QuickSettingItem::foregroundColor() const
|
||||
|
||||
return dpa.color(DPalette::ColorGroup::Normal, DPalette::ColorRole::Text);
|
||||
}
|
||||
|
||||
QuickSettingItem *QuickSettingFactory::createQuickWidget(PluginsItemInterface * const pluginInter)
|
||||
{
|
||||
// 如果显示在面板的图标或者Widget为空,则不让显示(例如电池插件)
|
||||
if (!(pluginInter->flags() & PluginFlag::Type_Common))
|
||||
return nullptr;
|
||||
|
||||
if (pluginInter->flags() & PluginFlag::Quick_Multi)
|
||||
return new MultiQuickItem(pluginInter);
|
||||
|
||||
if (pluginInter->flags() & PluginFlag::Quick_Full)
|
||||
return new FullQuickItem(pluginInter);
|
||||
|
||||
if (pluginInter->flags() & PluginFlag::Quick_Single)
|
||||
return new SingleQuickItem(pluginInter);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -61,10 +61,4 @@ private:
|
||||
QString m_itemKey;
|
||||
};
|
||||
|
||||
class QuickSettingFactory
|
||||
{
|
||||
public:
|
||||
static QuickSettingItem *createQuickWidget(PluginsItemInterface *const pluginInter);
|
||||
};
|
||||
|
||||
#endif // QUICKSETTINGITEM_H
|
||||
|
@ -214,3 +214,41 @@ void DockPopupWindow::onButtonPress(int type, int x, int y, const QString &key)
|
||||
emit accept();
|
||||
hide();
|
||||
}
|
||||
|
||||
PopupSwitchWidget::PopupSwitchWidget(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, m_containerLayout(new QVBoxLayout(this))
|
||||
, m_topWidget(nullptr)
|
||||
{
|
||||
m_containerLayout->setContentsMargins(0, 0, 0, 0);
|
||||
m_containerLayout->setSpacing(0);
|
||||
}
|
||||
|
||||
PopupSwitchWidget::~PopupSwitchWidget()
|
||||
{
|
||||
}
|
||||
|
||||
void PopupSwitchWidget::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;
|
||||
setFixedSize(widget->size());
|
||||
widget->installEventFilter(this);
|
||||
m_containerLayout->addWidget(widget);
|
||||
widget->show();
|
||||
}
|
||||
|
||||
bool PopupSwitchWidget::eventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
if (watched == m_topWidget && event->type() == QEvent::Resize) {
|
||||
setFixedSize(m_topWidget->size());
|
||||
}
|
||||
|
||||
return QWidget::eventFilter(watched, event);
|
||||
}
|
||||
|
@ -82,4 +82,22 @@ private:
|
||||
QWidget *m_extendWidget;
|
||||
};
|
||||
|
||||
class PopupSwitchWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit PopupSwitchWidget(QWidget *parent = nullptr);
|
||||
~PopupSwitchWidget();
|
||||
|
||||
void pushWidget(QWidget *widget);
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *watched, QEvent *event) override;
|
||||
|
||||
private:
|
||||
QVBoxLayout *m_containerLayout;
|
||||
QWidget *m_topWidget;
|
||||
};
|
||||
|
||||
#endif // DOCKPOPUPWINDOW_H
|
||||
|
@ -27,7 +27,6 @@
|
||||
#include "tray_delegate.h"
|
||||
#include "quicksettingcontroller.h"
|
||||
#include "pluginsitem.h"
|
||||
#include "quicksettingcontainer.h"
|
||||
#include "expandiconwidget.h"
|
||||
#include "quickdragcore.h"
|
||||
|
||||
@ -422,7 +421,7 @@ void DockTrayWindow::onDropIcon(QDropEvent *dropEvent)
|
||||
if (!dropEvent || !dropEvent->mimeData() || dropEvent->source() == this)
|
||||
return;
|
||||
|
||||
if (qobject_cast<QuickSettingContainer *>(dropEvent->source())) {
|
||||
if (m_quickIconWidget->isQuickWindow(dropEvent->source())) {
|
||||
const QuickPluginMimeData *mimeData = qobject_cast<const QuickPluginMimeData *>(dropEvent->mimeData());
|
||||
if (!mimeData)
|
||||
return;
|
||||
|
@ -22,7 +22,6 @@
|
||||
#include "quicksettingcontroller.h"
|
||||
#include "quicksettingitem.h"
|
||||
#include "pluginsiteminterface.h"
|
||||
#include "quicksettingcontainer.h"
|
||||
#include "appdrag.h"
|
||||
#include "quickpluginmodel.h"
|
||||
#include "quickdragcore.h"
|
||||
@ -112,9 +111,9 @@ QuickPluginWindow::~QuickPluginWindow()
|
||||
void QuickPluginWindow::initUi()
|
||||
{
|
||||
setAcceptDrops(true);
|
||||
m_mainLayout->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
|
||||
m_mainLayout->setAlignment(Qt::AlignCenter);
|
||||
m_mainLayout->setDirection(QBoxLayout::RightToLeft);
|
||||
m_mainLayout->setContentsMargins(ITEMSPACE, 0, ITEMSPACE, 0);
|
||||
m_mainLayout->setContentsMargins(0, 0, 0, 0);
|
||||
m_mainLayout->setSpacing(ITEMSPACE);
|
||||
}
|
||||
|
||||
@ -124,14 +123,17 @@ void QuickPluginWindow::setPositon(Position position)
|
||||
return;
|
||||
|
||||
m_position = position;
|
||||
QuickSettingContainer::setPosition(position);
|
||||
QuickDockItem::setPosition(position);
|
||||
for (int i = 0; i < m_mainLayout->count(); i++) {
|
||||
QuickDockItem *dockItemWidget = qobject_cast<QuickDockItem *>(m_mainLayout->itemAt(i)->widget());
|
||||
if (dockItemWidget) {
|
||||
dockItemWidget->setPosition(position);
|
||||
}
|
||||
}
|
||||
resizeDockItem();
|
||||
if (m_position == Dock::Position::Top || m_position == Dock::Position::Bottom) {
|
||||
m_mainLayout->setDirection(QBoxLayout::RightToLeft);
|
||||
m_mainLayout->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
|
||||
} else {
|
||||
m_mainLayout->setDirection(QBoxLayout::BottomToTop);
|
||||
m_mainLayout->setAlignment(Qt::AlignTop | Qt::AlignHCenter);
|
||||
}
|
||||
}
|
||||
|
||||
@ -176,7 +178,7 @@ QSize QuickPluginWindow::suitableSize(const Dock::Position &position) const
|
||||
}
|
||||
itemWidth += ITEMSPACE;
|
||||
|
||||
return QSize(itemWidth, ITEMSIZE);
|
||||
return QSize(itemWidth, QWIDGETSIZE_MAX);
|
||||
}
|
||||
|
||||
int itemHeight = 0;
|
||||
@ -187,7 +189,18 @@ QSize QuickPluginWindow::suitableSize(const Dock::Position &position) const
|
||||
}
|
||||
itemHeight += ITEMSPACE;
|
||||
|
||||
return QSize(ITEMSIZE, itemHeight);
|
||||
return QSize(QWIDGETSIZE_MAX, itemHeight);
|
||||
}
|
||||
|
||||
bool QuickPluginWindow::isQuickWindow(QObject *object) const
|
||||
{
|
||||
QList<PluginsItemInterface *> dockPlugins = QuickPluginModel::instance()->dockedPluginItems();
|
||||
for (PluginsItemInterface *plugin : dockPlugins) {
|
||||
if (plugin->pluginName() == QString("pluginManager") && plugin->itemPopupApplet(QUICK_ITEM_KEY) == object)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
PluginsItemInterface *QuickPluginWindow::findQuickSettingItem(const QPoint &mousePoint, const QList<PluginsItemInterface *> &settingItems)
|
||||
@ -223,6 +236,14 @@ bool QuickPluginWindow::eventFilter(QObject *watched, QEvent *event)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (watched == getPopWindow()->getContent()) {
|
||||
#define ITEMWIDTH 70
|
||||
#define QUICKITEMSPACE 10
|
||||
int maxWidth = ITEMWIDTH * 4 + (QUICKITEMSPACE * 5);
|
||||
int contentWidget = getPopWindow()->getContent()->width();
|
||||
if (contentWidget > maxWidth || contentWidget <= 0)
|
||||
getPopWindow()->getContent()->setFixedWidth(maxWidth);
|
||||
}
|
||||
switch (event->type()) {
|
||||
case QEvent::MouseButtonPress: {
|
||||
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
|
||||
@ -249,7 +270,7 @@ bool QuickPluginWindow::eventFilter(QObject *watched, QEvent *event)
|
||||
if (m_dragInfo->canDrag(mouseEvent->pos()))
|
||||
break;
|
||||
|
||||
showPopup(m_dragInfo->dockItem);
|
||||
showPopup(m_dragInfo->dockItem, m_dragInfo->dockItem->pluginItem(), m_dragInfo->dockItem->pluginItem()->itemPopupApplet(QUICK_ITEM_KEY), true);
|
||||
} while (false);
|
||||
m_dragInfo->reset();
|
||||
|
||||
@ -260,7 +281,7 @@ bool QuickPluginWindow::eventFilter(QObject *watched, QEvent *event)
|
||||
break;
|
||||
|
||||
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
|
||||
if (m_dragInfo->canDrag(mouseEvent->pos()))
|
||||
if (m_dragInfo->canDrag(mouseEvent->pos()) && m_dragInfo->dockItem->canMove())
|
||||
startDrag();
|
||||
|
||||
m_dragInfo->reset();
|
||||
@ -269,7 +290,7 @@ bool QuickPluginWindow::eventFilter(QObject *watched, QEvent *event)
|
||||
case QEvent::Drop: {
|
||||
m_dragEnterMimeData = nullptr;
|
||||
QDropEvent *dropEvent = static_cast<QDropEvent *>(event);
|
||||
if (qobject_cast<QuickSettingContainer *>(dropEvent->source())) {
|
||||
if (isQuickWindow(dropEvent->source())) {
|
||||
const QuickPluginMimeData *mimeData = qobject_cast<const QuickPluginMimeData *>(dropEvent->mimeData());
|
||||
if (mimeData)
|
||||
dragPlugin(mimeData->pluginItemInterface());
|
||||
@ -353,7 +374,7 @@ void QuickPluginWindow::onRequestUpdate()
|
||||
itemWidget = pluginItems[item];
|
||||
} else {
|
||||
itemWidget = new QuickDockItem(item, quickController->itemKey(item), this);
|
||||
itemWidget->setFixedSize(itemWidget->suitableSize());
|
||||
updateDockItemSize(itemWidget);
|
||||
itemWidget->installEventFilter(this);
|
||||
itemWidget->setMouseTracking(true);
|
||||
countChanged = true;
|
||||
@ -412,7 +433,7 @@ void QuickPluginWindow::onUpdatePlugin(PluginsItemInterface *itemInter, const Do
|
||||
|
||||
QuickDockItem *quickDockItem = getDockItemByPlugin(itemInter);
|
||||
if (quickDockItem) {
|
||||
quickDockItem->setFixedSize(quickDockItem->suitableSize());
|
||||
updateDockItemSize(quickDockItem);
|
||||
quickDockItem->update();
|
||||
}
|
||||
}
|
||||
@ -481,11 +502,21 @@ QuickDockItem *QuickPluginWindow::getActiveDockItem(QPoint point) const
|
||||
|
||||
void QuickPluginWindow::showPopup(QuickDockItem *item, PluginsItemInterface *itemInter, QWidget *childPage, bool isClicked)
|
||||
{
|
||||
if (!isVisible())
|
||||
if (!isVisible() || !item)
|
||||
return;
|
||||
|
||||
bool canBack = true;
|
||||
DockPopupWindow *popWindow = QuickSettingContainer::popWindow();
|
||||
if (!childPage) {
|
||||
const QString itemKey = QuickSettingController::instance()->itemKey(itemInter);
|
||||
QStringList commandArgument = itemInter->itemCommand(itemKey).split(" ");
|
||||
if (commandArgument.size() > 0) {
|
||||
QString command = commandArgument.first();
|
||||
commandArgument.removeFirst();
|
||||
QProcess::startDetached(command, commandArgument);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
DockPopupWindow *popWindow = getPopWindow();
|
||||
if (isClicked && popWindow->isVisible()) {
|
||||
// 如果是点击插件,并且该插件曾经打开快捷面板且已经是显示状态,那么就直接隐藏快捷面板
|
||||
popWindow->hide();
|
||||
@ -508,14 +539,12 @@ void QuickPluginWindow::showPopup(QuickDockItem *item, PluginsItemInterface *ite
|
||||
}
|
||||
}
|
||||
|
||||
PopupSwitchWidget *switchWidget = static_cast<PopupSwitchWidget *>(popWindow->getContent());
|
||||
switchWidget->installEventFilter(this);
|
||||
switchWidget->pushWidget(childPage);
|
||||
popWindow->setExtendWidget(item);
|
||||
popWindow->show(popupPoint(item), true);
|
||||
canBack = false;
|
||||
}
|
||||
|
||||
QuickSettingContainer *container = static_cast<QuickSettingContainer *>(popWindow->getContent());
|
||||
container->showPage(childPage, itemInter, canBack);
|
||||
popWindow->raise();
|
||||
}
|
||||
|
||||
QList<QuickDockItem *> QuickPluginWindow::quickDockItems()
|
||||
@ -536,6 +565,62 @@ QList<QuickDockItem *> QuickPluginWindow::quickDockItems()
|
||||
return dockItems;
|
||||
}
|
||||
|
||||
// 根据位置获取箭头的方向
|
||||
static DArrowRectangle::ArrowDirection getDirection(const Dock::Position &position)
|
||||
{
|
||||
switch (position) {
|
||||
case Dock::Position::Top:
|
||||
return DArrowRectangle::ArrowDirection::ArrowTop;
|
||||
case Dock::Position::Left:
|
||||
return DArrowRectangle::ArrowDirection::ArrowLeft;
|
||||
case Dock::Position::Right:
|
||||
return DArrowRectangle::ArrowDirection::ArrowRight;
|
||||
default:
|
||||
return DArrowRectangle::ArrowDirection::ArrowBottom;
|
||||
}
|
||||
|
||||
return DArrowRectangle::ArrowDirection::ArrowBottom;
|
||||
}
|
||||
|
||||
DockPopupWindow *QuickPluginWindow::getPopWindow() const
|
||||
{
|
||||
static DockPopupWindow *popWindow = nullptr;
|
||||
if (popWindow)
|
||||
return popWindow;
|
||||
|
||||
popWindow = new DockPopupWindow;
|
||||
popWindow->setShadowBlurRadius(20);
|
||||
popWindow->setRadius(18);
|
||||
popWindow->setShadowYOffset(2);
|
||||
popWindow->setShadowXOffset(0);
|
||||
popWindow->setArrowWidth(18);
|
||||
popWindow->setArrowHeight(10);
|
||||
popWindow->setArrowDirection(getDirection(m_position));
|
||||
popWindow->setWindowFlags(Qt::FramelessWindowHint | Qt::Tool);
|
||||
PopupSwitchWidget *content = new PopupSwitchWidget(popWindow);
|
||||
popWindow->setContent(content);
|
||||
return popWindow;
|
||||
}
|
||||
|
||||
void QuickPluginWindow::updateDockItemSize(QuickDockItem *dockItem)
|
||||
{
|
||||
if (m_position == Dock::Position::Top || m_position == Dock::Position::Bottom) {
|
||||
dockItem->setFixedSize(dockItem->suitableSize().width(), height());
|
||||
} else {
|
||||
dockItem->setFixedSize(width(), dockItem->suitableSize().height());
|
||||
}
|
||||
}
|
||||
|
||||
void QuickPluginWindow::resizeDockItem()
|
||||
{
|
||||
for (int i = 0; i < m_mainLayout->count(); i++) {
|
||||
QuickDockItem *dockItemWidget = qobject_cast<QuickDockItem *>(m_mainLayout->itemAt(i)->widget());
|
||||
if (dockItemWidget) {
|
||||
updateDockItemSize(dockItemWidget);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int QuickPluginWindow::getDropIndex(QPoint point)
|
||||
{
|
||||
QList<QuickDockItem *> dockedItems = quickDockItems();
|
||||
@ -582,6 +667,12 @@ void QuickPluginWindow::dragMoveEvent(QDragMoveEvent *event)
|
||||
event->accept();
|
||||
}
|
||||
|
||||
void QuickPluginWindow::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
resizeDockItem();
|
||||
QWidget::resizeEvent(event);
|
||||
}
|
||||
|
||||
void QuickPluginWindow::initConnection()
|
||||
{
|
||||
QuickPluginModel *model = QuickPluginModel::instance();
|
||||
@ -596,15 +687,15 @@ void QuickPluginWindow::initConnection()
|
||||
* @param parent
|
||||
*/
|
||||
|
||||
Dock::Position QuickDockItem::m_position(Dock::Position::Bottom);
|
||||
|
||||
QuickDockItem::QuickDockItem(PluginsItemInterface *pluginItem, const QString &itemKey, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, m_pluginItem(pluginItem)
|
||||
, m_itemKey(itemKey)
|
||||
, m_position(Dock::Position::Bottom)
|
||||
, m_popupWindow(new DockPopupWindow)
|
||||
, m_contextMenu(new QMenu(this))
|
||||
, m_tipParent(nullptr)
|
||||
, m_mainWidget(nullptr)
|
||||
, m_mainLayout(nullptr)
|
||||
, m_dockItemParent(nullptr)
|
||||
{
|
||||
@ -625,6 +716,7 @@ QuickDockItem::~QuickDockItem()
|
||||
void QuickDockItem::setPosition(Dock::Position position)
|
||||
{
|
||||
m_position = position;
|
||||
updateWidgetSize();
|
||||
}
|
||||
|
||||
PluginsItemInterface *QuickDockItem::pluginItem()
|
||||
@ -637,6 +729,11 @@ bool QuickDockItem::canInsert() const
|
||||
return (m_pluginItem->flags() & PluginFlag::Attribute_CanInsert);
|
||||
}
|
||||
|
||||
bool QuickDockItem::canMove() const
|
||||
{
|
||||
return (m_pluginItem->flags() & PluginFlag::Attribute_CanDrag);
|
||||
}
|
||||
|
||||
void QuickDockItem::hideToolTip()
|
||||
{
|
||||
m_popupWindow->hide();
|
||||
@ -679,13 +776,11 @@ void QuickDockItem::paintEvent(QPaintEvent *event)
|
||||
return QWidget::paintEvent(event);
|
||||
|
||||
QPixmap pixmap = iconPixmap();
|
||||
int width = ICONWIDTH;
|
||||
int height = ICONHEIGHT;
|
||||
if (m_pluginItem->pluginSizePolicy() == PluginsItemInterface::PluginSizePolicy::Custom) {
|
||||
width = pixmap.width();
|
||||
height = pixmap.height();
|
||||
}
|
||||
QRect pixmapRect = QRect(QPoint((rect().width() - width) / 2, (rect().height() - height) / 2), pixmap.size());
|
||||
if (pixmap.isNull())
|
||||
return QWidget::paintEvent(event);
|
||||
|
||||
QSize size = suitableSize();
|
||||
QRect pixmapRect = QRect(QPoint((rect().width() - size.width()) / 2, (rect().height() - size.height()) / 2), pixmap.size());
|
||||
|
||||
QPainter painter(this);
|
||||
painter.drawPixmap(pixmapRect, pixmap);
|
||||
@ -770,7 +865,7 @@ void QuickDockItem::showEvent(QShowEvent *event)
|
||||
QWidget *itemWidget = m_pluginItem->itemWidget(m_itemKey);
|
||||
if (itemWidget && m_mainLayout->indexOf(itemWidget) < 0) {
|
||||
itemWidget->show();
|
||||
itemWidget->setFixedSize(size());
|
||||
itemWidget->setFixedSize(suitableSize());
|
||||
m_mainLayout->addWidget(itemWidget);
|
||||
}
|
||||
}
|
||||
@ -790,12 +885,19 @@ void QuickDockItem::hideEvent(QHideEvent *event)
|
||||
|
||||
bool QuickDockItem::eventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
// 让插件来处理当前插件的事件
|
||||
if (watched == this)
|
||||
return m_pluginItem->eventHandler(event);
|
||||
|
||||
return QWidget::eventFilter(watched, event);
|
||||
}
|
||||
|
||||
void QuickDockItem::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
QWidget::resizeEvent(event);
|
||||
updateWidgetSize();
|
||||
}
|
||||
|
||||
QPixmap QuickDockItem::iconPixmap() const
|
||||
{
|
||||
QIcon icon = m_pluginItem->icon(DockPart::QuickShow);
|
||||
@ -804,8 +906,9 @@ QPixmap QuickDockItem::iconPixmap() const
|
||||
QSize size = icon.availableSizes().first();
|
||||
return icon.pixmap(size);
|
||||
}
|
||||
int pixmapSize = static_cast<int>(ICONHEIGHT * (QCoreApplication::testAttribute(Qt::AA_UseHighDpiPixmaps) ? 1 : qApp->devicePixelRatio()));
|
||||
return icon.pixmap(pixmapSize, pixmapSize);
|
||||
int pixmapWidth = static_cast<int>(ICONWIDTH * (QCoreApplication::testAttribute(Qt::AA_UseHighDpiPixmaps) ? 1 : qApp->devicePixelRatio()));
|
||||
int pixmapHeight = static_cast<int>(ICONHEIGHT * (QCoreApplication::testAttribute(Qt::AA_UseHighDpiPixmaps) ? 1 : qApp->devicePixelRatio()));
|
||||
return icon.pixmap(pixmapWidth, pixmapHeight);
|
||||
}
|
||||
|
||||
return QPixmap();
|
||||
@ -817,7 +920,14 @@ void QuickDockItem::initUi()
|
||||
if (!pixmap.isNull())
|
||||
return;
|
||||
|
||||
m_mainLayout = new QHBoxLayout(this);
|
||||
m_topLayout = new QHBoxLayout(this);
|
||||
m_topLayout->setContentsMargins(0, 0, 0, 0);
|
||||
m_topLayout->setAlignment(Qt::AlignCenter);
|
||||
m_mainWidget = new QWidget(this);
|
||||
m_topLayout->addWidget(m_mainWidget);
|
||||
updateWidgetSize();
|
||||
|
||||
m_mainLayout = new QHBoxLayout(m_mainWidget);
|
||||
m_mainLayout->setContentsMargins(0, 0, 0, 0);
|
||||
QWidget *itemWidget = m_pluginItem->itemWidget(m_itemKey);
|
||||
if (itemWidget) {
|
||||
@ -849,6 +959,23 @@ void QuickDockItem::initConnection()
|
||||
connect(qApp, &QApplication::aboutToQuit, m_popupWindow, &DockPopupWindow::deleteLater);
|
||||
}
|
||||
|
||||
void QuickDockItem::updateWidgetSize()
|
||||
{
|
||||
if (!m_mainWidget)
|
||||
return;
|
||||
|
||||
QSize size = suitableSize();
|
||||
int width = size.width();
|
||||
int height = size.height();
|
||||
if (m_position == Dock::Position::Top || m_position == Dock::Position::Bottom) {
|
||||
// 上下方向
|
||||
m_mainWidget->setFixedSize(QWIDGETSIZE_MAX, height);
|
||||
} else {
|
||||
// 左右方向
|
||||
m_mainWidget->setFixedSize(width, QWIDGETSIZE_MAX);
|
||||
}
|
||||
}
|
||||
|
||||
QPoint QuickDockItem::topleftPoint() const
|
||||
{
|
||||
QPoint p = this->pos();
|
||||
|
@ -28,7 +28,6 @@
|
||||
class QuickSettingItem;
|
||||
class PluginsItemInterface;
|
||||
class QHBoxLayout;
|
||||
class QuickSettingContainer;
|
||||
class QStandardItemModel;
|
||||
class QStandardItem;
|
||||
class QMouseEvent;
|
||||
@ -57,6 +56,8 @@ public:
|
||||
QSize suitableSize() const;
|
||||
QSize suitableSize(const Dock::Position &position) const;
|
||||
|
||||
bool isQuickWindow(QObject *object) const;
|
||||
|
||||
Q_SIGNALS:
|
||||
void itemCountChanged();
|
||||
|
||||
@ -65,6 +66,7 @@ protected:
|
||||
void dragEnterEvent(QDragEnterEvent *event) override;
|
||||
void dragLeaveEvent(QDragLeaveEvent *event) override;
|
||||
void dragMoveEvent(QDragMoveEvent *event) override;
|
||||
void resizeEvent(QResizeEvent *event) override;
|
||||
|
||||
private Q_SLOTS:
|
||||
void onRequestUpdate();
|
||||
@ -82,6 +84,9 @@ private:
|
||||
QuickDockItem *getActiveDockItem(QPoint point) const;
|
||||
void showPopup(QuickDockItem *item, PluginsItemInterface *itemInter = nullptr, QWidget *childPage = nullptr, bool isClicked = true);
|
||||
QList<QuickDockItem *> quickDockItems();
|
||||
DockPopupWindow *getPopWindow() const;
|
||||
void updateDockItemSize(QuickDockItem *dockItem);
|
||||
void resizeDockItem();
|
||||
|
||||
private:
|
||||
QBoxLayout *m_mainLayout;
|
||||
@ -99,9 +104,10 @@ public:
|
||||
explicit QuickDockItem(PluginsItemInterface *pluginItem, const QString &itemKey, QWidget *parent = nullptr);
|
||||
~QuickDockItem();
|
||||
|
||||
static void setPosition(Dock::Position position);
|
||||
void setPosition(Dock::Position position);
|
||||
PluginsItemInterface *pluginItem();
|
||||
bool canInsert() const;
|
||||
bool canMove() const;
|
||||
void hideToolTip();
|
||||
|
||||
QSize suitableSize() const;
|
||||
@ -114,6 +120,7 @@ protected:
|
||||
void showEvent(QShowEvent *event) override;
|
||||
void hideEvent(QHideEvent *event) override;
|
||||
bool eventFilter(QObject *watched, QEvent *event) override;
|
||||
void resizeEvent(QResizeEvent *event) override;
|
||||
|
||||
private:
|
||||
QPoint topleftPoint() const;
|
||||
@ -125,16 +132,20 @@ private:
|
||||
void initAttribute();
|
||||
void initConnection();
|
||||
|
||||
void updateWidgetSize();
|
||||
|
||||
private Q_SLOTS:
|
||||
void onMenuActionClicked(QAction *action);
|
||||
|
||||
private:
|
||||
PluginsItemInterface *m_pluginItem;
|
||||
QString m_itemKey;
|
||||
static Dock::Position m_position;
|
||||
Dock::Position m_position;
|
||||
DockPopupWindow *m_popupWindow;
|
||||
QMenu *m_contextMenu;
|
||||
QWidget *m_tipParent;
|
||||
QHBoxLayout *m_topLayout;
|
||||
QWidget *m_mainWidget;
|
||||
QHBoxLayout *m_mainLayout;
|
||||
QWidget *m_dockItemParent;
|
||||
};
|
||||
|
@ -1,466 +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 "quicksettingcontainer.h"
|
||||
#include "quicksettingcontroller.h"
|
||||
#include "pluginsiteminterface.h"
|
||||
#include "quicksettingitem.h"
|
||||
#include "dockpopupwindow.h"
|
||||
#include "slidercontainer.h"
|
||||
#include "pluginchildpage.h"
|
||||
#include "utils.h"
|
||||
#include "quickdragcore.h"
|
||||
|
||||
#include <DListView>
|
||||
#include <DStyle>
|
||||
#include <QDrag>
|
||||
|
||||
#include <QVBoxLayout>
|
||||
#include <QMetaObject>
|
||||
#include <QStackedLayout>
|
||||
#include <QMouseEvent>
|
||||
#include <QLabel>
|
||||
#include <QBitmap>
|
||||
#include <QPainterPath>
|
||||
|
||||
DWIDGET_USE_NAMESPACE
|
||||
|
||||
struct QuickDragInfo {
|
||||
QPoint dragPosition;
|
||||
QWidget *dragItem = nullptr;
|
||||
PluginsItemInterface *pluginInter = nullptr;
|
||||
void reset() {
|
||||
dragPosition.setX(0);
|
||||
dragPosition.setY(0);
|
||||
dragItem = nullptr;
|
||||
pluginInter = nullptr;
|
||||
}
|
||||
bool isNull() {
|
||||
return !dragItem;
|
||||
}
|
||||
} QuickDragInfo;
|
||||
|
||||
#define ITEMWIDTH 70
|
||||
#define ITEMHEIGHT 60
|
||||
#define ITEMSPACE 10
|
||||
#define COLUMNCOUNT 4
|
||||
|
||||
DockPopupWindow *QuickSettingContainer::m_popWindow = nullptr;
|
||||
Dock::Position QuickSettingContainer::m_position = Dock::Position::Bottom;
|
||||
|
||||
QuickSettingContainer::QuickSettingContainer(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, m_switchLayout(new QStackedLayout(this))
|
||||
, m_mainWidget(new QWidget(this))
|
||||
, m_pluginWidget(new QWidget(m_mainWidget))
|
||||
, m_pluginLayout(new QGridLayout(m_pluginWidget))
|
||||
, m_componentWidget(new QWidget(m_mainWidget))
|
||||
, m_mainlayout(new QVBoxLayout(m_mainWidget))
|
||||
, m_pluginLoader(QuickSettingController::instance())
|
||||
, m_childPage(new PluginChildPage(this))
|
||||
, m_dragInfo(new struct QuickDragInfo)
|
||||
, m_childShowPlugin(nullptr)
|
||||
{
|
||||
initUi();
|
||||
initConnection();
|
||||
m_childPage->installEventFilter(this);
|
||||
setMouseTracking(true);
|
||||
}
|
||||
|
||||
QuickSettingContainer::~QuickSettingContainer()
|
||||
{
|
||||
delete m_dragInfo;
|
||||
}
|
||||
|
||||
void QuickSettingContainer::showPage(QWidget *widget, PluginsItemInterface *pluginInter, bool canBack)
|
||||
{
|
||||
if (widget && pluginInter && widget != m_mainWidget) {
|
||||
m_childShowPlugin = pluginInter;
|
||||
m_childPage->setTitle(pluginInter->pluginDisplayName());
|
||||
m_childPage->setCanBack(canBack);
|
||||
m_childPage->pushWidget(widget);
|
||||
m_switchLayout->setCurrentWidget(m_childPage);
|
||||
} else {
|
||||
m_childShowPlugin = nullptr;
|
||||
m_switchLayout->setCurrentIndex(0);
|
||||
}
|
||||
|
||||
onResizeView();
|
||||
}
|
||||
|
||||
// 根据位置获取箭头的方向
|
||||
static DArrowRectangle::ArrowDirection getDirection(const Dock::Position &position)
|
||||
{
|
||||
switch (position) {
|
||||
case Dock::Position::Top:
|
||||
return DArrowRectangle::ArrowDirection::ArrowTop;
|
||||
case Dock::Position::Left:
|
||||
return DArrowRectangle::ArrowDirection::ArrowLeft;
|
||||
case Dock::Position::Right:
|
||||
return DArrowRectangle::ArrowDirection::ArrowRight;
|
||||
default:
|
||||
return DArrowRectangle::ArrowDirection::ArrowBottom;
|
||||
}
|
||||
|
||||
return DArrowRectangle::ArrowDirection::ArrowBottom;
|
||||
}
|
||||
|
||||
DockPopupWindow *QuickSettingContainer::popWindow()
|
||||
{
|
||||
if (m_popWindow)
|
||||
return m_popWindow;
|
||||
|
||||
m_popWindow = new DockPopupWindow;
|
||||
m_popWindow->setShadowBlurRadius(20);
|
||||
m_popWindow->setRadius(18);
|
||||
m_popWindow->setShadowYOffset(2);
|
||||
m_popWindow->setShadowXOffset(0);
|
||||
m_popWindow->setArrowWidth(18);
|
||||
m_popWindow->setArrowHeight(10);
|
||||
m_popWindow->setArrowDirection(getDirection(m_position));
|
||||
m_popWindow->setContent(new QuickSettingContainer(m_popWindow));
|
||||
m_popWindow->setWindowFlags(Qt::FramelessWindowHint | Qt::Tool);
|
||||
return m_popWindow;
|
||||
}
|
||||
|
||||
void QuickSettingContainer::setPosition(Position position)
|
||||
{
|
||||
if (m_position == position)
|
||||
return;
|
||||
|
||||
m_position = position;
|
||||
|
||||
if (m_popWindow) {
|
||||
m_popWindow->setArrowDirection(getDirection(m_position));
|
||||
// 在任务栏位置发生变化的时候,需要将当前的content获取后,重新调用setContent接口
|
||||
// 如果不调用,那么就会出现内容在容器内部的位置错误,界面上的布局会乱
|
||||
QWidget *widget = m_popWindow->getContent();
|
||||
m_popWindow->setContent(widget);
|
||||
}
|
||||
}
|
||||
|
||||
bool QuickSettingContainer::eventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
switch (event->type()) {
|
||||
case QEvent::Resize: {
|
||||
onResizeView();
|
||||
break;
|
||||
}
|
||||
case QEvent::MouseButtonPress: {
|
||||
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
|
||||
QuickSettingItem *item = qobject_cast<QuickSettingItem *>(watched);
|
||||
if (item) {
|
||||
m_dragInfo->dragPosition = mouseEvent->pos();
|
||||
m_dragInfo->dragItem = item;
|
||||
m_dragInfo->pluginInter = item->pluginItem();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case QEvent::MouseButtonRelease: {
|
||||
m_dragInfo->reset();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return QWidget::eventFilter(watched, event);
|
||||
}
|
||||
|
||||
void QuickSettingContainer::appendPlugin(PluginsItemInterface *itemInter, bool needLayout)
|
||||
{
|
||||
QuickSettingItem *quickItem = QuickSettingFactory::createQuickWidget(itemInter);
|
||||
if (!quickItem)
|
||||
return;
|
||||
|
||||
quickItem->setParent(m_pluginWidget);
|
||||
quickItem->setMouseTracking(true);
|
||||
quickItem->installEventFilter(this);
|
||||
connect(quickItem, &QuickSettingItem::requestShowChildWidget, this, &QuickSettingContainer::onShowChildWidget);
|
||||
m_quickSettings << quickItem;
|
||||
if (quickItem->type() == QuickSettingItem::QuickSettingType::Full) {
|
||||
// 插件位置占据整行,例如声音、亮度和音乐等
|
||||
m_componentWidget->layout()->addWidget(quickItem);
|
||||
updateFullItemLayout();
|
||||
} else if (needLayout) {
|
||||
// 插件占据两行或者一行
|
||||
updateItemLayout();
|
||||
}
|
||||
|
||||
onResizeView();
|
||||
}
|
||||
|
||||
void QuickSettingContainer::onPluginRemove(PluginsItemInterface *itemInter)
|
||||
{
|
||||
QList<QuickSettingItem *>::Iterator removeItemIter = std::find_if(m_quickSettings.begin(), m_quickSettings.end(), [ = ](QuickSettingItem *item)->bool {
|
||||
return item->pluginItem() == itemInter;
|
||||
});
|
||||
|
||||
if (removeItemIter == m_quickSettings.end())
|
||||
return;
|
||||
|
||||
QuickSettingItem *removeItem = *removeItemIter;
|
||||
removeItem->detachPlugin();
|
||||
|
||||
if (removeItem->type() == QuickSettingItem::QuickSettingType::Full)
|
||||
m_componentWidget->layout()->removeWidget(removeItem);
|
||||
else
|
||||
m_pluginLayout->removeWidget(removeItem);
|
||||
|
||||
m_quickSettings.removeOne(removeItem);
|
||||
removeItem->deleteLater();
|
||||
if (m_childShowPlugin == itemInter)
|
||||
showPage(nullptr);
|
||||
|
||||
updateItemLayout();
|
||||
updateFullItemLayout();
|
||||
onResizeView();
|
||||
}
|
||||
|
||||
void QuickSettingContainer::onShowChildWidget(QWidget *childWidget)
|
||||
{
|
||||
QuickSettingItem *quickWidget = qobject_cast<QuickSettingItem *>(sender());
|
||||
if (!quickWidget)
|
||||
return;
|
||||
|
||||
showPage(childWidget, quickWidget->pluginItem(), true);
|
||||
}
|
||||
|
||||
void QuickSettingContainer::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
if (m_dragInfo->isNull())
|
||||
return;
|
||||
|
||||
QPoint pointCurrent = event->pos();
|
||||
if (qAbs(m_dragInfo->dragPosition.x() - pointCurrent.x()) > 5
|
||||
|| qAbs(m_dragInfo->dragPosition.y() - pointCurrent.y()) > 5) {
|
||||
QuickSettingItem *moveItem = qobject_cast<QuickSettingItem *>(m_dragInfo->dragItem);
|
||||
QuickIconDrag *drag = new QuickIconDrag(this, moveItem->dragPixmap());
|
||||
QuickPluginMimeData *mimedata = new QuickPluginMimeData(m_dragInfo->pluginInter, drag);
|
||||
drag->setMimeData(mimedata);
|
||||
drag->setDragHotPot(m_dragInfo->dragPosition);
|
||||
|
||||
m_dragInfo->reset();
|
||||
drag->exec(Qt::CopyAction);
|
||||
}
|
||||
}
|
||||
|
||||
void QuickSettingContainer::updateItemLayout()
|
||||
{
|
||||
// 清空之前的控件,重新添加
|
||||
while (m_pluginLayout->count() > 0)
|
||||
m_pluginLayout->takeAt(0);
|
||||
|
||||
// 将插件按照两列和一列的顺序来进行排序
|
||||
QMap<QuickSettingItem::QuickSettingType, QList<QuickSettingItem *>> quickSettings;
|
||||
QMap<QuickSettingItem::QuickSettingType, QMap<QuickSettingItem *, int>> orderQuickSettings;
|
||||
QuickSettingController *quickController = QuickSettingController::instance();
|
||||
for (QuickSettingItem *item : m_quickSettings) {
|
||||
QuickSettingItem::QuickSettingType type = item->type();
|
||||
if (type == QuickSettingItem::QuickSettingType::Full)
|
||||
continue;
|
||||
|
||||
QJsonObject metaData = quickController->metaData(item->pluginItem());
|
||||
if (metaData.contains("order"))
|
||||
orderQuickSettings[type][item] = metaData.value("order").toInt();
|
||||
else
|
||||
quickSettings[type] << item;
|
||||
}
|
||||
// 将需要排序的插件按照顺序插入到原来的数组中
|
||||
for (auto itQuick = orderQuickSettings.begin(); itQuick != orderQuickSettings.end(); itQuick++) {
|
||||
QuickSettingItem::QuickSettingType type = itQuick.key();
|
||||
QMap<QuickSettingItem *, int> &orderQuicks = itQuick.value();
|
||||
for (auto it = orderQuicks.begin(); it != orderQuicks.end(); it++) {
|
||||
int index = it.value();
|
||||
if (index >= 0 && index < quickSettings[type].size())
|
||||
quickSettings[type][index] = it.key();
|
||||
else
|
||||
quickSettings[type] << it.key();
|
||||
}
|
||||
}
|
||||
auto insertQuickSetting = [ quickSettings, this ](QuickSettingItem::QuickSettingType type, int &row, int &column) {
|
||||
if (!quickSettings.contains(type))
|
||||
return;
|
||||
|
||||
int usedColumn = (type == QuickSettingItem::QuickSettingType::Multi ? 2 : 1);
|
||||
QList<QuickSettingItem *> quickPlugins = quickSettings[type];
|
||||
for (QuickSettingItem *quickItem : quickPlugins) {
|
||||
quickItem->setVisible(true);
|
||||
m_pluginLayout->addWidget(quickItem, row, column, 1, usedColumn);
|
||||
column += usedColumn;
|
||||
if (column >= COLUMNCOUNT) {
|
||||
row++;
|
||||
column = 0;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int row = 0;
|
||||
int column = 0;
|
||||
insertQuickSetting(QuickSettingItem::QuickSettingType::Multi, row, column);
|
||||
insertQuickSetting(QuickSettingItem::QuickSettingType::Single, row, column);
|
||||
}
|
||||
|
||||
void QuickSettingContainer::updateFullItemLayout()
|
||||
{
|
||||
while (m_componentWidget->layout()->count() > 0)
|
||||
m_componentWidget->layout()->takeAt(0);
|
||||
|
||||
QuickSettingController *quickController = QuickSettingController::instance();
|
||||
QList<QuickSettingItem *> fullItems;
|
||||
QMap<QuickSettingItem *, int> fullItemOrder;
|
||||
for (QuickSettingItem *item : m_quickSettings) {
|
||||
if (item->type() != QuickSettingItem::QuickSettingType::Full)
|
||||
continue;
|
||||
|
||||
fullItems << item;
|
||||
int order = -1;
|
||||
QJsonObject metaData = quickController->metaData(item->pluginItem());
|
||||
if (metaData.contains("order"))
|
||||
order = metaData.value("order").toInt();
|
||||
|
||||
fullItemOrder[item] = order;
|
||||
}
|
||||
|
||||
std::sort(fullItems.begin(), fullItems.end(), [ fullItemOrder ](QuickSettingItem *item1, QuickSettingItem *item2) {
|
||||
int order1 = fullItemOrder.value(item1, -1);
|
||||
int order2 = fullItemOrder.value(item2, -1);
|
||||
if (order1 == order2)
|
||||
return true;
|
||||
if (order1 == -1)
|
||||
return false;
|
||||
if (order2 == -1)
|
||||
return true;
|
||||
|
||||
return order1 < order2;
|
||||
});
|
||||
|
||||
for (QuickSettingItem *item : fullItems) {
|
||||
item->setVisible(true);
|
||||
m_componentWidget->layout()->addWidget(item);
|
||||
}
|
||||
}
|
||||
|
||||
void QuickSettingContainer::initUi()
|
||||
{
|
||||
m_mainlayout->setSpacing(ITEMSPACE);
|
||||
m_mainlayout->setContentsMargins(ITEMSPACE, ITEMSPACE, ITEMSPACE, ITEMSPACE);
|
||||
|
||||
m_pluginLayout->setContentsMargins(0, 0, 0, 0);
|
||||
m_pluginLayout->setSpacing(ITEMSPACE);
|
||||
m_pluginLayout->setAlignment(Qt::AlignLeft);
|
||||
for (int i = 0; i < COLUMNCOUNT; i++)
|
||||
m_pluginLayout->setColumnMinimumWidth(i, ITEMWIDTH);
|
||||
|
||||
m_pluginWidget->setLayout(m_pluginLayout);
|
||||
m_mainlayout->addWidget(m_pluginWidget);
|
||||
|
||||
QVBoxLayout *ctrlLayout = new QVBoxLayout(m_componentWidget);
|
||||
ctrlLayout->setContentsMargins(0, 0, 0, 0);
|
||||
ctrlLayout->setSpacing(ITEMSPACE);
|
||||
ctrlLayout->setDirection(QBoxLayout::BottomToTop);
|
||||
|
||||
m_mainlayout->addWidget(m_componentWidget);
|
||||
// 加载所有的插件
|
||||
QList<PluginsItemInterface *> plugins = m_pluginLoader->pluginItems(QuickSettingController::PluginAttribute::Quick);
|
||||
for (PluginsItemInterface *plugin : plugins)
|
||||
appendPlugin(plugin, false);
|
||||
|
||||
m_switchLayout->addWidget(m_mainWidget);
|
||||
m_switchLayout->addWidget(m_childPage);
|
||||
|
||||
setMouseTracking(true);
|
||||
setAcceptDrops(true);
|
||||
|
||||
QMetaObject::invokeMethod(this, [ = ] {
|
||||
if (plugins.size() > 0) {
|
||||
updateItemLayout();
|
||||
updateFullItemLayout();
|
||||
}
|
||||
// 设置当前窗口的大小
|
||||
onResizeView();
|
||||
setFixedWidth(ITEMWIDTH * 4 + (ITEMSPACE * 5));
|
||||
}, Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
void QuickSettingContainer::initConnection()
|
||||
{
|
||||
connect(m_pluginLoader, &QuickSettingController::pluginInserted, this, [ = ](PluginsItemInterface *itemInter, const QuickSettingController::PluginAttribute pluginAttr) {
|
||||
if (pluginAttr != QuickSettingController::PluginAttribute::Quick)
|
||||
return;
|
||||
|
||||
appendPlugin(itemInter);
|
||||
});
|
||||
connect(m_pluginLoader, &QuickSettingController::pluginRemoved, this, &QuickSettingContainer::onPluginRemove);
|
||||
connect(m_pluginLoader, &QuickSettingController::pluginUpdated, this, &QuickSettingContainer::onPluginUpdated);
|
||||
|
||||
connect(m_childPage, &PluginChildPage::back, this, [ this ] {
|
||||
showPage(m_mainWidget);
|
||||
});
|
||||
connect(m_childPage, &PluginChildPage::closeSelf, this, [ this ] {
|
||||
if (!m_childPage->isBack())
|
||||
topLevelWidget()->hide();
|
||||
});
|
||||
}
|
||||
|
||||
// 调整尺寸
|
||||
void QuickSettingContainer::onResizeView()
|
||||
{
|
||||
if (m_switchLayout->currentWidget() == m_mainWidget) {
|
||||
int selfPluginCount = 0;
|
||||
int fullItemHeight = 0;
|
||||
int widgetCount = 0;
|
||||
for (QuickSettingItem *item : m_quickSettings) {
|
||||
if (item->type() == QuickSettingItem::QuickSettingType::Full) {
|
||||
fullItemHeight += item->height();
|
||||
widgetCount++;
|
||||
continue;
|
||||
}
|
||||
// 如果是置顶的插件,则认为它占用两个普通插件的位置
|
||||
int increCount = (item->type() == QuickSettingItem::QuickSettingType::Multi ? 2 : 1);
|
||||
selfPluginCount += increCount;
|
||||
}
|
||||
|
||||
int rowCount = selfPluginCount / COLUMNCOUNT;
|
||||
if (selfPluginCount % COLUMNCOUNT > 0)
|
||||
rowCount++;
|
||||
|
||||
m_pluginWidget->setFixedHeight(ITEMHEIGHT * rowCount + ITEMSPACE * (rowCount - 1));
|
||||
m_componentWidget->setFixedHeight(fullItemHeight + (widgetCount - 1) * ITEMSPACE);
|
||||
|
||||
setFixedHeight(ITEMSPACE * 3 + m_pluginWidget->height() + m_componentWidget->height());
|
||||
} else if (m_switchLayout->currentWidget() == m_childPage) {
|
||||
setFixedHeight(m_childPage->height());
|
||||
}
|
||||
}
|
||||
|
||||
void QuickSettingContainer::onPluginUpdated(PluginsItemInterface *itemInter, const DockPart dockPart)
|
||||
{
|
||||
if (dockPart != DockPart::QuickPanel)
|
||||
return;
|
||||
|
||||
for (QuickSettingItem *settingItem : m_quickSettings) {
|
||||
if (settingItem->pluginItem() != itemInter)
|
||||
continue;
|
||||
|
||||
settingItem->updateShow();
|
||||
break;
|
||||
}
|
||||
}
|
@ -1,99 +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 QUICKSETTINGCONTAINER_H
|
||||
#define QUICKSETTINGCONTAINER_H
|
||||
|
||||
#include "pluginproxyinterface.h"
|
||||
|
||||
#include "dtkwidget_global.h"
|
||||
|
||||
#include <DListView>
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class DockItem;
|
||||
class QVBoxLayout;
|
||||
class QuickSettingController;
|
||||
class BrightnessModel;
|
||||
class BrightnessWidget;
|
||||
class QuickSettingItem;
|
||||
class DockPopupWindow;
|
||||
class QStackedLayout;
|
||||
class VolumeDevicesWidget;
|
||||
class QLabel;
|
||||
class PluginChildPage;
|
||||
class QGridLayout;
|
||||
class DisplaySettingWidget;
|
||||
struct QuickDragInfo;
|
||||
|
||||
DWIDGET_USE_NAMESPACE
|
||||
|
||||
class QuickSettingContainer : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static DockPopupWindow *popWindow();
|
||||
static void setPosition(Dock::Position position);
|
||||
void showPage(QWidget *widget, PluginsItemInterface *pluginInter = nullptr, bool canBack = false);
|
||||
|
||||
protected:
|
||||
void mouseMoveEvent(QMouseEvent *event) override;
|
||||
bool eventFilter(QObject *watched, QEvent *event) override;
|
||||
|
||||
explicit QuickSettingContainer(QWidget *parent = nullptr);
|
||||
~QuickSettingContainer() override;
|
||||
|
||||
private Q_SLOTS:
|
||||
void onPluginRemove(PluginsItemInterface *itemInter);
|
||||
void onShowChildWidget(QWidget *childWidget);
|
||||
void onResizeView();
|
||||
void onPluginUpdated(PluginsItemInterface *itemInter, const DockPart dockPart);
|
||||
|
||||
private:
|
||||
// 加载UI
|
||||
void initUi();
|
||||
// 初始化槽函数
|
||||
void initConnection();
|
||||
// 调整控件位置
|
||||
void updateItemLayout();
|
||||
// 调整全列插件的位置
|
||||
void updateFullItemLayout();
|
||||
// 插入插件
|
||||
void appendPlugin(PluginsItemInterface *itemInter, bool needLayout = true);
|
||||
|
||||
private:
|
||||
static DockPopupWindow *m_popWindow;
|
||||
static Dock::Position m_position;
|
||||
QStackedLayout *m_switchLayout;
|
||||
QWidget *m_mainWidget;
|
||||
QWidget *m_pluginWidget;
|
||||
QGridLayout *m_pluginLayout;
|
||||
QWidget *m_componentWidget;
|
||||
QVBoxLayout *m_mainlayout;
|
||||
QuickSettingController *m_pluginLoader;
|
||||
PluginChildPage *m_childPage;
|
||||
QuickDragInfo *m_dragInfo;
|
||||
QList<QuickSettingItem *> m_quickSettings;
|
||||
PluginsItemInterface *m_childShowPlugin;
|
||||
};
|
||||
|
||||
#endif // PLUGINCONTAINER_H
|
@ -24,7 +24,6 @@
|
||||
#include "tray_delegate.h"
|
||||
#include "tray_model.h"
|
||||
#include "constants.h"
|
||||
#include "quicksettingcontainer.h"
|
||||
#include "systempluginwindow.h"
|
||||
#include "datetimedisplayer.h"
|
||||
#include "expandiconwidget.h"
|
||||
@ -486,7 +485,7 @@ void TrayManagerWindow::dropEvent(QDropEvent *e)
|
||||
if (!e || !e->mimeData() || e->source() == this)
|
||||
return;
|
||||
|
||||
if (qobject_cast<QuickSettingContainer *>(e->source())) {
|
||||
if (m_quickIconWidget->isQuickWindow(e->source())) {
|
||||
const QuickPluginMimeData *mimeData = qobject_cast<const QuickPluginMimeData *>(e->mimeData());
|
||||
if (!mimeData)
|
||||
return;
|
||||
|
Loading…
x
Reference in New Issue
Block a user