mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-02 15:45:21 +00:00
fix: 修复U盘插件不显示的问题
老版本的U盘插件没有适配icon接口,需要根据实际情况将itemWidget显示 Log: 修复U盘插件不显示的问题 Influence: 系统中使用v20的U盘插件,插入U盘,查看U盘图标是否显示 Task: https://pms.uniontech.com/task-view-223159.html Change-Id: I7d2e7867203962ced078087c66fbddb7020d30df
This commit is contained in:
parent
13988c0b2a
commit
5530675d05
@ -172,6 +172,10 @@ QIcon PluginAdapter::icon(const DockPart &dockPart, DGuiApplicationHelper::Color
|
||||
switch (dockPart) {
|
||||
case DockPart::QuickPanel:
|
||||
case DockPart::SystemPanel: {
|
||||
// 如果是托盘插件,则让他返回空图标,直接将QWidget展示
|
||||
if (m_pluginLoader->fileName().contains(TRAY_PATH))
|
||||
return QIcon();
|
||||
|
||||
// 如果图标为空,就使用itemWidget的截图作为它的图标,这种一般是适用于老版本插件或者没有实现v23接口的插件
|
||||
QSize oldSize = itemWidget->size();
|
||||
itemWidget->setFixedSize(ICONWIDTH, ICONHEIGHT);
|
||||
|
@ -234,10 +234,10 @@ 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()))
|
||||
startDrag();
|
||||
m_dragInfo->reset();
|
||||
}
|
||||
|
||||
m_dragInfo->reset();
|
||||
break;
|
||||
}
|
||||
case QEvent::Drop: {
|
||||
@ -694,7 +694,8 @@ void QuickDockItem::showEvent(QShowEvent *event)
|
||||
|
||||
QWidget *itemWidget = m_pluginItem->itemWidget(m_itemKey);
|
||||
if (itemWidget && m_mainLayout->indexOf(itemWidget) < 0) {
|
||||
itemWidget->setFixedSize(ICONWIDTH - 2, ICONHEIGHT - 2);
|
||||
itemWidget->show();
|
||||
itemWidget->setFixedSize(size());
|
||||
m_mainLayout->addWidget(itemWidget);
|
||||
}
|
||||
}
|
||||
@ -707,6 +708,7 @@ void QuickDockItem::hideEvent(QHideEvent *event)
|
||||
QWidget *itemWidget = m_pluginItem->itemWidget(m_itemKey);
|
||||
if (itemWidget && m_mainLayout->indexOf(itemWidget) >= 0) {
|
||||
itemWidget->setParent(m_dockItemParent);
|
||||
itemWidget->hide();
|
||||
m_mainLayout->removeWidget(itemWidget);
|
||||
}
|
||||
}
|
||||
|
@ -97,7 +97,6 @@ public:
|
||||
explicit QuickDockItem(PluginsItemInterface *pluginItem, const QString &itemKey, QWidget *parent = nullptr);
|
||||
~QuickDockItem();
|
||||
|
||||
void setPositon(Dock::Position position);
|
||||
PluginsItemInterface *pluginItem();
|
||||
bool canInsert() const;
|
||||
void hideToolTip();
|
||||
|
@ -47,18 +47,20 @@ SystemPluginItem::SystemPluginItem(PluginsItemInterface *const pluginInter, cons
|
||||
{
|
||||
qDebug() << "load tray plugins item: " << m_pluginInter->pluginName() << itemKey << m_centralWidget;
|
||||
|
||||
QIcon icon = m_pluginInter->icon(DockPart::SystemPanel);
|
||||
if (m_centralWidget) {
|
||||
m_centralWidget->setParent(this);
|
||||
m_centralWidget->setVisible(true);
|
||||
m_centralWidget->installEventFilter(this);
|
||||
if (icon.isNull()) {
|
||||
// 此处先创建一个Layout,在该窗体show的时候将m_centralWidget添加到layout上面
|
||||
QBoxLayout *hLayout = new QHBoxLayout(this);
|
||||
hLayout->setSpacing(0);
|
||||
hLayout->setMargin(0);
|
||||
setLayout(hLayout);
|
||||
m_centralWidget->installEventFilter(this);
|
||||
} else {
|
||||
m_centralWidget->setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
QBoxLayout *hLayout = new QHBoxLayout(this);
|
||||
hLayout->addWidget(m_centralWidget);
|
||||
hLayout->setSpacing(0);
|
||||
hLayout->setMargin(0);
|
||||
|
||||
setLayout(hLayout);
|
||||
setAccessibleName(m_itemKey);
|
||||
setAttribute(Qt::WA_TranslucentBackground);
|
||||
|
||||
@ -194,8 +196,11 @@ bool SystemPluginItem::event(QEvent *event)
|
||||
|
||||
bool SystemPluginItem::eventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
if (watched == this && event->type() == QEvent::DeferredDelete)
|
||||
if (watched == this && event->type() == QEvent::DeferredDelete
|
||||
&& m_centralWidget && m_centralWidget->parentWidget()) {
|
||||
m_centralWidget->setParent(nullptr);
|
||||
m_centralWidget->setVisible(false);
|
||||
}
|
||||
|
||||
return BaseTrayWidget::eventFilter(watched, event);
|
||||
}
|
||||
@ -282,6 +287,43 @@ void SystemPluginItem::showEvent(QShowEvent *event)
|
||||
return BaseTrayWidget::showEvent(event);
|
||||
}
|
||||
|
||||
void SystemPluginItem::hideEvent(QHideEvent *event)
|
||||
{
|
||||
if (m_pluginInter->icon(DockPart::SystemPanel).isNull()
|
||||
&& m_centralWidget && m_centralWidget->parentWidget() == this) {
|
||||
layout()->removeWidget(m_centralWidget);
|
||||
m_centralWidget->setParent(nullptr);
|
||||
m_centralWidget->setVisible(false);
|
||||
}
|
||||
BaseTrayWidget::hideEvent(event);
|
||||
}
|
||||
|
||||
void SystemPluginItem::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
QIcon icon = m_pluginInter->icon(DockPart::SystemPanel);
|
||||
if (icon.isNull()) {
|
||||
showCentralWidget();
|
||||
return BaseTrayWidget::paintEvent(event);
|
||||
}
|
||||
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
QSize iconSize = this->size();
|
||||
QList<QSize> sizes = icon.availableSizes();
|
||||
if (sizes.size() > 0) {
|
||||
QSize availableSize = sizes.first();
|
||||
if (iconSize.width() > availableSize.width()) {
|
||||
x = (iconSize.width() - availableSize.width()) / 2;
|
||||
y = (iconSize.height() - availableSize.height()) / 2;
|
||||
iconSize = availableSize;
|
||||
}
|
||||
}
|
||||
|
||||
QPixmap pixmap = icon.pixmap(iconSize);
|
||||
QPainter painter(this);
|
||||
painter.drawPixmap(QRect(QPoint(x, y), iconSize), pixmap);
|
||||
}
|
||||
|
||||
const QPoint SystemPluginItem::popupMarkPoint() const
|
||||
{
|
||||
QPoint p(topleftPoint());
|
||||
@ -480,6 +522,16 @@ void SystemPluginItem::menuActionClicked(QAction *action)
|
||||
invokedMenuItem(action->data().toString(), true);
|
||||
}
|
||||
|
||||
void SystemPluginItem::showCentralWidget()
|
||||
{
|
||||
if (!m_pluginInter->icon(DockPart::SystemPanel).isNull() || !m_centralWidget)
|
||||
return;
|
||||
|
||||
m_centralWidget->setParent(this);
|
||||
m_centralWidget->setVisible(true);
|
||||
layout()->addWidget(m_centralWidget);
|
||||
}
|
||||
|
||||
void SystemPluginItem::onContextMenuAccepted()
|
||||
{
|
||||
emit requestRefershWindowVisible();
|
||||
|
@ -31,6 +31,7 @@
|
||||
class QGSettings;
|
||||
class QMenu;
|
||||
class DockPopupWindow;
|
||||
class QHBoxLayout;
|
||||
|
||||
class SystemPluginItem : public BaseTrayWidget
|
||||
{
|
||||
@ -72,7 +73,9 @@ protected:
|
||||
void leaveEvent(QEvent *event) override;
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
void mouseReleaseEvent(QMouseEvent *event) override;
|
||||
void showEvent(QShowEvent* event) override;
|
||||
void showEvent(QShowEvent *event) override;
|
||||
void hideEvent(QHideEvent *event) override;
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
|
||||
protected:
|
||||
const QPoint popupMarkPoint() const;
|
||||
@ -95,6 +98,7 @@ private:
|
||||
void onGSettingsChanged(const QString &key);
|
||||
bool checkGSettingsControl() const;
|
||||
void menuActionClicked(QAction *action);
|
||||
void showCentralWidget();
|
||||
|
||||
private:
|
||||
bool m_popupShown;
|
||||
|
Loading…
x
Reference in New Issue
Block a user