mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 09:23:03 +00:00
trigger popup menu when click out of icon
Change-Id: Ib85c1a38ee88b574d99e403716a4f0bee140e055
This commit is contained in:
parent
cdd53ef2a3
commit
ed47da35fe
@ -102,7 +102,13 @@ void AppItem::mouseReleaseEvent(QMouseEvent *e)
|
|||||||
|
|
||||||
void AppItem::mousePressEvent(QMouseEvent *e)
|
void AppItem::mousePressEvent(QMouseEvent *e)
|
||||||
{
|
{
|
||||||
DockItem::mousePressEvent(e);
|
if (e->button() == Qt::RightButton)
|
||||||
|
{
|
||||||
|
if (perfectIconRect().contains(e->pos()))
|
||||||
|
return showContextMenu();
|
||||||
|
else
|
||||||
|
return QWidget::mousePressEvent(e);
|
||||||
|
}
|
||||||
|
|
||||||
if (e->button() == Qt::LeftButton)
|
if (e->button() == Qt::LeftButton)
|
||||||
MousePressPos = e->pos();
|
MousePressPos = e->pos();
|
||||||
|
@ -37,6 +37,19 @@ void DockItem::mousePressEvent(QMouseEvent *e)
|
|||||||
return showContextMenu();
|
return showContextMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QRect DockItem::perfectIconRect() const
|
||||||
|
{
|
||||||
|
const QRect itemRect = rect();
|
||||||
|
const int iconSize = std::min(itemRect.width(), itemRect.height());
|
||||||
|
|
||||||
|
QRect iconRect;
|
||||||
|
iconRect.setWidth(iconSize);
|
||||||
|
iconRect.setHeight(iconSize);
|
||||||
|
iconRect.moveTopLeft(itemRect.center() - iconRect.center());
|
||||||
|
|
||||||
|
return iconRect;
|
||||||
|
}
|
||||||
|
|
||||||
void DockItem::showContextMenu()
|
void DockItem::showContextMenu()
|
||||||
{
|
{
|
||||||
const QString menuJson = contextMenu();
|
const QString menuJson = contextMenu();
|
||||||
|
@ -33,6 +33,8 @@ protected:
|
|||||||
void paintEvent(QPaintEvent *e);
|
void paintEvent(QPaintEvent *e);
|
||||||
void mousePressEvent(QMouseEvent *e);
|
void mousePressEvent(QMouseEvent *e);
|
||||||
|
|
||||||
|
const QRect perfectIconRect() const;
|
||||||
|
|
||||||
void showContextMenu();
|
void showContextMenu();
|
||||||
virtual void invokedMenuItem(const QString &itemId, const bool checked);
|
virtual void invokedMenuItem(const QString &itemId, const bool checked);
|
||||||
virtual const QString contextMenu() const;
|
virtual const QString contextMenu() const;
|
||||||
|
@ -27,6 +27,9 @@ void LauncherItem::resizeEvent(QResizeEvent *e)
|
|||||||
|
|
||||||
void LauncherItem::mousePressEvent(QMouseEvent *e)
|
void LauncherItem::mousePressEvent(QMouseEvent *e)
|
||||||
{
|
{
|
||||||
|
if (e->button() == Qt::RightButton && !perfectIconRect().contains(e->pos()))
|
||||||
|
return QWidget::mousePressEvent(e);
|
||||||
|
|
||||||
if (e->button() != Qt::LeftButton)
|
if (e->button() != Qt::LeftButton)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -208,7 +208,6 @@ void DockSettings::dockItemCountChanged()
|
|||||||
|
|
||||||
void DockSettings::calculateWindowConfig()
|
void DockSettings::calculateWindowConfig()
|
||||||
{
|
{
|
||||||
const QRect primaryRect = m_displayInter->primaryRect();
|
|
||||||
const int defaultHeight = AppItem::itemBaseHeight();
|
const int defaultHeight = AppItem::itemBaseHeight();
|
||||||
const int defaultWidth = AppItem::itemBaseWidth();
|
const int defaultWidth = AppItem::itemBaseWidth();
|
||||||
|
|
||||||
@ -219,12 +218,12 @@ void DockSettings::calculateWindowConfig()
|
|||||||
case Top:
|
case Top:
|
||||||
case Bottom:
|
case Bottom:
|
||||||
m_mainWindowSize.setHeight(defaultHeight);
|
m_mainWindowSize.setHeight(defaultHeight);
|
||||||
m_mainWindowSize.setWidth(primaryRect.width());
|
m_mainWindowSize.setWidth(m_primaryRect.width());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Left:
|
case Left:
|
||||||
case Right:
|
case Right:
|
||||||
m_mainWindowSize.setHeight(primaryRect.height());
|
m_mainWindowSize.setHeight(m_primaryRect.height());
|
||||||
m_mainWindowSize.setWidth(defaultWidth);
|
m_mainWindowSize.setWidth(defaultWidth);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -234,33 +233,37 @@ void DockSettings::calculateWindowConfig()
|
|||||||
}
|
}
|
||||||
else if (m_displayMode == Dock::Fashion)
|
else if (m_displayMode == Dock::Fashion)
|
||||||
{
|
{
|
||||||
int appItemCount = 0;
|
// int appItemCount = 0;
|
||||||
int pluginItemCount = 0;
|
// int pluginItemCount = 0;
|
||||||
|
int perfectWidth = 0;
|
||||||
|
int perfectHeight = 0;
|
||||||
const QList<DockItem *> itemList = m_itemController->itemList();
|
const QList<DockItem *> itemList = m_itemController->itemList();
|
||||||
for (auto item : itemList)
|
for (auto item : itemList)
|
||||||
{
|
{
|
||||||
switch (item->itemType())
|
switch (item->itemType())
|
||||||
{
|
{
|
||||||
case DockItem::Launcher:
|
case DockItem::Launcher:
|
||||||
case DockItem::App: ++appItemCount; break;
|
case DockItem::App: perfectWidth += defaultWidth;
|
||||||
case DockItem::Plugins: ++pluginItemCount; break;
|
perfectHeight += defaultHeight; break;
|
||||||
|
case DockItem::Plugins: perfectWidth += item->sizeHint().width();
|
||||||
|
perfectHeight += item->sizeHint().height(); break;
|
||||||
default:;
|
default:;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const int perfectWidth = qMin(primaryRect.width(), defaultWidth * (appItemCount + pluginItemCount));
|
const int calcWidth = qMin(m_primaryRect.width(), perfectWidth);
|
||||||
const int perfectHeight = qMin(primaryRect.height(), defaultHeight * (appItemCount + pluginItemCount));
|
const int calcHeight = qMin(m_primaryRect.height(), perfectHeight);
|
||||||
switch (m_position)
|
switch (m_position)
|
||||||
{
|
{
|
||||||
case Top:
|
case Top:
|
||||||
case Bottom:
|
case Bottom:
|
||||||
m_mainWindowSize.setHeight(defaultHeight);
|
m_mainWindowSize.setHeight(defaultHeight);
|
||||||
m_mainWindowSize.setWidth(perfectWidth);
|
m_mainWindowSize.setWidth(calcWidth);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Left:
|
case Left:
|
||||||
case Right:
|
case Right:
|
||||||
m_mainWindowSize.setHeight(perfectHeight);
|
m_mainWindowSize.setHeight(calcHeight);
|
||||||
m_mainWindowSize.setWidth(defaultWidth);
|
m_mainWindowSize.setWidth(defaultWidth);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user