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-07-15 11:00:55 +08:00
|
|
|
|
#include "dockpopupwindow.h"
|
2021-11-05 21:29:32 +08:00
|
|
|
|
#include "imageutil.h"
|
2021-08-06 17:23:05 +08:00
|
|
|
|
#include "utils.h"
|
2016-07-15 11:00:55 +08:00
|
|
|
|
|
2016-08-30 15:11:09 +08:00
|
|
|
|
#include <QScreen>
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QDesktopWidget>
|
2020-03-13 12:59:02 +08:00
|
|
|
|
#include <QAccessible>
|
|
|
|
|
#include <QAccessibleEvent>
|
2021-11-05 21:29:32 +08:00
|
|
|
|
#include <QCursor>
|
|
|
|
|
#include <QGSettings>
|
2016-08-30 15:11:09 +08:00
|
|
|
|
|
2016-07-15 11:00:55 +08:00
|
|
|
|
DWIDGET_USE_NAMESPACE
|
|
|
|
|
|
|
|
|
|
DockPopupWindow::DockPopupWindow(QWidget *parent)
|
|
|
|
|
: DArrowRectangle(ArrowBottom, parent),
|
2016-07-18 10:09:26 +08:00
|
|
|
|
m_model(false),
|
2022-01-05 15:52:40 +08:00
|
|
|
|
m_regionInter(new DRegionMonitor(this)),
|
|
|
|
|
m_enableMouseRelease(true)
|
2016-07-15 11:00:55 +08:00
|
|
|
|
{
|
2020-11-27 16:35:17 +08:00
|
|
|
|
setMargin(0);
|
2017-05-15 10:52:59 +08:00
|
|
|
|
m_wmHelper = DWindowManagerHelper::instance();
|
|
|
|
|
|
|
|
|
|
compositeChanged();
|
|
|
|
|
|
2020-08-18 11:18:00 +08:00
|
|
|
|
setWindowFlags(Qt::X11BypassWindowManagerHint | Qt::WindowStaysOnTopHint | Qt::WindowDoesNotAcceptFocus);
|
2021-08-06 17:23:05 +08:00
|
|
|
|
if (Utils::IS_WAYLAND_DISPLAY) {
|
|
|
|
|
setAttribute(Qt::WA_NativeWindow);
|
2021-11-11 19:09:51 +08:00
|
|
|
|
windowHandle()->setProperty("_d_dwayland_window-type", "dock");
|
2021-08-06 17:23:05 +08:00
|
|
|
|
}else {
|
|
|
|
|
setAttribute(Qt::WA_InputMethodEnabled, false);
|
|
|
|
|
}
|
2016-08-11 15:32:48 +08:00
|
|
|
|
|
2017-05-15 10:52:59 +08:00
|
|
|
|
connect(m_wmHelper, &DWindowManagerHelper::hasCompositeChanged, this, &DockPopupWindow::compositeChanged);
|
2021-12-09 13:50:05 +08:00
|
|
|
|
connect(m_regionInter, &DRegionMonitor::buttonRelease, this, &DockPopupWindow::onGlobMouseRelease);
|
2016-07-15 11:00:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-19 15:08:16 +08:00
|
|
|
|
DockPopupWindow::~DockPopupWindow()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-15 11:00:55 +08:00
|
|
|
|
bool DockPopupWindow::model() const
|
|
|
|
|
{
|
2018-03-15 11:35:10 +08:00
|
|
|
|
return isVisible() && m_model;
|
2016-07-15 11:00:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-27 14:08:23 +08:00
|
|
|
|
void DockPopupWindow::setContent(QWidget *content)
|
|
|
|
|
{
|
|
|
|
|
QWidget *lastWidget = getContent();
|
|
|
|
|
if (lastWidget)
|
|
|
|
|
lastWidget->removeEventFilter(this);
|
|
|
|
|
content->installEventFilter(this);
|
|
|
|
|
|
2020-03-13 12:59:02 +08:00
|
|
|
|
QAccessibleEvent event(this, QAccessible::NameChanged);
|
|
|
|
|
QAccessible::updateAccessibility(&event);
|
|
|
|
|
|
2020-07-16 06:28:02 +00:00
|
|
|
|
if (!content->objectName().trimmed().isEmpty())
|
|
|
|
|
setAccessibleName(content->objectName() + "-popup");
|
2016-07-28 10:59:21 +08:00
|
|
|
|
|
2016-07-27 14:08:23 +08:00
|
|
|
|
DArrowRectangle::setContent(content);
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-15 11:00:55 +08:00
|
|
|
|
void DockPopupWindow::show(const QPoint &pos, const bool model)
|
|
|
|
|
{
|
|
|
|
|
m_model = model;
|
2016-07-27 14:08:23 +08:00
|
|
|
|
m_lastPoint = pos;
|
2016-07-15 11:00:55 +08:00
|
|
|
|
|
2017-03-06 09:45:38 +08:00
|
|
|
|
show(pos.x(), pos.y());
|
2016-07-18 10:09:26 +08:00
|
|
|
|
|
2019-05-30 14:01:37 +08:00
|
|
|
|
if (m_regionInter->registered()) {
|
2017-09-28 16:08:37 +08:00
|
|
|
|
m_regionInter->unregisterRegion();
|
2019-05-30 14:01:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_model) {
|
|
|
|
|
m_regionInter->registerRegion();
|
2018-04-26 20:05:54 +08:00
|
|
|
|
}
|
2022-01-05 15:52:40 +08:00
|
|
|
|
blockButtonRelease();
|
2016-07-18 10:09:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-06 09:45:38 +08:00
|
|
|
|
void DockPopupWindow::show(const int x, const int y)
|
|
|
|
|
{
|
2017-03-24 15:55:33 +08:00
|
|
|
|
m_lastPoint = QPoint(x, y);
|
2022-01-05 15:52:40 +08:00
|
|
|
|
blockButtonRelease();
|
2017-03-06 09:45:38 +08:00
|
|
|
|
|
2017-06-30 10:53:48 +08:00
|
|
|
|
DArrowRectangle::show(x, y);
|
2017-03-06 09:45:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-05 15:52:40 +08:00
|
|
|
|
void DockPopupWindow::blockButtonRelease()
|
|
|
|
|
{
|
|
|
|
|
// 短暂的不处理鼠标release事件,防止出现刚显示又被隐藏的情况
|
|
|
|
|
m_enableMouseRelease = false;
|
|
|
|
|
QTimer::singleShot(10, this, [this] {
|
|
|
|
|
m_enableMouseRelease = true;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-19 15:08:16 +08:00
|
|
|
|
void DockPopupWindow::hide()
|
|
|
|
|
{
|
2017-09-28 16:08:37 +08:00
|
|
|
|
if (m_regionInter->registered())
|
|
|
|
|
m_regionInter->unregisterRegion();
|
2016-07-19 15:08:16 +08:00
|
|
|
|
|
|
|
|
|
DArrowRectangle::hide();
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-05 14:33:57 +08:00
|
|
|
|
void DockPopupWindow::showEvent(QShowEvent *e)
|
|
|
|
|
{
|
|
|
|
|
DArrowRectangle::showEvent(e);
|
2021-12-31 15:09:12 +08:00
|
|
|
|
if (Utils::IS_WAYLAND_DISPLAY) {
|
|
|
|
|
Utils::updateCursor(this);
|
|
|
|
|
}
|
2016-09-05 14:33:57 +08:00
|
|
|
|
|
2017-12-15 16:47:16 +08:00
|
|
|
|
QTimer::singleShot(1, this, &DockPopupWindow::ensureRaised);
|
2016-09-05 14:33:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-09-01 10:55:19 +08:00
|
|
|
|
void DockPopupWindow::enterEvent(QEvent *e)
|
|
|
|
|
{
|
|
|
|
|
DArrowRectangle::enterEvent(e);
|
2021-12-31 15:09:12 +08:00
|
|
|
|
if (Utils::IS_WAYLAND_DISPLAY) {
|
|
|
|
|
Utils::updateCursor(this);
|
|
|
|
|
}
|
2016-09-01 10:55:19 +08:00
|
|
|
|
|
2017-12-15 16:47:16 +08:00
|
|
|
|
QTimer::singleShot(1, this, &DockPopupWindow::ensureRaised);
|
2016-09-01 10:55:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-27 14:08:23 +08:00
|
|
|
|
bool DockPopupWindow::eventFilter(QObject *o, QEvent *e)
|
|
|
|
|
{
|
|
|
|
|
if (o != getContent() || e->type() != QEvent::Resize)
|
|
|
|
|
return false;
|
|
|
|
|
|
2016-07-27 14:49:29 +08:00
|
|
|
|
// FIXME: ensure position move after global mouse release event
|
2018-03-13 17:29:46 +08:00
|
|
|
|
if (isVisible())
|
2018-03-27 17:39:29 +08:00
|
|
|
|
{
|
|
|
|
|
QTimer::singleShot(10, this, [=] {
|
|
|
|
|
// NOTE(sbw): double check is necessary, in this time, the popup maybe already hided.
|
|
|
|
|
if (isVisible())
|
|
|
|
|
show(m_lastPoint, m_model);
|
|
|
|
|
});
|
|
|
|
|
}
|
2016-07-27 14:49:29 +08:00
|
|
|
|
|
2016-07-27 14:08:23 +08:00
|
|
|
|
return false;
|
2016-07-18 10:09:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-28 16:08:37 +08:00
|
|
|
|
void DockPopupWindow::onGlobMouseRelease(const QPoint &mousePos, const int flag)
|
2016-07-18 10:09:26 +08:00
|
|
|
|
{
|
2016-07-19 15:08:16 +08:00
|
|
|
|
Q_ASSERT(m_model);
|
2016-07-18 10:09:26 +08:00
|
|
|
|
|
2022-01-05 15:52:40 +08:00
|
|
|
|
if (!m_enableMouseRelease)
|
|
|
|
|
return;
|
|
|
|
|
|
2019-05-30 14:01:37 +08:00
|
|
|
|
if (!((flag == DRegionMonitor::WatchedFlags::Button_Left) ||
|
|
|
|
|
(flag == DRegionMonitor::WatchedFlags::Button_Right))) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-18 10:09:26 +08:00
|
|
|
|
const QRect rect = QRect(pos(), size());
|
2017-09-28 16:08:37 +08:00
|
|
|
|
if (rect.contains(mousePos))
|
2016-07-18 10:09:26 +08:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
emit accept();
|
|
|
|
|
|
2017-09-28 16:08:37 +08:00
|
|
|
|
m_regionInter->unregisterRegion();
|
2016-07-15 11:00:55 +08:00
|
|
|
|
}
|
2017-05-15 10:52:59 +08:00
|
|
|
|
|
|
|
|
|
void DockPopupWindow::compositeChanged()
|
|
|
|
|
{
|
|
|
|
|
if (m_wmHelper->hasComposite())
|
|
|
|
|
setBorderColor(QColor(255, 255, 255, 255 * 0.05));
|
|
|
|
|
else
|
|
|
|
|
setBorderColor(QColor("#2C3238"));
|
|
|
|
|
}
|
2017-12-15 16:47:16 +08:00
|
|
|
|
|
|
|
|
|
void DockPopupWindow::ensureRaised()
|
|
|
|
|
{
|
|
|
|
|
if (isVisible())
|
|
|
|
|
raise();
|
|
|
|
|
}
|