fix: show dock menu when click on some area out of tray

https://github.com/linuxdeepin/internal-discussion/issues/853

Change-Id: Iaf0e76b7de4ce394c83ee40cd0685828d7dc77d0
This commit is contained in:
listenerri 2019-01-14 17:48:43 +08:00
parent 96970ee4bd
commit 2d61405db9
Notes: gerrit 2019-01-14 18:01:15 +08:00
Verified+1: <jenkins@deepin.com>
Code-Review+2: listenerri <listenerri@gmail.com>
Submitted-by: listenerri <listenerri@gmail.com>
Submitted-at: Mon, 14 Jan 2019 18:01:14 +0800
Reviewed-on: https://cr.deepin.io/41325
Project: dde/dde-dock
Branch: refs/heads/master
3 changed files with 21 additions and 8 deletions

View File

@ -42,9 +42,11 @@ AbstractTrayWidget::~AbstractTrayWidget()
void AbstractTrayWidget::mousePressEvent(QMouseEvent *event)
{
// do not call Parent::mousePressEvent or the DockItem will catch this event
// and show dock-context-menu immediately when right button of mouse is pressed in fashion mode
if (event->button() == Qt::RightButton) {
// call QWidget::mousePressEvent means to show dock-context-menu
// when right button of mouse is pressed immediately in fashion mode
// here we hide the right button press event when it is click in the special area
if (event->button() == Qt::RightButton && perfectIconRect().contains(event->pos())) {
event->accept();
return;
}
@ -101,3 +103,16 @@ void AbstractTrayWidget::handleMouseRelease() {
Q_EMIT clicked();
}
}
const QRect AbstractTrayWidget::perfectIconRect() const
{
const QRect itemRect = rect();
const int iconSize = std::min(itemRect.width(), itemRect.height()) * 0.8;
QRect iconRect;
iconRect.setWidth(iconSize);
iconRect.setHeight(iconSize);
iconRect.moveTopLeft(itemRect.center() - iconRect.center());
return iconRect;
}

View File

@ -56,6 +56,7 @@ protected:
void mouseReleaseEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
void handleMouseRelease();
const QRect perfectIconRect() const;
private:
QTimer *m_handleMouseReleaseTimer;

View File

@ -195,11 +195,8 @@ void SystemTrayItem::mousePressEvent(QMouseEvent *event)
hideNonModel();
if (event->button() == Qt::RightButton) {
const QPoint p(event->pos() - rect().center());
if (p.manhattanLength() < std::min(width(), height()) * 0.8 * 0.5)
{
showContextMenu();
return;
if (perfectIconRect().contains(event->pos())) {
return showContextMenu();
}
}