2023-02-16 13:51:55 +08:00
|
|
|
|
// Copyright (C) 2022 ~ 2022 Deepin Technology Co., Ltd.
|
|
|
|
|
// SPDX-FileCopyrightText: 2018 - 2023 UnionTech Software Technology Co., Ltd.
|
|
|
|
|
//
|
|
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
|
2022-05-12 17:09:10 +08:00
|
|
|
|
#include "systempluginwindow.h"
|
2023-06-07 14:11:50 +08:00
|
|
|
|
#include "docksettings.h"
|
2022-05-12 17:09:10 +08:00
|
|
|
|
#include "systempluginitem.h"
|
2022-10-19 03:50:12 +00:00
|
|
|
|
#include "quicksettingcontroller.h"
|
2022-12-12 09:52:52 +00:00
|
|
|
|
#include "utils.h"
|
2022-05-12 17:09:10 +08:00
|
|
|
|
|
|
|
|
|
#include <DListView>
|
2022-12-01 10:17:37 +08:00
|
|
|
|
#include <DGuiApplicationHelper>
|
|
|
|
|
|
2022-05-12 17:09:10 +08:00
|
|
|
|
#include <QBoxLayout>
|
2022-05-26 18:07:43 +08:00
|
|
|
|
#include <QDir>
|
2022-05-12 17:09:10 +08:00
|
|
|
|
#include <QMetaObject>
|
2022-06-15 13:35:50 +00:00
|
|
|
|
#include <QGuiApplication>
|
2023-04-07 14:43:09 +08:00
|
|
|
|
#include <QPainter>
|
2023-06-07 14:11:50 +08:00
|
|
|
|
#include <sys/types.h>
|
2022-05-12 17:09:10 +08:00
|
|
|
|
|
|
|
|
|
#define MAXICONSIZE 48
|
|
|
|
|
#define MINICONSIZE 24
|
|
|
|
|
#define ICONMARGIN 8
|
|
|
|
|
|
2023-06-07 14:11:50 +08:00
|
|
|
|
SystemPluginWindow::SystemPluginWindow(QWidget *parent)
|
2022-05-25 09:42:01 +08:00
|
|
|
|
: QWidget(parent)
|
2022-05-12 17:09:10 +08:00
|
|
|
|
, m_listView(new DListView(this))
|
2022-10-19 03:50:12 +00:00
|
|
|
|
, m_displayMode(Dock::DisplayMode::Efficient)
|
2022-05-12 17:09:10 +08:00
|
|
|
|
, m_position(Dock::Position::Bottom)
|
|
|
|
|
, m_mainLayout(new QBoxLayout(QBoxLayout::Direction::LeftToRight, this))
|
|
|
|
|
{
|
|
|
|
|
initUi();
|
2022-10-19 03:50:12 +00:00
|
|
|
|
initConnection();
|
2022-05-12 17:09:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SystemPluginWindow::~SystemPluginWindow()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-19 03:50:12 +00:00
|
|
|
|
void SystemPluginWindow::setDisplayMode(const DisplayMode &displayMode)
|
|
|
|
|
{
|
|
|
|
|
m_displayMode = displayMode;
|
2022-12-12 09:52:52 +00:00
|
|
|
|
QList<StretchPluginsItem *> items = stretchItems();
|
|
|
|
|
switch (m_position) {
|
|
|
|
|
case Dock::Position::Top:
|
|
|
|
|
case Dock::Position::Bottom: {
|
|
|
|
|
for (StretchPluginsItem *item : items)
|
|
|
|
|
item->setDisplayMode(displayMode);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case Dock::Position::Left:
|
|
|
|
|
case Dock::Position::Right: {
|
|
|
|
|
for (StretchPluginsItem *item : items)
|
|
|
|
|
item->setDisplayMode(displayMode);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-11-09 10:17:33 +00:00
|
|
|
|
}
|
2022-10-19 03:50:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-12 17:09:10 +08:00
|
|
|
|
void SystemPluginWindow::setPositon(Position position)
|
|
|
|
|
{
|
|
|
|
|
if (m_position == position)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
m_position = position;
|
|
|
|
|
|
|
|
|
|
if (m_position == Dock::Position::Top || m_position == Dock::Position::Bottom)
|
|
|
|
|
m_mainLayout->setDirection(QBoxLayout::Direction::LeftToRight);
|
|
|
|
|
else
|
|
|
|
|
m_mainLayout->setDirection(QBoxLayout::Direction::TopToBottom);
|
2022-05-26 18:07:43 +08:00
|
|
|
|
|
2022-11-09 05:36:03 +00:00
|
|
|
|
StretchPluginsItem::setPosition(position);
|
|
|
|
|
|
2022-05-26 18:07:43 +08:00
|
|
|
|
QObjectList childObjects = children();
|
|
|
|
|
for (QObject *childObject : childObjects) {
|
|
|
|
|
StretchPluginsItem *item = qobject_cast<StretchPluginsItem *>(childObject);
|
|
|
|
|
if (!item)
|
|
|
|
|
continue;
|
|
|
|
|
|
2022-11-09 05:36:03 +00:00
|
|
|
|
item->update();
|
2022-05-26 18:07:43 +08:00
|
|
|
|
}
|
2022-05-12 17:09:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-08-25 19:31:31 +00:00
|
|
|
|
QSize SystemPluginWindow::suitableSize() const
|
|
|
|
|
{
|
|
|
|
|
return suitableSize(m_position);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QSize SystemPluginWindow::suitableSize(const Position &position) const
|
2022-05-12 17:09:10 +08:00
|
|
|
|
{
|
2022-12-12 09:52:52 +00:00
|
|
|
|
QList<StretchPluginsItem *> items = stretchItems();
|
2022-08-25 19:31:31 +00:00
|
|
|
|
if (position == Dock::Position::Top || position == Dock::Position::Bottom) {
|
2022-05-26 18:07:43 +08:00
|
|
|
|
int itemWidth = 0;
|
2022-12-12 09:52:52 +00:00
|
|
|
|
for (StretchPluginsItem *item : items)
|
|
|
|
|
itemWidth += item->suitableSize(position).width();
|
2022-05-12 17:09:10 +08:00
|
|
|
|
|
2022-05-26 18:07:43 +08:00
|
|
|
|
return QSize(itemWidth, QWIDGETSIZE_MAX);
|
2022-05-12 17:09:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-26 18:07:43 +08:00
|
|
|
|
int itemHeight = 0;
|
2022-12-12 09:52:52 +00:00
|
|
|
|
for (StretchPluginsItem *item : items)
|
2022-08-25 19:31:31 +00:00
|
|
|
|
itemHeight += item->suitableSize(position).height();
|
2022-05-12 17:09:10 +08:00
|
|
|
|
|
2022-05-26 18:07:43 +08:00
|
|
|
|
return QSize(QWIDGETSIZE_MAX, itemHeight);
|
2022-05-12 17:09:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-02 06:57:46 +00:00
|
|
|
|
bool SystemPluginWindow::eventFilter(QObject *watched, QEvent *event)
|
|
|
|
|
{
|
|
|
|
|
if (event->type() == QEvent::Drop)
|
|
|
|
|
Q_EMIT requestDrop(static_cast<QDropEvent *>(event));
|
|
|
|
|
|
|
|
|
|
return QWidget::eventFilter(watched, event);
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-12 17:09:10 +08:00
|
|
|
|
void SystemPluginWindow::initUi()
|
|
|
|
|
{
|
2022-05-26 18:07:43 +08:00
|
|
|
|
m_mainLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
m_mainLayout->setSpacing(0);
|
2022-11-02 06:57:46 +00:00
|
|
|
|
installEventFilter(this);
|
2022-05-12 17:09:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-19 03:50:12 +00:00
|
|
|
|
void SystemPluginWindow::initConnection()
|
|
|
|
|
{
|
|
|
|
|
QuickSettingController *quickController = QuickSettingController::instance();
|
2022-11-04 07:28:51 +00:00
|
|
|
|
connect(quickController, &QuickSettingController::pluginInserted, this, [ = ](PluginsItemInterface *itemInter, const QuickSettingController::PluginAttribute pluginAttr) {
|
2022-11-02 06:35:04 +00:00
|
|
|
|
if (pluginAttr != QuickSettingController::PluginAttribute::System)
|
2022-10-19 03:50:12 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
pluginAdded(itemInter);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
connect(quickController, &QuickSettingController::pluginRemoved, this, &SystemPluginWindow::onPluginItemRemoved);
|
|
|
|
|
connect(quickController, &QuickSettingController::pluginUpdated, this, &SystemPluginWindow::onPluginItemUpdated);
|
|
|
|
|
|
2022-11-02 06:35:04 +00:00
|
|
|
|
QList<PluginsItemInterface *> plugins = quickController->pluginItems(QuickSettingController::PluginAttribute::System);
|
2022-10-19 03:50:12 +00:00
|
|
|
|
for (int i = 0; i < plugins.size(); i++)
|
|
|
|
|
pluginAdded(plugins[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StretchPluginsItem *SystemPluginWindow::findPluginItemWidget(PluginsItemInterface *pluginItem)
|
2022-06-17 10:54:29 +08:00
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < m_mainLayout->count(); i++) {
|
|
|
|
|
QLayoutItem *layoutItem = m_mainLayout->itemAt(i);
|
|
|
|
|
if (!layoutItem)
|
|
|
|
|
continue;
|
|
|
|
|
|
2022-10-19 03:50:12 +00:00
|
|
|
|
StretchPluginsItem *itemWidget = qobject_cast<StretchPluginsItem *>(layoutItem->widget());
|
|
|
|
|
if (itemWidget && itemWidget->pluginInter() == pluginItem)
|
|
|
|
|
return itemWidget;
|
2022-06-17 10:54:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-19 03:50:12 +00:00
|
|
|
|
return nullptr;
|
2022-06-17 10:54:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-19 03:50:12 +00:00
|
|
|
|
void SystemPluginWindow::pluginAdded(PluginsItemInterface *plugin)
|
2022-05-12 17:09:10 +08:00
|
|
|
|
{
|
2023-06-07 14:11:50 +08:00
|
|
|
|
StretchPluginsItem *item = new StretchPluginsItem(plugin, QuickSettingController::instance()->itemKey(plugin));
|
2022-10-19 03:50:12 +00:00
|
|
|
|
item->setDisplayMode(m_displayMode);
|
|
|
|
|
item->setPosition(m_position);
|
2022-11-02 06:57:46 +00:00
|
|
|
|
item->installEventFilter(this);
|
2022-10-19 03:50:12 +00:00
|
|
|
|
item->setParent(this);
|
|
|
|
|
item->show();
|
|
|
|
|
m_mainLayout->addWidget(item);
|
2022-06-20 15:03:35 +08:00
|
|
|
|
Q_EMIT itemChanged();
|
2022-05-12 17:09:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-12-12 09:52:52 +00:00
|
|
|
|
QList<StretchPluginsItem *> SystemPluginWindow::stretchItems() const
|
|
|
|
|
{
|
|
|
|
|
QList<StretchPluginsItem *> items;
|
|
|
|
|
QObjectList childObjects = children();
|
|
|
|
|
for (QObject *childObject : childObjects) {
|
|
|
|
|
StretchPluginsItem *item = qobject_cast<StretchPluginsItem *>(childObject);
|
|
|
|
|
if (!item)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
items << item;
|
|
|
|
|
}
|
|
|
|
|
return items;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-19 03:50:12 +00:00
|
|
|
|
void SystemPluginWindow::onPluginItemRemoved(PluginsItemInterface *pluginItem)
|
2022-05-12 17:09:10 +08:00
|
|
|
|
{
|
2022-10-19 03:50:12 +00:00
|
|
|
|
StretchPluginsItem *item = findPluginItemWidget(pluginItem);
|
|
|
|
|
if (item) {
|
|
|
|
|
item->setParent(nullptr);
|
|
|
|
|
item->hide();
|
|
|
|
|
m_mainLayout->removeWidget(item);
|
|
|
|
|
Q_EMIT itemChanged();
|
|
|
|
|
}
|
2022-05-12 17:09:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-19 03:50:12 +00:00
|
|
|
|
void SystemPluginWindow::onPluginItemUpdated(PluginsItemInterface *pluginItem)
|
2022-05-12 17:09:10 +08:00
|
|
|
|
{
|
2022-10-19 03:50:12 +00:00
|
|
|
|
StretchPluginsItem *item = findPluginItemWidget(pluginItem);
|
|
|
|
|
if (item)
|
|
|
|
|
item->update();
|
2022-05-12 17:09:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-31 10:55:04 +08:00
|
|
|
|
// 图标的尺寸
|
2022-05-26 18:07:43 +08:00
|
|
|
|
#define ICONSIZE 20
|
|
|
|
|
#define ICONTEXTSPACE 6
|
|
|
|
|
#define PLUGIN_ITEM_DRAG_THRESHOLD 20
|
|
|
|
|
|
2022-11-09 05:36:03 +00:00
|
|
|
|
Dock::Position StretchPluginsItem::m_position = Dock::Position::Bottom;
|
|
|
|
|
|
2023-06-07 14:11:50 +08:00
|
|
|
|
StretchPluginsItem::StretchPluginsItem(PluginsItemInterface * const pluginInter, const QString &itemKey, QWidget *parent)
|
2022-05-26 18:07:43 +08:00
|
|
|
|
: DockItem(parent)
|
|
|
|
|
, m_pluginInter(pluginInter)
|
|
|
|
|
, m_itemKey(itemKey)
|
2022-11-09 10:17:33 +00:00
|
|
|
|
, m_displayMode(Dock::DisplayMode::Efficient)
|
2023-06-07 14:11:50 +08:00
|
|
|
|
, m_windowSizeFashion(DockSettings::instance()->getWindowSizeFashion())
|
2022-05-26 18:07:43 +08:00
|
|
|
|
{
|
2023-06-07 14:11:50 +08:00
|
|
|
|
connect(DockSettings::instance(), &DockSettings::windowSizeFashionChanged, this, [=](uint size) {
|
|
|
|
|
m_windowSizeFashion = size;
|
|
|
|
|
});
|
2022-05-26 18:07:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StretchPluginsItem::~StretchPluginsItem()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-19 03:50:12 +00:00
|
|
|
|
void StretchPluginsItem::setDisplayMode(const DisplayMode &displayMode)
|
|
|
|
|
{
|
|
|
|
|
m_displayMode = displayMode;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-26 18:07:43 +08:00
|
|
|
|
void StretchPluginsItem::setPosition(Position position)
|
|
|
|
|
{
|
|
|
|
|
m_position = position;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString StretchPluginsItem::itemKey() const
|
|
|
|
|
{
|
|
|
|
|
return m_itemKey;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-25 19:31:31 +00:00
|
|
|
|
QSize StretchPluginsItem::suitableSize() const
|
|
|
|
|
{
|
|
|
|
|
return suitableSize(m_position);
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-26 18:07:43 +08:00
|
|
|
|
PluginsItemInterface *StretchPluginsItem::pluginInter() const
|
|
|
|
|
{
|
|
|
|
|
return m_pluginInter;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StretchPluginsItem::paintEvent(QPaintEvent *event)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(event);
|
|
|
|
|
QPainter painter(this);
|
2022-12-02 15:41:34 +08:00
|
|
|
|
QIcon icon = m_pluginInter->icon(DockPart::SystemPanel);
|
2022-05-26 18:07:43 +08:00
|
|
|
|
|
|
|
|
|
QRect rctPixmap(rect());
|
|
|
|
|
if (needShowText()) {
|
|
|
|
|
int textHeight = QFontMetrics(textFont()).height();
|
|
|
|
|
// 文本与图标的间距为6
|
|
|
|
|
int iconTop = (height() - textHeight - ICONSIZE - ICONTEXTSPACE) / 2;
|
|
|
|
|
rctPixmap.setX((width() - ICONSIZE) / 2);
|
|
|
|
|
rctPixmap.setY(iconTop);
|
|
|
|
|
rctPixmap.setWidth(ICONSIZE);
|
|
|
|
|
rctPixmap.setHeight(ICONSIZE);
|
|
|
|
|
// 先绘制下面的文本
|
|
|
|
|
painter.setFont(textFont());
|
|
|
|
|
painter.drawText(QRect(0, iconTop + ICONSIZE + ICONTEXTSPACE, width(), textHeight), Qt::AlignCenter, m_pluginInter->pluginDisplayName());
|
|
|
|
|
} else {
|
|
|
|
|
rctPixmap.setX((width() - ICONSIZE) / 2);
|
|
|
|
|
rctPixmap.setY((height() - ICONSIZE) / 2);
|
|
|
|
|
rctPixmap.setWidth(ICONSIZE);
|
|
|
|
|
rctPixmap.setHeight(ICONSIZE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 绘制图标
|
2022-12-19 15:05:49 +08:00
|
|
|
|
int iconSize = static_cast<int>(ICONSIZE * (QCoreApplication::testAttribute(Qt::AA_UseHighDpiPixmaps) ? 1 : qApp->devicePixelRatio()));
|
2022-06-15 13:35:50 +00:00
|
|
|
|
painter.drawPixmap(rctPixmap, icon.pixmap(iconSize, iconSize));
|
2022-05-26 18:07:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-08-25 19:31:31 +00:00
|
|
|
|
QSize StretchPluginsItem::suitableSize(const Position &position) const
|
2022-05-26 18:07:43 +08:00
|
|
|
|
{
|
2022-08-25 19:31:31 +00:00
|
|
|
|
if (position == Dock::Position::Top || position == Dock::Position::Bottom) {
|
2022-11-09 05:36:03 +00:00
|
|
|
|
int textWidth = 0;
|
|
|
|
|
if (needShowText())
|
|
|
|
|
textWidth = QFontMetrics(textFont(position)).boundingRect(m_pluginInter->pluginDisplayName()).width();
|
2023-01-31 10:55:04 +08:00
|
|
|
|
return QSize(qMax(textWidth, ICONSIZE) + (m_displayMode == Dock::DisplayMode::Efficient ? 5 : 10) * 2, -1);
|
2022-05-26 18:07:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-31 10:55:04 +08:00
|
|
|
|
int height = 6; // 图标上边距6
|
|
|
|
|
height += ICONSIZE; // 图标尺寸20
|
|
|
|
|
if (m_displayMode == Dock::DisplayMode::Fashion) {
|
|
|
|
|
height += ICONTEXTSPACE; // 图标与文字间距6
|
|
|
|
|
if (needShowText()) // 只有在显示文本的时候才计算文本的高度
|
|
|
|
|
height += QFontMetrics(textFont(position)).height(); // 文本高度
|
|
|
|
|
}
|
|
|
|
|
height += 4; // 下间距4
|
2022-05-26 18:07:43 +08:00
|
|
|
|
return QSize(-1, height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QFont StretchPluginsItem::textFont() const
|
|
|
|
|
{
|
2022-08-25 19:31:31 +00:00
|
|
|
|
return textFont(m_position);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QFont StretchPluginsItem::textFont(const Position &position) const
|
|
|
|
|
{
|
|
|
|
|
if (position == Dock::Position::Top || position == Dock::Position::Bottom) {
|
2022-05-26 18:07:43 +08:00
|
|
|
|
static QList<QFont> fonts{ DFontSizeManager::instance()->t9(),
|
|
|
|
|
DFontSizeManager::instance()->t8(),
|
|
|
|
|
DFontSizeManager::instance()->t7(),
|
|
|
|
|
DFontSizeManager::instance()->t6() };
|
|
|
|
|
#define MINHEIGHT 50
|
2022-08-25 19:31:31 +00:00
|
|
|
|
// 如果当前的实际位置和请求的位置不一致,说明当前正在切换位置,此时将它的宽度作为它的高度(左到下切换的时候,左侧的宽度和下面的高度一致)
|
|
|
|
|
int size = (m_position == position ? height() : width());
|
|
|
|
|
int index = qMin(qMax((size - MINHEIGHT) / 2, 0), fonts.size() - 1);
|
2022-05-26 18:07:43 +08:00
|
|
|
|
return fonts[index];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return DFontSizeManager::instance()->t10();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool StretchPluginsItem::needShowText() const
|
|
|
|
|
{
|
2022-10-19 03:50:12 +00:00
|
|
|
|
// 如果是高效模式,则不需要显示下面的文本
|
|
|
|
|
if (m_displayMode == Dock::DisplayMode::Efficient)
|
|
|
|
|
return false;
|
2022-12-12 09:52:52 +00:00
|
|
|
|
|
|
|
|
|
// 图标与文本,图标距离上方和文本距离下方的尺寸
|
|
|
|
|
#define SPACEMARGIN 6
|
|
|
|
|
// 文本的高度
|
|
|
|
|
#define TEXTSIZE 14
|
|
|
|
|
// 当前插件父窗口与顶层窗口的上下边距
|
|
|
|
|
#define OUTMARGIN 7
|
|
|
|
|
|
2022-06-01 15:11:45 +08:00
|
|
|
|
// 任务栏在上方或者下方显示的时候,根据设计图,只有在当前区域高度大于50的时候才同时显示文本和图标
|
2022-05-26 18:07:43 +08:00
|
|
|
|
if (m_position == Dock::Position::Top || m_position == Dock::Position::Bottom)
|
2023-06-07 14:11:50 +08:00
|
|
|
|
return ((Utils::isDraging() ? topLevelWidget()->height() : m_windowSizeFashion) >=
|
2022-12-12 09:52:52 +00:00
|
|
|
|
(OUTMARGIN * 2 + SPACEMARGIN * 3 + ICONSIZE + TEXTSIZE));
|
2022-05-26 18:07:43 +08:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QString StretchPluginsItem::contextMenu() const
|
|
|
|
|
{
|
|
|
|
|
return m_pluginInter->itemContextMenu(m_itemKey);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-14 10:46:42 +00:00
|
|
|
|
void StretchPluginsItem::invokedMenuItem(const QString &itemId, const bool checked)
|
|
|
|
|
{
|
|
|
|
|
m_pluginInter->invokedMenuItem(m_itemKey, itemId, checked);
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-18 10:24:21 +00:00
|
|
|
|
QWidget *StretchPluginsItem::popupTips()
|
|
|
|
|
{
|
|
|
|
|
return m_pluginInter->itemTipsWidget(m_itemKey);
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-26 18:07:43 +08:00
|
|
|
|
void StretchPluginsItem::mousePressEvent(QMouseEvent *e)
|
|
|
|
|
{
|
|
|
|
|
m_hover = false;
|
|
|
|
|
update();
|
|
|
|
|
|
|
|
|
|
if (PopupWindow->isVisible())
|
|
|
|
|
hideNonModel();
|
|
|
|
|
|
|
|
|
|
if (e->button() == Qt::LeftButton)
|
|
|
|
|
m_mousePressPoint = e->pos();
|
|
|
|
|
|
|
|
|
|
m_popupTipsDelayTimer->stop();
|
|
|
|
|
hideNonModel();
|
|
|
|
|
|
|
|
|
|
if (e->button() == Qt::RightButton
|
|
|
|
|
&& perfectIconRect().contains(e->pos()))
|
|
|
|
|
return showContextMenu();
|
|
|
|
|
|
|
|
|
|
DockItem::mousePressEvent(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StretchPluginsItem::mouseReleaseEvent(QMouseEvent *e)
|
|
|
|
|
{
|
|
|
|
|
DockItem::mouseReleaseEvent(e);
|
|
|
|
|
|
|
|
|
|
if (e->button() != Qt::LeftButton)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (checkAndResetTapHoldGestureState() && e->source() == Qt::MouseEventSynthesizedByQt)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const QPoint distance = e->pos() - m_mousePressPoint;
|
|
|
|
|
if (distance.manhattanLength() < PLUGIN_ITEM_DRAG_THRESHOLD)
|
|
|
|
|
mouseClick();
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-12 13:55:34 +08:00
|
|
|
|
void StretchPluginsItem::enterEvent(QEvent *event)
|
|
|
|
|
{
|
2023-03-09 16:46:07 +08:00
|
|
|
|
if (auto view = qobject_cast<SystemPluginWindow *>(parentWidget()))
|
|
|
|
|
view->requestDrawBackground(rect());
|
|
|
|
|
|
2023-01-12 13:55:34 +08:00
|
|
|
|
update();
|
|
|
|
|
DockItem::enterEvent(event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StretchPluginsItem::leaveEvent(QEvent *event)
|
|
|
|
|
{
|
2023-03-09 16:46:07 +08:00
|
|
|
|
if (auto view = qobject_cast<SystemPluginWindow *>(parentWidget()))
|
|
|
|
|
view->requestDrawBackground(QRect());
|
2023-01-12 13:55:34 +08:00
|
|
|
|
update();
|
|
|
|
|
DockItem::leaveEvent(event);
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-26 18:07:43 +08:00
|
|
|
|
void StretchPluginsItem::mouseClick()
|
|
|
|
|
{
|
2022-11-10 01:11:28 +00:00
|
|
|
|
QStringList commandArgument = m_pluginInter->itemCommand(m_itemKey).split(" ");
|
|
|
|
|
if (commandArgument.size() > 0) {
|
|
|
|
|
QString command = commandArgument.first();
|
|
|
|
|
commandArgument.removeFirst();
|
|
|
|
|
QProcess::startDetached(command, commandArgument);
|
2022-05-26 18:07:43 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// request popup applet
|
|
|
|
|
if (QWidget *w = m_pluginInter->itemPopupApplet(m_itemKey))
|
|
|
|
|
showPopupApplet(w);
|
|
|
|
|
}
|