fix: 为了将maintain/5.1分支合入uos,重新对任务栏图标点击、移动、拖动范围处理

由原来的提交的用鼠标当前坐标是否在图标范围内的判断方式修改为设置图标布局的边距的方式。以便于将maintain/5.1分支合入uos而不影响其他
功能

Log: 重新对任务栏图标可点击、移动或拖动范围进行处理
Change-Id: Icf6df593f468c247c6d4fc5c2ba0936d5135626b
Reviewed-on: http://gerrit.uniontech.com/c/dde-dock/+/4271
Reviewed-by: <mailman@uniontech.com>
Reviewed-by: fanpengcheng <fanpengcheng@uniontech.com>
Tested-by: <mailman@uniontech.com>
This commit is contained in:
chenjun 2020-09-10 15:51:33 +08:00
parent e32e33de85
commit 88d52e28d1
20 changed files with 151 additions and 310 deletions

View File

@ -179,15 +179,9 @@ void DockItem::enterEvent(QEvent *e)
return; return;
} }
if (containCursorPos()) { m_hover = true;
m_hover = true; m_hoverEffect->setHighlighting(true);
m_hoverEffect->setHighlighting(true); m_popupTipsDelayTimer->start();
m_popupTipsDelayTimer->start();
} else {
m_hover = false;
m_hoverEffect->setHighlighting(false);
m_popupTipsDelayTimer->stop();
}
update(); update();
@ -213,16 +207,9 @@ void DockItem::leaveEvent(QEvent *e)
void DockItem::mouseMoveEvent(QMouseEvent *e) void DockItem::mouseMoveEvent(QMouseEvent *e)
{ {
if (containCursorPos()) { m_hover = true;
m_hover = true; m_hoverEffect->setHighlighting(true);
m_hoverEffect->setHighlighting(true); m_popupTipsDelayTimer->start();
m_popupTipsDelayTimer->start();
} else {
m_hover = false;
m_hoverEffect->setHighlighting(false);
m_popupTipsDelayTimer->stop();
hidePopup();
}
update(); update();
@ -291,20 +278,6 @@ void DockItem::onContextMenuAccepted()
emit requestWindowAutoHide(true); emit requestWindowAutoHide(true);
} }
bool DockItem::containCursorPos()
{
QPoint cursorPos = this->mapFromGlobal(QCursor::pos());
QRect rect(this->rect());
int iconSize = qMin(rect.width(), rect.height());
int w = (rect.width() - iconSize) / 2;
int h = (rect.height() - iconSize) / 2;
rect = rect.adjusted(w, h, -w, -h);
return rect.contains(cursorPos);
}
void DockItem::showHoverTips() void DockItem::showHoverTips()
{ {
// another model popup window already exists // another model popup window already exists

View File

@ -60,7 +60,6 @@ public:
QSize sizeHint() const override; QSize sizeHint() const override;
virtual QString accessibleName(); virtual QString accessibleName();
bool containCursorPos();
public slots: public slots:
virtual void refershIcon() {} virtual void refershIcon() {}

View File

@ -140,10 +140,6 @@ void PluginsItem::mousePressEvent(QMouseEvent *e)
return; return;
} }
if (!containCursorPos()) {
return;
}
update(); update();
if (PopupWindow->isVisible()) if (PopupWindow->isVisible())
@ -164,10 +160,6 @@ void PluginsItem::mouseMoveEvent(QMouseEvent *e)
DockItem::mouseMoveEvent(e); DockItem::mouseMoveEvent(e);
if (!containCursorPos()) {
return;
}
e->accept(); e->accept();
const QPoint distance = e->pos() - MousePressPoint; const QPoint distance = e->pos() - MousePressPoint;
@ -191,10 +183,6 @@ void PluginsItem::mouseReleaseEvent(QMouseEvent *e)
e->accept(); e->accept();
if (!containCursorPos()) {
return;
}
const QPoint distance = e->pos() - MousePressPoint; const QPoint distance = e->pos() - MousePressPoint;
if (distance.manhattanLength() < PLUGIN_ITEM_DRAG_THRESHOLD) if (distance.manhattanLength() < PLUGIN_ITEM_DRAG_THRESHOLD)
mouseClicked(); mouseClicked();

View File

