2016-07-15 11:00:55 +08:00
|
|
|
#include "dockpopupwindow.h"
|
|
|
|
|
|
|
|
DWIDGET_USE_NAMESPACE
|
|
|
|
|
|
|
|
DockPopupWindow::DockPopupWindow(QWidget *parent)
|
|
|
|
: DArrowRectangle(ArrowBottom, parent),
|
2016-07-18 10:09:26 +08:00
|
|
|
m_model(false),
|
|
|
|
|
|
|
|
m_acceptDelayTimer(new QTimer(this)),
|
|
|
|
|
|
|
|
m_mouseInter(new DBusXMouseArea(this))
|
2016-07-15 11:00:55 +08:00
|
|
|
{
|
2016-07-18 10:09:26 +08:00
|
|
|
m_acceptDelayTimer->setSingleShot(true);
|
|
|
|
m_acceptDelayTimer->setInterval(100);
|
2016-07-15 11:00:55 +08:00
|
|
|
|
2016-07-18 10:09:26 +08:00
|
|
|
connect(m_acceptDelayTimer, &QTimer::timeout, this, &DockPopupWindow::accept);
|
|
|
|
connect(m_mouseInter, &DBusXMouseArea::ButtonRelease, this, &DockPopupWindow::globalMouseRelease);
|
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
|
|
|
|
{
|
|
|
|
return m_model;
|
|
|
|
}
|
|
|
|
|
2016-07-27 14:08:23 +08:00
|
|
|
void DockPopupWindow::setContent(QWidget *content)
|
|
|
|
{
|
|
|
|
QWidget *lastWidget = getContent();
|
|
|
|
if (lastWidget)
|
|
|
|
lastWidget->removeEventFilter(this);
|
|
|
|
content->installEventFilter(this);
|
|
|
|
|
2016-07-28 10:59:21 +08:00
|
|
|
setAccessibleName(content->objectName() + "-popup");
|
|
|
|
|
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
|
|
|
|
|
|
|
DArrowRectangle::show(pos.x(), pos.y());
|
2016-07-18 10:09:26 +08:00
|
|
|
|
2016-07-19 15:08:16 +08:00
|
|
|
if (!model && !m_mouseAreaKey.isEmpty())
|
|
|
|
{
|
|
|
|
m_mouseInter->UnregisterArea(m_mouseAreaKey);
|
|
|
|
m_mouseAreaKey.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (model && m_mouseAreaKey.isEmpty())
|
2016-07-18 10:09:26 +08:00
|
|
|
m_mouseAreaKey = m_mouseInter->RegisterFullScreen();
|
|
|
|
}
|
|
|
|
|
2016-07-19 15:08:16 +08:00
|
|
|
void DockPopupWindow::hide()
|
|
|
|
{
|
|
|
|
if (!m_mouseAreaKey.isEmpty())
|
|
|
|
{
|
|
|
|
m_mouseInter->UnregisterArea(m_mouseAreaKey);
|
|
|
|
m_mouseAreaKey.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
DArrowRectangle::hide();
|
|
|
|
}
|
|
|
|
|
2016-07-18 10:09:26 +08:00
|
|
|
void DockPopupWindow::mousePressEvent(QMouseEvent *e)
|
|
|
|
{
|
|
|
|
DArrowRectangle::mousePressEvent(e);
|
|
|
|
|
2016-07-19 15:08:16 +08:00
|
|
|
// if (e->button() == Qt::LeftButton)
|
2016-08-01 14:26:15 +08:00
|
|
|
// m_acceptDelayTimer->start();
|
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
|
2016-07-28 09:49:43 +08:00
|
|
|
QTimer::singleShot(100, this, [this] {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
|
|
|
}
|
|
|
|
|
2016-07-20 16:30:56 +08:00
|
|
|
void DockPopupWindow::globalMouseRelease(int button, int x, int y, const QString &id)
|
2016-07-18 10:09:26 +08:00
|
|
|
{
|
2016-07-20 16:30:56 +08:00
|
|
|
Q_UNUSED(button);
|
|
|
|
|
|
|
|
if (id != m_mouseAreaKey)
|
|
|
|
return;
|
|
|
|
|
2016-07-19 15:08:16 +08:00
|
|
|
Q_ASSERT(m_model);
|
2016-07-18 10:09:26 +08:00
|
|
|
|
|
|
|
const QRect rect = QRect(pos(), size());
|
2016-07-20 16:30:56 +08:00
|
|
|
const QPoint pos = QPoint(x, y);
|
2016-07-18 10:09:26 +08:00
|
|
|
|
|
|
|
if (rect.contains(pos))
|
|
|
|
return;
|
|
|
|
|
|
|
|
emit accept();
|
|
|
|
|
|
|
|
m_mouseInter->UnregisterArea(m_mouseAreaKey);
|
2016-07-19 15:08:16 +08:00
|
|
|
m_mouseAreaKey.clear();
|
2016-07-15 11:00:55 +08:00
|
|
|
}
|