diff --git a/frame/window/docktraywindow.cpp b/frame/window/docktraywindow.cpp index 32eb4a0de..b1cc9e55f 100644 --- a/frame/window/docktraywindow.cpp +++ b/frame/window/docktraywindow.cpp @@ -318,8 +318,6 @@ void DockTrayWindow::initConnection() connect(m_model, &TrayModel::rowCountChanged, this, &DockTrayWindow::onUpdateComponentSize); connect(m_model, &TrayModel::rowCountChanged, m_trayView, &TrayGridView::onUpdateEditorView); connect(m_model, &TrayModel::requestRefreshEditor, m_trayView, &TrayGridView::onUpdateEditorView); - connect(m_trayView, &TrayGridView::requestRemove, m_model, &TrayModel::removeRow); - connect(m_trayView, &TrayGridView::requestRemove, this, &DockTrayWindow::onUpdateComponentSize); connect(m_trayView, &TrayGridView::dragFinished, this, [ this ] { // 如果拖拽结束,则隐藏托盘 Q_EMIT m_delegate->requestDrag(false); diff --git a/frame/window/tray/tray_delegate.cpp b/frame/window/tray/tray_delegate.cpp index 3945e8d57..7b0359d73 100644 --- a/frame/window/tray/tray_delegate.cpp +++ b/frame/window/tray/tray_delegate.cpp @@ -151,7 +151,7 @@ void TrayDelegate::setEditorData(QWidget *editor, const QModelIndex &index) cons { BaseTrayWidget *widget = static_cast(editor); if (widget) { - widget->setNeedShow(true); + widget->setNeedShow(!index.data(TrayModel::Blank).toBool()); } } @@ -222,7 +222,7 @@ ExpandIconWidget *TrayDelegate::expandWidget() if (!dataModel) return nullptr; - for (int i = 0; i < dataModel->rowCount() - 1; i++) { + for (int i = 0; i < dataModel->rowCount(); i++) { QModelIndex index = dataModel->index(i, 0); ExpandIconWidget *widget = qobject_cast(m_listView->indexWidget(index)); if (widget) diff --git a/frame/window/tray/tray_gridview.cpp b/frame/window/tray/tray_gridview.cpp index 35c55e82a..2df7a6f10 100644 --- a/frame/window/tray/tray_gridview.cpp +++ b/frame/window/tray/tray_gridview.cpp @@ -388,6 +388,26 @@ const QModelIndex TrayGridView::getIndexFromPos(QPoint currentPoint) const return QModelIndex(); } +bool TrayGridView::mouseInDock() +{ + QPoint mousePosition = QCursor::pos(); + QRect dockRect(topLevelWidget()->pos(), topLevelWidget()->size()); + switch (m_positon) { + case Dock::Position::Bottom: { + return mousePosition.y() > dockRect.top(); + } + case Dock::Position::Left: { + return mousePosition.x() < dockRect.right(); + } + case Dock::Position::Top: { + return mousePosition.y() < dockRect.bottom(); + } + case Dock::Position::Right: { + return mousePosition.x() > dockRect.left(); + } + } +} + void TrayGridView::handleDropEvent(QDropEvent *e) { setState(DListView::NoState); @@ -492,7 +512,7 @@ bool TrayGridView::beginDrag(Qt::DropActions supportedActions) listModel->setDragKey(modelIndex.data(TrayModel::Role::KeyRole).toString()); listModel->setDragingIndex(modelIndex); // 删除当前的图标 - WinInfo winInfo = listModel->takeIndex(modelIndex); + WinInfo winInfo = listModel->getWinInfo(modelIndex); Qt::DropAction dropAct = drag->exec(supportedActions); @@ -504,12 +524,15 @@ bool TrayGridView::beginDrag(Qt::DropActions supportedActions) if (listModel->isIconTray()) { // 如果当前是从托盘区域释放,按照原来的流程走 QPropertyAnimation *posAni = new QPropertyAnimation(pixLabel, "pos", pixLabel); - connect(posAni, &QPropertyAnimation::finished, [ this, listModel, pixLabel, modelIndex, winInfo ] () { + connect(posAni, &QPropertyAnimation::finished, [ this, listModel, pixLabel, winInfo ] () { pixLabel->hide(); pixLabel->deleteLater(); listModel->setDragKey(QString()); - listModel->insertRow(modelIndex.row(), winInfo); clearDragModelIndex(); + QModelIndex dropIndex = indexAt(m_dropPos); + // 拖转完成后,将拖动的图标插入到新的位置 + //listModel->moveToIndex(winInfo, dropIndex.row()); + listModel->dropSwap(dropIndex.row()); listModel->setExpandVisible(!TrayModel::getIconModel()->isEmpty()); m_dropPos = QPoint(); @@ -518,7 +541,7 @@ bool TrayGridView::beginDrag(Qt::DropActions supportedActions) onUpdateEditorView(); Q_EMIT dragFinished(); }); - + // 拖拽完成后,将当前拖拽的item从原来的列表中移除,后来会根据实际情况将item插入到特定的列表中 posAni->setEasingCurve(QEasingCurve::Linear); posAni->setDuration(m_aniDuringTime); posAni->setStartValue((QCursor::pos() - QPoint(0, pixLabel->height() / 2))); @@ -528,19 +551,25 @@ bool TrayGridView::beginDrag(Qt::DropActions supportedActions) Q_EMIT dragFinished(); } else { - // 如果当前是从任务栏区域释放,则将释放后的图标放到托盘 listModel->setDragKey(QString()); clearDragModelIndex(); TrayModel *trayModel = TrayModel::getIconModel(); - trayModel->addRow(winInfo); + if (!mouseInDock()) { + listModel->removeWinInfo(winInfo); + trayModel->addRow(winInfo); + trayModel->saveConfig(-1, winInfo); + } + // 如果是任务栏的的托盘区,则更新是否显示展开入口 + listModel->setExpandVisible(trayModel->rowCount() > 0, false); m_dragPos = QPoint(); m_dropPos = QPoint(); - - trayModel->saveConfig(-1, winInfo); Q_EMIT dragFinished(); } } else { + // 拖拽完成后,将当前拖拽的item从原来的列表中移除,后来会根据实际情况将item插入到特定的列表中 + listModel->removeWinInfo(winInfo); + // 这里是将图标从一个区域移动到另外一个区域 listModel->setDragKey(QString()); clearDragModelIndex(); if (listModel->isIconTray()) { diff --git a/frame/window/tray/tray_gridview.h b/frame/window/tray/tray_gridview.h index 3951de3c6..60dc54762 100644 --- a/frame/window/tray/tray_gridview.h +++ b/frame/window/tray/tray_gridview.h @@ -51,7 +51,6 @@ public Q_SLOTS: void onUpdateEditorView(); Q_SIGNALS: - void requestRemove(const QString &); void dragLeaved(); void dragEntered(); void dragFinished(); @@ -76,6 +75,7 @@ private: void initUi(); void createAnimation(const int pos, const bool moveNext, const bool isLastAni); const QModelIndex getIndexFromPos(QPoint currentPoint) const; + bool mouseInDock(); private: QEasingCurve::Type m_aniCurveType; diff --git a/frame/window/tray/tray_model.cpp b/frame/window/tray/tray_model.cpp index 4ef2876b7..fccc210b3 100644 --- a/frame/window/tray/tray_model.cpp +++ b/frame/window/tray/tray_model.cpp @@ -93,19 +93,16 @@ void TrayModel::dropSwap(int newPos) if (!m_dragModelIndex.isValid()) return; - removeRows(m_dragModelIndex.row(), 1, QModelIndex()); - dropInsert(newPos); + int row = m_dragModelIndex.row(); - emit QAbstractItemModel::dataChanged(m_dragModelIndex, m_dropModelIndex); -} + if (row < m_winInfos.size()) + m_dragInfo = m_winInfos.takeAt(row); -void TrayModel::dropInsert(int newPos) -{ - beginInsertRows(QModelIndex(), newPos, newPos); WinInfo name = m_dragInfo; m_winInfos.insert(newPos, name); - // 更新输入法的位置 - endInsertRows(); + + emit QAbstractItemModel::dataChanged(m_dragModelIndex, m_dropModelIndex); + requestRefreshEditor(); } void TrayModel::clearDragDropIndex() @@ -115,7 +112,6 @@ void TrayModel::clearDragDropIndex() m_dragModelIndex = m_dropModelIndex = QModelIndex(); - Q_EMIT requestRefreshEditor(); emit QAbstractItemModel::dataChanged(startIndex, endIndex); emit QAbstractItemModel::dataChanged(endIndex, startIndex); } @@ -125,7 +121,6 @@ void TrayModel::setDragingIndex(const QModelIndex index) m_dragModelIndex = index; m_dropModelIndex = index; - Q_EMIT requestRefreshEditor(); emit QAbstractListModel::dataChanged(index, index); } @@ -278,7 +273,6 @@ QVariant TrayModel::data(const QModelIndex &index, int role) const bool TrayModel::removeRows(int row, int count, const QModelIndex &parent) { Q_UNUSED(count); - Q_UNUSED(parent); if (m_winInfos.size() - 1 < row) return false; @@ -353,20 +347,13 @@ void TrayModel::clear() Q_EMIT rowCountChanged(); } -WinInfo TrayModel::takeIndex(const QModelIndex &index) +WinInfo TrayModel::getWinInfo(const QModelIndex &index) { int row = index.row(); if (row < 0 || row >= m_winInfos.size()) return WinInfo(); - WinInfo win = m_winInfos[row]; - beginResetModel(); - m_winInfos.removeAt(row); - endResetModel(); - - Q_EMIT rowCountChanged(); - - return win; + return m_winInfos[row]; } void TrayModel::onXEmbedTrayAdded(quint32 winId) @@ -462,6 +449,21 @@ void TrayModel::saveConfig(int index, const WinInfo &winInfo) SETTINGCONFIG->setValue(DOCKQUICKTRAYNAME, m_fixedTrayNames); } +void TrayModel::removeWinInfo(WinInfo winInfo) +{ + for (const WinInfo &info : m_winInfos) { + if (winInfo == info) { + int index = m_winInfos.indexOf(info); + beginRemoveRows(QModelIndex(), index, index); + m_winInfos.removeOne(info); + endRemoveRows(); + + Q_EMIT rowCountChanged(); + break; + } + } +} + bool TrayModel::inTrayConfig(const QString itemKey) const { if (m_isTrayIcon) { @@ -640,7 +642,7 @@ void TrayModel::onIndicatorAdded(const QString &indicatorName) const QString &itemKey = IndicatorTrayItem::toIndicatorKey(indicatorName); for (const WinInfo &info : m_winInfos) { - if (info.key == itemKey) + if (info.itemKey == itemKey) return; } @@ -648,7 +650,7 @@ void TrayModel::onIndicatorAdded(const QString &indicatorName) WinInfo info; info.type = Incicator; info.key = itemKey; - info.itemKey = IndicatorTrayItem::toIndicatorKey(indicatorName); + info.itemKey = itemKey; m_winInfos.append(info); sortItems(); @@ -754,7 +756,7 @@ void TrayModel::onSettingChanged(const QString &key, const QVariant &value) void TrayModel::removeRow(const QString &itemKey) { for (const WinInfo &info : m_winInfos) { - if (info.key == itemKey) { + if (info.itemKey == itemKey) { int index = m_winInfos.indexOf(info); beginRemoveRows(QModelIndex(), index, index); m_winInfos.removeOne(info); diff --git a/frame/window/tray/tray_model.h b/frame/window/tray/tray_model.h index 7eb6e25a6..a3713a830 100644 --- a/frame/window/tray/tray_model.h +++ b/frame/window/tray/tray_model.h @@ -91,7 +91,6 @@ public: static TrayModel *getIconModel(); void dropSwap(int newPos); - void dropInsert(int newPos); void clearDragDropIndex(); void setDragingIndex(const QModelIndex index); @@ -111,8 +110,9 @@ public: bool isEmpty() const; void clear(); - WinInfo takeIndex(const QModelIndex &index); + WinInfo getWinInfo(const QModelIndex &index); void saveConfig(int index, const WinInfo &winInfo); + void removeWinInfo(WinInfo winInfo); Q_SIGNALS: void requestUpdateIcon(quint32); @@ -121,7 +121,6 @@ Q_SIGNALS: void requestRefreshEditor(); public Q_SLOTS: - void removeRow(const QString &itemKey); void addRow(WinInfo info); void insertRow(int index, WinInfo info); @@ -152,6 +151,7 @@ protected: Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE; private: + void removeRow(const QString &itemKey); bool exist(const QString &itemKey); QString fileNameByServiceName(const QString &serviceName) const; bool isTypeWriting(const QString &servicePath) const; diff --git a/frame/window/tray/widgets/expandiconwidget.cpp b/frame/window/tray/widgets/expandiconwidget.cpp index 4e34c59d8..77a3cbe5b 100644 --- a/frame/window/tray/widgets/expandiconwidget.cpp +++ b/frame/window/tray/widgets/expandiconwidget.cpp @@ -171,7 +171,6 @@ TrayGridWidget *ExpandIconWidget::popupTrayView() connect(trayDelegate, &TrayDelegate::removeRow, trayView, [ = ](const QModelIndex &index) { trayView->model()->removeRow(index.row(),index.parent()); }); - connect(trayView, &TrayGridView::requestRemove, trayModel, &TrayModel::removeRow); connect(trayModel, &TrayModel::requestOpenEditor, trayView, [ trayView ](const QModelIndex &index) { trayView->openPersistentEditor(index); }); @@ -335,7 +334,7 @@ ExpandIconWidget *TrayGridWidget::expandWidget() const if (!dataModel) return nullptr; - for (int i = 0; i < dataModel->rowCount() - 1; i++) { + for (int i = 0; i < dataModel->rowCount(); i++) { QModelIndex index = dataModel->index(i, 0); ExpandIconWidget *widget = qobject_cast(m_referGridView->indexWidget(index)); if (widget) diff --git a/frame/window/tray/widgets/systempluginitem.cpp b/frame/window/tray/widgets/systempluginitem.cpp index bc21dca9b..29a98b906 100644 --- a/frame/window/tray/widgets/systempluginitem.cpp +++ b/frame/window/tray/widgets/systempluginitem.cpp @@ -47,9 +47,11 @@ SystemPluginItem::SystemPluginItem(PluginsItemInterface *const pluginInter, cons { qDebug() << "load tray plugins item: " << m_pluginInter->pluginName() << itemKey << m_centralWidget; - m_centralWidget->setParent(this); - m_centralWidget->setVisible(true); - m_centralWidget->installEventFilter(this); + if (m_centralWidget) { + m_centralWidget->setParent(this); + m_centralWidget->setVisible(true); + m_centralWidget->installEventFilter(this); + } QBoxLayout *hLayout = new QHBoxLayout(this); hLayout->addWidget(m_centralWidget); @@ -89,6 +91,8 @@ SystemPluginItem::SystemPluginItem(PluginsItemInterface *const pluginInter, cons m_popupAdjustDelayTimer->setInterval(10); m_popupAdjustDelayTimer->setSingleShot(true); + installEventFilter(this); + connect(m_popupTipsDelayTimer, &QTimer::timeout, this, &SystemPluginItem::showHoverTips); connect(m_popupAdjustDelayTimer, &QTimer::timeout, this, &SystemPluginItem::updatePopupPosition, Qt::QueuedConnection); connect(m_contextMenu, &QMenu::triggered, this, &SystemPluginItem::menuActionClicked); @@ -188,6 +192,14 @@ bool SystemPluginItem::event(QEvent *event) return BaseTrayWidget::event(event); } +bool SystemPluginItem::eventFilter(QObject *watched, QEvent *event) +{ + if (watched == this && event->type() == QEvent::DeferredDelete) + m_centralWidget->setParent(nullptr); + + return BaseTrayWidget::eventFilter(watched, event); +} + void SystemPluginItem::enterEvent(QEvent *event) { if (checkGSettingsControl()) { diff --git a/frame/window/tray/widgets/systempluginitem.h b/frame/window/tray/widgets/systempluginitem.h index 7e1fa28ec..cba056d27 100644 --- a/frame/window/tray/widgets/systempluginitem.h +++ b/frame/window/tray/widgets/systempluginitem.h @@ -67,6 +67,7 @@ signals: protected: bool event(QEvent *event) override; + bool eventFilter(QObject *watched, QEvent *event) override; void enterEvent(QEvent *event) override; void leaveEvent(QEvent *event) override; void mousePressEvent(QMouseEvent *event) override; diff --git a/frame/window/traymanagerwindow.cpp b/frame/window/traymanagerwindow.cpp index 3440f8ae2..031fb166a 100644 --- a/frame/window/traymanagerwindow.cpp +++ b/frame/window/traymanagerwindow.cpp @@ -270,7 +270,6 @@ void TrayManagerWindow::initUi() void TrayManagerWindow::initConnection() { - connect(m_trayView, &TrayGridView::requestRemove, m_model, &TrayModel::removeRow); connect(m_model, &TrayModel::rowCountChanged, this, &TrayManagerWindow::onTrayCountChanged); connect(m_model, &TrayModel::rowCountChanged, m_trayView, &TrayGridView::onUpdateEditorView); connect(m_model, &TrayModel::requestRefreshEditor, m_trayView, &TrayGridView::onUpdateEditorView);