fix popup not hide when right click on sys tray

Change-Id: I7a8a0369501072625d6ca385840f5a9aec6a7c82
This commit is contained in:
石博文 2017-11-21 14:22:07 +08:00
parent bf26867d0f
commit 5b5a3e335e
Notes: Deepin Code Review 2017-11-22 11:27:44 +08:00
Verified+1: Anonymous Coward #1000004
Code-Review+2: 石博文 <sbw@sbw.so>
Submitted-by: 石博文 <sbw@sbw.so>
Submitted-at: Wed, 22 Nov 2017 11:27:44 +0800
Reviewed-on: https://cr.deepin.io/28721
Project: dde/dde-dock
Branch: refs/heads/master
9 changed files with 40 additions and 21 deletions

View File

@ -201,6 +201,11 @@ void DockItem::showHoverTips()
if (PopupWindow->isVisible() && PopupWindow->model())
return;
// if not in geometry area
const QRect r(topleftPoint(), size());
if (!r.contains(QCursor::pos()))
return;
QWidget * const content = popupTips();
if (!content)
return;
@ -276,14 +281,9 @@ QWidget *DockItem::popupTips()
return nullptr;
}
const QPoint DockItem::popupMarkPoint()
const QPoint DockItem::popupMarkPoint() const
{
QPoint p;
QWidget *w = this;
do {
p += w->pos();
w = qobject_cast<QWidget *>(w->parent());
} while (w);
QPoint p(topleftPoint());
const QRect r = rect();
const int offset = 2;
@ -298,6 +298,18 @@ const QPoint DockItem::popupMarkPoint()
return p;
}
const QPoint DockItem::topleftPoint() const
{
QPoint p;
const QWidget *w = this;
do {
p += w->pos();
w = qobject_cast<QWidget *>(w->parent());
} while (w);
return p;
}
void DockItem::hidePopup()
{
m_popupTipsDelayTimer->stop();

View File

@ -72,7 +72,8 @@ protected:
void leaveEvent(QEvent *e);
const QRect perfectIconRect() const;
const QPoint popupMarkPoint();
const QPoint popupMarkPoint() const;
const QPoint topleftPoint() const;
void hidePopup();
void popupWindowAccept();

View File

@ -112,10 +112,11 @@ void PluginsItem::refershIcon()
void PluginsItem::mousePressEvent(QMouseEvent *e)
{
QWidget::mousePressEvent(e);
if (e->button() == Qt::LeftButton)
MousePressPoint = e->pos();
else if (e->button() == Qt::RightButton)
if (!PopupWindow->isModal() && PopupWindow->isVisible())
hidePopup();
}
void PluginsItem::mouseMoveEvent(QMouseEvent *e)

View File

@ -126,6 +126,7 @@ void SoundItem::mousePressEvent(QMouseEvent *e)
const QPoint p(e->pos() - rect().center());
if (p.manhattanLength() < std::min(width(), height()) * 0.8 * 0.5)
{
e->accept();
emit requestContextMenu();
return;
}

View File

@ -46,7 +46,7 @@ void SoundPlugin::init(PluginProxyInterface *proxyInter)
m_proxyInter = proxyInter;
m_soundItem = new SoundItem;
connect(m_soundItem, &SoundItem::requestContextMenu, [this] {m_proxyInter->requestContextMenu(this, QString());});
connect(m_soundItem, &SoundItem::requestContextMenu, [this] { m_proxyInter->requestContextMenu(this, QString()); });
if (m_settings.value(STATE_KEY, true).toBool())
m_proxyInter->itemAdded(this, QString());

View File

@ -116,7 +116,7 @@ void FashionTrayItem::mousePressEvent(QMouseEvent *e)
if (dis.manhattanLength() > std::min(width(), height()) / 2 * 0.8)
return QWidget::mousePressEvent(e);
if (e->button() != Qt::RightButton)
// if (e->button() != Qt::RightButton)
QWidget::mousePressEvent(e);
m_pressPoint = e->pos();

View File

@ -75,7 +75,13 @@ void SystemTrayPlugin::displayModeChanged(const Dock::DisplayMode mode)
QWidget *SystemTrayPlugin::itemWidget(const QString &itemKey)
{
if (itemKey == FASHION_MODE_ITEM)
{
// refresh active tray
if (!m_fashionItem->activeTray())
m_fashionItem->setActiveTray(m_trayList.first());
return m_fashionItem;
}
const quint32 trayWinId = itemKey.toUInt();
@ -210,8 +216,9 @@ void SystemTrayPlugin::trayRemoved(const quint32 winId)
if (m_trayApplet->isVisible())
updateTipsContent();
if (m_fashionItem->activeTray() != widget)
if (m_fashionItem->activeTray() && m_fashionItem->activeTray() != widget)
return;
// reset active tray
if (m_trayList.values().isEmpty())
{

View File

@ -155,24 +155,21 @@ void TrayWidget::paintEvent(QPaintEvent *e)
void TrayWidget::mousePressEvent(QMouseEvent *e)
{
e->accept();
const QPoint point(e->pos() - rect().center());
if (point.manhattanLength() > 24)
return QWidget::mousePressEvent(e);
e->ignore();
m_pressPoint = e->pos();
QWidget::mousePressEvent(e);
}
void TrayWidget::mouseReleaseEvent(QMouseEvent *e)
{
QWidget::mouseReleaseEvent(e);
const QPoint point(e->pos() - rect().center());
if (point.manhattanLength() > 24)
return;
const QPoint distance = e->pos() - m_pressPoint;
if (distance.manhattanLength() > DRAG_THRESHOLD)
return;
e->accept();
QPoint globalPos = QCursor::pos();
uint8_t buttonIndex = XCB_BUTTON_INDEX_1;

View File

@ -69,7 +69,7 @@ private:
QTimer *m_updateTimer;
QTimer *m_ignoreRepeat;
QPoint m_pressPoint;
// QPoint m_pressPoint;
};
#endif // TRAYWIDGET_H