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:35:50 +08:00
|
|
|
#ifndef QUICKPLUGINWINDOW_H
|
|
|
|
#define QUICKPLUGINWINDOW_H
|
|
|
|
|
|
|
|
#include "constants.h"
|
|
|
|
|
|
|
|
#include <QWidget>
|
|
|
|
|
|
|
|
class QuickSettingItem;
|
|
|
|
class PluginsItemInterface;
|
|
|
|
class QHBoxLayout;
|
|
|
|
class QStandardItemModel;
|
|
|
|
class QStandardItem;
|
|
|
|
class QMouseEvent;
|
2022-05-17 20:57:09 +08:00
|
|
|
class QBoxLayout;
|
2022-05-30 20:29:53 +08:00
|
|
|
class QuickDockItem;
|
2022-10-18 10:24:21 +00:00
|
|
|
class DockPopupWindow;
|
|
|
|
class QMenu;
|
2022-12-12 10:30:44 +00:00
|
|
|
class QuickPluginMimeData;
|
2022-06-09 13:16:49 +08:00
|
|
|
enum class DockPart;
|
2022-05-12 17:35:50 +08:00
|
|
|
|
2023-01-11 09:09:36 +08:00
|
|
|
namespace Dtk { namespace Widget { class DListView; class DStandardItem; } }
|
2022-05-12 17:35:50 +08:00
|
|
|
|
|
|
|
using namespace Dtk::Widget;
|
|
|
|
|
|
|
|
class QuickPluginWindow : public QWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2023-01-31 10:55:04 +08:00
|
|
|
explicit QuickPluginWindow(Dock::DisplayMode displayMode, QWidget *parent = nullptr);
|
2022-05-12 17:35:50 +08:00
|
|
|
~QuickPluginWindow() override;
|
|
|
|
|
|
|
|
void setPositon(Dock::Position position);
|
2022-05-30 20:29:53 +08:00
|
|
|
void dragPlugin(PluginsItemInterface *item);
|
2022-05-12 17:35:50 +08:00
|
|
|
|
2022-08-25 19:31:31 +00:00
|
|
|
QSize suitableSize() const;
|
|
|
|
QSize suitableSize(const Dock::Position &position) const;
|
2022-05-12 17:35:50 +08:00
|
|
|
|
2023-01-05 17:03:02 +08:00
|
|
|
bool isQuickWindow(QObject *object) const;
|
|
|
|
|
2022-05-17 20:57:09 +08:00
|
|
|
Q_SIGNALS:
|
|
|
|
void itemCountChanged();
|
|
|
|
|
2022-05-12 17:35:50 +08:00
|
|
|
protected:
|
2022-11-02 06:57:46 +00:00
|
|
|
bool eventFilter(QObject *watched, QEvent *event) override;
|
2022-12-12 10:30:44 +00:00
|
|
|
void dragEnterEvent(QDragEnterEvent *event) override;
|
|
|
|
void dragLeaveEvent(QDragLeaveEvent *event) override;
|
|
|
|
void dragMoveEvent(QDragMoveEvent *event) override;
|
2023-01-05 17:03:02 +08:00
|
|
|
void resizeEvent(QResizeEvent *event) override;
|
2022-05-12 17:35:50 +08:00
|
|
|
|
2022-05-17 20:57:09 +08:00
|
|
|
private Q_SLOTS:
|
2022-11-02 06:57:46 +00:00
|
|
|
void onRequestUpdate();
|
2022-06-09 13:16:49 +08:00
|
|
|
void onUpdatePlugin(PluginsItemInterface *itemInter, const DockPart &dockPart);
|
2023-01-12 11:06:36 +08:00
|
|
|
void onRequestAppletVisible(PluginsItemInterface * itemInter, const QString &itemKey, bool visible);
|
2022-05-17 20:57:09 +08:00
|
|
|
|
2022-05-12 17:35:50 +08:00
|
|
|
private:
|
|
|
|
void initUi();
|
|
|
|
void initConnection();
|
2022-11-23 09:34:12 +00:00
|
|
|
void startDrag();
|
2022-05-30 20:29:53 +08:00
|
|
|
PluginsItemInterface *findQuickSettingItem(const QPoint &mousePoint, const QList<PluginsItemInterface *> &settingItems);
|
|
|
|
int getDropIndex(QPoint point);
|
2022-11-18 10:29:51 +00:00
|
|
|
QPoint popupPoint(QWidget *widget) const;
|
2022-05-30 20:29:53 +08:00
|
|
|
QuickDockItem *getDockItemByPlugin(PluginsItemInterface *item);
|
2022-11-02 06:57:46 +00:00
|
|
|
QuickDockItem *getActiveDockItem(QPoint point) const;
|
2022-12-15 19:58:43 +08:00
|
|
|
void showPopup(QuickDockItem *item, PluginsItemInterface *itemInter = nullptr, QWidget *childPage = nullptr, bool isClicked = true);
|
2022-12-12 10:30:44 +00:00
|
|
|
QList<QuickDockItem *> quickDockItems();
|
2023-01-05 17:03:02 +08:00
|
|
|
DockPopupWindow *getPopWindow() const;
|
|
|
|
void updateDockItemSize(QuickDockItem *dockItem);
|
|
|
|
void resizeDockItem();
|
2022-05-12 17:35:50 +08:00
|
|
|
|
|
|
|
private:
|
2022-05-17 20:57:09 +08:00
|
|
|
QBoxLayout *m_mainLayout;
|
2022-05-12 17:35:50 +08:00
|
|
|
Dock::Position m_position;
|
2022-11-02 06:57:46 +00:00
|
|
|
struct DragInfo *m_dragInfo;
|
2022-12-12 10:30:44 +00:00
|
|
|
QuickPluginMimeData *m_dragEnterMimeData;
|
2023-01-31 10:55:04 +08:00
|
|
|
Dock::DisplayMode m_displayMode;
|
2022-05-30 20:29:53 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// 用于在任务栏上显示的插件
|
|
|
|
class QuickDockItem : public QWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2022-11-28 15:30:34 +08:00
|
|
|
explicit QuickDockItem(PluginsItemInterface *pluginItem, const QString &itemKey, QWidget *parent = nullptr);
|
2022-05-30 20:29:53 +08:00
|
|
|
~QuickDockItem();
|
|
|
|
|
2023-01-05 17:03:02 +08:00
|
|
|
void setPosition(Dock::Position position);
|
2022-05-30 20:29:53 +08:00
|
|
|
PluginsItemInterface *pluginItem();
|
2022-11-28 15:30:34 +08:00
|
|
|
bool canInsert() const;
|
2023-01-05 17:03:02 +08:00
|
|
|
bool canMove() const;
|
2022-11-16 12:10:29 +00:00
|
|
|
void hideToolTip();
|
2022-05-30 20:29:53 +08:00
|
|
|
|
2022-12-30 19:20:22 +08:00
|
|
|
QSize suitableSize() const;
|
|
|
|
|
2022-05-30 20:29:53 +08:00
|
|
|
protected:
|
2022-10-18 10:24:21 +00:00
|
|
|
void paintEvent(QPaintEvent *event) override;
|
|
|
|
void mousePressEvent(QMouseEvent *event) override;
|
|
|
|
void enterEvent(QEvent *event) override;
|
|
|
|
void leaveEvent(QEvent *event) override;
|
2022-11-23 13:39:16 +00:00
|
|
|
void showEvent(QShowEvent *event) override;
|
|
|
|
void hideEvent(QHideEvent *event) override;
|
2022-12-02 18:30:35 +08:00
|
|
|
bool eventFilter(QObject *watched, QEvent *event) override;
|
2023-01-05 17:03:02 +08:00
|
|
|
void resizeEvent(QResizeEvent *event) override;
|
2022-05-30 20:29:53 +08:00
|
|
|
|
2022-10-18 10:24:21 +00:00
|
|
|
private:
|
|
|
|
QPoint topleftPoint() const;
|
|
|
|
QPoint popupMarkPoint() const;
|
|
|
|
|
2022-11-23 09:34:12 +00:00
|
|
|
QPixmap iconPixmap() const;
|
|
|
|
|
2022-11-23 13:39:16 +00:00
|
|
|
void initUi();
|
|
|
|
void initAttribute();
|
|
|
|
void initConnection();
|
|
|
|
|
2023-01-05 17:03:02 +08:00
|
|
|
void updateWidgetSize();
|
2023-01-12 13:55:34 +08:00
|
|
|
int shadowRadius() const;
|
|
|
|
int iconSize() const;
|
2023-01-05 17:03:02 +08:00
|
|
|
|
2022-11-16 06:22:51 +00:00
|
|
|
private Q_SLOTS:
|
|
|
|
void onMenuActionClicked(QAction *action);
|
|
|
|
|
2022-05-30 20:29:53 +08:00
|
|
|
private:
|
|
|
|
PluginsItemInterface *m_pluginItem;
|
2022-10-19 03:50:12 +00:00
|
|
|
QString m_itemKey;
|
2023-01-05 17:03:02 +08:00
|
|
|
Dock::Position m_position;
|
2022-10-18 10:24:21 +00:00
|
|
|
DockPopupWindow *m_popupWindow;
|
|
|
|
QMenu *m_contextMenu;
|
2022-11-18 09:22:39 +00:00
|
|
|
QWidget *m_tipParent;
|
2023-01-05 17:03:02 +08:00
|
|
|
QHBoxLayout *m_topLayout;
|
|
|
|
QWidget *m_mainWidget;
|
2022-11-23 13:39:16 +00:00
|
|
|
QHBoxLayout *m_mainLayout;
|
2022-11-28 15:30:34 +08:00
|
|
|
QWidget *m_dockItemParent;
|
2023-01-12 13:55:34 +08:00
|
|
|
bool m_isEnter;
|
2022-05-12 17:35:50 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // QUICKPLUGINWINDOW_H
|