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
|
|
|
}
|
|
|
|
|
|
|
|
bool DockPopupWindow::model() const
|
|
|
|
{
|
|
|
|
return m_model;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DockPopupWindow::show(const QPoint &pos, const bool model)
|
|
|
|
{
|
|
|
|
m_model = model;
|
|
|
|
|
|
|
|
DArrowRectangle::show(pos.x(), pos.y());
|
2016-07-18 10:09:26 +08:00
|
|
|
|
|
|
|
if (model)
|
|
|
|
m_mouseAreaKey = m_mouseInter->RegisterFullScreen();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DockPopupWindow::mousePressEvent(QMouseEvent *e)
|
|
|
|
{
|
|
|
|
DArrowRectangle::mousePressEvent(e);
|
|
|
|
|
|
|
|
if (e->button() == Qt::LeftButton)
|
|
|
|
m_acceptDelayTimer->start();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DockPopupWindow::globalMouseRelease()
|
|
|
|
{
|
2016-07-18 20:01:03 +08:00
|
|
|
if (!m_model)
|
|
|
|
return;
|
2016-07-18 10:09:26 +08:00
|
|
|
|
|
|
|
const QRect rect = QRect(pos(), size());
|
|
|
|
const QPoint pos = QCursor::pos();
|
|
|
|
|
|
|
|
if (rect.contains(pos))
|
|
|
|
return;
|
|
|
|
|
|
|
|
emit accept();
|
|
|
|
|
|
|
|
m_mouseInter->UnregisterArea(m_mouseAreaKey);
|
2016-07-15 11:00:55 +08:00
|
|
|
}
|