diff --git a/panels/dock/tray/CMakeLists.txt b/panels/dock/tray/CMakeLists.txt index b5fc161c4..6c23b2d16 100644 --- a/panels/dock/tray/CMakeLists.txt +++ b/panels/dock/tray/CMakeLists.txt @@ -17,8 +17,6 @@ qt_add_qml_module(dock-tray SOURCES traysortordermodel.cpp traysortordermodel.h - trayitempositionregister.cpp - trayitempositionregister.h trayitempositionmanager.cpp trayitempositionmanager.h ksortfilterproxymodel.cpp diff --git a/panels/dock/tray/package/TrayContainer.qml b/panels/dock/tray/package/TrayContainer.qml index 84e13a2d4..1d204a616 100644 --- a/panels/dock/tray/package/TrayContainer.qml +++ b/panels/dock/tray/package/TrayContainer.qml @@ -84,8 +84,6 @@ Item { readonly property int itemPadding: DDT.TrayItemPositionManager.itemPadding property int trayHeight: 50 - property size containerSize: DDT.TrayItemPositionManager.visualSize - property bool isDragging: DDT.TraySortOrderModel.actionsAlwaysVisible property bool animationEnable: false // visiualIndex default value is -1 property int dropHoverIndex: -1 @@ -183,9 +181,6 @@ Item { DDT.TrayItemPositionManager.orientation = Qt.binding(function() { return root.isHorizontal ? Qt.Horizontal : Qt.Vertical }); - DDT.TrayItemPositionManager.visualItemCount = Qt.binding(function() { - return root.model.rowCount - }); DDT.TrayItemPositionManager.dockHeight = Qt.binding(function() { return root.trayHeight }); diff --git a/panels/dock/tray/package/TrayItemPositioner.qml b/panels/dock/tray/package/TrayItemPositioner.qml index 890e69054..01d5ec846 100644 --- a/panels/dock/tray/package/TrayItemPositioner.qml +++ b/panels/dock/tray/package/TrayItemPositioner.qml @@ -13,11 +13,6 @@ Control { property bool isDragging: DDT.TraySortOrderModel.actionsAlwaysVisible - DDT.TrayItemPositionRegister.visualIndex: DelegateModel.visualIndex - DDT.TrayItemPositionRegister.visualSize: (model.sectionType !== "stashed") ? Qt.size(width, height) : Qt.size(0, 0) - DDT.TrayItemPositionRegister.surfaceId: model.surfaceId - DDT.TrayItemPositionRegister.sectionType: model.sectionType - width: visualSize.width !== 0 ? visualSize.width : DDT.TrayItemPositionManager.itemVisualSize.width height: visualSize.height !== 0 ? visualSize.height : DDT.TrayItemPositionManager.itemVisualSize.height diff --git a/panels/dock/tray/package/tray.qml b/panels/dock/tray/package/tray.qml index 6fbc0b120..c4c4f2ae4 100644 --- a/panels/dock/tray/package/tray.qml +++ b/panels/dock/tray/package/tray.qml @@ -98,9 +98,6 @@ AppletItem { trayHeight: isHorizontal ? tray.implicitHeight : tray.implicitWidth surfaceAcceptor: isTrayPluginPopup color: "transparent" - Component.onCompleted: { - DDT.TrayItemPositionManager.layoutHealthCheck(1500) - } } function isTrayPluginPopup(surfaceId) diff --git a/panels/dock/tray/trayitempositionmanager.cpp b/panels/dock/tray/trayitempositionmanager.cpp index 80c45b3f5..48a54ae14 100644 --- a/panels/dock/tray/trayitempositionmanager.cpp +++ b/panels/dock/tray/trayitempositionmanager.cpp @@ -15,80 +15,6 @@ static const int itemPadding = 4; static const int itemSpacing = 2; static const QSize itemVisualSize = QSize(itemSize + itemPadding * 2, itemSize + itemPadding * 2); -void TrayItemPositionManager::registerVisualItemSize(int index, const QSize &size) -{ - while (m_registeredItemsSize.count() < (index + 1)) { - m_registeredItemsSize.append(itemVisualSize); - } - QSize oldSize = m_registeredItemsSize[index]; - m_registeredItemsSize[index] = size; - - // The registered itemsize may change, and the layout needs to be updated when it does. - if (oldSize != size) { - emit visualItemSizeChanged(); - } -} - -QSize TrayItemPositionManager::visualItemSize(int index) const -{ - if (m_registeredItemsSize.count() <= index) return itemVisualSize; - return m_registeredItemsSize.at(index); -} - -QSize TrayItemPositionManager::visualSize(int index, bool includeLastSpacing) const -{ - if (m_orientation == Qt::Horizontal) { - int width = 0; - for (int i = 0; i <= index; i++) { - width += (visualItemSize(i).width() + itemSpacing); - } - return QSize((!includeLastSpacing && index > 0) ? (width - itemSpacing) : width, m_dockHeight); - } else { - int height = 0; - for (int i = 0; i <= index; i++) { - height += (visualItemSize(i).height() + itemSpacing); - } - return QSize(m_dockHeight, (!includeLastSpacing && index > 0) ? (height - itemSpacing) : height); - } -} - -DropIndex TrayItemPositionManager::itemIndexByPoint(const QPoint point) const -{ - if (m_orientation == Qt::Horizontal) { - int pos = point.x(); - int width = 0; - for (int i = 0; i < m_visualItemCount; i++) { - int visualWidth = visualItemSize(i).width(); - if (pos < (width + visualWidth + itemSpacing)) { - pos -= width; - return DropIndex { - .index = i, - .isOnItem = pos <= visualWidth, - .isBefore = pos < (visualWidth / 2) - }; - } - width += (visualWidth + itemSpacing); - } - return DropIndex { .index = m_visualItemCount - 1 }; - } else { - int pos = point.y(); - int height = 0; - for (int i = 0; i <= m_visualItemCount; i++) { - int visualHeight = visualItemSize(i).height(); - if (pos < (height + visualHeight + itemSpacing)) { - pos -= height; - return DropIndex { - .index = i, - .isOnItem = pos <= visualHeight, - .isBefore = pos < (visualHeight / 2) - }; - } - height += (visualHeight + itemSpacing); - } - return DropIndex { .index = m_visualItemCount - 1 }; - } -} - Qt::Orientation TrayItemPositionManager::orientation() const { return m_orientation; @@ -99,49 +25,12 @@ int TrayItemPositionManager::dockHeight() const return m_dockHeight; } -// This should only be used to check layout issue or workaround layout issues. -// Do NOT rely on this to correct layout issue in a long run! -void TrayItemPositionManager::layoutHealthCheck(int delayMs) -{ - QTimer::singleShot(delayMs, [this](){ - if (m_dockHeight == 0) { - qWarning() << "dock height is not valid, aborting layout health check..."; - return; - } - QSize result(visualSize(m_visualItemCount - 1, false)); - if (m_visualSize != result) { - qWarning() << "layout size not matched, will trigger a force re-layout..."; - emit orientationChanged(m_orientation); - } else { - qDebug() << "no problem founded while performing layout health check!"; - } - }); - qDebug() << "layout health check scheduled!"; -} - TrayItemPositionManager::TrayItemPositionManager(QObject *parent) : QObject(parent) { m_itemSpacing = itemSpacing; m_itemPadding = itemPadding; m_itemVisualSize = itemVisualSize; - - connect(this, &TrayItemPositionManager::visualItemCountChanged, - this, &TrayItemPositionManager::updateVisualSize); - connect(this, &TrayItemPositionManager::dockHeightChanged, - this, &TrayItemPositionManager::updateVisualSize); - connect(this, &TrayItemPositionManager::orientationChanged, - this, &TrayItemPositionManager::updateVisualSize); - connect(this, &TrayItemPositionManager::visualItemSizeChanged, - this, &TrayItemPositionManager::updateVisualSize); -} - -void TrayItemPositionManager::updateVisualSize() -{ - if (m_dockHeight == 0) return; - QSize result(visualSize(m_visualItemCount - 1, false)); - qDebug() << "updateVisualSize()" << m_dockHeight << result; - setProperty("visualSize", result); } } diff --git a/panels/dock/tray/trayitempositionmanager.h b/panels/dock/tray/trayitempositionmanager.h index f2f5e9f86..355eaa57a 100644 --- a/panels/dock/tray/trayitempositionmanager.h +++ b/panels/dock/tray/trayitempositionmanager.h @@ -28,10 +28,6 @@ class TrayItemPositionManager : public QObject // dock properties, to notify tray items its property has been changed Q_PROPERTY(Qt::Orientation orientation MEMBER m_orientation NOTIFY orientationChanged) Q_PROPERTY(int dockHeight MEMBER m_dockHeight NOTIFY dockHeightChanged) - // position manager properties, when tray items reports visualPositionChanged, re-calculate this - Q_PROPERTY(QSize visualSize MEMBER m_visualSize NOTIFY visualSizeChanged) - // position manager properties, use to know how to calculate the actual width of visualSize - Q_PROPERTY(int visualItemCount MEMBER m_visualItemCount NOTIFY visualItemCountChanged) Q_PROPERTY(QSize itemVisualSize MEMBER m_itemVisualSize CONSTANT FINAL) Q_PROPERTY(int itemSpacing MEMBER m_itemSpacing CONSTANT FINAL) Q_PROPERTY(int itemPadding MEMBER m_itemPadding CONSTANT FINAL) @@ -51,13 +47,8 @@ class TrayItemPositionManager : public QObject return &instance(); } - void registerVisualItemSize(int index, const QSize & size); - QSize visualItemSize(int index) const; - QSize visualSize(int index, bool includeLastSpacing = true) const; - Q_INVOKABLE DropIndex itemIndexByPoint(const QPoint point) const; Qt::Orientation orientation() const; int dockHeight() const; - Q_INVOKABLE void layoutHealthCheck(int delayMs = 200); signals: void orientationChanged(Qt::Orientation); @@ -69,13 +60,8 @@ class TrayItemPositionManager : public QObject private: explicit TrayItemPositionManager(QObject *parent = nullptr); - void updateVisualSize(); - Qt::Orientation m_orientation; - QSize m_visualSize; int m_dockHeight; - int m_visualItemCount; - QList m_registeredItemsSize; QSize m_itemVisualSize; int m_itemSpacing; int m_itemPadding; diff --git a/panels/dock/tray/trayitempositionregister.cpp b/panels/dock/tray/trayitempositionregister.cpp deleted file mode 100644 index 0f1dd0ad2..000000000 --- a/panels/dock/tray/trayitempositionregister.cpp +++ /dev/null @@ -1,54 +0,0 @@ -// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: GPL-3.0-or-later - -#include "trayitempositionregister.h" - -#include "trayitempositionmanager.h" - -namespace docktray { - -TrayItemPositionRegisterAttachedType::TrayItemPositionRegisterAttachedType(QObject *parent) - : QObject(parent) -{ - // register / update visual position - connect(this, &TrayItemPositionRegisterAttachedType::visualIndexChanged, - this, [this](){ - registerVisualSize(); - emit visualPositionChanged(); - }); - connect(this, &TrayItemPositionRegisterAttachedType::visualSizeChanged, - this, [this](){ - registerVisualSize(); - emit visualPositionChanged(); - }); - // recalculate position - connect(&TrayItemPositionManager::instance(), &TrayItemPositionManager::orientationChanged, - this, &TrayItemPositionRegisterAttachedType::visualPositionChanged); - connect(&TrayItemPositionManager::instance(), &TrayItemPositionManager::dockHeightChanged, - this, &TrayItemPositionRegisterAttachedType::visualPositionChanged); - connect(&TrayItemPositionManager::instance(), &TrayItemPositionManager::visualItemCountChanged, - this, &TrayItemPositionRegisterAttachedType::visualPositionChanged); - connect(&TrayItemPositionManager::instance(), &TrayItemPositionManager::visualItemSizeChanged, - this, &TrayItemPositionRegisterAttachedType::visualPositionChanged); -} - -QPoint TrayItemPositionRegisterAttachedType::visualPosition() const -{ - TrayItemPositionManager & pm = TrayItemPositionManager::instance(); - if (pm.orientation() == Qt::Horizontal) { - int width = m_visualIndex == 0 ? 0 : pm.visualSize(m_visualIndex - 1).width(); - return QPoint(width, (pm.dockHeight() - m_visualSize.height()) / 2); - } else { - int height = m_visualIndex == 0 ? 0 : pm.visualSize(m_visualIndex - 1).height(); - return QPoint((pm.dockHeight() - m_visualSize.width()) / 2, height); - } -} - -void TrayItemPositionRegisterAttachedType::registerVisualSize() -{ - if (m_visualIndex == -1 || m_visualSize.isEmpty()) return; - TrayItemPositionManager::instance().registerVisualItemSize(m_visualIndex, m_visualSize); -} - -} diff --git a/panels/dock/tray/trayitempositionregister.h b/panels/dock/tray/trayitempositionregister.h deleted file mode 100644 index 1de6bf742..000000000 --- a/panels/dock/tray/trayitempositionregister.h +++ /dev/null @@ -1,57 +0,0 @@ -// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: GPL-3.0-or-later - -#pragma once - -#include -#include -#include - -namespace docktray { - -class TrayItemPositionRegisterAttachedType : public QObject -{ - Q_OBJECT - Q_PROPERTY(QString surfaceId MEMBER m_surfaceId NOTIFY surfaceIdChanged) - Q_PROPERTY(QString sectionType MEMBER m_sectionType NOTIFY sectionTypeChanged) - Q_PROPERTY(int visualIndex MEMBER m_visualIndex NOTIFY visualIndexChanged) - Q_PROPERTY(QSize visualSize MEMBER m_visualSize NOTIFY visualSizeChanged) - Q_PROPERTY(QPoint visualPosition READ visualPosition NOTIFY visualPositionChanged) - QML_ANONYMOUS -public: - TrayItemPositionRegisterAttachedType(QObject *parent); - - QPoint visualPosition() const; - -signals: - void surfaceIdChanged(QString); - void sectionTypeChanged(QString); - void visualIndexChanged(int); - void visualSizeChanged(QSize); - void visualPositionChanged(); - -private: - void registerVisualSize(); - - QString m_surfaceId; - QString m_sectionType; - int m_visualIndex = -1; - QSize m_visualSize; -}; - -// ------------------------------------------------------- - -class TrayItemPositionRegister : public QObject -{ - Q_OBJECT - QML_ATTACHED(TrayItemPositionRegisterAttachedType) - QML_ELEMENT -public: - static TrayItemPositionRegisterAttachedType *qmlAttachedProperties(QObject *object) - { - return new TrayItemPositionRegisterAttachedType(object); - } -}; - -}