dde-dock/frame/window/quickpluginwindow.h
donghualin 5530675d05 fix: 修复U盘插件不显示的问题
老版本的U盘插件没有适配icon接口,需要根据实际情况将itemWidget显示

Log: 修复U盘插件不显示的问题
Influence: 系统中使用v20的U盘插件,插入U盘,查看U盘图标是否显示
Task: https://pms.uniontech.com/task-view-223159.html
Change-Id: I7d2e7867203962ced078087c66fbddb7020d30df
2022-12-05 15:00:43 +08:00

139 lines
4.0 KiB
C++

/*
* 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 QUICKPLUGINWINDOW_H
#define QUICKPLUGINWINDOW_H
#include "constants.h"
#include <QWidget>
class QuickSettingItem;
class PluginsItemInterface;
class QHBoxLayout;
class QuickSettingContainer;
class QStandardItemModel;
class QStandardItem;
class QMouseEvent;
class QBoxLayout;
class QuickDockItem;
class DockPopupWindow;
class QMenu;
enum class DockPart;
namespace Dtk { namespace Gui { class DRegionMonitor; }
namespace Widget { class DListView; class DStandardItem; } }
using namespace Dtk::Widget;
class QuickPluginWindow : public QWidget
{
Q_OBJECT
public:
explicit QuickPluginWindow(QWidget *parent = nullptr);
~QuickPluginWindow() override;
void setPositon(Dock::Position position);
void dragPlugin(PluginsItemInterface *item);
QSize suitableSize() const;
QSize suitableSize(const Dock::Position &position) const;
Q_SIGNALS:
void itemCountChanged();
void requestDrop(QDropEvent *dropEvent);
protected:
bool eventFilter(QObject *watched, QEvent *event) override;
private Q_SLOTS:
void onRequestUpdate();
void onPluginDropItem(QDropEvent *event);
void onPluginDragMove(QDragMoveEvent *event);
void onUpdatePlugin(PluginsItemInterface *itemInter, const DockPart &dockPart);
void onRequestAppletShow(PluginsItemInterface * itemInter, const QString &itemKey);
private:
void initUi();
void initConnection();
void startDrag();
PluginsItemInterface *findQuickSettingItem(const QPoint &mousePoint, const QList<PluginsItemInterface *> &settingItems);
int getDropIndex(QPoint point);
QPoint popupPoint(QWidget *widget) const;
QuickDockItem *getDockItemByPlugin(PluginsItemInterface *item);
QuickDockItem *getActiveDockItem(QPoint point) const;
void showPopup(QuickDockItem *item, PluginsItemInterface *itemInter = nullptr, QWidget *childPage = nullptr);
private:
QBoxLayout *m_mainLayout;
Dock::Position m_position;
struct DragInfo *m_dragInfo;
};
// 用于在任务栏上显示的插件
class QuickDockItem : public QWidget
{
Q_OBJECT
public:
explicit QuickDockItem(PluginsItemInterface *pluginItem, const QString &itemKey, QWidget *parent = nullptr);
~QuickDockItem();
PluginsItemInterface *pluginItem();
bool canInsert() const;
void hideToolTip();
protected:
void paintEvent(QPaintEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
void enterEvent(QEvent *event) override;
void leaveEvent(QEvent *event) override;
void showEvent(QShowEvent *event) override;
void hideEvent(QHideEvent *event) override;
bool eventFilter(QObject *watched, QEvent *event) override;
private:
QPoint topleftPoint() const;
QPoint popupMarkPoint() const;
QPixmap iconPixmap() const;
void initUi();
void initAttribute();
void initConnection();
private Q_SLOTS:
void onMenuActionClicked(QAction *action);
private:
PluginsItemInterface *m_pluginItem;
QString m_itemKey;
Dock::Position m_position;
DockPopupWindow *m_popupWindow;
QMenu *m_contextMenu;
QWidget *m_tipParent;
QHBoxLayout *m_mainLayout;
bool m_canInsert;
QWidget *m_dockItemParent;
};
#endif // QUICKPLUGINWINDOW_H