2017-09-18 14:33:44 +08:00
|
|
|
|
/*
|
2018-02-07 11:52:47 +08:00
|
|
|
|
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
|
2017-09-18 14:33:44 +08:00
|
|
|
|
*
|
|
|
|
|
* Author: sbw <sbw@sbw.so>
|
|
|
|
|
*
|
|
|
|
|
* Maintainer: sbw <sbw@sbw.so>
|
2018-06-04 21:09:41 +08:00
|
|
|
|
* listenerri <listenerri@gmail.com>
|
2017-09-18 14:33:44 +08:00
|
|
|
|
*
|
|
|
|
|
* 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/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2016-06-03 16:06:11 +08:00
|
|
|
|
#include "appitem.h"
|
2020-12-16 17:38:41 +08:00
|
|
|
|
#include "themeappicon.h"
|
|
|
|
|
#include "xcb_misc.h"
|
|
|
|
|
#include "appswingeffectbuilder.h"
|
2021-11-05 21:45:53 +08:00
|
|
|
|
#include "utils.h"
|
2022-08-12 08:13:00 +00:00
|
|
|
|
#include "screenspliter.h"
|
2016-06-14 16:01:01 +08:00
|
|
|
|
|
2017-06-09 16:18:15 +08:00
|
|
|
|
#include <X11/X.h>
|
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
|
|
2016-06-03 16:06:11 +08:00
|
|
|
|
#include <QPainter>
|
2016-06-07 14:40:45 +08:00
|
|
|
|
#include <QDrag>
|
|
|
|
|
#include <QMouseEvent>
|
2017-03-28 16:52:38 +08:00
|
|
|
|
#include <QApplication>
|
2017-04-26 17:59:35 +08:00
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
|
#include <QGraphicsScene>
|
|
|
|
|
#include <QTimeLine>
|
2018-02-22 11:44:57 +08:00
|
|
|
|
#include <QX11Info>
|
2019-08-01 15:59:25 +08:00
|
|
|
|
#include <QGSettings>
|
2021-03-20 12:10:45 +08:00
|
|
|
|
|
2019-11-07 20:39:09 +08:00
|
|
|
|
#include <DGuiApplicationHelper>
|
2021-11-26 14:59:36 +08:00
|
|
|
|
#include <DConfig>
|
2016-06-03 16:06:11 +08:00
|
|
|
|
|
2021-10-12 16:59:59 +08:00
|
|
|
|
DGUI_USE_NAMESPACE
|
2021-11-26 14:59:36 +08:00
|
|
|
|
DCORE_USE_NAMESPACE
|
2021-10-12 16:59:59 +08:00
|
|
|
|
|
2016-06-07 14:40:45 +08:00
|
|
|
|
#define APP_DRAG_THRESHOLD 20
|
|
|
|
|
|
2016-06-15 16:17:51 +08:00
|
|
|
|
QPoint AppItem::MousePressPos;
|
2016-06-06 14:57:07 +08:00
|
|
|
|
|
2022-08-18 15:41:46 +00:00
|
|
|
|
AppItem::AppItem(DockInter *dockInter, const QGSettings *appSettings, const QGSettings *activeAppSettings, const QGSettings *dockedAppSettings, const QDBusObjectPath &entry, QWidget *parent)
|
2020-05-22 13:10:52 +08:00
|
|
|
|
: DockItem(parent)
|
2021-03-20 12:10:45 +08:00
|
|
|
|
, m_appSettings(appSettings)
|
|
|
|
|
, m_activeAppSettings(activeAppSettings)
|
|
|
|
|
, m_dockedAppSettings(dockedAppSettings)
|
2020-05-22 13:10:52 +08:00
|
|
|
|
, m_appPreviewTips(nullptr)
|
2022-06-21 17:42:50 +08:00
|
|
|
|
, m_itemEntryInter(new DockEntryInter(dockServiceName(), entry.path(), QDBusConnection::sessionBus(), this))
|
2020-05-22 13:10:52 +08:00
|
|
|
|
, m_swingEffectView(nullptr)
|
|
|
|
|
, m_itemAnimation(nullptr)
|
|
|
|
|
, m_wmHelper(DWindowManagerHelper::instance())
|
|
|
|
|
, m_drag(nullptr)
|
|
|
|
|
, m_retryTimes(0)
|
2021-05-26 10:50:43 +08:00
|
|
|
|
, m_iconValid(true)
|
2020-05-22 13:10:52 +08:00
|
|
|
|
, m_lastclickTimes(0)
|
|
|
|
|
, m_appIcon(QPixmap())
|
|
|
|
|
, m_updateIconGeometryTimer(new QTimer(this))
|
|
|
|
|
, m_retryObtainIconTimer(new QTimer(this))
|
|
|
|
|
, m_refershIconTimer(new QTimer(this))
|
2021-05-26 17:52:52 +08:00
|
|
|
|
, m_themeType(DGuiApplicationHelper::instance()->themeType())
|
2022-07-08 09:05:54 +00:00
|
|
|
|
, m_createMSecs(QDateTime::currentMSecsSinceEpoch())
|
2022-08-12 08:13:00 +00:00
|
|
|
|
, m_screenSpliter(ScreenSpliterFactory::createScreenSpliter(this, m_itemEntryInter))
|
2022-08-18 15:41:46 +00:00
|
|
|
|
, m_dockInter(dockInter)
|
2016-06-03 16:06:11 +08:00
|
|
|
|
{
|
2017-04-26 17:59:35 +08:00
|
|
|
|
QHBoxLayout *centralLayout = new QHBoxLayout;
|
|
|
|
|
centralLayout->setMargin(0);
|
2017-05-02 16:32:38 +08:00
|
|
|
|
centralLayout->setSpacing(0);
|
2017-04-26 17:59:35 +08:00
|
|
|
|
|
2020-05-27 14:24:18 +08:00
|
|
|
|
setObjectName(m_itemEntryInter->name());
|
2019-08-29 17:21:02 +08:00
|
|
|
|
setAcceptDrops(true);
|
2017-04-26 17:59:35 +08:00
|
|
|
|
setLayout(centralLayout);
|
|
|
|
|
|
2018-02-22 11:44:57 +08:00
|
|
|
|
m_id = m_itemEntryInter->id();
|
|
|
|
|
m_active = m_itemEntryInter->isActive();
|
2016-06-06 14:28:28 +08:00
|
|
|
|
|
2016-07-22 14:59:43 +08:00
|
|
|
|
m_updateIconGeometryTimer->setInterval(500);
|
|
|
|
|
m_updateIconGeometryTimer->setSingleShot(true);
|
|
|
|
|
|
2021-04-26 15:12:17 +08:00
|
|
|
|
m_retryObtainIconTimer->setInterval(3000);
|
2018-08-30 12:03:25 +08:00
|
|
|
|
m_retryObtainIconTimer->setSingleShot(true);
|
|
|
|
|
|
2020-05-22 13:10:14 +08:00
|
|
|
|
m_refershIconTimer->setInterval(1000);
|
|
|
|
|
m_refershIconTimer->setSingleShot(false);
|
|
|
|
|
|
2018-02-22 11:44:57 +08:00
|
|
|
|
connect(m_itemEntryInter, &DockEntryInter::IsActiveChanged, this, &AppItem::activeChanged);
|
|
|
|
|
connect(m_itemEntryInter, &DockEntryInter::IsActiveChanged, this, static_cast<void (AppItem::*)()>(&AppItem::update));
|
|
|
|
|
connect(m_itemEntryInter, &DockEntryInter::WindowInfosChanged, this, &AppItem::updateWindowInfos, Qt::QueuedConnection);
|
2021-03-06 18:40:13 +08:00
|
|
|
|
connect(m_itemEntryInter, &DockEntryInter::IconChanged, this, &AppItem::refreshIcon);
|
2022-08-15 18:07:14 +00:00
|
|
|
|
connect(m_itemEntryInter, &DockEntryInter::ModeChanged, this, &AppItem::modeChanged);
|
2017-05-02 10:49:27 +08:00
|
|
|
|
connect(m_updateIconGeometryTimer, &QTimer::timeout, this, &AppItem::updateWindowIconGeometries, Qt::QueuedConnection);
|
2021-03-06 18:40:13 +08:00
|
|
|
|
connect(m_retryObtainIconTimer, &QTimer::timeout, this, &AppItem::refreshIcon, Qt::QueuedConnection);
|
2017-05-02 10:49:27 +08:00
|
|
|
|
|
2020-10-29 18:08:30 +08:00
|
|
|
|
connect(this, &AppItem::requestUpdateEntryGeometries, this, &AppItem::updateWindowIconGeometries);
|
|
|
|
|
|
2018-02-22 14:19:52 +08:00
|
|
|
|
updateWindowInfos(m_itemEntryInter->windowInfos());
|
2019-08-01 15:59:25 +08:00
|
|
|
|
|
2021-03-20 12:10:45 +08:00
|
|
|
|
if (m_appSettings)
|
|
|
|
|
connect(m_appSettings, &QGSettings::changed, this, &AppItem::onGSettingsChanged);
|
|
|
|
|
if (m_dockedAppSettings)
|
|
|
|
|
connect(m_dockedAppSettings, &QGSettings::changed, this, &AppItem::onGSettingsChanged);
|
|
|
|
|
if (m_activeAppSettings)
|
|
|
|
|
connect(m_activeAppSettings, &QGSettings::changed, this, &AppItem::onGSettingsChanged);
|
2021-02-03 14:49:02 +08:00
|
|
|
|
|
2019-11-07 20:39:09 +08:00
|
|
|
|
connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, &AppItem::onThemeTypeChanged);
|
2020-05-22 13:10:14 +08:00
|
|
|
|
|
2021-05-08 10:00:43 +08:00
|
|
|
|
/** 日历 1S定时判断是否刷新icon的处理 */
|
2021-08-25 21:03:30 +08:00
|
|
|
|
connect(m_refershIconTimer, &QTimer::timeout, this, &AppItem::onRefreshIcon);
|
2017-04-12 15:31:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-26 14:28:10 +08:00
|
|
|
|
/**将属于同一个应用的窗口合并到同一个应用图标
|
|
|
|
|
* @brief AppItem::checkEntry
|
|
|
|
|
*/
|
2021-02-01 10:28:22 +08:00
|
|
|
|
void AppItem::checkEntry()
|
|
|
|
|
{
|
|
|
|
|
m_itemEntryInter->Check();
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-14 11:22:19 +08:00
|
|
|
|
const QString AppItem::appId() const
|
|
|
|
|
{
|
|
|
|
|
return m_id;
|
2016-06-03 16:06:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-08-18 15:41:46 +00:00
|
|
|
|
QString AppItem::name() const
|
|
|
|
|
{
|
|
|
|
|
return m_itemEntryInter->name();
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-22 13:10:52 +08:00
|
|
|
|
bool AppItem::isValid() const
|
2018-12-25 14:52:32 +08:00
|
|
|
|
{
|
|
|
|
|
return m_itemEntryInter->isValid() && !m_itemEntryInter->id().isEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-22 14:59:43 +08:00
|
|
|
|
// Update _NET_WM_ICON_GEOMETRY property for windows that every item
|
|
|
|
|
// that manages, so that WM can do proper animations for specific
|
|
|
|
|
// window behaviors like minimization.
|
|
|
|
|
void AppItem::updateWindowIconGeometries()
|
|
|
|
|
{
|
2021-11-05 21:45:53 +08:00
|
|
|
|
// wayland没做处理
|
|
|
|
|
if (Utils::IS_WAYLAND_DISPLAY)
|
|
|
|
|
return;
|
|
|
|
|
|
2017-06-06 11:06:02 +08:00
|
|
|
|
const QRect r(mapToGlobal(QPoint(0, 0)),
|
2019-08-21 12:52:53 +08:00
|
|
|
|
mapToGlobal(QPoint(width(), height())));
|
2021-03-12 13:20:13 +08:00
|
|
|
|
if (!QX11Info::connection()) {
|
|
|
|
|
qWarning() << "QX11Info::connection() is 0x0";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-06 11:06:02 +08:00
|
|
|
|
auto *xcb_misc = XcbMisc::instance();
|
2016-07-22 14:59:43 +08:00
|
|
|
|
|
2018-02-22 11:44:57 +08:00
|
|
|
|
for (auto it(m_windowInfos.cbegin()); it != m_windowInfos.cend(); ++it)
|
2017-06-06 11:06:02 +08:00
|
|
|
|
xcb_misc->set_window_icon_geometry(it.key(), r);
|
2016-07-22 14:59:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-26 14:28:10 +08:00
|
|
|
|
/**取消驻留在dock上的应用
|
|
|
|
|
* @brief AppItem::undock
|
|
|
|
|
*/
|
2018-06-04 21:09:41 +08:00
|
|
|
|
void AppItem::undock()
|
|
|
|
|
{
|
|
|
|
|
m_itemEntryInter->RequestUndock();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWidget *AppItem::appDragWidget()
|
|
|
|
|
{
|
2019-01-17 11:00:40 +08:00
|
|
|
|
if (m_drag) {
|
|
|
|
|
return m_drag->appDragWidget();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nullptr;
|
2018-06-04 21:09:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AppItem::setDockInfo(Dock::Position dockPosition, const QRect &dockGeometry)
|
|
|
|
|
{
|
2019-01-17 11:00:40 +08:00
|
|
|
|
if (m_drag) {
|
|
|
|
|
m_drag->appDragWidget()->setDockInfo(dockPosition, dockGeometry);
|
|
|
|
|
}
|
2018-06-04 21:09:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-08-12 08:13:00 +00:00
|
|
|
|
void AppItem::setDraging(bool drag)
|
|
|
|
|
{
|
|
|
|
|
if (drag == isDragging())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
DockItem::setDraging(drag);
|
|
|
|
|
if (!drag)
|
|
|
|
|
m_screenSpliter->releaseSplit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AppItem::startSplit(const QRect &rect)
|
|
|
|
|
{
|
|
|
|
|
m_screenSpliter->startSplit(rect);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AppItem::supportSplitWindow()
|
|
|
|
|
{
|
|
|
|
|
return m_screenSpliter->suportSplitScreen();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AppItem::splitWindowOnScreen(ScreenSpliter::SplitDirection direction)
|
|
|
|
|
{
|
|
|
|
|
return m_screenSpliter->split(direction);
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-15 18:07:14 +00:00
|
|
|
|
int AppItem::mode() const
|
|
|
|
|
{
|
|
|
|
|
return m_itemEntryInter->mode();
|
|
|
|
|
}
|
2022-08-18 15:41:46 +00:00
|
|
|
|
|
2022-08-15 18:07:14 +00:00
|
|
|
|
|
2022-08-18 15:41:46 +00:00
|
|
|
|
DockEntryInter *AppItem::itemEntryInter() const
|
|
|
|
|
{
|
|
|
|
|
return m_itemEntryInter;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-13 12:59:02 +08:00
|
|
|
|
QString AppItem::accessibleName()
|
|
|
|
|
{
|
|
|
|
|
return m_itemEntryInter->name();
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-08 09:05:54 +00:00
|
|
|
|
void AppItem::requestDock()
|
|
|
|
|
{
|
|
|
|
|
m_itemEntryInter->RequestDock();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AppItem::isDocked() const
|
|
|
|
|
{
|
|
|
|
|
return m_itemEntryInter->isDocked();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qint64 AppItem::appOpenMSecs() const
|
|
|
|
|
{
|
|
|
|
|
return m_createMSecs;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-08 01:25:37 +00:00
|
|
|
|
void AppItem::updateMSecs()
|
|
|
|
|
{
|
|
|
|
|
m_createMSecs = QDateTime::currentMSecsSinceEpoch();
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-18 15:41:46 +00:00
|
|
|
|
const WindowInfoMap &AppItem::windowsMap() const
|
|
|
|
|
{
|
|
|
|
|
return m_windowInfos;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-08 16:19:12 +08:00
|
|
|
|
void AppItem::moveEvent(QMoveEvent *e)
|
|
|
|
|
{
|
|
|
|
|
DockItem::moveEvent(e);
|
|
|
|
|
|
2019-01-17 11:00:40 +08:00
|
|
|
|
if (m_drag) {
|
|
|
|
|
m_drag->appDragWidget()->setOriginPos(mapToGlobal(appIconPosition()));
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-08 16:19:12 +08:00
|
|
|
|
m_updateIconGeometryTimer->start();
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-03 16:06:11 +08:00
|
|
|
|
void AppItem::paintEvent(QPaintEvent *e)
|
|
|
|
|
{
|
|
|
|
|
DockItem::paintEvent(e);
|
|
|
|
|
|
2022-07-29 06:06:58 +00:00
|
|
|
|
if (isDragging() || (m_swingEffectView != nullptr && DockDisplayMode != Fashion))
|
2016-06-07 16:01:37 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2016-06-03 16:06:11 +08:00
|
|
|
|
QPainter painter(this);
|
2016-06-21 19:25:30 +08:00
|
|
|
|
if (!painter.isActive())
|
|
|
|
|
return;
|
2016-09-08 15:53:51 +08:00
|
|
|
|
painter.setRenderHint(QPainter::Antialiasing, true);
|
|
|
|
|
painter.setRenderHint(QPainter::SmoothPixmapTransform, true);
|
2016-06-21 19:25:30 +08:00
|
|
|
|
|
2017-05-02 16:32:38 +08:00
|
|
|
|
const QRectF itemRect = rect();
|
2016-06-06 14:28:28 +08:00
|
|
|
|
|
2019-08-21 12:52:53 +08:00
|
|
|
|
if (DockDisplayMode == Efficient) {
|
2019-11-14 10:34:50 +08:00
|
|
|
|
// draw background
|
|
|
|
|
qreal min = qMin(itemRect.width(), itemRect.height());
|
|
|
|
|
QRectF backgroundRect = QRectF(itemRect.x(), itemRect.y(), min, min);
|
|
|
|
|
backgroundRect = backgroundRect.marginsRemoved(QMargins(2, 2, 2, 2));
|
|
|
|
|
backgroundRect.moveCenter(itemRect.center());
|
2016-06-23 14:28:47 +08:00
|
|
|
|
|
2019-11-14 10:34:50 +08:00
|
|
|
|
QPainterPath path;
|
|
|
|
|
path.addRoundedRect(backgroundRect, 8, 8);
|
2016-06-23 14:28:47 +08:00
|
|
|
|
|
2022-08-18 15:41:46 +00:00
|
|
|
|
// 在没有开启窗口多开的情况下,显示背景色
|
|
|
|
|
if (!m_dockInter->showMultiWindow()) {
|
|
|
|
|
if (m_active) {
|
|
|
|
|
QColor color = Qt::black;
|
|
|
|
|
color.setAlpha(255 * 0.8);
|
|
|
|
|
painter.fillPath(path, color);
|
|
|
|
|
} else if (!m_windowInfos.isEmpty()) {
|
|
|
|
|
if (hasAttention()) {
|
|
|
|
|
painter.fillPath(path, QColor(241, 138, 46, 255 * .8));
|
|
|
|
|
} else {
|
|
|
|
|
QColor color = Qt::black;
|
|
|
|
|
color.setAlpha(255 * 0.3);
|
|
|
|
|
painter.fillPath(path, color);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-02-22 14:19:52 +08:00
|
|
|
|
}
|
2019-08-21 12:52:53 +08:00
|
|
|
|
} else {
|
|
|
|
|
if (!m_windowInfos.isEmpty()) {
|
2016-07-12 16:33:01 +08:00
|
|
|
|
QPoint p;
|
|
|
|
|
QPixmap pixmap;
|
|
|
|
|
QPixmap activePixmap;
|
2019-11-14 10:34:50 +08:00
|
|
|
|
if (DGuiApplicationHelper::DarkType == m_themeType) {
|
2019-11-07 20:39:09 +08:00
|
|
|
|
m_horizontalIndicator = QPixmap(":/indicator/resources/indicator_dark.svg");
|
|
|
|
|
m_verticalIndicator = QPixmap(":/indicator/resources/indicator_dark_ver.svg");
|
2019-11-14 10:34:50 +08:00
|
|
|
|
} else {
|
2019-11-07 20:39:09 +08:00
|
|
|
|
m_horizontalIndicator = QPixmap(":/indicator/resources/indicator.svg");
|
|
|
|
|
m_verticalIndicator = QPixmap(":/indicator/resources/indicator_ver.svg");
|
|
|
|
|
}
|
|
|
|
|
m_activeHorizontalIndicator = QPixmap(":/indicator/resources/indicator_active.svg");
|
|
|
|
|
m_activeVerticalIndicator = QPixmap(":/indicator/resources/indicator_active_ver.svg");
|
2019-08-21 12:52:53 +08:00
|
|
|
|
switch (DockPosition) {
|
2016-06-23 14:28:47 +08:00
|
|
|
|
case Top:
|
2016-07-12 16:33:01 +08:00
|
|
|
|
pixmap = m_horizontalIndicator;
|
|
|
|
|
activePixmap = m_activeHorizontalIndicator;
|
|
|
|
|
p.setX((itemRect.width() - pixmap.width()) / 2);
|
|
|
|
|
p.setY(1);
|
2016-06-23 14:28:47 +08:00
|
|
|
|
break;
|
|
|
|
|
case Bottom:
|
2016-07-12 16:33:01 +08:00
|
|
|
|
pixmap = m_horizontalIndicator;
|
|
|
|
|
activePixmap = m_activeHorizontalIndicator;
|
|
|
|
|
p.setX((itemRect.width() - pixmap.width()) / 2);
|
|
|
|
|
p.setY(itemRect.height() - pixmap.height() - 1);
|
2016-06-23 14:28:47 +08:00
|
|
|
|
break;
|
|
|
|
|
case Left:
|
2016-07-12 16:33:01 +08:00
|
|
|
|
pixmap = m_verticalIndicator;
|
|
|
|
|
activePixmap = m_activeVerticalIndicator;
|
|
|
|
|
p.setX(1);
|
|
|
|
|
p.setY((itemRect.height() - pixmap.height()) / 2);
|
2016-06-23 14:28:47 +08:00
|
|
|
|
break;
|
|
|
|
|
case Right:
|
2016-07-12 16:33:01 +08:00
|
|
|
|
pixmap = m_verticalIndicator;
|
|
|
|
|
activePixmap = m_activeVerticalIndicator;
|
|
|
|
|
p.setX(itemRect.width() - pixmap.width() - 1);
|
|
|
|
|
p.setY((itemRect.height() - pixmap.height()) / 2);
|
2016-06-23 14:28:47 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-12 16:33:01 +08:00
|
|
|
|
if (m_active)
|
|
|
|
|
painter.drawPixmap(p, activePixmap);
|
|
|
|
|
else
|
|
|
|
|
painter.drawPixmap(p, pixmap);
|
2016-06-23 10:50:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-06-06 14:28:28 +08:00
|
|
|
|
|
2018-07-04 14:18:12 +08:00
|
|
|
|
if (m_swingEffectView != nullptr)
|
2018-02-27 15:25:15 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2016-06-27 20:16:35 +08:00
|
|
|
|
// icon
|
2019-01-17 11:00:40 +08:00
|
|
|
|
if (m_appIcon.isNull())
|
2017-06-16 09:00:53 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2019-01-17 11:00:40 +08:00
|
|
|
|
painter.drawPixmap(appIconPosition(), m_appIcon);
|
2016-06-03 16:06:11 +08:00
|
|
|
|
}
|
2016-06-06 14:28:28 +08:00
|
|
|
|
|
|
|
|
|
void AppItem::mouseReleaseEvent(QMouseEvent *e)
|
|
|
|
|
{
|
2019-08-01 15:59:25 +08:00
|
|
|
|
if (checkGSettingsControl()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-05 21:46:46 +08:00
|
|
|
|
// 获取时间戳qint64转quint64,是不存在任何问题的
|
|
|
|
|
quint64 curTimestamp = QDateTime::currentDateTime().toMSecsSinceEpoch();
|
|
|
|
|
if ((curTimestamp - m_lastclickTimes) < 300)
|
2019-12-23 17:56:51 +08:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
m_lastclickTimes = curTimestamp;
|
|
|
|
|
|
2021-02-03 14:49:02 +08:00
|
|
|
|
// 鼠标在图标外边松开时,没必要响应点击操作
|
|
|
|
|
const QRect rect { QPoint(0, 0), size()};
|
|
|
|
|
if (!rect.contains(mapFromGlobal(QCursor::pos())))
|
|
|
|
|
return;
|
|
|
|
|
|
2017-02-15 16:34:30 +08:00
|
|
|
|
if (e->button() == Qt::MiddleButton) {
|
2018-02-22 11:44:57 +08:00
|
|
|
|
m_itemEntryInter->NewInstance(QX11Info::getTimestamp());
|
2018-11-30 14:57:11 +08:00
|
|
|
|
|
|
|
|
|
// play launch effect
|
|
|
|
|
if (m_windowInfos.isEmpty())
|
|
|
|
|
playSwingEffect();
|
|
|
|
|
|
2017-02-15 16:34:30 +08:00
|
|
|
|
} else if (e->button() == Qt::LeftButton) {
|
2018-11-30 17:47:08 +08:00
|
|
|
|
if (checkAndResetTapHoldGestureState() && e->source() == Qt::MouseEventSynthesizedByQt) {
|
2018-11-13 16:01:36 +08:00
|
|
|
|
qDebug() << "tap and hold gesture detected, ignore the synthesized mouse release event";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-31 16:06:34 +08:00
|
|
|
|
qDebug() << "app item clicked, name:" << m_itemEntryInter->name()
|
2019-08-21 12:52:53 +08:00
|
|
|
|
<< "id:" << m_itemEntryInter->id() << "my-id:" << m_id << "icon:" << m_itemEntryInter->icon();
|
2017-04-26 17:59:35 +08:00
|
|
|
|
|
2022-08-18 15:41:46 +00:00
|
|
|
|
if (m_dockInter->showMultiWindow()) {
|
|
|
|
|
// 如果开启了多窗口显示,则直接新建一个窗口
|
|
|
|
|
m_itemEntryInter->NewInstance(QX11Info::getTimestamp());
|
|
|
|
|
} else {
|
|
|
|
|
// 如果没有开启新窗口显示,则
|
|
|
|
|
m_itemEntryInter->Activate(QX11Info::getTimestamp());
|
|
|
|
|
// play launch effect
|
|
|
|
|
if (m_windowInfos.isEmpty() && DGuiApplicationHelper::isSpecialEffectsEnvironment())
|
|
|
|
|
playSwingEffect();
|
|
|
|
|
}
|
2017-02-15 16:34:30 +08:00
|
|
|
|
}
|
2016-06-07 14:40:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AppItem::mousePressEvent(QMouseEvent *e)
|
|
|
|
|
{
|
2019-08-01 15:59:25 +08:00
|
|
|
|
if (checkGSettingsControl()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-08-09 10:58:47 +08:00
|
|
|
|
m_updateIconGeometryTimer->stop();
|
2017-05-18 15:41:17 +08:00
|
|
|
|
hidePopup();
|
2016-08-09 10:58:47 +08:00
|
|
|
|
|
2016-06-15 16:17:51 +08:00
|
|
|
|
if (e->button() == Qt::LeftButton)
|
|
|
|
|
MousePressPos = e->pos();
|
2018-12-17 14:38:09 +08:00
|
|
|
|
|
|
|
|
|
// context menu will handle in DockItem
|
|
|
|
|
DockItem::mousePressEvent(e);
|
2016-06-07 14:40:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AppItem::mouseMoveEvent(QMouseEvent *e)
|
|
|
|
|
{
|
2016-06-14 15:17:25 +08:00
|
|
|
|
e->accept();
|
|
|
|
|
|
2017-05-02 16:57:58 +08:00
|
|
|
|
// handle preview
|
2020-03-13 12:59:02 +08:00
|
|
|
|
// if (e->buttons() == Qt::NoButton)
|
|
|
|
|
// return showPreview();
|
2017-05-02 16:57:58 +08:00
|
|
|
|
|
2016-06-07 14:40:45 +08:00
|
|
|
|
// handle drag
|
|
|
|
|
if (e->buttons() != Qt::LeftButton)
|
|
|
|
|
return;
|
|
|
|
|
|
2017-04-27 15:34:04 +08:00
|
|
|
|
const QPoint pos = e->pos();
|
|
|
|
|
if (!rect().contains(pos))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const QPoint distance = pos - MousePressPos;
|
2017-05-02 16:57:58 +08:00
|
|
|
|
if (distance.manhattanLength() > APP_DRAG_THRESHOLD)
|
|
|
|
|
return startDrag();
|
2016-06-07 14:40:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-30 16:34:02 +08:00
|
|
|
|
void AppItem::wheelEvent(QWheelEvent *e)
|
|
|
|
|
{
|
2019-08-01 15:59:25 +08:00
|
|
|
|
if (checkGSettingsControl()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-30 16:34:02 +08:00
|
|
|
|
QWidget::wheelEvent(e);
|
|
|
|
|
|
2018-12-17 10:04:15 +08:00
|
|
|
|
if (qAbs(e->angleDelta().y()) > 20) {
|
|
|
|
|
m_itemEntryInter->PresentWindows();
|
|
|
|
|
}
|
2016-08-30 16:34:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-15 11:20:05 +08:00
|
|
|
|
void AppItem::resizeEvent(QResizeEvent *e)
|
|
|
|
|
{
|
|
|
|
|
DockItem::resizeEvent(e);
|
|
|
|
|
|
2021-03-06 18:40:13 +08:00
|
|
|
|
refreshIcon();
|
2016-06-15 11:20:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-23 14:45:57 +08:00
|
|
|
|
void AppItem::dragEnterEvent(QDragEnterEvent *e)
|
|
|
|
|
{
|
2019-08-01 15:59:25 +08:00
|
|
|
|
if (checkGSettingsControl()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-23 15:30:06 +08:00
|
|
|
|
// ignore drag from panel
|
2018-11-05 11:26:20 +08:00
|
|
|
|
if (e->source()) {
|
|
|
|
|
return e->ignore();
|
|
|
|
|
}
|
2016-06-23 15:30:06 +08:00
|
|
|
|
|
2016-07-18 17:10:15 +08:00
|
|
|
|
// ignore request dock event
|
2018-08-22 12:52:47 +08:00
|
|
|
|
QString draggingMimeKey = e->mimeData()->formats().contains("RequestDock") ? "RequestDock" : "text/plain";
|
|
|
|
|
if (QMimeDatabase().mimeTypeForFile(e->mimeData()->data(draggingMimeKey)).name() == "application/x-desktop") {
|
2018-11-05 11:26:20 +08:00
|
|
|
|
return e->ignore();
|
2018-08-22 12:52:47 +08:00
|
|
|
|
}
|
2016-07-18 17:10:15 +08:00
|
|
|
|
|
2016-06-23 15:30:06 +08:00
|
|
|
|
e->accept();
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-25 20:28:11 +08:00
|
|
|
|
void AppItem::dragMoveEvent(QDragMoveEvent *e)
|
|
|
|
|
{
|
2019-08-01 15:59:25 +08:00
|
|
|
|
if (checkGSettingsControl()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-25 20:28:11 +08:00
|
|
|
|
DockItem::dragMoveEvent(e);
|
|
|
|
|
|
2018-02-22 11:44:57 +08:00
|
|
|
|
if (m_windowInfos.isEmpty())
|
2017-04-25 20:28:11 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2018-07-10 15:21:10 +08:00
|
|
|
|
if (!PopupWindow->isVisible() || !m_appPreviewTips)
|
2017-04-25 20:28:11 +08:00
|
|
|
|
showPreview();
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-23 15:30:06 +08:00
|
|
|
|
void AppItem::dropEvent(QDropEvent *e)
|
|
|
|
|
{
|
|
|
|
|
QStringList uriList;
|
2017-02-27 15:04:49 +08:00
|
|
|
|
for (auto uri : e->mimeData()->urls()) {
|
|
|
|
|
uriList << uri.toEncoded();
|
|
|
|
|
}
|
2016-06-23 15:30:06 +08:00
|
|
|
|
|
2017-02-27 15:04:49 +08:00
|
|
|
|
qDebug() << "accept drop event with URIs: " << uriList;
|
2018-02-22 11:44:57 +08:00
|
|
|
|
m_itemEntryInter->HandleDragDrop(QX11Info::getTimestamp(), uriList);
|
2016-06-23 14:45:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-18 13:13:56 +08:00
|
|
|
|
void AppItem::leaveEvent(QEvent *e)
|
|
|
|
|
{
|
|
|
|
|
DockItem::leaveEvent(e);
|
|
|
|
|
|
2018-07-10 15:21:10 +08:00
|
|
|
|
if (m_appPreviewTips) {
|
|
|
|
|
if (m_appPreviewTips->isVisible()) {
|
|
|
|
|
m_appPreviewTips->prepareHide();
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-08-18 13:13:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-04 10:39:03 +08:00
|
|
|
|
void AppItem::showHoverTips()
|
|
|
|
|
{
|
2019-08-01 15:59:25 +08:00
|
|
|
|
if (checkGSettingsControl()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-22 11:44:57 +08:00
|
|
|
|
if (!m_windowInfos.isEmpty())
|
2017-05-04 10:39:03 +08:00
|
|
|
|
return showPreview();
|
|
|
|
|
|
|
|
|
|
DockItem::showHoverTips();
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-15 16:17:51 +08:00
|
|
|
|
void AppItem::invokedMenuItem(const QString &itemId, const bool checked)
|
|
|
|
|
{
|
2016-06-21 10:12:43 +08:00
|
|
|
|
Q_UNUSED(checked);
|
|
|
|
|
|
2018-02-22 11:44:57 +08:00
|
|
|
|
m_itemEntryInter->HandleMenuItem(QX11Info::getTimestamp(), itemId);
|
2016-06-15 16:17:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QString AppItem::contextMenu() const
|
|
|
|
|
{
|
2018-02-22 11:44:57 +08:00
|
|
|
|
return m_itemEntryInter->menu();
|
2016-06-15 16:17:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-18 14:13:36 +08:00
|
|
|
|
QWidget *AppItem::popupTips()
|
|
|
|
|
{
|
2021-12-31 17:27:09 +08:00
|
|
|
|
if (checkGSettingsControl())
|
2019-08-01 15:59:25 +08:00
|
|
|
|
return nullptr;
|
|
|
|
|
|
2022-07-29 06:06:58 +00:00
|
|
|
|
if (isDragging())
|
2016-07-18 17:10:15 +08:00
|
|
|
|
return nullptr;
|
2016-07-18 14:13:36 +08:00
|
|
|
|
|
2021-12-31 17:27:09 +08:00
|
|
|
|
static TipsWidget appNameTips(topLevelWidget());
|
2022-01-06 16:01:50 +08:00
|
|
|
|
appNameTips.setAccessibleName("tip");
|
|
|
|
|
appNameTips.setObjectName(m_itemEntryInter->name());
|
2021-12-31 17:27:09 +08:00
|
|
|
|
|
2019-08-21 12:52:53 +08:00
|
|
|
|
if (!m_windowInfos.isEmpty()) {
|
2018-02-22 11:44:57 +08:00
|
|
|
|
const quint32 currentWindow = m_itemEntryInter->currentWindow();
|
|
|
|
|
Q_ASSERT(m_windowInfos.contains(currentWindow));
|
2021-12-31 17:27:09 +08:00
|
|
|
|
appNameTips.setText(m_windowInfos[currentWindow].title.simplified());
|
2016-07-19 15:11:28 +08:00
|
|
|
|
} else {
|
2021-12-31 17:27:09 +08:00
|
|
|
|
appNameTips.setText(m_itemEntryInter->name().simplified());
|
2016-07-19 15:11:28 +08:00
|
|
|
|
}
|
2016-07-18 14:13:36 +08:00
|
|
|
|
|
2021-12-31 17:27:09 +08:00
|
|
|
|
return &appNameTips;
|
2016-07-18 14:13:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-07 14:40:45 +08:00
|
|
|
|
void AppItem::startDrag()
|
|
|
|
|
{
|
2019-08-29 17:21:02 +08:00
|
|
|
|
// 拖拽实现放到mainpanelcontrol
|
|
|
|
|
|
|
|
|
|
/*
|
2019-08-21 12:52:53 +08:00
|
|
|
|
if (!acceptDrops())
|
|
|
|
|
return;
|
|
|
|
|
|
2019-08-01 15:59:25 +08:00
|
|
|
|
if (checkGSettingsControl()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-20 15:32:33 +08:00
|
|
|
|
m_dragging = true;
|
2016-06-07 16:01:37 +08:00
|
|
|
|
update();
|
|
|
|
|
|
2017-12-28 16:21:10 +08:00
|
|
|
|
const QPixmap &dragPix = m_appIcon;
|
2016-08-09 16:50:48 +08:00
|
|
|
|
|
2018-06-04 21:09:41 +08:00
|
|
|
|
m_drag = new AppDrag(this);
|
|
|
|
|
m_drag->setMimeData(new QMimeData);
|
|
|
|
|
|
2019-01-17 11:00:40 +08:00
|
|
|
|
// handle drag finished here
|
2019-08-21 12:52:53 +08:00
|
|
|
|
connect(m_drag->appDragWidget(), &AppDragWidget::destroyed, this, [ = ] {
|
2019-01-17 11:00:40 +08:00
|
|
|
|
m_dragging = false;
|
2019-07-15 15:30:06 +08:00
|
|
|
|
m_drag.clear();
|
2019-01-17 11:00:40 +08:00
|
|
|
|
setVisible(true);
|
|
|
|
|
update();
|
|
|
|
|
});
|
|
|
|
|
|
2018-06-04 21:09:41 +08:00
|
|
|
|
if (m_wmHelper->hasComposite()) {
|
|
|
|
|
m_drag->setPixmap(dragPix);
|
2019-01-17 11:00:40 +08:00
|
|
|
|
m_drag->appDragWidget()->setOriginPos(mapToGlobal(appIconPosition()));
|
2018-06-04 21:09:41 +08:00
|
|
|
|
emit dragStarted();
|
|
|
|
|
m_drag->exec(Qt::MoveAction);
|
|
|
|
|
} else {
|
|
|
|
|
m_drag->QDrag::setPixmap(dragPix);
|
|
|
|
|
m_drag->setHotSpot(dragPix.rect().center() / dragPix.devicePixelRatioF());
|
|
|
|
|
emit dragStarted();
|
|
|
|
|
m_drag->QDrag::exec(Qt::MoveAction);
|
|
|
|
|
}
|
2016-06-07 14:40:45 +08:00
|
|
|
|
|
2018-06-04 21:09:41 +08:00
|
|
|
|
// MainPanel will put this item to Item-Container when received this signal(MainPanel::itemDropped)
|
|
|
|
|
//emit itemDropped(m_drag->target());
|
2016-06-20 16:46:53 +08:00
|
|
|
|
|
2018-06-04 21:09:41 +08:00
|
|
|
|
if (!m_wmHelper->hasComposite()) {
|
|
|
|
|
if (!m_drag->target()) {
|
|
|
|
|
m_itemEntryInter->RequestUndock();
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-08-29 17:21:02 +08:00
|
|
|
|
*/
|
2016-06-06 14:28:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-22 14:19:52 +08:00
|
|
|
|
bool AppItem::hasAttention() const
|
|
|
|
|
{
|
2021-05-31 17:37:21 +08:00
|
|
|
|
auto it = std::find_if(m_windowInfos.constBegin(), m_windowInfos.constEnd(), [ = ] (const auto &info) {
|
|
|
|
|
return info.attention;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return (it != m_windowInfos.end());
|
2018-02-22 14:19:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-17 11:00:40 +08:00
|
|
|
|
QPoint AppItem::appIconPosition() const
|
|
|
|
|
{
|
2019-04-23 14:28:09 +08:00
|
|
|
|
const auto ratio = devicePixelRatioF();
|
2019-01-17 11:00:40 +08:00
|
|
|
|
const QRectF itemRect = rect();
|
|
|
|
|
const QRectF iconRect = m_appIcon.rect();
|
|
|
|
|
const qreal iconX = itemRect.center().x() - iconRect.center().x() / ratio;
|
|
|
|
|
const qreal iconY = itemRect.center().y() - iconRect.center().y() / ratio;
|
|
|
|
|
|
|
|
|
|
return QPoint(iconX, iconY);
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-22 14:19:52 +08:00
|
|
|
|
void AppItem::updateWindowInfos(const WindowInfoMap &info)
|
2016-06-06 14:28:28 +08:00
|
|
|
|
{
|
2022-07-08 09:05:54 +00:00
|
|
|
|
// 如果是打开第一个窗口,则更新窗口时间
|
|
|
|
|
if (m_windowInfos.isEmpty() && !info.isEmpty())
|
2022-08-08 01:25:37 +00:00
|
|
|
|
updateMSecs();
|
2022-07-08 09:05:54 +00:00
|
|
|
|
|
2018-02-22 14:19:52 +08:00
|
|
|
|
m_windowInfos = info;
|
2021-03-12 13:20:13 +08:00
|
|
|
|
if (m_appPreviewTips)
|
|
|
|
|
m_appPreviewTips->setWindowInfos(m_windowInfos, m_itemEntryInter->GetAllowedCloseWindows().value());
|
2017-06-06 11:06:02 +08:00
|
|
|
|
m_updateIconGeometryTimer->start();
|
2017-04-25 20:28:11 +08:00
|
|
|
|
|
2018-02-27 15:25:15 +08:00
|
|
|
|
// process attention effect
|
2019-08-21 12:52:53 +08:00
|
|
|
|
if (hasAttention()) {
|
2018-02-27 15:25:15 +08:00
|
|
|
|
if (DockDisplayMode == DisplayMode::Fashion)
|
|
|
|
|
playSwingEffect();
|
|
|
|
|
} else {
|
2018-03-19 11:33:16 +08:00
|
|
|
|
stopSwingEffect();
|
2018-02-27 15:25:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-14 15:01:27 +08:00
|
|
|
|
update();
|
2022-08-18 15:41:46 +00:00
|
|
|
|
|
|
|
|
|
// 通知外面窗体数量发生变化,需要更新多开窗口的信息
|
|
|
|
|
Q_EMIT windowCountChanged();
|
2016-06-06 14:28:28 +08:00
|
|
|
|
}
|
2016-06-14 16:01:01 +08:00
|
|
|
|
|
2021-03-06 18:40:13 +08:00
|
|
|
|
void AppItem::refreshIcon()
|
2016-06-14 16:01:01 +08:00
|
|
|
|
{
|
2018-07-03 12:33:31 +08:00
|
|
|
|
if (!isVisible())
|
|
|
|
|
return;
|
|
|
|
|
|
2018-02-22 11:44:57 +08:00
|
|
|
|
const QString icon = m_itemEntryInter->icon();
|
2016-06-23 14:28:47 +08:00
|
|
|
|
const int iconSize = qMin(width(), height());
|
|
|
|
|
|
2016-07-11 17:17:32 +08:00
|
|
|
|
if (DockDisplayMode == Efficient)
|
2021-04-26 11:28:47 +08:00
|
|
|
|
m_iconValid = ThemeAppIcon::getIcon(m_appIcon, icon, iconSize * 0.7, !m_iconValid);
|
2017-12-28 16:21:10 +08:00
|
|
|
|
else
|
2021-04-26 11:28:47 +08:00
|
|
|
|
m_iconValid = ThemeAppIcon::getIcon(m_appIcon, icon, iconSize * 0.8, !m_iconValid);
|
2017-03-13 08:02:33 +08:00
|
|
|
|
|
2020-05-22 13:10:52 +08:00
|
|
|
|
if (!m_refershIconTimer->isActive() && m_itemEntryInter->icon() == "dde-calendar") {
|
2020-05-22 13:10:14 +08:00
|
|
|
|
m_refershIconTimer->start();
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-22 09:56:28 +08:00
|
|
|
|
if (!m_iconValid) {
|
2021-04-26 15:12:17 +08:00
|
|
|
|
if (m_retryTimes < 10) {
|
2018-08-30 12:03:25 +08:00
|
|
|
|
m_retryTimes++;
|
2018-08-31 16:06:34 +08:00
|
|
|
|
qDebug() << m_itemEntryInter->name() << "obtain app icon(" << icon << ")failed, retry times:" << m_retryTimes;
|
2021-04-26 15:12:17 +08:00
|
|
|
|
// Maybe the icon was installed after we loaded the caches.
|
|
|
|
|
// QIcon::setThemeSearchPaths will force Qt to re-check the gtk cache validity.
|
|
|
|
|
QIcon::setThemeSearchPaths(QIcon::themeSearchPaths());
|
|
|
|
|
|
2018-08-30 12:03:25 +08:00
|
|
|
|
m_retryObtainIconTimer->start();
|
2021-04-22 09:56:28 +08:00
|
|
|
|
} else {
|
2021-04-26 15:12:17 +08:00
|
|
|
|
// 如果图标获取失败,一分钟后再自动刷新一次(如果还是显示异常,基本需要应用自身看下为什么了)
|
2021-04-22 09:56:28 +08:00
|
|
|
|
if (!m_iconValid)
|
2021-04-26 15:12:17 +08:00
|
|
|
|
QTimer::singleShot(60 * 1000, this, &AppItem::refreshIcon);
|
2018-08-30 12:03:25 +08:00
|
|
|
|
}
|
2021-04-22 09:56:28 +08:00
|
|
|
|
|
|
|
|
|
update();
|
|
|
|
|
|
2018-08-30 12:03:25 +08:00
|
|
|
|
return;
|
2022-08-12 08:13:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_retryTimes > 0) {
|
2018-08-30 12:03:25 +08:00
|
|
|
|
// reset times
|
|
|
|
|
m_retryTimes = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-23 16:57:02 +08:00
|
|
|
|
update();
|
|
|
|
|
|
2017-06-06 11:06:02 +08:00
|
|
|
|
m_updateIconGeometryTimer->start();
|
2016-06-23 14:28:47 +08:00
|
|
|
|
}
|
2016-06-14 16:01:01 +08:00
|
|
|
|
|
2021-08-25 21:03:30 +08:00
|
|
|
|
void AppItem::onRefreshIcon()
|
|
|
|
|
{
|
|
|
|
|
if (QDate::currentDate() == m_curDate)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
m_curDate = QDate::currentDate();
|
|
|
|
|
refreshIcon();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AppItem::onResetPreview()
|
|
|
|
|
{
|
2021-11-25 01:55:52 -04:00
|
|
|
|
if (m_appPreviewTips != nullptr) {
|
|
|
|
|
m_appPreviewTips->deleteLater();
|
|
|
|
|
m_appPreviewTips = nullptr;
|
|
|
|
|
}
|
2021-08-25 21:03:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-23 14:28:47 +08:00
|
|
|
|
void AppItem::activeChanged()
|
|
|
|
|
{
|
|
|
|
|
m_active = !m_active;
|
2016-06-14 16:01:01 +08:00
|
|
|
|
}
|
2017-03-28 15:44:13 +08:00
|
|
|
|
|
2017-04-25 16:36:58 +08:00
|
|
|
|
void AppItem::showPreview()
|
2017-03-28 15:44:13 +08:00
|
|
|
|
{
|
2018-02-22 11:44:57 +08:00
|
|
|
|
if (m_windowInfos.isEmpty())
|
2017-05-02 16:57:58 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2021-11-25 01:55:52 -04:00
|
|
|
|
m_appPreviewTips = new PreviewContainer;
|
2022-01-25 10:22:59 +08:00
|
|
|
|
m_appPreviewTips->setWindowInfos(m_windowInfos, m_itemEntryInter->GetAllowedCloseWindows().value());
|
2022-02-18 13:25:53 +08:00
|
|
|
|
m_appPreviewTips->updateLayoutDirection(DockPosition);
|
2017-05-04 10:39:03 +08:00
|
|
|
|
|
2018-07-10 15:21:10 +08:00
|
|
|
|
connect(m_appPreviewTips, &PreviewContainer::requestActivateWindow, this, &AppItem::requestActivateWindow, Qt::QueuedConnection);
|
|
|
|
|
connect(m_appPreviewTips, &PreviewContainer::requestPreviewWindow, this, &AppItem::requestPreviewWindow, Qt::QueuedConnection);
|
2019-04-12 17:17:19 +08:00
|
|
|
|
connect(m_appPreviewTips, &PreviewContainer::requestCancelPreviewWindow, this, &AppItem::requestCancelPreview);
|
|
|
|
|
connect(m_appPreviewTips, &PreviewContainer::requestHidePopup, this, &AppItem::hidePopup);
|
2018-07-10 15:21:10 +08:00
|
|
|
|
connect(m_appPreviewTips, &PreviewContainer::requestCheckWindows, m_itemEntryInter, &DockEntryInter::Check);
|
2017-03-28 16:52:38 +08:00
|
|
|
|
|
2021-08-25 21:03:30 +08:00
|
|
|
|
connect(m_appPreviewTips, &PreviewContainer::requestActivateWindow, this, &AppItem::onResetPreview);
|
|
|
|
|
connect(m_appPreviewTips, &PreviewContainer::requestCancelPreviewWindow, this, &AppItem::onResetPreview);
|
|
|
|
|
connect(m_appPreviewTips, &PreviewContainer::requestHidePopup, this, &AppItem::onResetPreview);
|
2018-07-30 15:09:36 +08:00
|
|
|
|
|
2021-09-14 17:08:36 +08:00
|
|
|
|
// 预览标题显示方式的配置
|
2021-12-31 17:27:09 +08:00
|
|
|
|
DConfig config(QString("com.deepin.dde.dock.dconfig"), QString());
|
|
|
|
|
if (config.isValid() && config.keyList().contains("Dock_Show_Window_name"))
|
|
|
|
|
m_appPreviewTips->setTitleDisplayMode(config.value("Dock_Show_Window_name").toInt());
|
2021-09-14 17:08:36 +08:00
|
|
|
|
|
2018-02-22 17:19:55 +08:00
|
|
|
|
showPopupWindow(m_appPreviewTips, true);
|
2017-03-28 15:44:13 +08:00
|
|
|
|
}
|
2017-06-15 16:41:40 +08:00
|
|
|
|
|
2018-02-27 15:25:15 +08:00
|
|
|
|
void AppItem::playSwingEffect()
|
|
|
|
|
{
|
2018-03-19 14:25:46 +08:00
|
|
|
|
// NOTE(sbw): return if animation view already playing
|
2018-07-04 14:18:12 +08:00
|
|
|
|
if (m_swingEffectView != nullptr)
|
2018-03-19 14:25:46 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2021-11-30 15:09:34 +08:00
|
|
|
|
if (rect().isEmpty())
|
|
|
|
|
return checkAttentionEffect();
|
|
|
|
|
|
2018-03-19 11:33:16 +08:00
|
|
|
|
stopSwingEffect();
|
2018-03-14 11:24:57 +08:00
|
|
|
|
|
2018-07-04 14:18:12 +08:00
|
|
|
|
QPair<QGraphicsView *, QGraphicsItemAnimation *> pair = SwingEffect(
|
2021-03-06 19:33:43 +08:00
|
|
|
|
this, m_appIcon, rect(), devicePixelRatioF());
|
2018-03-09 14:59:33 +08:00
|
|
|
|
|
2018-07-04 14:18:12 +08:00
|
|
|
|
m_swingEffectView = pair.first;
|
|
|
|
|
m_itemAnimation = pair.second;
|
2018-02-27 15:25:15 +08:00
|
|
|
|
|
2018-07-04 14:18:12 +08:00
|
|
|
|
QTimeLine *tl = m_itemAnimation->timeLine();
|
2021-08-25 21:03:30 +08:00
|
|
|
|
connect(tl, &QTimeLine::stateChanged, this, [ = ](QTimeLine::State newState) {
|
2018-07-04 14:18:12 +08:00
|
|
|
|
if (newState == QTimeLine::NotRunning) {
|
|
|
|
|
m_swingEffectView->hide();
|
|
|
|
|
layout()->removeWidget(m_swingEffectView);
|
|
|
|
|
m_swingEffectView = nullptr;
|
|
|
|
|
m_itemAnimation = nullptr;
|
|
|
|
|
checkAttentionEffect();
|
|
|
|
|
}
|
|
|
|
|
});
|
2018-02-27 15:25:15 +08:00
|
|
|
|
|
2018-07-04 14:18:12 +08:00
|
|
|
|
layout()->addWidget(m_swingEffectView);
|
2018-03-02 11:59:03 +08:00
|
|
|
|
tl->start();
|
2018-02-27 15:25:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-19 11:33:16 +08:00
|
|
|
|
void AppItem::stopSwingEffect()
|
|
|
|
|
{
|
2018-07-04 14:18:12 +08:00
|
|
|
|
if (m_swingEffectView == nullptr || m_itemAnimation == nullptr)
|
|
|
|
|
return;
|
|
|
|
|
|
2018-03-19 11:33:16 +08:00
|
|
|
|
// stop swing effect
|
|
|
|
|
m_swingEffectView->setVisible(false);
|
|
|
|
|
|
2018-07-04 14:18:12 +08:00
|
|
|
|
if (m_itemAnimation->timeLine() && m_itemAnimation->timeLine()->state() != QTimeLine::NotRunning)
|
|
|
|
|
m_itemAnimation->timeLine()->stop();
|
2018-03-19 11:33:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-27 15:25:15 +08:00
|
|
|
|
void AppItem::checkAttentionEffect()
|
|
|
|
|
{
|
2019-08-21 12:52:53 +08:00
|
|
|
|
QTimer::singleShot(1000, this, [ = ] {
|
2018-02-27 15:25:15 +08:00
|
|
|
|
if (DockDisplayMode == DisplayMode::Fashion && hasAttention())
|
|
|
|
|
playSwingEffect();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-21 12:52:53 +08:00
|
|
|
|
void AppItem::onGSettingsChanged(const QString &key)
|
|
|
|
|
{
|
2019-08-01 15:59:25 +08:00
|
|
|
|
if (key != "enable") {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-20 12:10:45 +08:00
|
|
|
|
const QGSettings *setting = m_itemEntryInter->isDocked()
|
|
|
|
|
? m_dockedAppSettings
|
|
|
|
|
: m_activeAppSettings;
|
2019-08-01 15:59:25 +08:00
|
|
|
|
|
2021-03-20 12:10:45 +08:00
|
|
|
|
if (setting && setting->keys().contains("enable")) {
|
2021-03-25 14:20:52 +08:00
|
|
|
|
const bool isEnable = !m_appSettings || (m_appSettings->keys().contains("enable") && m_appSettings->get("enable").toBool());
|
2019-08-01 15:59:25 +08:00
|
|
|
|
setVisible(isEnable && setting->get("enable").toBool());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AppItem::checkGSettingsControl() const
|
|
|
|
|
{
|
2021-03-20 12:10:45 +08:00
|
|
|
|
const QGSettings *setting = m_itemEntryInter->isDocked()
|
|
|
|
|
? m_dockedAppSettings
|
|
|
|
|
: m_activeAppSettings;
|
2019-08-01 15:59:25 +08:00
|
|
|
|
|
2021-05-07 19:47:43 +08:00
|
|
|
|
return ((m_appSettings && m_appSettings->keys().contains("control") && m_appSettings->get("control").toBool())
|
|
|
|
|
|| (setting && setting->keys().contains("control") && setting->get("control").toBool()));
|
2019-08-01 15:59:25 +08:00
|
|
|
|
}
|
2019-11-07 20:39:09 +08:00
|
|
|
|
|
|
|
|
|
void AppItem::onThemeTypeChanged(DGuiApplicationHelper::ColorType themeType)
|
|
|
|
|
{
|
|
|
|
|
m_themeType = themeType;
|
|
|
|
|
update();
|
|
|
|
|
}
|
2021-08-25 21:03:30 +08:00
|
|
|
|
|
|
|
|
|
// 放到最下面是因为析构函数和匿名函数会影响lcov统计单元测试的覆盖率
|
|
|
|
|
AppItem::~AppItem()
|
|
|
|
|
{
|
|
|
|
|
stopSwingEffect();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AppItem::showEvent(QShowEvent *e)
|
|
|
|
|
{
|
|
|
|
|
DockItem::showEvent(e);
|
|
|
|
|
|
|
|
|
|
QTimer::singleShot(0, this, [ = ] {
|
|
|
|
|
onGSettingsChanged("enable");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
refreshIcon();
|
|
|
|
|
}
|