2022-09-06 11:36:55 +08:00
|
|
|
|
// SPDX-FileCopyrightText: 2011 - 2022 UnionTech Software Technology Co., Ltd.
|
|
|
|
|
//
|
|
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
2017-09-18 14:33:44 +08:00
|
|
|
|
|
2017-03-28 15:44:13 +08:00
|
|
|
|
#include "previewcontainer.h"
|
2021-11-05 21:29:32 +08:00
|
|
|
|
#include "imageutil.h"
|
|
|
|
|
#include "utils.h"
|
2017-03-28 15:44:13 +08:00
|
|
|
|
|
2017-07-31 17:06:10 +08:00
|
|
|
|
#include <QDesktopWidget>
|
|
|
|
|
#include <QScreen>
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QDragEnterEvent>
|
2021-05-17 13:20:54 +08:00
|
|
|
|
#include <QDesktopWidget>
|
2021-11-05 21:29:32 +08:00
|
|
|
|
#include <QCursor>
|
|
|
|
|
#include <QGSettings>
|
2022-10-14 09:01:35 +06:00
|
|
|
|
#include <QScrollBar>
|
|
|
|
|
#include <QScroller>
|
2017-07-31 17:06:10 +08:00
|
|
|
|
|
|
|
|
|
#define SPACING 0
|
|
|
|
|
#define MARGIN 0
|
2017-03-28 15:44:13 +08:00
|
|
|
|
|
|
|
|
|
PreviewContainer::PreviewContainer(QWidget *parent)
|
2021-03-12 13:20:13 +08:00
|
|
|
|
: QWidget(parent)
|
|
|
|
|
, m_needActivate(false)
|
2022-10-14 09:01:35 +06:00
|
|
|
|
, m_canPreview(true)
|
|
|
|
|
, m_dockSize(40)
|
2021-03-12 13:20:13 +08:00
|
|
|
|
, m_floatingPreview(new FloatingPreview(this))
|
2022-10-14 09:01:35 +06:00
|
|
|
|
, m_preparePreviewTimer(new QTimer(this))
|
2021-03-12 13:20:13 +08:00
|
|
|
|
, m_mouseLeaveTimer(new QTimer(this))
|
|
|
|
|
, m_wmHelper(DWindowManagerHelper::instance())
|
2021-09-14 17:08:36 +08:00
|
|
|
|
, m_titleMode(HoverShow)
|
2017-03-28 15:44:13 +08:00
|
|
|
|
{
|
2022-10-14 09:01:35 +06:00
|
|
|
|
m_windowListLayout = new QBoxLayout(QBoxLayout::LeftToRight);
|
2017-07-31 17:06:10 +08:00
|
|
|
|
m_windowListLayout->setSpacing(SPACING);
|
|
|
|
|
m_windowListLayout->setContentsMargins(MARGIN, MARGIN, MARGIN, MARGIN);
|
2017-03-28 15:44:13 +08:00
|
|
|
|
|
2022-10-14 09:01:35 +06:00
|
|
|
|
m_windowListWidget = new QWidget(this);
|
|
|
|
|
m_windowListWidget->setAccessibleName("centralLayoutWidget");
|
|
|
|
|
m_windowListWidget->setLayout(m_windowListLayout);
|
|
|
|
|
m_windowListWidget->setMinimumSize(SNAP_WIDTH, SNAP_HEIGHT);
|
|
|
|
|
m_windowListWidget->installEventFilter(this);
|
|
|
|
|
m_windowListWidget->setAttribute(Qt::WA_TranslucentBackground);
|
|
|
|
|
m_windowListWidget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
|
|
|
|
|
|
|
|
|
m_scrollArea = new QScrollArea(this);
|
|
|
|
|
m_scrollArea->setAccessibleName("Preview_scrollArea");
|
|
|
|
|
m_scrollArea->setWidgetResizable(false);
|
|
|
|
|
m_scrollArea->setFrameStyle(QFrame::NoFrame);
|
|
|
|
|
m_scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
|
m_scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
|
m_scrollArea->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
m_scrollArea->setBackgroundRole(QPalette::Base);
|
|
|
|
|
m_scrollArea->setWidget(m_windowListWidget);
|
|
|
|
|
m_scrollArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
|
|
|
|
|
|
|
|
|
QVBoxLayout * mainLayout = new QVBoxLayout;
|
|
|
|
|
mainLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
mainLayout->setSpacing(0);
|
|
|
|
|
mainLayout->addWidget(m_scrollArea);
|
|
|
|
|
setLayout(mainLayout);
|
|
|
|
|
|
|
|
|
|
// 设置触摸屏手势识别
|
|
|
|
|
QScroller::grabGesture(m_scrollArea->viewport(), QScroller::LeftMouseButtonGesture);
|
|
|
|
|
QScroller *scroller = QScroller::scroller(m_scrollArea->viewport());
|
|
|
|
|
m_sp.setScrollMetric(QScrollerProperties::VerticalOvershootPolicy, QScrollerProperties::OvershootWhenScrollable);
|
|
|
|
|
m_sp.setScrollMetric(QScrollerProperties::HorizontalOvershootPolicy, QScrollerProperties::OvershootWhenScrollable);
|
|
|
|
|
scroller->setScrollerProperties(m_sp);
|
|
|
|
|
|
2017-05-04 10:39:03 +08:00
|
|
|
|
m_mouseLeaveTimer->setSingleShot(true);
|
2017-07-31 17:06:10 +08:00
|
|
|
|
m_mouseLeaveTimer->setInterval(300);
|
2017-05-04 10:39:03 +08:00
|
|
|
|
|
2022-10-14 09:01:35 +06:00
|
|
|
|
m_preparePreviewTimer->setSingleShot(true);
|
|
|
|
|
m_preparePreviewTimer->setInterval(300);
|
|
|
|
|
|
|
|
|
|
m_floatingPreview->installEventFilter(this);
|
2017-07-31 17:06:10 +08:00
|
|
|
|
m_floatingPreview->setVisible(false);
|
|
|
|
|
|
2019-04-23 18:17:07 +08:00
|
|
|
|
m_waitForShowPreviewTimer = new QTimer(this);
|
|
|
|
|
m_waitForShowPreviewTimer->setSingleShot(true);
|
|
|
|
|
m_waitForShowPreviewTimer->setInterval(200);
|
|
|
|
|
|
2017-07-31 17:06:10 +08:00
|
|
|
|
setAcceptDrops(true);
|
|
|
|
|
setFixedSize(SNAP_WIDTH, SNAP_HEIGHT);
|
2017-05-04 10:39:03 +08:00
|
|
|
|
|
|
|
|
|
connect(m_mouseLeaveTimer, &QTimer::timeout, this, &PreviewContainer::checkMouseLeave, Qt::QueuedConnection);
|
2019-04-23 18:17:07 +08:00
|
|
|
|
connect(m_waitForShowPreviewTimer, &QTimer::timeout, this, &PreviewContainer::previewFloating);
|
2022-10-14 09:01:35 +06:00
|
|
|
|
|
|
|
|
|
// 预览界面在滚动时,暂时不允许预览,避免在滚动时频繁切换预览造成闪屏
|
|
|
|
|
connect(m_scrollArea->horizontalScrollBar(), &QScrollBar::valueChanged, this, [ = ]{
|
|
|
|
|
m_floatingPreview->setVisible(false);
|
|
|
|
|
m_canPreview = false;
|
|
|
|
|
if (m_preparePreviewTimer->isActive()) {
|
|
|
|
|
m_preparePreviewTimer->stop();
|
|
|
|
|
}
|
|
|
|
|
m_preparePreviewTimer->start();
|
|
|
|
|
});
|
|
|
|
|
connect(m_scrollArea->verticalScrollBar(), &QScrollBar::valueChanged, this, [ = ]{
|
|
|
|
|
m_floatingPreview->setVisible(false);
|
|
|
|
|
m_canPreview = false;
|
|
|
|
|
if (m_preparePreviewTimer->isActive()) {
|
|
|
|
|
m_preparePreviewTimer->stop();
|
|
|
|
|
}
|
|
|
|
|
m_preparePreviewTimer->start();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 停止滚动后允许预览
|
|
|
|
|
connect(m_preparePreviewTimer, &QTimer::timeout, this, [ = ]{
|
|
|
|
|
m_canPreview = true;
|
|
|
|
|
if (m_wmHelper->hasComposite()) {
|
|
|
|
|
m_waitForShowPreviewTimer->start();
|
|
|
|
|
}
|
|
|
|
|
});
|
2017-03-28 15:44:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-08-13 14:17:45 +08:00
|
|
|
|
void PreviewContainer::setWindowInfos(const WindowInfoMap &infos, const WindowList &allowClose)
|
2017-03-28 15:44:13 +08:00
|
|
|
|
{
|
2017-07-31 17:06:10 +08:00
|
|
|
|
// check removed window
|
2021-02-07 17:38:19 +08:00
|
|
|
|
for (auto it(m_snapshots.begin()); it != m_snapshots.end();) {
|
|
|
|
|
if (!infos.contains(it.key())) {
|
2017-07-31 17:06:10 +08:00
|
|
|
|
m_windowListLayout->removeWidget(it.value());
|
|
|
|
|
it.value()->deleteLater();
|
|
|
|
|
it = m_snapshots.erase(it);
|
|
|
|
|
} else {
|
|
|
|
|
++it;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-07 17:38:19 +08:00
|
|
|
|
for (auto it(infos.cbegin()); it != infos.cend(); ++it) {
|
2018-08-13 14:17:45 +08:00
|
|
|
|
const WId key = it.key();
|
|
|
|
|
if (!m_snapshots.contains(key))
|
|
|
|
|
appendSnapWidget(key);
|
|
|
|
|
m_snapshots[key]->setWindowInfo(it.value());
|
|
|
|
|
m_snapshots[key]->setCloseAble(allowClose.contains(key));
|
2017-07-31 17:06:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-02-07 17:38:19 +08:00
|
|
|
|
if (m_snapshots.isEmpty()) {
|
2019-04-12 17:17:19 +08:00
|
|
|
|
emit requestCancelPreviewWindow();
|
|
|
|
|
emit requestHidePopup();
|
2021-02-07 17:38:19 +08:00
|
|
|
|
}
|
2017-12-28 16:57:49 +08:00
|
|
|
|
|
2021-08-25 21:03:30 +08:00
|
|
|
|
adjustSize(m_wmHelper->hasComposite());
|
2017-07-31 17:06:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-14 17:08:36 +08:00
|
|
|
|
void PreviewContainer::setTitleDisplayMode(int mode)
|
|
|
|
|
{
|
|
|
|
|
m_titleMode = static_cast<TitleDisplayMode>(mode);
|
|
|
|
|
|
|
|
|
|
if (!m_wmHelper->hasComposite())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
m_floatingPreview->setFloatingTitleVisible(m_titleMode == HoverShow);
|
|
|
|
|
|
|
|
|
|
for (AppSnapshot *snap : m_snapshots) {
|
|
|
|
|
snap->setTitleVisible(m_titleMode == AlwaysShow);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-31 17:06:10 +08:00
|
|
|
|
void PreviewContainer::updateLayoutDirection(const Dock::Position dockPos)
|
|
|
|
|
{
|
2022-10-14 09:01:35 +06:00
|
|
|
|
m_dockPos = dockPos;
|
|
|
|
|
if (m_wmHelper->hasComposite() && (dockPos == Dock::Top || dockPos == Dock::Bottom)) {
|
2017-07-31 17:06:10 +08:00
|
|
|
|
m_windowListLayout->setDirection(QBoxLayout::LeftToRight);
|
2022-10-14 09:01:35 +06:00
|
|
|
|
|
|
|
|
|
m_scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
|
|
|
|
m_scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
|
|
|
|
|
|
m_sp.setScrollMetric(QScrollerProperties::VerticalOvershootPolicy, QScrollerProperties::OvershootAlwaysOff);
|
|
|
|
|
m_sp.setScrollMetric(QScrollerProperties::HorizontalOvershootPolicy, QScrollerProperties::OvershootWhenScrollable);
|
|
|
|
|
} else {
|
|
|
|
|
m_scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
|
m_scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
2017-07-31 17:06:10 +08:00
|
|
|
|
m_windowListLayout->setDirection(QBoxLayout::TopToBottom);
|
|
|
|
|
|
2022-10-14 09:01:35 +06:00
|
|
|
|
m_sp.setScrollMetric(QScrollerProperties::VerticalOvershootPolicy, QScrollerProperties::OvershootWhenScrollable);
|
|
|
|
|
m_sp.setScrollMetric(QScrollerProperties::HorizontalOvershootPolicy, QScrollerProperties::OvershootAlwaysOff);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-25 21:03:30 +08:00
|
|
|
|
adjustSize(m_wmHelper->hasComposite());
|
2017-07-31 17:06:10 +08:00
|
|
|
|
}
|
2017-05-04 10:39:03 +08:00
|
|
|
|
|
2022-10-14 09:01:35 +06:00
|
|
|
|
void PreviewContainer::updateDockSize(const int size)
|
|
|
|
|
{
|
|
|
|
|
m_dockSize = size;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-31 17:06:10 +08:00
|
|
|
|
void PreviewContainer::checkMouseLeave()
|
|
|
|
|
{
|
|
|
|
|
const bool hover = underMouse();
|
|
|
|
|
|
2017-11-29 10:33:42 +08:00
|
|
|
|
if (hover)
|
|
|
|
|
return;
|
2017-11-20 14:46:56 +08:00
|
|
|
|
|
2017-11-29 10:33:42 +08:00
|
|
|
|
m_floatingPreview->setVisible(false);
|
2017-05-04 10:39:03 +08:00
|
|
|
|
|
2019-05-22 16:39:31 +08:00
|
|
|
|
if (m_wmHelper->hasComposite()) {
|
|
|
|
|
if (m_needActivate) {
|
|
|
|
|
m_needActivate = false;
|
|
|
|
|
emit requestActivateWindow(m_floatingPreview->trackedWid());
|
|
|
|
|
} else {
|
2020-10-24 11:03:03 +08:00
|
|
|
|
Q_EMIT requestHidePopup();
|
2019-05-22 16:39:31 +08:00
|
|
|
|
emit requestCancelPreviewWindow();
|
|
|
|
|
}
|
2017-05-04 10:39:03 +08:00
|
|
|
|
}
|
2019-04-12 17:56:04 +08:00
|
|
|
|
|
|
|
|
|
emit requestHidePopup();
|
2017-07-31 17:06:10 +08:00
|
|
|
|
}
|
2017-05-04 10:39:03 +08:00
|
|
|
|
|
2017-08-18 13:13:56 +08:00
|
|
|
|
void PreviewContainer::prepareHide()
|
|
|
|
|
{
|
|
|
|
|
m_mouseLeaveTimer->start();
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-13 09:15:56 +08:00
|
|
|
|
void PreviewContainer::adjustSize(bool composite)
|
2017-07-31 17:06:10 +08:00
|
|
|
|
{
|
2022-10-14 09:01:35 +06:00
|
|
|
|
const bool horizontal = m_windowListLayout->direction() == QBoxLayout::LeftToRight;
|
|
|
|
|
const int count = m_snapshots.size();
|
|
|
|
|
|
2022-01-13 09:15:56 +08:00
|
|
|
|
const int screenWidth = QDesktopWidget().screenGeometry(this).width();
|
|
|
|
|
const int screenHeight = QDesktopWidget().screenGeometry(this).height();
|
2021-01-06 17:52:20 +08:00
|
|
|
|
|
2022-01-13 09:15:56 +08:00
|
|
|
|
//先根据屏幕宽高计算出能预览的最大数量,然后根据数量计算界面宽高
|
2021-02-07 17:38:19 +08:00
|
|
|
|
if (composite) {
|
|
|
|
|
if (horizontal) {
|
|
|
|
|
const int h = SNAP_HEIGHT + MARGIN * 2;
|
|
|
|
|
const int w = SNAP_WIDTH * count + MARGIN * 2 + SPACING * (count - 1);
|
2017-05-04 10:39:03 +08:00
|
|
|
|
|
2022-10-14 09:01:35 +06:00
|
|
|
|
m_windowListWidget->setFixedSize(w, h);
|
|
|
|
|
setFixedSize(qMin(w, screenWidth), h);
|
2021-02-07 17:38:19 +08:00
|
|
|
|
} else {
|
|
|
|
|
const int h = SNAP_HEIGHT * count + MARGIN * 2 + SPACING * (count - 1);
|
2022-10-14 09:01:35 +06:00
|
|
|
|
const int w = SNAP_WIDTH + MARGIN * 2;
|
2017-03-28 16:52:38 +08:00
|
|
|
|
|
2022-10-14 09:01:35 +06:00
|
|
|
|
m_windowListWidget->setFixedSize(w, h);
|
|
|
|
|
setFixedSize(w, qMin(h, screenHeight));
|
2021-02-07 17:38:19 +08:00
|
|
|
|
}
|
|
|
|
|
} else if (m_windowListLayout->count()) {
|
|
|
|
|
// 2D
|
|
|
|
|
const int h = SNAP_HEIGHT_WITHOUT_COMPOSITE * count + MARGIN * 2 + SPACING * (count - 1);
|
2017-07-31 17:06:10 +08:00
|
|
|
|
|
2022-10-14 09:01:35 +06:00
|
|
|
|
int titleWidth = 0;
|
2022-01-20 14:47:12 +08:00
|
|
|
|
for (int i = 0; i < m_windowListLayout->count(); i++) {
|
2022-10-14 09:01:35 +06:00
|
|
|
|
auto snapshotWidget = static_cast<AppSnapshot *>(m_windowListLayout->itemAt(i)->widget());
|
|
|
|
|
titleWidth = qMax(titleWidth, snapshotWidget->minimumWidth());
|
2022-01-20 14:47:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-14 09:01:35 +06:00
|
|
|
|
m_windowListWidget->setFixedSize(titleWidth, h);
|
2022-01-13 09:15:56 +08:00
|
|
|
|
|
2022-10-14 09:01:35 +06:00
|
|
|
|
if (m_dockPos == Dock::Top || m_dockPos == Dock::Bottom) {
|
|
|
|
|
// 滚动区域高度 = 屏幕高度 - 任务栏高度 - 箭头高度
|
|
|
|
|
setFixedSize(titleWidth, qMin(h, screenHeight - m_dockSize - 20));
|
|
|
|
|
} else {
|
|
|
|
|
// 滚动区域高度 = 屏幕高度
|
|
|
|
|
setFixedSize(titleWidth, qMin(h, screenHeight));
|
2022-01-13 09:15:56 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-07-31 17:06:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PreviewContainer::appendSnapWidget(const WId wid)
|
|
|
|
|
{
|
2022-01-13 09:15:56 +08:00
|
|
|
|
//创建预览界面,默认不显示,等计算出显示数量后再加入布局并显示
|
2017-07-31 17:06:10 +08:00
|
|
|
|
AppSnapshot *snap = new AppSnapshot(wid);
|
|
|
|
|
|
2019-04-12 17:17:19 +08:00
|
|
|
|
connect(snap, &AppSnapshot::clicked, this, &PreviewContainer::onSnapshotClicked, Qt::QueuedConnection);
|
2017-07-31 17:06:10 +08:00
|
|
|
|
connect(snap, &AppSnapshot::entered, this, &PreviewContainer::previewEntered, Qt::QueuedConnection);
|
2019-05-29 14:25:35 +08:00
|
|
|
|
connect(snap, &AppSnapshot::requestCheckWindow, this, &PreviewContainer::requestCheckWindows, Qt::QueuedConnection);
|
2021-08-25 21:03:30 +08:00
|
|
|
|
connect(snap, &AppSnapshot::requestCloseAppSnapshot, this, &PreviewContainer::onRequestCloseAppSnapshot);
|
2017-05-02 19:33:07 +08:00
|
|
|
|
|
2017-07-31 17:06:10 +08:00
|
|
|
|
m_snapshots.insert(wid, snap);
|
2022-10-14 09:01:35 +06:00
|
|
|
|
m_windowListLayout->addWidget(snap);
|
2017-03-28 15:44:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-31 15:09:12 +08:00
|
|
|
|
void PreviewContainer::enterEvent(QEvent *e)
|
2021-11-05 21:29:32 +08:00
|
|
|
|
{
|
2021-12-31 15:09:12 +08:00
|
|
|
|
if (Utils::IS_WAYLAND_DISPLAY) {
|
|
|
|
|
Utils::updateCursor(this);
|
2021-11-05 21:29:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-31 17:06:10 +08:00
|
|
|
|
QWidget::enterEvent(e);
|
2017-05-10 10:44:47 +08:00
|
|
|
|
|
2017-07-31 17:06:10 +08:00
|
|
|
|
m_needActivate = false;
|
|
|
|
|
m_mouseLeaveTimer->stop();
|
2019-06-19 16:38:48 +08:00
|
|
|
|
|
|
|
|
|
if (m_wmHelper->hasComposite()) {
|
|
|
|
|
m_waitForShowPreviewTimer->start();
|
|
|
|
|
}
|
2017-03-28 15:44:13 +08:00
|
|
|
|
}
|
2017-04-25 20:28:11 +08:00
|
|
|
|
|
|
|
|
|
void PreviewContainer::leaveEvent(QEvent *e)
|
|
|
|
|
{
|
|
|
|
|
QWidget::leaveEvent(e);
|
|
|
|
|
|
2017-05-04 10:39:03 +08:00
|
|
|
|
m_mouseLeaveTimer->start();
|
2019-04-23 18:17:07 +08:00
|
|
|
|
m_waitForShowPreviewTimer->stop();
|
2017-05-04 10:39:03 +08:00
|
|
|
|
}
|
2017-04-25 20:28:11 +08:00
|
|
|
|
|
2017-07-31 17:06:10 +08:00
|
|
|
|
void PreviewContainer::dragEnterEvent(QDragEnterEvent *e)
|
2017-05-04 10:39:03 +08:00
|
|
|
|
{
|
2018-01-12 15:25:28 +08:00
|
|
|
|
if (!m_wmHelper->hasComposite())
|
|
|
|
|
return;
|
|
|
|
|
|
2017-07-31 17:06:10 +08:00
|
|
|
|
e->accept();
|
2017-05-04 10:39:03 +08:00
|
|
|
|
|
2017-07-31 17:06:10 +08:00
|
|
|
|
m_needActivate = false;
|
2017-05-04 10:39:03 +08:00
|
|
|
|
m_mouseLeaveTimer->stop();
|
2017-04-25 20:28:11 +08:00
|
|
|
|
}
|
2017-05-02 19:33:07 +08:00
|
|
|
|
|
2017-07-31 17:06:10 +08:00
|
|
|
|
void PreviewContainer::dragLeaveEvent(QDragLeaveEvent *e)
|
2017-05-02 19:33:07 +08:00
|
|
|
|
{
|
2017-07-31 17:06:10 +08:00
|
|
|
|
e->ignore();
|
|
|
|
|
|
|
|
|
|
m_needActivate = true;
|
2019-04-12 17:56:04 +08:00
|
|
|
|
m_mouseLeaveTimer->start();
|
2017-05-02 19:33:07 +08:00
|
|
|
|
}
|
2017-05-04 10:39:03 +08:00
|
|
|
|
|
2022-10-14 09:01:35 +06:00
|
|
|
|
bool PreviewContainer::eventFilter(QObject *watcher, QEvent *event)
|
|
|
|
|
{
|
|
|
|
|
// 将鼠标滚轮事件转换成水平滚动
|
|
|
|
|
if (watcher == m_windowListWidget && event->type() == QEvent::Wheel) {
|
|
|
|
|
QWheelEvent *wheelEvent = static_cast<QWheelEvent *>(event);
|
|
|
|
|
|
|
|
|
|
if (m_windowListLayout->direction() == Qt::LeftToRight) {
|
|
|
|
|
const int delta = wheelEvent->delta();
|
|
|
|
|
const int currValue = m_scrollArea->horizontalScrollBar()->value();
|
|
|
|
|
|
|
|
|
|
if (currValue - delta <= 0) {
|
|
|
|
|
m_scrollArea->horizontalScrollBar()->setValue(0);
|
|
|
|
|
} else if (currValue - delta >= m_scrollArea->horizontalScrollBar()->maximum()) {
|
|
|
|
|
m_scrollArea->horizontalScrollBar()->setValue(m_scrollArea->horizontalScrollBar()->maximum());
|
|
|
|
|
} else {
|
|
|
|
|
m_scrollArea->horizontalScrollBar()->setValue(currValue - delta);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 在m_floatingPreview界面显示时,需要响应滚轮事件
|
|
|
|
|
if (watcher == m_floatingPreview && event->type() == QEvent::Wheel) {
|
|
|
|
|
QWheelEvent *wheelEvent = static_cast<QWheelEvent *>(event);
|
|
|
|
|
|
|
|
|
|
if (m_windowListLayout->direction() == Qt::LeftToRight) {
|
|
|
|
|
const int delta = wheelEvent->delta();
|
|
|
|
|
const int currValue = m_scrollArea->horizontalScrollBar()->value();
|
|
|
|
|
|
|
|
|
|
if (currValue - delta <= 0) {
|
|
|
|
|
m_scrollArea->horizontalScrollBar()->setValue(0);
|
|
|
|
|
} else if (currValue - delta >= m_scrollArea->horizontalScrollBar()->maximum()) {
|
|
|
|
|
m_scrollArea->horizontalScrollBar()->setValue(m_scrollArea->horizontalScrollBar()->maximum());
|
|
|
|
|
} else {
|
|
|
|
|
m_scrollArea->horizontalScrollBar()->setValue(currValue - delta);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
const int delta = wheelEvent->delta();
|
|
|
|
|
const int currValue = m_scrollArea->verticalScrollBar()->value();
|
|
|
|
|
|
|
|
|
|
if (currValue - delta <= 0) {
|
|
|
|
|
m_scrollArea->verticalScrollBar()->setValue(0);
|
|
|
|
|
} else if (currValue - delta >= m_scrollArea->verticalScrollBar()->maximum()) {
|
|
|
|
|
m_scrollArea->verticalScrollBar()->setValue(m_scrollArea->verticalScrollBar()->maximum());
|
|
|
|
|
} else {
|
|
|
|
|
m_scrollArea->verticalScrollBar()->setValue(currValue - delta);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return QWidget::eventFilter(watcher, event);
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-12 17:17:19 +08:00
|
|
|
|
void PreviewContainer::onSnapshotClicked(const WId wid)
|
|
|
|
|
{
|
2022-09-19 12:12:41 +08:00
|
|
|
|
if (Utils::IS_WAYLAND_DISPLAY) {
|
|
|
|
|
/* BUGFIX-159303 本地发现该问题仅在wayland下出现,问题已与窗管对接沟通过,根据窗管建议,上层进
|
|
|
|
|
规避,避免因底层强行修改引入新的问题 */
|
|
|
|
|
Q_EMIT requestCancelPreviewWindow();
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-02 06:45:02 +06:00
|
|
|
|
Q_EMIT requestActivateWindow(wid);
|
2019-04-12 17:17:19 +08:00
|
|
|
|
m_needActivate = true;
|
2020-07-02 06:45:02 +06:00
|
|
|
|
m_waitForShowPreviewTimer->stop();
|
|
|
|
|
requestHidePopup();
|
2019-04-12 17:17:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-31 17:06:10 +08:00
|
|
|
|
void PreviewContainer::previewEntered(const WId wid)
|
|
|
|
|
{
|
|
|
|
|
if (!m_wmHelper->hasComposite())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
AppSnapshot *snap = static_cast<AppSnapshot *>(sender());
|
2018-08-02 19:54:26 +08:00
|
|
|
|
if (!snap) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AppSnapshot *preSnap = m_floatingPreview->trackedWindow();
|
|
|
|
|
if (preSnap && preSnap != snap) {
|
2020-08-28 10:39:24 +08:00
|
|
|
|
preSnap->setWindowState();
|
2018-08-02 19:54:26 +08:00
|
|
|
|
}
|
2017-07-31 17:06:10 +08:00
|
|
|
|
|
2019-04-23 18:17:07 +08:00
|
|
|
|
m_currentWId = wid;
|
|
|
|
|
m_floatingPreview->trackWindow(snap);
|
2019-05-29 14:25:35 +08:00
|
|
|
|
|
|
|
|
|
if (m_waitForShowPreviewTimer->isActive()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
previewFloating();
|
2017-07-31 17:06:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-23 18:17:07 +08:00
|
|
|
|
void PreviewContainer::previewFloating()
|
|
|
|
|
{
|
2022-10-14 09:01:35 +06:00
|
|
|
|
if (!m_waitForShowPreviewTimer->isActive() && m_canPreview) {
|
|
|
|
|
// 将单个预览界面在滚动区域的坐标转换到当前界面坐标上
|
|
|
|
|
if (m_floatingPreview->trackedWindow()) {
|
|
|
|
|
const QRect snapGeometry = m_floatingPreview->trackedWindow()->geometry();
|
|
|
|
|
const QPoint topLeft = m_windowListWidget->mapTo(m_scrollArea, snapGeometry.topLeft());
|
|
|
|
|
const QPoint bottomRight = m_windowListWidget->mapTo(m_scrollArea, snapGeometry.bottomRight());
|
|
|
|
|
m_floatingPreview->setGeometry(QRect(topLeft, bottomRight));
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-02 06:45:02 +06:00
|
|
|
|
m_floatingPreview->setVisible(true);
|
|
|
|
|
m_floatingPreview->raise();
|
2019-04-23 18:17:07 +08:00
|
|
|
|
|
2020-07-02 06:45:02 +06:00
|
|
|
|
requestPreviewWindow(m_currentWId);
|
|
|
|
|
}
|
|
|
|
|
return;
|
2019-04-23 18:17:07 +08:00
|
|
|
|
}
|
2021-08-25 21:03:30 +08:00
|
|
|
|
|
|
|
|
|
void PreviewContainer::onRequestCloseAppSnapshot()
|
|
|
|
|
{
|
|
|
|
|
if (!m_wmHelper->hasComposite())
|
|
|
|
|
return ;
|
|
|
|
|
|
2021-12-06 14:28:59 +08:00
|
|
|
|
if (m_snapshots.keys().isEmpty()) {
|
2021-08-25 21:03:30 +08:00
|
|
|
|
Q_EMIT requestHidePopup();
|
|
|
|
|
Q_EMIT requestCancelPreviewWindow();
|
|
|
|
|
}
|
|
|
|
|
}
|