@ -255,8 +255,12 @@ void MainPanelControl::addTrayAreaItem(int index, QWidget *wdg)
void MainPanelControl::addPluginAreaItem(int index, QWidget *wdg) void MainPanelControl::addPluginAreaItem(int index, QWidget *wdg)
{ {
m_pluginLayout->insertWidget(index, wdg, 0, Qt::AlignCenter); //因为日期时间插件和其他插件的大小有异,为了方便设置边距,在插件区域布局再添加一层布局设置边距
resizeDockIcon(); //因此在处理插件图标时,需要通过两层布局判断是否为需要的插件,例如拖动插件位置等判断
QBoxLayout * boxLayout = new QBoxLayout(QBoxLayout::LeftToRight);
boxLayout->addWidget(wdg, 0, Qt::AlignCenter);
m_pluginLayout->insertLayout(index, boxLayout, 0);
resizeDockIcon();;
m_pluginAreaWidget->adjustSize(); m_pluginAreaWidget->adjustSize();
} }
@ -277,7 +281,16 @@ void MainPanelControl::removeTrayAreaItem(QWidget *wdg)
void MainPanelControl::removePluginAreaItem(QWidget *wdg) void MainPanelControl::removePluginAreaItem(QWidget *wdg)
{ {
m_pluginLayout->removeWidget(wdg); //因为日期时间插件大小和其他插件有异,为了方便设置边距,各插件中增加一层布局
//因此remove插件图标时需要从多的一层布局中取widget进行判断是否需要移除的插件
for (int i = 0; i < m_pluginLayout->count(); ++i) {
QLayoutItem *layoutItem = m_pluginLayout->itemAt(i);
QLayout *boxLayout = layoutItem->layout();
if (boxLayout && boxLayout->itemAt(0)->widget() == wdg) {
boxLayout->removeWidget(wdg);
m_pluginLayout->removeItem(layoutItem);
}
}
} }
void MainPanelControl::resizeEvent(QResizeEvent *event) void MainPanelControl::resizeEvent(QResizeEvent *event)
@ -375,9 +388,17 @@ void MainPanelControl::moveItem(DockItem *sourceItem, DockItem *targetItem)
int idx = -1; int idx = -1;
if (targetItem->itemType() == DockItem::App) if (targetItem->itemType() == DockItem::App)
idx = m_appAreaSonLayout->indexOf(targetItem); idx = m_appAreaSonLayout->indexOf(targetItem);
else if (targetItem->itemType() == DockItem::Plugins) else if (targetItem->itemType() == DockItem::Plugins){
idx = m_pluginLayout->indexOf(targetItem); //因为日期时间插件大小和其他插件大小有异,为了设置边距,在各插件中增加了一层布局
else if (targetItem->itemType() == DockItem::FixedPlugin) //因此有拖动图标时,需要从多的一层布局中判断是否相同插件而获取插件位置顺序
for (int i = 0; i < m_pluginLayout->count(); ++i) {
QLayout *layout = m_pluginLayout->itemAt(i)->layout();
if (layout && layout->itemAt(0)->widget() == targetItem) {
idx = i;
break;
}
}
} else if (targetItem->itemType() == DockItem::FixedPlugin)
idx = m_fixedAreaLayout->indexOf(targetItem); idx = m_fixedAreaLayout->indexOf(targetItem);
else else
return; return;
@ -611,10 +632,6 @@ bool MainPanelControl::eventFilter(QObject *watched, QEvent *event)
if (item->itemType() != DockItem::App && item->itemType() != DockItem::Plugins && item->itemType() != DockItem::FixedPlugin) if (item->itemType() != DockItem::App && item->itemType() != DockItem::Plugins && item->itemType() != DockItem::FixedPlugin)
return false; return false;
if (!item->containCursorPos()) {
return false;
}
const QPoint pos = mouseEvent->globalPos(); const QPoint pos = mouseEvent->globalPos();
const QPoint distance = pos - m_mousePressPos; const QPoint distance = pos - m_mousePressPos;
if (distance.manhattanLength() < QApplication::startDragDistance()) if (distance.manhattanLength() < QApplication::startDragDistance())
@ -720,22 +737,21 @@ DockItem *MainPanelControl::dropTargetItem(DockItem *sourceItem, QPoint point)
for (int i = 0 ; i < parentLayout->count(); ++i) { for (int i = 0 ; i < parentLayout->count(); ++i) {
QLayoutItem *layoutItem = parentLayout->itemAt(i); QLayoutItem *layoutItem = parentLayout->itemAt(i);
DockItem *dockItem = qobject_cast<DockItem *>(layoutItem->widget());
DockItem *dockItem = nullptr;
if (parentWidget == m_pluginAreaWidget) {
QLayout *layout = layoutItem->layout();
if (layout) {
dockItem = qobject_cast<DockItem *>(layout->itemAt(0)->widget());
}
} else{
dockItem = qobject_cast<DockItem *>(layoutItem->widget());
}
if (!dockItem) if (!dockItem)
continue; continue;
QRect rect; QRect rect(dockItem->pos(), dockItem->size());
rect.setTopLeft(dockItem->pos());
if (dockItem->itemType() == DockItem::Plugins) {
if ((m_position == Position::Top) || (m_position == Position::Bottom)) {
rect.setSize(QSize(PLUGIN_MAX_SIZE, height()));
} else {
rect.setSize(QSize(width(), PLUGIN_MAX_SIZE));
}
} else {
rect.setSize(dockItem->size());
}
if (rect.contains(point)) { if (rect.contains(point)) {
targetItem = dockItem; targetItem = dockItem;
break; break;
@ -866,31 +882,39 @@ void MainPanelControl::paintEvent(QPaintEvent *event)
void MainPanelControl::resizeDockIcon() void MainPanelControl::resizeDockIcon()
{ {
if (!m_tray)
return;
// 插件有点特殊因为会引入第三方的插件并不会受dock的缩放影响我们只能限制我们自己的插件否则会导致显示错误。 // 插件有点特殊因为会引入第三方的插件并不会受dock的缩放影响我们只能限制我们自己的插件否则会导致显示错误。
// 以下是受控制的插件 // 以下是受控制的插件
PluginsItem *trashPlugin = nullptr; PluginsItem *trashPlugin = nullptr;
PluginsItem *shutdownPlugin = nullptr; PluginsItem *shutdownPlugin = nullptr;
PluginsItem *keyboardPlugin = nullptr; PluginsItem *keyboardPlugin = nullptr;
PluginsItem *notificationPlugin = nullptr; PluginsItem *notificationPlugin = nullptr;
//因为日期时间大小和其他插件大小有异,为了设置边距,在各插件中增加了一层布局
//因此需要通过多一层布局来获取各插件
for (int i = 0; i < m_pluginLayout->count(); ++ i) { for (int i = 0; i < m_pluginLayout->count(); ++ i) {
PluginsItem *w = static_cast<PluginsItem *>(m_pluginLayout->itemAt(i)->widget()); QLayout *layout = m_pluginLayout->itemAt(i)->layout();
if (w->pluginName() == "trash") { if (layout) {
trashPlugin = w; PluginsItem *w = static_cast<PluginsItem *>(m_pluginLayout->itemAt(i)->widget());
} else if (w->pluginName() == "shutdown") { if (w) {
shutdownPlugin = w; if (w->pluginName() == "trash") {
} else if (w->pluginName() == "onboard") { trashPlugin = w;
keyboardPlugin = w; } else if (w->pluginName() == "shutdown") {
} else if (w->pluginName() == "notifications") { shutdownPlugin = w;
notificationPlugin = w; } else if (w->pluginName() == "onboard") {
keyboardPlugin = w;
} else if (w->pluginName() == "notifications") {
notificationPlugin = w;
}
}
} }
} }
// 总宽度 // 总宽度
int totalLength = ((m_position == Position::Top) || (m_position == Position::Bottom)) ? width() : height(); int totalLength = ((m_position == Position::Top) || (m_position == Position::Bottom)) ? width() : height();
// 减去托盘间隔区域 // 减去托盘间隔区域
totalLength -= (m_tray->trayVisableItemCount() + 1) * 10; if (m_tray) {
totalLength -= (m_tray->trayVisableItemCount() + 1) * 10;
}
// 减去3个分割线的宽度 // 减去3个分割线的宽度
totalLength -= 3 * SPLITER_SIZE; totalLength -= 3 * SPLITER_SIZE;
@ -915,7 +939,12 @@ void MainPanelControl::resizeDockIcon()
return; return;
// 参与计算的插件的个数(包含托盘和插件,垃圾桶,关机,屏幕键盘) // 参与计算的插件的个数(包含托盘和插件,垃圾桶,关机,屏幕键盘)
int pluginCount = m_tray->trayVisableItemCount() + (trashPlugin ? 1 : 0) + (shutdownPlugin ? 1 : 0) + (keyboardPlugin ? 1 : 0) + (notificationPlugin ? 1 : 0); int pluginCount = 0;
if (m_tray) {
pluginCount = m_tray->trayVisableItemCount() + (trashPlugin ? 1 : 0) + (shutdownPlugin ? 1 : 0) + (keyboardPlugin ? 1 : 0) + (notificationPlugin ? 1 : 0);
} else {
pluginCount = (trashPlugin ? 1 : 0) + (shutdownPlugin ? 1 : 0) + (keyboardPlugin ? 1 : 0) + (notificationPlugin ? 1 : 0);
}
// icon个数 // icon个数
int iconCount = m_fixedAreaLayout->count() + m_appAreaSonLayout->count() + pluginCount; int iconCount = m_fixedAreaLayout->count() + m_appAreaSonLayout->count() + pluginCount;
// 余数 // 余数
@ -956,8 +985,10 @@ void MainPanelControl::resizeDockIcon()
void MainPanelControl::calcuDockIconSize(int w, int h, PluginsItem *trashPlugin, PluginsItem *shutdownPlugin, PluginsItem *keyboardPlugin, PluginsItem *notificationPlugin) void MainPanelControl::calcuDockIconSize(int w, int h, PluginsItem *trashPlugin, PluginsItem *shutdownPlugin, PluginsItem *keyboardPlugin, PluginsItem *notificationPlugin)
{ {
int appItemSize = qMin(w, h);
for (int i = 0; i < m_fixedAreaLayout->count(); ++i) { for (int i = 0; i < m_fixedAreaLayout->count(); ++i) {
m_fixedAreaLayout->itemAt(i)->widget()->setFixedSize(w, h); m_fixedAreaLayout->itemAt(i)->widget()->setFixedSize(appItemSize, appItemSize);
} }
if (m_position == Dock::Position::Top || m_position == Dock::Position::Bottom) { if (m_position == Dock::Position::Top || m_position == Dock::Position::Bottom) {
@ -971,7 +1002,7 @@ void MainPanelControl::calcuDockIconSize(int w, int h, PluginsItem *trashPlugin,
} }
for (int i = 0; i < m_appAreaSonLayout->count(); ++i) { for (int i = 0; i < m_appAreaSonLayout->count(); ++i) {
m_appAreaSonLayout->itemAt(i)->widget()->setFixedSize(w, h); m_appAreaSonLayout->itemAt(i)->widget()->setFixedSize(appItemSize, appItemSize);
} }
// 托盘上每个图标大小 // 托盘上每个图标大小
@ -988,58 +1019,83 @@ void MainPanelControl::calcuDockIconSize(int w, int h, PluginsItem *trashPlugin,
if (tray_item_size < 20) if (tray_item_size < 20)
return; return;
m_tray->centralWidget()->setProperty("iconSize", tray_item_size); if (m_tray) {
m_tray->centralWidget()->setProperty("iconSize", tray_item_size);
// 插件
if ((m_position == Position::Top) || (m_position == Position::Bottom)) {
if (shutdownPlugin)
shutdownPlugin->setFixedSize(tray_item_size, h - 20);
if (keyboardPlugin)
keyboardPlugin->setFixedSize(tray_item_size, h - 20);
if (notificationPlugin)
notificationPlugin->setFixedSize(tray_item_size, h - 20);
if (trashPlugin)
trashPlugin->setFixedSize(tray_item_size, h - 20);
} else {
if (shutdownPlugin)
shutdownPlugin->setFixedSize(w - 20, tray_item_size);
if (keyboardPlugin)
keyboardPlugin->setFixedSize(w - 20, tray_item_size);
if (notificationPlugin)
notificationPlugin->setFixedSize(w - 20, tray_item_size);
if (trashPlugin)
trashPlugin->setFixedSize(w - 20, tray_item_size);
} }
if (shutdownPlugin)
shutdownPlugin->setFixedSize(tray_item_size, tray_item_size);
if (keyboardPlugin)
keyboardPlugin->setFixedSize(tray_item_size, tray_item_size);
if (notificationPlugin)
notificationPlugin->setFixedSize(tray_item_size, tray_item_size);
if (trashPlugin)
trashPlugin->setFixedSize(tray_item_size, tray_item_size);
//因为日期时间大小和其他插件大小有异,为了设置边距,在各插件中增加了一层布局
//因此需要通过多一层布局来获取各插件
if ((m_position == Position::Top) || (m_position == Position::Bottom)) { if ((m_position == Position::Top) || (m_position == Position::Bottom)) {
// 三方插件 // 三方插件
for (int i = 0; i < m_pluginLayout->count(); ++ i) { for (int i = 0; i < m_pluginLayout->count(); ++ i) {
PluginsItem *pItem = static_cast<PluginsItem *>(m_pluginLayout->itemAt(i)->widget()); QLayout *layout = m_pluginLayout->itemAt(i)->layout();
if (pItem != trashPlugin && pItem != shutdownPlugin && pItem != keyboardPlugin && pItem !=notificationPlugin) { if (layout) {
if (pItem->pluginName() == "datetime"){ PluginsItem *pItem = static_cast<PluginsItem *>(layout->itemAt(0)->widget());
pItem->setFixedSize(pItem->sizeHint().width(), h); if (pItem && pItem != trashPlugin && pItem != shutdownPlugin && pItem != keyboardPlugin && pItem !=notificationPlugin) {
} else if (pItem->pluginName() == "AiAssistant"){ if (pItem->pluginName() == "datetime") {
pItem->setFixedSize(tray_item_size, h - 20); pItem->setFixedSize(pItem->sizeHint().width(), h);
} else { } else {
pItem->setFixedSize(pItem->sizeHint().width(), h - 20); pItem->setFixedSize(tray_item_size, tray_item_size);
}
} }
} }
} }
} else { } else {
// 三方插件 // 三方插件
for (int i = 0; i < m_pluginLayout->count(); ++ i) { for (int i = 0; i < m_pluginLayout->count(); ++ i) {
PluginsItem *pItem = static_cast<PluginsItem *>(m_pluginLayout->itemAt(i)->widget()); QLayout *layout = m_pluginLayout->itemAt(i)->layout();
if (pItem != trashPlugin && pItem != shutdownPlugin && pItem != keyboardPlugin && pItem !=notificationPlugin) { if (layout) {
if (pItem->pluginName() == "datetime"){ PluginsItem *pItem = static_cast<PluginsItem *>(layout->itemAt(0)->widget());
pItem->setFixedSize(w, pItem->sizeHint().height()); if (pItem && pItem != trashPlugin && pItem != shutdownPlugin && pItem != keyboardPlugin && pItem !=notificationPlugin) {
} else if (pItem->pluginName() == "AiAssistant"){ if (pItem->pluginName() == "datetime") {
pItem->setFixedSize(w - 20, tray_item_size); pItem->setFixedSize(w, pItem->sizeHint().height());
} else { } else {
pItem->setFixedSize(w - 20, pItem->sizeHint().height()); pItem->setFixedSize(tray_item_size, tray_item_size);
}
} }
} }
} }
} }
int appTopAndBottomMargin = 0;
int appLeftAndRightMargin = 0;
int trayTopAndBottomMargin = 0;
int trayLeftAndRightMargin = 0;
if ((m_position == Position::Top) || (m_position == Position::Bottom)) {
appTopAndBottomMargin = (m_fixedAreaWidget->height() - appItemSize) / 2;
trayTopAndBottomMargin = (m_trayAreaWidget->height() - tray_item_size) / 2;
} else {
appLeftAndRightMargin = (m_fixedAreaWidget->width() - appItemSize) / 2;
trayLeftAndRightMargin = (m_trayAreaWidget->width() - tray_item_size) / 2;
}
m_fixedAreaLayout->setContentsMargins(appLeftAndRightMargin, appTopAndBottomMargin, appLeftAndRightMargin, appTopAndBottomMargin);
m_appAreaSonLayout->setContentsMargins(appLeftAndRightMargin, appTopAndBottomMargin, appLeftAndRightMargin, appTopAndBottomMargin);
m_trayAreaLayout->setContentsMargins(trayLeftAndRightMargin, trayTopAndBottomMargin, trayLeftAndRightMargin, trayTopAndBottomMargin);
//因为日期时间插件大小和其他插件大小有异,需要单独设置各插件的边距
//而不对日期时间插件设置边距
for (int i = 0; i < m_pluginLayout->count(); ++ i) {
QLayout *layout = m_pluginLayout->itemAt(i)->layout();
if (layout) {
PluginsItem *pItem = static_cast<PluginsItem *>(layout->itemAt(0)->widget());
if (pItem && pItem->pluginName() != "datetime") {
layout->setContentsMargins(trayLeftAndRightMargin, trayTopAndBottomMargin, trayLeftAndRightMargin, trayTopAndBottomMargin);
}
}
}
} }
void MainPanelControl::getTrayVisableItemCount() void MainPanelControl::getTrayVisableItemCount()

View File

@ -121,11 +121,7 @@ const QPixmap OnboardItem::loadSvg(const QString &fileName, const QSize &size) c
void OnboardItem::mousePressEvent(QMouseEvent *event) void OnboardItem::mousePressEvent(QMouseEvent *event)
{ {
if (containCursorPos()) { m_pressed = true;
m_pressed = true;
} else {
m_pressed = false;
}
update(); update();
@ -143,11 +139,7 @@ void OnboardItem::mouseReleaseEvent(QMouseEvent *event)
void OnboardItem::mouseMoveEvent(QMouseEvent *event) void OnboardItem::mouseMoveEvent(QMouseEvent *event)
{ {
if (containCursorPos()) { m_hover = true;
m_hover = true;
} else {
m_hover = false;
}
update(); update();
@ -167,17 +159,3 @@ void OnboardItem::resizeEvent(QResizeEvent *event)
{ {
QWidget::resizeEvent(event); QWidget::resizeEvent(event);
} }
bool OnboardItem::containCursorPos()
{
QPoint cursorPos = this->mapFromGlobal(QCursor::pos());
QRect rect(this->rect());
int iconSize = qMin(rect.width(), rect.height());
int w = (rect.width() - iconSize) / 2;
int h = (rect.height() - iconSize) / 2;
rect = rect.adjusted(w, h, -w, -h);
return rect.contains(cursorPos);
}

View File

@ -44,7 +44,6 @@ private:
void mouseMoveEvent(QMouseEvent *event) override; void mouseMoveEvent(QMouseEvent *event) override;
void leaveEvent(QEvent *event) override; void leaveEvent(QEvent *event) override;
void resizeEvent(QResizeEvent *event) override; void resizeEvent(QResizeEvent *event) override;
bool containCursorPos();
private: private:
Dock::DisplayMode m_displayMode; Dock::DisplayMode m_displayMode;

View File

@ -122,27 +122,9 @@ const QPixmap ShutdownWidget::loadSvg(const QString &fileName, const QSize &size
return pixmap; return pixmap;
} }
bool ShutdownWidget::containCursorPos()
{
QPoint cursorPos = this->mapFromGlobal(QCursor::pos());
QRect rect(this->rect());
int iconSize = qMin(rect.width(), rect.height());
int w = (rect.width() - iconSize) / 2;
int h = (rect.height() - iconSize) / 2;
rect = rect.adjusted(w, h, -w, -h);
return rect.contains(cursorPos);
}
void ShutdownWidget::mousePressEvent(QMouseEvent *event) void ShutdownWidget::mousePressEvent(QMouseEvent *event)
{ {
if (containCursorPos()) { m_pressed = true;
m_pressed = true;
} else {
m_pressed = false;
}
update(); update();
@ -160,11 +142,7 @@ void ShutdownWidget::mouseReleaseEvent(QMouseEvent *event)
void ShutdownWidget::mouseMoveEvent(QMouseEvent *event) void ShutdownWidget::mouseMoveEvent(QMouseEvent *event)
{ {
if (containCursorPos()) { m_hover = true;
m_hover = true;
} else {
m_hover = false;
}
update(); update();

View File

@ -43,7 +43,6 @@ protected:
private: private:
const QPixmap loadSvg(const QString &fileName, const QSize &size) const; const QPixmap loadSvg(const QString &fileName, const QSize &size) const;
bool containCursorPos();
private: private:
Dock::DisplayMode m_displayMode; Dock::DisplayMode m_displayMode;

View File

@ -134,17 +134,3 @@ void AbstractTrayWidget::resizeEvent(QResizeEvent *event)
setMaximumWidth(QWIDGETSIZE_MAX); setMaximumWidth(QWIDGETSIZE_MAX);
} }
} }
bool AbstractTrayWidget::containCursorPos()
{
QPoint cursorPos = this->mapFromGlobal(QCursor::pos());
QRect rect(this->rect());
int iconSize = qMin(rect.width(), rect.height());
int w = (rect.width() - iconSize) / 2;
int h = (rect.height() - iconSize) / 2;
rect = rect.adjusted(w, h, -w, -h);
return rect.contains(cursorPos);
}

View File

@ -60,7 +60,6 @@ protected:
void handleMouseRelease(); void handleMouseRelease();
const QRect perfectIconRect() const; const QRect perfectIconRect() const;
void resizeEvent(QResizeEvent *event) override; void resizeEvent(QResizeEvent *event) override;
bool containCursorPos();
private: private:
QTimer *m_handleMouseReleaseTimer; QTimer *m_handleMouseReleaseTimer;

View File

@ -149,11 +149,6 @@ void AbstractContainer::setExpand(const bool expand)
refreshVisible(); refreshVisible();
} }
//QSize AbstractContainer::sizeHint() const
//{
// return totalSize();
//}
void AbstractContainer::setItemSize(int itemSize) void AbstractContainer::setItemSize(int itemSize)
{ {
m_itemSize = itemSize; m_itemSize = itemSize;

View File

@ -149,9 +149,8 @@ void FashionTrayControlWidget::mouseReleaseEvent(QMouseEvent *event)
if (event->button() == Qt::LeftButton) { if (event->button() == Qt::LeftButton) {
event->accept(); event->accept();
if (containCursorPos()) { setExpanded(!m_expanded);
setExpanded(!m_expanded);
}
return; return;
} }
@ -165,11 +164,7 @@ void FashionTrayControlWidget::mousePressEvent(QMouseEvent *event)
return QWidget::mousePressEvent(event); return QWidget::mousePressEvent(event);
} }
if (containCursorPos()) { m_pressed = true;
m_pressed = true;
} else {
m_pressed = false;
}
update(); update();
@ -178,11 +173,7 @@ void FashionTrayControlWidget::mousePressEvent(QMouseEvent *event)
void FashionTrayControlWidget::enterEvent(QEvent *event) void FashionTrayControlWidget::enterEvent(QEvent *event)
{ {
if (containCursorPos()) { m_hover = true;
m_hover = true;
} else {
m_hover = false;
}
update(); update();
@ -203,19 +194,6 @@ void FashionTrayControlWidget::resizeEvent(QResizeEvent *event)
QWidget::resizeEvent(event); QWidget::resizeEvent(event);
} }
void FashionTrayControlWidget::mouseMoveEvent(QMouseEvent *event)
{
if (containCursorPos()) {
m_hover = true;
} else {
m_hover = false;
}
update();
QWidget::mouseMoveEvent(event);
}
void FashionTrayControlWidget::refreshArrowPixmap() void FashionTrayControlWidget::refreshArrowPixmap()
{ {
QString iconPath; QString iconPath;
@ -238,17 +216,3 @@ void FashionTrayControlWidget::refreshArrowPixmap()
const auto ratio = devicePixelRatioF(); const auto ratio = devicePixelRatioF();
m_arrowPix = ImageUtil::loadSvg(iconPath, ":/icons/resources/", PLUGIN_ICON_MAX_SIZE, ratio); m_arrowPix = ImageUtil::loadSvg(iconPath, ":/icons/resources/", PLUGIN_ICON_MAX_SIZE, ratio);
} }
bool FashionTrayControlWidget::containCursorPos()
{
QPoint cursorPos = this->mapFromGlobal(QCursor::pos());
QRect rect(this->rect());
int iconSize = qMin(rect.width(), rect.height());
int w = (rect.width() - iconSize) / 2;
int h = (rect.height() - iconSize) / 2;
rect = rect.adjusted(w, h, -w, -h);
return rect.contains(cursorPos);
}

View File

@ -48,11 +48,9 @@ protected:
void enterEvent(QEvent *event) override; void enterEvent(QEvent *event) override;
void leaveEvent(QEvent *event) override; void leaveEvent(QEvent *event) override;
void resizeEvent(QResizeEvent *event) override; void resizeEvent(QResizeEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
private: private:
void refreshArrowPixmap(); void refreshArrowPixmap();
bool containCursorPos();
private: private:
QTimer *m_expandDelayTimer; QTimer *m_expandDelayTimer;

View File

@ -141,11 +141,7 @@ void FashionTrayWidgetWrapper::mousePressEvent(QMouseEvent *event)
MousePressPoint = event->pos(); MousePressPoint = event->pos();
} }
if (containCursorPos()) { m_pressed = true;
m_pressed = true;
} else {
m_pressed = false;
}
update(); update();
@ -179,11 +175,7 @@ void FashionTrayWidgetWrapper::dragEnterEvent(QDragEnterEvent *event)
void FashionTrayWidgetWrapper::enterEvent(QEvent *event) void FashionTrayWidgetWrapper::enterEvent(QEvent *event)
{ {
if (containCursorPos()) { m_hover = true;
m_hover = true;
} else {
m_hover = false;
}
update(); update();
@ -228,11 +220,7 @@ void FashionTrayWidgetWrapper::handleMouseMove(QMouseEvent *event)
if(m_absTrayWidget.isNull()) if(m_absTrayWidget.isNull())
return; return;
if (containCursorPos()) { m_hover = true;
m_hover = true;
} else {
m_hover = false;
}
update(); update();
@ -244,10 +232,6 @@ void FashionTrayWidgetWrapper::handleMouseMove(QMouseEvent *event)
return; return;
} }
if (!containCursorPos()) {
return;
}
event->accept(); event->accept();
QDrag drag(this); QDrag drag(this);
@ -283,20 +267,6 @@ void FashionTrayWidgetWrapper::onTrayWidgetClicked()
setAttention(false); setAttention(false);
} }
bool FashionTrayWidgetWrapper::containCursorPos()
{
QPoint cursorPos = this->mapFromGlobal(QCursor::pos());
QRect rect(this->rect());
int iconSize = qMin(rect.width(), rect.height());
int w = (rect.width() - iconSize) / 2;
int h = (rect.height() - iconSize) / 2;
rect = rect.adjusted(w, h, -w, -h);
return rect.contains(cursorPos);
}
bool FashionTrayWidgetWrapper::attention() const bool FashionTrayWidgetWrapper::attention() const
{ {
return m_attention; return m_attention;

View File

@ -64,7 +64,6 @@ private:
void handleMouseMove(QMouseEvent *event); void handleMouseMove(QMouseEvent *event);
void onTrayWidgetNeedAttention(); void onTrayWidgetNeedAttention();
void onTrayWidgetClicked(); void onTrayWidgetClicked();
bool containCursorPos();
private: private:
QPointer<AbstractTrayWidget> m_absTrayWidget; QPointer<AbstractTrayWidget> m_absTrayWidget;

View File

@ -560,12 +560,7 @@ QPixmap SNITrayWidget::newIconPixmap(IconType iconType)
void SNITrayWidget::enterEvent(QEvent *event) void SNITrayWidget::enterEvent(QEvent *event)
{ {
if (containCursorPos()) { m_popupTipsDelayTimer->start();
m_popupTipsDelayTimer->start();
} else {
m_popupTipsDelayTimer->stop();
hidePopup();
}
AbstractTrayWidget::enterEvent(event); AbstractTrayWidget::enterEvent(event);
} }
@ -581,18 +576,6 @@ void SNITrayWidget::leaveEvent(QEvent *event)
AbstractTrayWidget::leaveEvent(event); AbstractTrayWidget::leaveEvent(event);
} }
void SNITrayWidget::mouseMoveEvent(QMouseEvent *event)
{
if (containCursorPos()) {
m_popupTipsDelayTimer->start();
} else {
m_popupTipsDelayTimer->stop();
hidePopup();
}
AbstractTrayWidget::mouseMoveEvent(event);
}
void SNITrayWidget::showHoverTips() void SNITrayWidget::showHoverTips()
{ {
if (PopupWindow->model()) if (PopupWindow->model())

View File

@ -101,7 +101,6 @@ private Q_SLOTS:
void popupWindowAccept(); void popupWindowAccept();
void enterEvent(QEvent *event) override; void enterEvent(QEvent *event) override;
void leaveEvent(QEvent *event) override; void leaveEvent(QEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
private: private:
void paintEvent(QPaintEvent *e) override; void paintEvent(QPaintEvent *e) override;

View File

@ -203,12 +203,7 @@ void SystemTrayItem::enterEvent(QEvent *event)
return; return;
} }
if (containCursorPos()) { m_popupTipsDelayTimer->start();
m_popupTipsDelayTimer->start();
} else {
m_popupTipsDelayTimer->stop();
hidePopup();
}
update(); update();
@ -294,18 +289,6 @@ void SystemTrayItem::showEvent(QShowEvent *event)
return AbstractTrayWidget::showEvent(event); return AbstractTrayWidget::showEvent(event);
} }
void SystemTrayItem::mouseMoveEvent(QMouseEvent *event)
{
if (containCursorPos()) {
m_popupTipsDelayTimer->start();
} else {
m_popupTipsDelayTimer->stop();
hidePopup();
}
AbstractTrayWidget::mouseMoveEvent(event);
}
const QPoint SystemTrayItem::popupMarkPoint() const const QPoint SystemTrayItem::popupMarkPoint() const
{ {
QPoint p(topleftPoint()); QPoint p(topleftPoint());

View File

@ -72,7 +72,6 @@ protected:
void mousePressEvent(QMouseEvent *event) override; void mousePressEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override; void mouseReleaseEvent(QMouseEvent *event) override;
void showEvent(QShowEvent* event) override; void showEvent(QShowEvent* event) override;
void mouseMoveEvent(QMouseEvent* event) override;
protected: protected:
const QPoint popupMarkPoint() const; const QPoint popupMarkPoint() const;

View File

@ -147,11 +147,7 @@ void XEmbedTrayWidget::mouseMoveEvent(QMouseEvent *e)
return; return;
} }
if (containCursorPos()) { m_sendHoverEvent->start();
m_sendHoverEvent->start();;
} else {
m_sendHoverEvent->stop();
}
} }
void XEmbedTrayWidget::configContainerPosition() void XEmbedTrayWidget::configContainerPosition()