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>
|
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
|
2016-06-14 16:01:01 +08:00
|
|
|
#include "util/themeappicon.h"
|
2016-06-27 20:16:35 +08:00
|
|
|
#include "util/imagefactory.h"
|
2016-07-22 14:59:43 +08:00
|
|
|
#include "xcb/xcb_misc.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 <QGraphicsItemAnimation>
|
|
|
|
#include <QTimeLine>
|
2018-02-22 11:44:57 +08:00
|
|
|
#include <QX11Info>
|
2016-06-03 16:06:11 +08:00
|
|
|
|
2016-06-07 14:40:45 +08:00
|
|
|
#define APP_DRAG_THRESHOLD 20
|
|
|
|
|
2018-02-22 11:44:57 +08:00
|
|
|
const static qreal Frames[] = { 0,
|
|
|
|
0.327013,
|
|
|
|
0.987033,
|
|
|
|
1.77584,
|
|
|
|
2.61157,
|
|
|
|
3.45043,
|
|
|
|
4.26461,
|
|
|
|
5.03411,
|
|
|
|
5.74306,
|
|
|
|
6.37782,
|
|
|
|
6.92583,
|
|
|
|
7.37484,
|
|
|
|
7.71245,
|
|
|
|
7.92557,
|
|
|
|
8, 7.86164,
|
|
|
|
7.43184,
|
|
|
|
6.69344,
|
|
|
|
5.64142,
|
|
|
|
4.2916,
|
|
|
|
2.68986,
|
|
|
|
0.91694,
|
|
|
|
-0.91694,
|
|
|
|
-2.68986,
|
|
|
|
-4.2916,
|
|
|
|
-5.64142,
|
|
|
|
-6.69344,
|
|
|
|
-7.43184,
|
|
|
|
-7.86164,
|
|
|
|
-8,
|
|
|
|
-7.86164,
|
|
|
|
-7.43184,
|
|
|
|
-6.69344,
|
|
|
|
-5.64142,
|
|
|
|
-4.2916,
|
|
|
|
-2.68986,
|
|
|
|
-0.91694,
|
|
|
|
0.91694,
|
|
|
|
2.68986,
|
|
|
|
4.2916,
|
|
|
|
5.64142,
|
|
|
|
6.69344,
|
|
|
|
7.43184,
|
|
|
|
7.86164,
|
|
|
|
8,
|
|
|
|
7.93082,
|
|
|
|
7.71592,
|
|
|
|
7.34672,
|
|
|
|
6.82071,
|
|
|
|
6.1458,
|
|
|
|
5.34493,
|
|
|
|
4.45847,
|
|
|
|
3.54153,
|
|
|
|
2.65507,
|
|
|
|
1.8542,
|
|
|
|
1.17929,
|
|
|
|
0.653279,
|
|
|
|
0.28408,
|
|
|
|
0.0691776,
|
|
|
|
0,
|
|
|
|
};
|
2017-04-26 17:59:35 +08:00
|
|
|
|
2016-06-21 17:24:03 +08:00
|
|
|
int AppItem::IconBaseSize;
|
2016-06-15 16:17:51 +08:00
|
|
|
QPoint AppItem::MousePressPos;
|
2016-06-06 14:57:07 +08:00
|
|
|
|
2016-06-03 16:06:11 +08:00
|
|
|
AppItem::AppItem(const QDBusObjectPath &entry, QWidget *parent)
|
2016-08-08 09:52:05 +08:00
|
|
|
: DockItem(parent),
|
2016-07-18 14:13:36 +08:00
|
|
|
m_appNameTips(new QLabel(this)),
|
2017-07-31 17:06:10 +08:00
|
|
|
m_appPreviewTips(new PreviewContainer(this)),
|
2018-02-22 11:44:57 +08:00
|
|
|
m_itemEntryInter(new DockEntryInter("com.deepin.dde.daemon.Dock", entry.path(), QDBusConnection::sessionBus(), this)),
|
2017-04-26 17:59:35 +08:00
|
|
|
|
|
|
|
m_itemView(new QGraphicsView(this)),
|
|
|
|
m_itemScene(new QGraphicsScene(this)),
|
|
|
|
|
2016-07-12 16:33:01 +08:00
|
|
|
m_draging(false),
|
2017-06-16 09:00:53 +08:00
|
|
|
|
2017-12-28 16:21:10 +08:00
|
|
|
m_appIcon(QPixmap()),
|
2017-06-16 09:00:53 +08:00
|
|
|
|
2016-07-12 16:33:01 +08:00
|
|
|
m_horizontalIndicator(QPixmap(":/indicator/resources/indicator.png")),
|
|
|
|
m_verticalIndicator(QPixmap(":/indicator/resources/indicator_ver.png")),
|
|
|
|
m_activeHorizontalIndicator(QPixmap(":/indicator/resources/indicator_active.png")),
|
2016-07-22 14:59:43 +08:00
|
|
|
m_activeVerticalIndicator(QPixmap(":/indicator/resources/indicator_active_ver.png")),
|
2017-06-16 15:26:20 +08:00
|
|
|
m_updateIconGeometryTimer(new QTimer(this)),
|
|
|
|
|
|
|
|
m_smallWatcher(new QFutureWatcher<QPixmap>(this)),
|
|
|
|
m_largeWatcher(new QFutureWatcher<QPixmap>(this))
|
2016-06-03 16:06:11 +08:00
|
|
|
{
|
2017-04-26 17:59:35 +08:00
|
|
|
QHBoxLayout *centralLayout = new QHBoxLayout;
|
|
|
|
centralLayout->addWidget(m_itemView);
|
|
|
|
centralLayout->setMargin(0);
|
2017-05-02 16:32:38 +08:00
|
|
|
centralLayout->setSpacing(0);
|
2017-04-26 17:59:35 +08:00
|
|
|
|
2018-02-22 11:44:57 +08:00
|
|
|
setAccessibleName(m_itemEntryInter->name());
|
2016-06-23 14:45:57 +08:00
|
|
|
setAcceptDrops(true);
|
2017-04-26 17:59:35 +08:00
|
|
|
setLayout(centralLayout);
|
|
|
|
|
|
|
|
m_itemView->setScene(m_itemScene);
|
2017-05-02 16:32:38 +08:00
|
|
|
m_itemView->setAlignment(Qt::AlignCenter);
|
2017-04-26 17:59:35 +08:00
|
|
|
m_itemView->setVisible(false);
|
2017-04-27 14:31:04 +08:00
|
|
|
m_itemView->setFrameStyle(QFrame::NoFrame);
|
2017-05-02 16:32:38 +08:00
|
|
|
m_itemView->setContentsMargins(0, 0, 0, 0);
|
2017-04-27 14:31:04 +08:00
|
|
|
m_itemView->setRenderHints(QPainter::SmoothPixmapTransform);
|
|
|
|
m_itemView->setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
|
2017-04-26 17:59:35 +08:00
|
|
|
m_itemView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
m_itemView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
2016-06-06 14:28:28 +08:00
|
|
|
|
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
|
|
|
|
2018-02-22 11:44:57 +08:00
|
|
|
m_appNameTips->setObjectName(m_itemEntryInter->name());
|
|
|
|
m_appNameTips->setAccessibleName(m_itemEntryInter->name() + "-tips");
|
2016-07-18 14:13:36 +08:00
|
|
|
m_appNameTips->setVisible(false);
|
|
|
|
m_appNameTips->setStyleSheet("color:white;"
|
2017-03-29 10:48:42 +08:00
|
|
|
"padding:0px 3px;");
|
2016-07-18 14:13:36 +08:00
|
|
|
|
2016-07-22 14:59:43 +08:00
|
|
|
m_updateIconGeometryTimer->setInterval(500);
|
|
|
|
m_updateIconGeometryTimer->setSingleShot(true);
|
|
|
|
|
2017-04-25 20:28:11 +08:00
|
|
|
m_appPreviewTips->setVisible(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);
|
|
|
|
connect(m_itemEntryInter, &DockEntryInter::IconChanged, this, &AppItem::refershIcon);
|
2016-06-14 16:01:01 +08:00
|
|
|
|
2017-05-02 10:49:27 +08:00
|
|
|
connect(m_updateIconGeometryTimer, &QTimer::timeout, this, &AppItem::updateWindowIconGeometries, Qt::QueuedConnection);
|
|
|
|
|
2017-07-31 17:06:10 +08:00
|
|
|
connect(m_appPreviewTips, &PreviewContainer::requestActivateWindow, this, &AppItem::requestActivateWindow, Qt::QueuedConnection);
|
|
|
|
connect(m_appPreviewTips, &PreviewContainer::requestPreviewWindow, this, &AppItem::requestPreviewWindow, Qt::QueuedConnection);
|
2017-11-20 14:46:56 +08:00
|
|
|
connect(m_appPreviewTips, &PreviewContainer::requestCancelAndHidePreview, this, &AppItem::cancelAndHidePreview);
|
2018-02-22 11:44:57 +08:00
|
|
|
connect(m_appPreviewTips, &PreviewContainer::requestCheckWindows, m_itemEntryInter, &DockEntryInter::Check);
|
2017-03-28 16:52:38 +08:00
|
|
|
|
2018-02-22 14:19:52 +08:00
|
|
|
updateWindowInfos(m_itemEntryInter->windowInfos());
|
2017-06-23 16:57:02 +08:00
|
|
|
refershIcon();
|
2016-06-14 11:22:19 +08:00
|
|
|
}
|
|
|
|
|
2017-04-12 15:31:36 +08:00
|
|
|
AppItem::~AppItem()
|
|
|
|
{
|
|
|
|
m_appNameTips->deleteLater();
|
|
|
|
m_appPreviewTips->deleteLater();
|
|
|
|
}
|
|
|
|
|
2016-06-14 11:22:19 +08:00
|
|
|
const QString AppItem::appId() const
|
|
|
|
{
|
|
|
|
return m_id;
|
2016-06-03 16:06:11 +08:00
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
{
|
2017-06-06 11:06:02 +08:00
|
|
|
const QRect r(mapToGlobal(QPoint(0, 0)),
|
|
|
|
mapToGlobal(QPoint(width(),height())));
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-06-21 17:24:03 +08:00
|
|
|
void AppItem::setIconBaseSize(const int size)
|
|
|
|
{
|
|
|
|
IconBaseSize = size;
|
|
|
|
}
|
|
|
|
|
|
|
|
int AppItem::iconBaseSize()
|
|
|
|
{
|
|
|
|
return IconBaseSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
int AppItem::itemBaseWidth()
|
|
|
|
{
|
2016-06-23 14:28:47 +08:00
|
|
|
if (DockDisplayMode == Dock::Fashion)
|
|
|
|
return itemBaseHeight() * 1.1;
|
|
|
|
else
|
|
|
|
return itemBaseHeight() * 1.4;
|
2016-06-21 17:24:03 +08:00
|
|
|
}
|
|
|
|
|
2017-06-08 16:19:12 +08:00
|
|
|
void AppItem::moveEvent(QMoveEvent *e)
|
|
|
|
{
|
|
|
|
DockItem::moveEvent(e);
|
|
|
|
|
|
|
|
m_updateIconGeometryTimer->start();
|
|
|
|
}
|
|
|
|
|
2016-06-21 17:24:03 +08:00
|
|
|
int AppItem::itemBaseHeight()
|
|
|
|
{
|
2016-07-11 17:17:32 +08:00
|
|
|
if (DockDisplayMode == Efficient)
|
|
|
|
return IconBaseSize * 1.2;
|
|
|
|
else
|
|
|
|
return IconBaseSize * 1.5;
|
2016-06-21 17:24:03 +08:00
|
|
|
}
|
|
|
|
|
2016-06-03 16:06:11 +08:00
|
|
|
void AppItem::paintEvent(QPaintEvent *e)
|
|
|
|
{
|
|
|
|
DockItem::paintEvent(e);
|
|
|
|
|
2017-04-26 17:59:35 +08:00
|
|
|
if (m_draging || m_itemView->isVisible())
|
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
|
|
|
|
2016-06-14 16:01:01 +08:00
|
|
|
// draw background
|
2017-05-02 16:32:38 +08:00
|
|
|
QRectF backgroundRect = itemRect;
|
2016-07-11 17:17:32 +08:00
|
|
|
if (DockDisplayMode == Efficient)
|
|
|
|
{
|
|
|
|
switch (DockPosition)
|
|
|
|
{
|
|
|
|
case Top:
|
|
|
|
case Bottom:
|
2016-08-09 14:51:03 +08:00
|
|
|
// backgroundRect = itemRect;//.marginsRemoved(QMargins(2, 0, 2, 0));
|
|
|
|
// backgroundRect = itemRect.marginsRemoved(QMargins(0, 1, 0, 1));
|
2016-07-11 17:17:32 +08:00
|
|
|
case Left:
|
|
|
|
case Right:
|
2016-08-09 14:51:03 +08:00
|
|
|
backgroundRect = itemRect.marginsRemoved(QMargins(1, 1, 1, 1));
|
|
|
|
// backgroundRect = itemRect.marginsRemoved(QMargins(1, 0, 1, 0));
|
2016-07-11 17:17:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-23 14:28:47 +08:00
|
|
|
if (DockDisplayMode == Efficient)
|
2016-06-23 10:50:26 +08:00
|
|
|
{
|
2016-06-23 14:28:47 +08:00
|
|
|
if (m_active)
|
2016-06-23 10:50:26 +08:00
|
|
|
{
|
2016-07-11 17:17:32 +08:00
|
|
|
painter.fillRect(backgroundRect, QColor(44, 167, 248, 255 * 0.3));
|
2016-06-23 14:28:47 +08:00
|
|
|
|
2016-07-11 17:17:32 +08:00
|
|
|
const int activeLineWidth = itemRect.height() > 50 ? 4 : 2;
|
2017-05-02 16:32:38 +08:00
|
|
|
QRectF activeRect = backgroundRect;
|
2016-06-23 14:28:47 +08:00
|
|
|
switch (DockPosition)
|
|
|
|
{
|
|
|
|
case Top: activeRect.setBottom(activeRect.top() + activeLineWidth); break;
|
|
|
|
case Bottom: activeRect.setTop(activeRect.bottom() - activeLineWidth); break;
|
|
|
|
case Left: activeRect.setRight(activeRect.left() + activeLineWidth); break;
|
|
|
|
case Right: activeRect.setLeft(activeRect.right() - activeLineWidth); break;
|
|
|
|
}
|
|
|
|
|
2016-07-11 17:17:32 +08:00
|
|
|
painter.fillRect(activeRect, QColor(44, 167, 248, 255));
|
2016-06-23 14:28:47 +08:00
|
|
|
}
|
2018-02-22 11:44:57 +08:00
|
|
|
else if (!m_windowInfos.isEmpty())
|
2018-02-22 14:19:52 +08:00
|
|
|
{
|
|
|
|
if (hasAttention())
|
|
|
|
painter.fillRect(backgroundRect, QColor(241, 138, 46, 255 * .8));
|
|
|
|
else
|
|
|
|
painter.fillRect(backgroundRect, QColor(255, 255, 255, 255 * 0.2));
|
|
|
|
}
|
2016-06-23 14:28:47 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-02-22 11:44:57 +08:00
|
|
|
if (!m_windowInfos.isEmpty())
|
2016-06-23 14:28:47 +08:00
|
|
|
{
|
2016-07-12 16:33:01 +08:00
|
|
|
QPoint p;
|
|
|
|
QPixmap pixmap;
|
|
|
|
QPixmap activePixmap;
|
2016-06-23 14:28:47 +08:00
|
|
|
switch (DockPosition)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2016-06-27 20:16:35 +08:00
|
|
|
// icon
|
2017-12-28 16:21:10 +08:00
|
|
|
const QPixmap &pixmap = m_appIcon;
|
2017-06-16 09:00:53 +08:00
|
|
|
if (pixmap.isNull())
|
|
|
|
return;
|
|
|
|
|
2016-09-08 15:53:51 +08:00
|
|
|
// icon pos
|
2017-09-15 10:17:15 +08:00
|
|
|
const auto ratio = qApp->devicePixelRatio();
|
|
|
|
const int iconX = itemRect.center().x() - pixmap.rect().center().x() / ratio;
|
|
|
|
const int iconY = itemRect.center().y() - pixmap.rect().center().y() / ratio;
|
2016-09-08 15:53:51 +08:00
|
|
|
|
2018-01-23 13:35:42 +08:00
|
|
|
painter.drawPixmap(iconX, iconY, pixmap);
|
2016-06-03 16:06:11 +08:00
|
|
|
}
|
2016-06-06 14:28:28 +08:00
|
|
|
|
|
|
|
void AppItem::mouseReleaseEvent(QMouseEvent *e)
|
|
|
|
{
|
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());
|
2017-02-15 16:34:30 +08:00
|
|
|
} else if (e->button() == Qt::LeftButton) {
|
2017-04-26 17:59:35 +08:00
|
|
|
|
2018-02-22 11:44:57 +08:00
|
|
|
m_itemEntryInter->Activate(QX11Info::getTimestamp());
|
2016-09-08 15:53:51 +08:00
|
|
|
|
2018-02-22 11:44:57 +08:00
|
|
|
if (!m_windowInfos.isEmpty())
|
2017-04-26 17:59:35 +08:00
|
|
|
return;
|
2016-09-08 15:53:51 +08:00
|
|
|
|
2017-02-15 16:34:30 +08:00
|
|
|
// start launching effects
|
2017-05-02 16:32:38 +08:00
|
|
|
m_itemScene->clear();
|
2017-09-15 11:48:10 +08:00
|
|
|
const auto ratio = qApp->devicePixelRatio();
|
2017-04-26 17:59:35 +08:00
|
|
|
const QRect r = rect();
|
2017-12-28 16:21:10 +08:00
|
|
|
const QPixmap &icon = m_appIcon;
|
2017-05-02 14:15:06 +08:00
|
|
|
QGraphicsPixmapItem *item = m_itemScene->addPixmap(icon);
|
2017-04-26 17:59:35 +08:00
|
|
|
item->setTransformationMode(Qt::SmoothTransformation);
|
2017-09-15 11:48:10 +08:00
|
|
|
item->setPos(QPointF(r.center()) - QPointF(icon.rect().center()) / ratio);
|
|
|
|
m_itemScene->setSceneRect(r);
|
2017-04-26 17:59:35 +08:00
|
|
|
m_itemView->setSceneRect(r);
|
2017-09-15 11:48:10 +08:00
|
|
|
m_itemView->setFixedSize(r.size());
|
2017-05-02 16:32:38 +08:00
|
|
|
// m_itemView->setSceneRect((r.width() - icon.width()) / 2, (r.height() - icon.height()) / 2, r.width(), r.height());
|
2017-04-26 17:59:35 +08:00
|
|
|
|
|
|
|
QTimeLine *tl = new QTimeLine;
|
2017-04-27 14:31:04 +08:00
|
|
|
tl->setDuration(1200);
|
2017-04-26 17:59:35 +08:00
|
|
|
tl->setFrameRange(0, 60);
|
|
|
|
tl->setLoopCount(1);
|
|
|
|
tl->setEasingCurve(QEasingCurve::Linear);
|
|
|
|
tl->setStartFrame(0);
|
|
|
|
tl->start();
|
|
|
|
|
|
|
|
QGraphicsItemAnimation *ani = new QGraphicsItemAnimation;
|
|
|
|
ani->setItem(item);
|
|
|
|
ani->setTimeLine(tl);
|
|
|
|
|
2017-09-15 11:48:10 +08:00
|
|
|
const int px = qreal(-icon.rect().center().x()) / ratio;
|
|
|
|
const int py = qreal(-icon.rect().center().y()) / ratio - 18.;
|
2017-05-02 14:15:06 +08:00
|
|
|
const QPoint pos = r.center() + QPoint(0, 18);
|
2017-04-26 17:59:35 +08:00
|
|
|
for (int i(0); i != 60; ++i)
|
|
|
|
{
|
2017-05-02 14:15:06 +08:00
|
|
|
ani->setPosAt(i / 60.0, pos);
|
2017-04-26 17:59:35 +08:00
|
|
|
ani->setTranslationAt(i / 60.0, px, py);
|
|
|
|
ani->setRotationAt(i / 60.0, Frames[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
connect(tl, &QTimeLine::finished, tl, &QTimeLine::deleteLater);
|
|
|
|
connect(tl, &QTimeLine::finished, ani, &QGraphicsItemAnimation::deleteLater);
|
|
|
|
connect(tl, &QTimeLine::finished, m_itemScene, &QGraphicsScene::clear);
|
|
|
|
connect(tl, &QTimeLine::finished, m_itemView, &QGraphicsView::hide);
|
|
|
|
|
|
|
|
m_itemView->setVisible(true);
|
2017-02-15 16:34:30 +08:00
|
|
|
}
|
2016-06-07 14:40:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void AppItem::mousePressEvent(QMouseEvent *e)
|
|
|
|
{
|
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-22 11:02:52 +08:00
|
|
|
if (e->button() == Qt::RightButton)
|
|
|
|
{
|
|
|
|
if (perfectIconRect().contains(e->pos()))
|
2016-08-10 10:15:03 +08:00
|
|
|
{
|
|
|
|
QMetaObject::invokeMethod(this, "showContextMenu", Qt::QueuedConnection);
|
|
|
|
return;
|
2017-05-18 15:41:17 +08:00
|
|
|
} else {
|
2016-06-22 11:02:52 +08:00
|
|
|
return QWidget::mousePressEvent(e);
|
2017-05-18 15:41:17 +08:00
|
|
|
}
|
2016-06-22 11:02:52 +08:00
|
|
|
}
|
2016-06-15 16:17:51 +08:00
|
|
|
|
|
|
|
if (e->button() == Qt::LeftButton)
|
|
|
|
MousePressPos = e->pos();
|
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
|
2017-05-04 10:39:03 +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)
|
|
|
|
{
|
|
|
|
QWidget::wheelEvent(e);
|
|
|
|
|
2018-02-22 11:44:57 +08:00
|
|
|
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);
|
|
|
|
|
2017-03-13 08:02:33 +08:00
|
|
|
refershIcon();
|
2016-06-15 11:20:05 +08:00
|
|
|
}
|
|
|
|
|
2016-06-23 14:45:57 +08:00
|
|
|
void AppItem::dragEnterEvent(QDragEnterEvent *e)
|
|
|
|
{
|
2016-06-23 15:30:06 +08:00
|
|
|
// ignore drag from panel
|
|
|
|
if (e->source())
|
|
|
|
return;
|
|
|
|
|
2016-07-18 17:10:15 +08:00
|
|
|
// ignore request dock event
|
|
|
|
if (e->mimeData()->formats().contains("RequestDock"))
|
|
|
|
return e->ignore();
|
|
|
|
|
2016-06-23 15:30:06 +08:00
|
|
|
e->accept();
|
|
|
|
}
|
|
|
|
|
2017-04-25 20:28:11 +08:00
|
|
|
void AppItem::dragMoveEvent(QDragMoveEvent *e)
|
|
|
|
{
|
|
|
|
DockItem::dragMoveEvent(e);
|
|
|
|
|
2018-02-22 11:44:57 +08:00
|
|
|
if (m_windowInfos.isEmpty())
|
2017-04-25 20:28:11 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (!PopupWindow->isVisible() || PopupWindow->getContent() != m_appPreviewTips)
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (m_appPreviewTips->isVisible())
|
|
|
|
m_appPreviewTips->prepareHide();
|
|
|
|
}
|
|
|
|
|
2017-05-04 10:39:03 +08:00
|
|
|
void AppItem::showHoverTips()
|
|
|
|
{
|
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()
|
|
|
|
{
|
2016-07-18 17:10:15 +08:00
|
|
|
if (m_draging)
|
|
|
|
return nullptr;
|
2016-07-18 14:13:36 +08:00
|
|
|
|
2018-02-22 11:44:57 +08:00
|
|
|
if (!m_windowInfos.isEmpty())
|
2016-07-19 15:11:28 +08:00
|
|
|
{
|
2018-02-22 11:44:57 +08:00
|
|
|
const quint32 currentWindow = m_itemEntryInter->currentWindow();
|
|
|
|
Q_ASSERT(m_windowInfos.contains(currentWindow));
|
2018-02-22 14:19:52 +08:00
|
|
|
m_appNameTips->setText(m_windowInfos[currentWindow].title);
|
2016-07-19 15:11:28 +08:00
|
|
|
} else {
|
2018-02-22 11:44:57 +08:00
|
|
|
m_appNameTips->setText(m_itemEntryInter->name());
|
2016-07-19 15:11:28 +08:00
|
|
|
}
|
2016-07-18 14:13:36 +08:00
|
|
|
|
|
|
|
return m_appNameTips;
|
|
|
|
}
|
|
|
|
|
2016-06-07 14:40:45 +08:00
|
|
|
void AppItem::startDrag()
|
|
|
|
{
|
2016-06-07 16:01:37 +08:00
|
|
|
m_draging = true;
|
|
|
|
update();
|
|
|
|
|
2017-12-28 16:21:10 +08:00
|
|
|
const QPixmap &dragPix = m_appIcon;
|
2016-08-09 16:50:48 +08:00
|
|
|
|
2016-06-07 14:40:45 +08:00
|
|
|
QDrag *drag = new QDrag(this);
|
2016-08-09 16:50:48 +08:00
|
|
|
drag->setPixmap(dragPix);
|
2017-09-21 16:57:56 +08:00
|
|
|
drag->setHotSpot(dragPix.rect().center() / dragPix.devicePixelRatioF());
|
2016-06-07 14:40:45 +08:00
|
|
|
drag->setMimeData(new QMimeData);
|
|
|
|
|
2016-06-20 14:28:25 +08:00
|
|
|
emit dragStarted();
|
2016-06-07 14:40:45 +08:00
|
|
|
const Qt::DropAction result = drag->exec(Qt::MoveAction);
|
2016-06-21 19:25:30 +08:00
|
|
|
Q_UNUSED(result);
|
2016-06-20 16:46:53 +08:00
|
|
|
|
|
|
|
// drag out of dock panel
|
|
|
|
if (!drag->target())
|
2018-02-22 11:44:57 +08:00
|
|
|
m_itemEntryInter->RequestUndock();
|
2016-06-07 16:01:37 +08:00
|
|
|
|
|
|
|
m_draging = false;
|
2016-06-20 15:42:31 +08:00
|
|
|
setVisible(true);
|
2016-06-07 16:01:37 +08:00
|
|
|
update();
|
2016-06-06 14:28:28 +08:00
|
|
|
}
|
|
|
|
|
2018-02-22 14:19:52 +08:00
|
|
|
bool AppItem::hasAttention() const
|
|
|
|
{
|
|
|
|
for (const auto &info : m_windowInfos)
|
|
|
|
if (info.attention)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppItem::updateWindowInfos(const WindowInfoMap &info)
|
2016-06-06 14:28:28 +08:00
|
|
|
{
|
2018-02-22 14:19:52 +08:00
|
|
|
m_windowInfos = info;
|
2018-02-22 11:44:57 +08:00
|
|
|
m_appPreviewTips->setWindowInfos(m_windowInfos);
|
2017-06-06 11:06:02 +08:00
|
|
|
m_updateIconGeometryTimer->start();
|
2017-04-25 20:28:11 +08:00
|
|
|
|
2016-06-14 15:01:27 +08:00
|
|
|
update();
|
2016-06-06 14:28:28 +08:00
|
|
|
}
|
2016-06-14 16:01:01 +08:00
|
|
|
|
2017-03-13 08:02:33 +08:00
|
|
|
void AppItem::refershIcon()
|
2016-06-14 16:01:01 +08:00
|
|
|
{
|
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)
|
2017-12-28 16:21:10 +08:00
|
|
|
m_appIcon = ThemeAppIcon::getIcon(icon, iconSize * 0.7);
|
|
|
|
else
|
|
|
|
m_appIcon = ThemeAppIcon::getIcon(icon, iconSize * 0.8);
|
2017-03-13 08:02:33 +08:00
|
|
|
|
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
|
|
|
|
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;
|
|
|
|
|
|
|
|
// test cursor position
|
2017-05-04 10:39:03 +08:00
|
|
|
// const QRect r = rect();
|
|
|
|
// const QPoint p = mapFromGlobal(QCursor::pos());
|
|
|
|
|
|
|
|
// switch (DockPosition)
|
|
|
|
// {
|
|
|
|
// case Top: if (p.y() != r.top()) return; break;
|
|
|
|
// case Left: if (p.x() != r.left()) return; break;
|
|
|
|
// case Right: if (p.x() != r.right()) return; break;
|
|
|
|
// case Bottom: if (p.y() != r.bottom()) return; break;
|
|
|
|
// default: return;
|
|
|
|
// }
|
2017-03-28 16:52:38 +08:00
|
|
|
|
2018-02-22 17:19:55 +08:00
|
|
|
showPopupWindow(m_appPreviewTips, true);
|
|
|
|
|
2018-02-22 11:44:57 +08:00
|
|
|
m_appPreviewTips->setWindowInfos(m_windowInfos);
|
2017-05-24 11:32:14 +08:00
|
|
|
m_appPreviewTips->updateSnapshots();
|
2017-03-28 16:52:38 +08:00
|
|
|
m_appPreviewTips->updateLayoutDirection(DockPosition);
|
2017-03-28 15:44:13 +08:00
|
|
|
}
|
2017-06-15 16:41:40 +08:00
|
|
|
|
2017-11-20 14:46:56 +08:00
|
|
|
void AppItem::cancelAndHidePreview()
|
|
|
|
{
|
|
|
|
hidePopup();
|
|
|
|
emit requestCancelPreview();
|
|
|
|
}
|
|
|
|
|