mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-02 15:45:21 +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)
|
||||
{
|
||||
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)
|
||||
MousePressPos = e->pos();
|
||||
|
@ -37,6 +37,19 @@ void DockItem::mousePressEvent(QMouseEvent *e)
|
||||
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()
|
||||
{
|
||||
const QString menuJson = contextMenu();
|
||||
|
@ -33,6 +33,8 @@ protected:
|
||||
void paintEvent(QPaintEvent *e);
|
||||
void mousePressEvent(QMouseEvent *e);
|
||||
|
||||
const QRect perfectIconRect() const;
|
||||
|
||||
void showContextMenu();
|
||||
virtual void invokedMenuItem(const QString &itemId, const bool checked);
|
||||
virtual const QString contextMenu() const;
|
||||
|
@ -27,6 +27,9 @@ void LauncherItem::resizeEvent(QResizeEvent *e)
|
||||
|
||||
void LauncherItem::mousePressEvent(QMouseEvent *e)
|
||||
{
|
||||
if (e->button() == Qt::RightButton && !perfectIconRect().contains(e->pos()))
|
||||
return QWidget::mousePressEvent(e);
|
||||
|
||||
if (e->button() != Qt::LeftButton)
|
||||
return;
|
||||
|
||||
|
@ -208,7 +208,6 @@ void DockSettings::dockItemCountChanged()
|
||||
|
||||
void DockSettings::calculateWindowConfig()
|
||||
{
|
||||
const QRect primaryRect = m_displayInter->primaryRect();
|
||||
const int defaultHeight = AppItem::itemBaseHeight();
|
||||
const int defaultWidth = AppItem::itemBaseWidth();
|
||||
|
||||
@ -219,12 +218,12 @@ void DockSettings::calculateWindowConfig()
|
||||
case Top:
|
||||
case Bottom:
|
||||
m_mainWindowSize.setHeight(defaultHeight);
|
||||
m_mainWindowSize.setWidth(primaryRect.width());
|
||||
m_mainWindowSize.setWidth(m_primaryRect.width());
|
||||
break;
|
||||
|
||||
case Left:
|
||||
case Right:
|
||||
m_mainWindowSize.setHeight(primaryRect.height());
|
||||
m_mainWindowSize.setHeight(m_primaryRect.height());
|
||||
m_mainWindowSize.setWidth(defaultWidth);
|
||||
break;
|
||||
|
||||
@ -234,33 +233,37 @@ void DockSettings::calculateWindowConfig()
|
||||
}
|
||||
else if (m_displayMode == Dock::Fashion)
|
||||
{
|
||||
int appItemCount = 0;
|
||||
int pluginItemCount = 0;
|
||||
// int appItemCount = 0;
|
||||
// int pluginItemCount = 0;
|
||||
int perfectWidth = 0;
|
||||
int perfectHeight = 0;
|
||||
const QList<DockItem *> itemList = m_itemController->itemList();
|
||||
for (auto item : itemList)
|
||||
{
|
||||
switch (item->itemType())
|
||||
{
|
||||
case DockItem::Launcher:
|
||||
case DockItem::App: ++appItemCount; break;
|
||||
case DockItem::Plugins: ++pluginItemCount; break;
|
||||
case DockItem::App: perfectWidth += defaultWidth;
|
||||
perfectHeight += defaultHeight; break;
|
||||
case DockItem::Plugins: perfectWidth += item->sizeHint().width();
|
||||
perfectHeight += item->sizeHint().height(); break;
|
||||
default:;
|
||||
}
|
||||
}
|
||||
|
||||
const int perfectWidth = qMin(primaryRect.width(), defaultWidth * (appItemCount + pluginItemCount));
|
||||
const int perfectHeight = qMin(primaryRect.height(), defaultHeight * (appItemCount + pluginItemCount));
|
||||
const int calcWidth = qMin(m_primaryRect.width(), perfectWidth);
|
||||
const int calcHeight = qMin(m_primaryRect.height(), perfectHeight);
|
||||
switch (m_position)
|
||||
{
|
||||
case Top:
|
||||
case Bottom:
|
||||
m_mainWindowSize.setHeight(defaultHeight);
|
||||
m_mainWindowSize.setWidth(perfectWidth);
|
||||
m_mainWindowSize.setWidth(calcWidth);
|
||||
break;
|
||||
|
||||
case Left:
|
||||
case Right:
|
||||
m_mainWindowSize.setHeight(perfectHeight);
|
||||
m_mainWindowSize.setHeight(calcHeight);
|
||||
m_mainWindowSize.setWidth(defaultWidth);
|
||||
break;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user