mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-03 00:15:21 +00:00
157 lines
4.0 KiB
C++
157 lines
4.0 KiB
C++
/*
|
|
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
|
|
*
|
|
* 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/>.
|
|
*/
|
|
|
|
#include "dockpopupwindow.h"
|
|
|
|
#include <QScreen>
|
|
#include <QApplication>
|
|
#include <QDesktopWidget>
|
|
|
|
DWIDGET_USE_NAMESPACE
|
|
|
|
DockPopupWindow::DockPopupWindow(QWidget *parent)
|
|
: DArrowRectangle(ArrowBottom, parent),
|
|
m_model(false),
|
|
|
|
m_acceptDelayTimer(new QTimer(this)),
|
|
|
|
m_regionInter(new DRegionMonitor(this)),
|
|
m_displayInter(new DBusDisplay(this))
|
|
{
|
|
m_acceptDelayTimer->setSingleShot(true);
|
|
m_acceptDelayTimer->setInterval(100);
|
|
|
|
m_wmHelper = DWindowManagerHelper::instance();
|
|
|
|
compositeChanged();
|
|
|
|
setBackgroundColor(DBlurEffectWidget::DarkColor);
|
|
setWindowFlags(Qt::X11BypassWindowManagerHint | Qt::WindowStaysOnTopHint | Qt::WindowDoesNotAcceptFocus);
|
|
setAttribute(Qt::WA_InputMethodEnabled, false);
|
|
|
|
connect(m_acceptDelayTimer, &QTimer::timeout, this, &DockPopupWindow::accept);
|
|
connect(m_wmHelper, &DWindowManagerHelper::hasCompositeChanged, this, &DockPopupWindow::compositeChanged);
|
|
connect(m_regionInter, &DRegionMonitor::buttonRelease, this, &DockPopupWindow::onGlobMouseRelease);
|
|
}
|
|
|
|
DockPopupWindow::~DockPopupWindow()
|
|
{
|
|
}
|
|
|
|
bool DockPopupWindow::model() const
|
|
{
|
|
return m_model;
|
|
}
|
|
|
|
void DockPopupWindow::setContent(QWidget *content)
|
|
{
|
|
QWidget *lastWidget = getContent();
|
|
if (lastWidget)
|
|
lastWidget->removeEventFilter(this);
|
|
content->installEventFilter(this);
|
|
|
|
setAccessibleName(content->objectName() + "-popup");
|
|
|
|
DArrowRectangle::setContent(content);
|
|
}
|
|
|
|
void DockPopupWindow::show(const QPoint &pos, const bool model)
|
|
{
|
|
m_model = model;
|
|
m_lastPoint = pos;
|
|
|
|
show(pos.x(), pos.y());
|
|
|
|
const bool regionRegistered = m_regionInter->registered();
|
|
if (!m_model && regionRegistered)
|
|
m_regionInter->unregisterRegion();
|
|
else if (m_model && !regionRegistered)
|
|
m_regionInter->registerRegion();
|
|
}
|
|
|
|
void DockPopupWindow::show(const int x, const int y)
|
|
{
|
|
m_lastPoint = QPoint(x, y);
|
|
|
|
DArrowRectangle::show(x, y);
|
|
}
|
|
|
|
void DockPopupWindow::hide()
|
|
{
|
|
if (m_regionInter->registered())
|
|
m_regionInter->unregisterRegion();
|
|
|
|
DArrowRectangle::hide();
|
|
}
|
|
|
|
void DockPopupWindow::showEvent(QShowEvent *e)
|
|
{
|
|
DArrowRectangle::showEvent(e);
|
|
|
|
QTimer::singleShot(1, this, &DockPopupWindow::ensureRaised);
|
|
}
|
|
|
|
void DockPopupWindow::enterEvent(QEvent *e)
|
|
{
|
|
DArrowRectangle::enterEvent(e);
|
|
|
|
QTimer::singleShot(1, this, &DockPopupWindow::ensureRaised);
|
|
}
|
|
|
|
bool DockPopupWindow::eventFilter(QObject *o, QEvent *e)
|
|
{
|
|
if (o != getContent() || e->type() != QEvent::Resize)
|
|
return false;
|
|
|
|
// FIXME: ensure position move after global mouse release event
|
|
QTimer::singleShot(100, this, [this] { if (isVisible()) show(m_lastPoint, m_model); });
|
|
|
|
return false;
|
|
}
|
|
|
|
void DockPopupWindow::onGlobMouseRelease(const QPoint &mousePos, const int flag)
|
|
{
|
|
Q_UNUSED(flag);
|
|
Q_ASSERT(m_model);
|
|
|
|
const QRect rect = QRect(pos(), size());
|
|
if (rect.contains(mousePos))
|
|
return;
|
|
|
|
emit accept();
|
|
|
|
m_regionInter->unregisterRegion();
|
|
}
|
|
|
|
void DockPopupWindow::compositeChanged()
|
|
{
|
|
if (m_wmHelper->hasComposite())
|
|
setBorderColor(QColor(255, 255, 255, 255 * 0.05));
|
|
else
|
|
setBorderColor(QColor("#2C3238"));
|
|
}
|
|
|
|
void DockPopupWindow::ensureRaised()
|
|
{
|
|
if (isVisible())
|
|
raise();
|
|
}
|