2023-02-16 13:51:55 +08:00
|
|
|
|
// Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
|
|
|
|
|
// SPDX-FileCopyrightText: 2018 - 2023 UnionTech Software Technology Co., Ltd.
|
2022-09-06 11:36:55 +08:00
|
|
|
|
//
|
|
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
2016-06-15 16:17:51 +08:00
|
|
|
|
|
2016-06-02 09:46:43 +08:00
|
|
|
|
#include "dockitem.h"
|
2020-03-12 12:34:09 +08:00
|
|
|
|
#include "pluginsitem.h"
|
2022-06-29 15:57:04 +00:00
|
|
|
|
#include "utils.h"
|
2016-06-15 16:17:51 +08:00
|
|
|
|
|
|
|
|
|
#include <QMouseEvent>
|
|
|
|
|
#include <QJsonObject>
|
2019-05-06 10:01:02 +08:00
|
|
|
|
#include <QCursor>
|
2021-05-25 13:05:45 +08:00
|
|
|
|
#include <QApplication>
|
2022-06-29 15:57:04 +00:00
|
|
|
|
#include <QMenu>
|
2016-06-02 09:46:43 +08:00
|
|
|
|
|
2020-03-12 12:34:09 +08:00
|
|
|
|
#define PLUGIN_MARGIN 10
|
2020-05-28 14:49:06 +08:00
|
|
|
|
#define ITEM_MAXSIZE 100
|
2019-12-04 09:27:11 +08:00
|
|
|
|
|
2016-06-21 17:24:03 +08:00
|
|
|
|
Position DockItem::DockPosition = Position::Top;
|
2016-06-23 14:28:47 +08:00
|
|
|
|
DisplayMode DockItem::DockDisplayMode = DisplayMode::Efficient;
|
2017-11-08 14:51:11 +08:00
|
|
|
|
QPointer<DockPopupWindow> DockItem::PopupWindow(nullptr);
|
2016-06-21 17:24:03 +08:00
|
|
|
|
|
2016-08-08 09:52:05 +08:00
|
|
|
|
DockItem::DockItem(QWidget *parent)
|
2019-08-22 17:18:30 +08:00
|
|
|
|
: QWidget(parent)
|
|
|
|
|
, m_hover(false)
|
|
|
|
|
, m_popupShown(false)
|
|
|
|
|
, m_tapAndHold(false)
|
|
|
|
|
, m_draging(false)
|
2022-06-29 15:57:04 +00:00
|
|
|
|
, m_contextMenu(new QMenu(this))
|
2019-08-22 17:18:30 +08:00
|
|
|
|
, m_popupTipsDelayTimer(new QTimer(this))
|
|
|
|
|
, m_popupAdjustDelayTimer(new QTimer(this))
|
2016-06-02 09:46:43 +08:00
|
|
|
|
{
|
2019-08-19 13:40:06 +08:00
|
|
|
|
if (PopupWindow.isNull()) {
|
2023-04-07 14:43:09 +08:00
|
|
|
|
DockPopupWindow *blurRectangle = new DockPopupWindow(nullptr);
|
|
|
|
|
blurRectangle->setRadius(18);
|
|
|
|
|
blurRectangle->setObjectName("apppopup");
|
2022-06-29 15:57:04 +00:00
|
|
|
|
if (Utils::IS_WAYLAND_DISPLAY) {
|
2023-04-07 14:43:09 +08:00
|
|
|
|
Qt::WindowFlags flags = blurRectangle->windowFlags() | Qt::FramelessWindowHint;
|
|
|
|
|
blurRectangle->setWindowFlags(flags);
|
2022-06-29 15:57:04 +00:00
|
|
|
|
}
|
2023-04-07 14:43:09 +08:00
|
|
|
|
PopupWindow = blurRectangle;
|
2021-05-25 13:05:45 +08:00
|
|
|
|
connect(qApp, &QApplication::aboutToQuit, PopupWindow, &DockPopupWindow::deleteLater);
|
2016-07-13 14:24:39 +08:00
|
|
|
|
}
|
2016-07-01 10:42:08 +08:00
|
|
|
|
|
2016-07-18 14:13:36 +08:00
|
|
|
|
m_popupTipsDelayTimer->setInterval(500);
|
2016-07-01 10:42:08 +08:00
|
|
|
|
m_popupTipsDelayTimer->setSingleShot(true);
|
|
|
|
|
|
2018-02-05 10:23:37 +08:00
|
|
|
|
m_popupAdjustDelayTimer->setInterval(10);
|
2017-06-16 10:50:16 +08:00
|
|
|
|
m_popupAdjustDelayTimer->setSingleShot(true);
|
2018-01-23 13:35:42 +08:00
|
|
|
|
|
2016-07-15 11:00:55 +08:00
|
|
|
|
connect(m_popupTipsDelayTimer, &QTimer::timeout, this, &DockItem::showHoverTips);
|
2018-02-05 10:23:37 +08:00
|
|
|
|
connect(m_popupAdjustDelayTimer, &QTimer::timeout, this, &DockItem::updatePopupPosition, Qt::QueuedConnection);
|
2022-06-29 15:57:04 +00:00
|
|
|
|
connect(m_contextMenu, &QMenu::triggered, this, &DockItem::menuActionClicked);
|
2018-11-13 16:01:36 +08:00
|
|
|
|
|
|
|
|
|
grabGesture(Qt::TapAndHoldGesture);
|
2019-08-19 13:40:06 +08:00
|
|
|
|
|
|
|
|
|
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-25 21:03:30 +08:00
|
|
|
|
DockItem::~DockItem()
|
|
|
|
|
{
|
|
|
|
|
if (m_popupShown)
|
|
|
|
|
popupWindowAccept();
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-19 13:40:06 +08:00
|
|
|
|
QSize DockItem::sizeHint() const
|
|
|
|
|
{
|
2021-08-25 21:03:30 +08:00
|
|
|
|
int size = qMin(qMin(maximumWidth(), maximumHeight()), ITEM_MAXSIZE);
|
2019-08-23 10:30:40 +08:00
|
|
|
|
|
|
|
|
|
return QSize(size, size);
|
2016-06-02 09:46:43 +08:00
|
|
|
|
}
|
2016-06-03 16:06:11 +08:00
|
|
|
|
|
2020-03-13 12:59:02 +08:00
|
|
|
|
QString DockItem::accessibleName()
|
|
|
|
|
{
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-21 17:24:03 +08:00
|
|
|
|
void DockItem::setDockPosition(const Position side)
|
2016-06-16 16:56:21 +08:00
|
|
|
|
{
|
2016-06-21 17:24:03 +08:00
|
|
|
|
DockPosition = side;
|
2016-06-16 16:56:21 +08:00
|
|
|
|
}
|
2016-06-06 11:37:09 +08:00
|
|
|
|
|
2016-06-23 14:28:47 +08:00
|
|
|
|
void DockItem::setDockDisplayMode(const DisplayMode mode)
|
|
|
|
|
{
|
|
|
|
|
DockDisplayMode = mode;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-13 16:01:36 +08:00
|
|
|
|
void DockItem::gestureEvent(QGestureEvent *event)
|
|
|
|
|
{
|
|
|
|
|
if (!event)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QGesture *gesture = event->gesture(Qt::TapAndHoldGesture);
|
|
|
|
|
|
|
|
|
|
if (!gesture)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
qDebug() << "got TapAndHoldGesture";
|
|
|
|
|
|
|
|
|
|
m_tapAndHold = true;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-05 10:23:37 +08:00
|
|
|
|
bool DockItem::event(QEvent *event)
|
|
|
|
|
{
|
2019-08-19 13:40:06 +08:00
|
|
|
|
if (m_popupShown) {
|
|
|
|
|
switch (event->type()) {
|
2018-02-05 10:23:37 +08:00
|
|
|
|
case QEvent::Paint:
|
|
|
|
|
if (!m_popupAdjustDelayTimer->isActive())
|
|
|
|
|
m_popupAdjustDelayTimer->start();
|
|
|
|
|
break;
|
|
|
|
|
default:;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-13 16:01:36 +08:00
|
|
|
|
if (event->type() == QEvent::Gesture)
|
2019-08-19 13:40:06 +08:00
|
|
|
|
gestureEvent(static_cast<QGestureEvent *>(event));
|
2018-11-13 16:01:36 +08:00
|
|
|
|
|
2018-02-05 10:23:37 +08:00
|
|
|
|
return QWidget::event(event);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-01 14:26:15 +08:00
|
|
|
|
void DockItem::updatePopupPosition()
|
|
|
|
|
{
|
2017-06-16 10:50:16 +08:00
|
|
|
|
Q_ASSERT(sender() == m_popupAdjustDelayTimer);
|
|
|
|
|
|
2018-03-15 11:35:10 +08:00
|
|
|
|
if (!m_popupShown || !PopupWindow->model())
|
2016-08-01 14:26:15 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2018-03-15 11:35:10 +08:00
|
|
|
|
if (PopupWindow->getContent() != m_lastPopupWidget.data())
|
|
|
|
|
return popupWindowAccept();
|
|
|
|
|
|
2016-08-01 14:26:15 +08:00
|
|
|
|
const QPoint p = popupMarkPoint();
|
|
|
|
|
PopupWindow->show(p, PopupWindow->model());
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-03 16:06:11 +08:00
|
|
|
|
void DockItem::paintEvent(QPaintEvent *e)
|
|
|
|
|
{
|
|
|
|
|
QWidget::paintEvent(e);
|
2016-08-02 09:43:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-15 16:17:51 +08:00
|
|
|
|
void DockItem::mousePressEvent(QMouseEvent *e)
|
|
|
|
|
{
|
2017-12-15 16:47:16 +08:00
|
|
|
|
m_popupTipsDelayTimer->stop();
|
|
|
|
|
hideNonModel();
|
|
|
|
|
|
2018-11-01 14:53:45 +08:00
|
|
|
|
if (e->button() == Qt::RightButton) {
|
2018-12-17 14:38:09 +08:00
|
|
|
|
if (perfectIconRect().contains(e->pos())) {
|
|
|
|
|
return showContextMenu();
|
|
|
|
|
}
|
2018-11-01 14:53:45 +08:00
|
|
|
|
}
|
2018-12-17 14:38:09 +08:00
|
|
|
|
|
|
|
|
|
// same as e->ignore above
|
|
|
|
|
QWidget::mousePressEvent(e);
|
2016-06-15 16:17:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-27 20:16:35 +08:00
|
|
|
|
void DockItem::enterEvent(QEvent *e)
|
|
|
|
|
{
|
2019-05-06 10:01:02 +08:00
|
|
|
|
// Remove the bottom area to prevent unintentional operation in auto-hide mode.
|
|
|
|
|
if (!rect().adjusted(0, 0, width(), height() - 5).contains(mapFromGlobal(QCursor::pos()))) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-27 20:16:35 +08:00
|
|
|
|
m_hover = true;
|
2020-08-10 18:46:09 +08:00
|
|
|
|
//FIXME: 可能是qt的bug,概率性导致崩溃,待修复
|
|
|
|
|
// m_hoverEffect->setHighlighting(true);
|
2020-09-07 23:51:50 +08:00
|
|
|
|
|
|
|
|
|
// 触屏不显示hover效果
|
|
|
|
|
if (!qApp->property(IS_TOUCH_STATE).toBool()) {
|
|
|
|
|
m_popupTipsDelayTimer->start();
|
|
|
|
|
}
|
2016-06-27 20:16:35 +08:00
|
|
|
|
|
|
|
|
|
update();
|
|
|
|
|
|
|
|
|
|
return QWidget::enterEvent(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DockItem::leaveEvent(QEvent *e)
|
|
|
|
|
{
|
2016-08-04 17:36:38 +08:00
|
|
|
|
QWidget::leaveEvent(e);
|
|
|
|
|
|
2016-06-27 20:16:35 +08:00
|
|
|
|
m_hover = false;
|
2020-08-10 18:46:09 +08:00
|
|
|
|
//FIXME: 可能是qt的bug,概率性导致崩溃,待修复
|
|
|
|
|
// m_hoverEffect->setHighlighting(false);
|
2016-07-01 10:42:08 +08:00
|
|
|
|
m_popupTipsDelayTimer->stop();
|
|
|
|
|
|
2016-07-18 09:32:01 +08:00
|
|
|
|
// auto hide if popup is not model window
|
2016-08-04 17:36:38 +08:00
|
|
|
|
if (m_popupShown && !PopupWindow->model())
|
2016-08-09 10:58:47 +08:00
|
|
|
|
hidePopup();
|
2016-06-27 20:16:35 +08:00
|
|
|
|
|
|
|
|
|
update();
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-22 11:02:52 +08:00
|
|
|
|
const QRect DockItem::perfectIconRect() const
|
|
|
|
|
{
|
|
|
|
|
const QRect itemRect = rect();
|
|
|
|
|
QRect iconRect;
|
|
|
|
|
|
2019-12-13 15:53:47 +08:00
|
|
|
|
if (itemType() == Plugins) {
|
2020-01-14 16:49:31 +08:00
|
|
|
|
iconRect.setWidth(itemRect.width());
|
|
|
|
|
iconRect.setHeight(itemRect.height());
|
2019-12-13 15:53:47 +08:00
|
|
|
|
} else {
|
|
|
|
|
const int iconSize = std::min(itemRect.width(), itemRect.height()) * 0.8;
|
|
|
|
|
iconRect.setWidth(iconSize);
|
|
|
|
|
iconRect.setHeight(iconSize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
iconRect.moveTopLeft(itemRect.center() - iconRect.center());
|
2016-06-22 11:02:52 +08:00
|
|
|
|
return iconRect;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-15 16:17:51 +08:00
|
|
|
|
void DockItem::showContextMenu()
|
|
|
|
|
{
|
|
|
|
|
const QString menuJson = contextMenu();
|
|
|
|
|
if (menuJson.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
2019-08-22 17:18:30 +08:00
|
|
|
|
QJsonDocument jsonDocument = QJsonDocument::fromJson(menuJson.toLocal8Bit().data());
|
|
|
|
|
if (jsonDocument.isNull())
|
2016-06-15 16:17:51 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2019-08-22 17:18:30 +08:00
|
|
|
|
QJsonObject jsonMenu = jsonDocument.object();
|
|
|
|
|
|
2022-06-29 15:57:04 +00:00
|
|
|
|
qDeleteAll(m_contextMenu->actions());
|
2016-06-23 19:32:53 +08:00
|
|
|
|
|
2019-08-22 17:18:30 +08:00
|
|
|
|
QJsonArray jsonMenuItems = jsonMenu.value("items").toArray();
|
|
|
|
|
for (auto item : jsonMenuItems) {
|
|
|
|
|
QJsonObject itemObj = item.toObject();
|
|
|
|
|
QAction *action = new QAction(itemObj.value("itemText").toString());
|
|
|
|
|
action->setCheckable(itemObj.value("isCheckable").toBool());
|
|
|
|
|
action->setChecked(itemObj.value("checked").toBool());
|
|
|
|
|
action->setData(itemObj.value("itemId").toString());
|
|
|
|
|
action->setEnabled(itemObj.value("isActive").toBool());
|
2022-06-29 15:57:04 +00:00
|
|
|
|
m_contextMenu->addAction(action);
|
2016-06-29 11:15:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-22 17:18:30 +08:00
|
|
|
|
hidePopup();
|
|
|
|
|
emit requestWindowAutoHide(false);
|
2016-06-15 16:17:51 +08:00
|
|
|
|
|
2022-06-29 15:57:04 +00:00
|
|
|
|
m_contextMenu->exec(QCursor::pos());
|
2016-06-15 16:17:51 +08:00
|
|
|
|
|
2019-08-22 17:18:30 +08:00
|
|
|
|
onContextMenuAccepted();
|
|
|
|
|
}
|
2017-11-21 16:11:36 +08:00
|
|
|
|
|
2019-08-22 17:18:30 +08:00
|
|
|
|
void DockItem::menuActionClicked(QAction *action)
|
|
|
|
|
{
|
|
|
|
|
invokedMenuItem(action->data().toString(), true);
|
2016-06-15 16:17:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-01 13:42:05 +08:00
|
|
|
|
void DockItem::onContextMenuAccepted()
|
|
|
|
|
{
|
2018-12-04 09:50:56 +08:00
|
|
|
|
emit requestRefreshWindowVisible();
|
2018-03-01 13:42:05 +08:00
|
|
|
|
emit requestWindowAutoHide(true);
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-15 11:00:55 +08:00
|
|
|
|
void DockItem::showHoverTips()
|
2016-07-01 10:42:08 +08:00
|
|
|
|
{
|
2018-08-19 22:46:49 +08:00
|
|
|
|
// another model popup window already exists
|
2018-03-27 15:28:09 +08:00
|
|
|
|
if (PopupWindow->model())
|
2016-07-18 09:32:01 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2019-08-19 13:40:06 +08:00
|
|
|
|
QWidget *const content = popupTips();
|
2016-07-13 16:47:59 +08:00
|
|
|
|
if (!content)
|
|
|
|
|
return;
|
|
|
|
|
|
2016-07-15 11:00:55 +08:00
|
|
|
|
showPopupWindow(content);
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-19 13:40:06 +08:00
|
|
|
|
void DockItem::showPopupWindow(QWidget *const content, const bool model)
|
2016-07-15 11:00:55 +08:00
|
|
|
|
{
|
2023-04-07 14:43:09 +08:00
|
|
|
|
if (itemType() == App) {
|
2019-12-04 11:05:31 +08:00
|
|
|
|
PopupWindow->setRadius(18);
|
2023-04-07 14:43:09 +08:00
|
|
|
|
} else {
|
2019-12-04 11:05:31 +08:00
|
|
|
|
PopupWindow->setRadius(6);
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-20 16:30:56 +08:00
|
|
|
|
m_popupShown = true;
|
2018-03-15 11:35:10 +08:00
|
|
|
|
m_lastPopupWidget = content;
|
2016-07-20 16:30:56 +08:00
|
|
|
|
|
2016-07-18 09:32:01 +08:00
|
|
|
|
if (model)
|
|
|
|
|
emit requestWindowAutoHide(false);
|
|
|
|
|
|
2017-11-08 14:51:11 +08:00
|
|
|
|
DockPopupWindow *popup = PopupWindow.data();
|
2016-07-15 11:00:55 +08:00
|
|
|
|
QWidget *lastContent = popup->getContent();
|
2016-07-13 16:47:59 +08:00
|
|
|
|
if (lastContent)
|
2017-05-04 10:09:27 +08:00
|
|
|
|
lastContent->setVisible(false);
|
2016-07-13 16:47:59 +08:00
|
|
|
|
|
2017-06-30 10:53:48 +08:00
|
|
|
|
popup->resize(content->sizeHint());
|
2023-04-07 14:43:09 +08:00
|
|
|
|
popup->setPosition(DockPosition);
|
2016-07-15 11:00:55 +08:00
|
|
|
|
popup->setContent(content);
|
2016-07-13 16:47:59 +08:00
|
|
|
|
|
|
|
|
|
const QPoint p = popupMarkPoint();
|
2017-05-02 16:57:58 +08:00
|
|
|
|
if (!popup->isVisible())
|
|
|
|
|
QMetaObject::invokeMethod(popup, "show", Qt::QueuedConnection, Q_ARG(QPoint, p), Q_ARG(bool, model));
|
|
|
|
|
else
|
|
|
|
|
popup->show(p, model);
|
2016-07-18 10:09:26 +08:00
|
|
|
|
|
2017-06-30 10:53:48 +08:00
|
|
|
|
connect(popup, &DockPopupWindow::accept, this, &DockItem::popupWindowAccept, Qt::UniqueConnection);
|
2016-07-01 10:42:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-18 09:32:01 +08:00
|
|
|
|
void DockItem::popupWindowAccept()
|
|
|
|
|
{
|
|
|
|
|
if (!PopupWindow->isVisible())
|
|
|
|
|
return;
|
|
|
|
|
|
2017-11-08 14:51:11 +08:00
|
|
|
|
disconnect(PopupWindow.data(), &DockPopupWindow::accept, this, &DockItem::popupWindowAccept);
|
2016-07-18 10:09:26 +08:00
|
|
|
|
|
2016-08-09 10:58:47 +08:00
|
|
|
|
hidePopup();
|
2016-07-18 09:32:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-19 13:40:06 +08:00
|
|
|
|
void DockItem::showPopupApplet(QWidget *const applet)
|
2016-07-27 14:08:23 +08:00
|
|
|
|
{
|
2018-08-19 22:46:49 +08:00
|
|
|
|
// another model popup window already exists
|
2018-03-15 11:35:10 +08:00
|
|
|
|
if (PopupWindow->model())
|
2016-07-27 14:08:23 +08:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
showPopupWindow(applet, true);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-15 16:17:51 +08:00
|
|
|
|
void DockItem::invokedMenuItem(const QString &itemId, const bool checked)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(itemId)
|
|
|
|
|
Q_UNUSED(checked)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QString DockItem::contextMenu() const
|
|
|
|
|
{
|
2016-06-15 17:44:38 +08:00
|
|
|
|
return QString();
|
2016-06-15 16:17:51 +08:00
|
|
|
|
}
|
2016-07-01 10:42:08 +08:00
|
|
|
|
|
2016-07-13 16:47:59 +08:00
|
|
|
|
QWidget *DockItem::popupTips()
|
|
|
|
|
{
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-13 16:01:36 +08:00
|
|
|
|
/*!
|
|
|
|
|
* \brief DockItem::checkAndResetTapHoldGestureState checks if a QTapAndHoldGesture
|
|
|
|
|
* happens during the mouse press and release event pair.
|
|
|
|
|
* \return true if yes, otherwise false.
|
|
|
|
|
*/
|
|
|
|
|
bool DockItem::checkAndResetTapHoldGestureState()
|
|
|
|
|
{
|
|
|
|
|
bool ret = m_tapAndHold;
|
|
|
|
|
m_tapAndHold = false;
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-12 12:34:09 +08:00
|
|
|
|
const QPoint DockItem::popupMarkPoint()
|
2016-07-01 10:42:08 +08:00
|
|
|
|
{
|
2017-11-21 14:22:07 +08:00
|
|
|
|
QPoint p(topleftPoint());
|
2016-07-01 10:42:08 +08:00
|
|
|
|
const QRect r = rect();
|
2019-08-19 13:40:06 +08:00
|
|
|
|
switch (DockPosition) {
|
2020-12-31 17:59:18 +08:00
|
|
|
|
case Top:
|
2023-04-07 14:43:09 +08:00
|
|
|
|
p += QPoint(r.width() / 2, r.height() + POPUP_PADDING);
|
2019-12-04 09:27:11 +08:00
|
|
|
|
break;
|
2020-12-31 17:59:18 +08:00
|
|
|
|
case Bottom:
|
2023-04-07 14:43:09 +08:00
|
|
|
|
p += QPoint(r.width() / 2, -POPUP_PADDING);
|
2019-12-04 09:27:11 +08:00
|
|
|
|
break;
|
2020-12-31 17:59:18 +08:00
|
|
|
|
case Left:
|
2023-04-07 14:43:09 +08:00
|
|
|
|
p += QPoint(r.width() + POPUP_PADDING, r.height() / 2);
|
2019-12-04 09:27:11 +08:00
|
|
|
|
break;
|
2020-12-31 17:59:18 +08:00
|
|
|
|
case Right:
|
2023-04-07 14:43:09 +08:00
|
|
|
|
p += QPoint(-POPUP_PADDING, r.height() / 2);
|
2019-12-04 09:27:11 +08:00
|
|
|
|
break;
|
2016-07-01 10:42:08 +08:00
|
|
|
|
}
|
|
|
|
|
return p;
|
|
|
|
|
}
|
2016-08-09 10:58:47 +08:00
|
|
|
|
|
2017-11-21 14:22:07 +08:00
|
|
|
|
const QPoint DockItem::topleftPoint() const
|
|
|
|
|
{
|
2020-12-31 17:59:18 +08:00
|
|
|
|
QPoint p = this->pos();
|
|
|
|
|
/* 由于点击范围的问题,在图标的外面加了一层布局,这个布局的边距需要考虑 */
|
|
|
|
|
switch (DockPosition) {
|
|
|
|
|
case Top:
|
|
|
|
|
p.setY(p.y() * 2);
|
|
|
|
|
break;
|
|
|
|
|
case Bottom:
|
|
|
|
|
p.setY(0);
|
|
|
|
|
break;
|
|
|
|
|
case Left:
|
|
|
|
|
p.setX(p.x() * 2);
|
|
|
|
|
break;
|
|
|
|
|
case Right:
|
|
|
|
|
p.setX(0);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
const QWidget *w = qobject_cast<QWidget *>(this->parent());
|
|
|
|
|
while (w) {
|
2017-11-21 14:22:07 +08:00
|
|
|
|
p += w->pos();
|
|
|
|
|
w = qobject_cast<QWidget *>(w->parent());
|
2020-12-31 17:59:18 +08:00
|
|
|
|
}
|
2017-11-21 14:22:07 +08:00
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-09 10:58:47 +08:00
|
|
|
|
void DockItem::hidePopup()
|
|
|
|
|
{
|
2017-03-06 09:45:38 +08:00
|
|
|
|
m_popupTipsDelayTimer->stop();
|
2018-03-15 11:35:10 +08:00
|
|
|
|
m_popupAdjustDelayTimer->stop();
|
2016-08-09 10:58:47 +08:00
|
|
|
|
m_popupShown = false;
|
|
|
|
|
PopupWindow->hide();
|
2017-05-18 16:03:54 +08:00
|
|
|
|
|
2017-11-15 20:43:26 +08:00
|
|
|
|
emit PopupWindow->accept();
|
2017-05-18 16:03:54 +08:00
|
|
|
|
emit requestWindowAutoHide(true);
|
2016-08-09 10:58:47 +08:00
|
|
|
|
}
|
2017-12-15 16:47:16 +08:00
|
|
|
|
|
2019-08-21 12:52:53 +08:00
|
|
|
|
void DockItem::setDraging(bool bDrag)
|
|
|
|
|
{
|
|
|
|
|
m_draging = bDrag;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-15 16:47:16 +08:00
|
|
|
|
void DockItem::hideNonModel()
|
|
|
|
|
{
|
|
|
|
|
// auto hide if popup is not model window
|
|
|
|
|
if (m_popupShown && !PopupWindow->model())
|
|
|
|
|
hidePopup();
|
|
|
|
|
}
|
2019-12-30 11:10:36 +08:00
|
|
|
|
|
|
|
|
|
bool DockItem::isDragging()
|
|
|
|
|
{
|
|
|
|
|
return m_draging;
|
|
|
|
|
}
|