diff --git a/src/private/DropIndicatorOverlayInterface.cpp b/src/private/DropIndicatorOverlayInterface.cpp index 61710c9b..d4fee8e2 100644 --- a/src/private/DropIndicatorOverlayInterface.cpp +++ b/src/private/DropIndicatorOverlayInterface.cpp @@ -72,6 +72,11 @@ bool DropIndicatorOverlayInterface::isHovered() const return m_windowBeingDragged != nullptr; } +DropIndicatorOverlayInterface::DropLocation DropIndicatorOverlayInterface::currentDropLocation() const +{ + return m_currentDropLocation; +} + KDDockWidgets::Location DropIndicatorOverlayInterface::multisplitterLocationFor(DropIndicatorOverlayInterface::DropLocation dropLoc) { switch (dropLoc) { @@ -103,14 +108,20 @@ void DropIndicatorOverlayInterface::onFrameDestroyed() void DropIndicatorOverlayInterface::onHoveredFrameChanged(Frame *) { - } void DropIndicatorOverlayInterface::setCurrentDropLocation(DropIndicatorOverlayInterface::DropLocation location) { - m_currentDropLocation = location; + if (m_currentDropLocation != location) { + m_currentDropLocation = location; + Q_EMIT currentDropLocationChanged(); + } } +void DropIndicatorOverlayInterface::hover(QPoint globalPos) +{ + hover_impl(globalPos); +} void DropIndicatorOverlayInterface::setHoveredFrameRect(QRect rect) { @@ -118,5 +129,4 @@ void DropIndicatorOverlayInterface::setHoveredFrameRect(QRect rect) m_hoveredFrameRect = rect; Q_EMIT hoveredFrameRectChanged(); } - } diff --git a/src/private/DropIndicatorOverlayInterface_p.h b/src/private/DropIndicatorOverlayInterface_p.h index 39205c5c..0aac9f68 100644 --- a/src/private/DropIndicatorOverlayInterface_p.h +++ b/src/private/DropIndicatorOverlayInterface_p.h @@ -26,6 +26,7 @@ class DOCKS_EXPORT_FOR_UNIT_TESTS DropIndicatorOverlayInterface : public QWidget { Q_OBJECT Q_PROPERTY(QRect hoveredFrameRect READ hoveredFrameRect NOTIFY hoveredFrameRectChanged) + Q_PROPERTY(KDDockWidgets::DropIndicatorOverlayInterface::DropLocation currentDropLocation READ currentDropLocation NOTIFY currentDropLocationChanged) public: enum Type { TypeNone = 0, @@ -53,12 +54,12 @@ public: void setWindowBeingDragged(const FloatingWindow *); QRect hoveredFrameRect() const; bool isHovered() const; - DropLocation currentDropLocation() const { return m_currentDropLocation; } + DropLocation currentDropLocation() const; Frame *hoveredFrame() const { return m_hoveredFrame; } void setCurrentDropLocation(DropIndicatorOverlayInterface::DropLocation location); virtual Type indicatorType() const = 0; - virtual void hover(QPoint globalPos) = 0; + void hover(QPoint globalPos); virtual QPoint posForIndicator(DropLocation) const = 0; // Used by unit-tests only @@ -67,17 +68,20 @@ public: Q_SIGNALS: void hoveredFrameChanged(KDDockWidgets::Frame *); void hoveredFrameRectChanged(); + void currentDropLocationChanged(); private: void onFrameDestroyed(); void setHoveredFrameRect(QRect); QRect m_hoveredFrameRect; + DropLocation m_currentDropLocation = DropLocation_None; protected: + virtual void hover_impl(QPoint globalPos) = 0; virtual void onHoveredFrameChanged(Frame *); virtual void updateVisibility() = 0; + Frame *m_hoveredFrame = nullptr; - DropLocation m_currentDropLocation = DropLocation_None; QPointer m_windowBeingDragged; DropArea *const m_dropArea; }; diff --git a/src/private/indicators/ClassicIndicators.cpp b/src/private/indicators/ClassicIndicators.cpp index 45f57740..d29b6e18 100644 --- a/src/private/indicators/ClassicIndicators.cpp +++ b/src/private/indicators/ClassicIndicators.cpp @@ -45,7 +45,7 @@ DropIndicatorOverlayInterface::Type ClassicIndicators::indicatorType() const return TypeClassic; } -void ClassicIndicators::hover(QPoint globalPos) +void ClassicIndicators::hover_impl(QPoint globalPos) { m_indicatorWindow->hover(globalPos); } diff --git a/src/private/indicators/ClassicIndicatorsWindow.cpp b/src/private/indicators/ClassicIndicatorsWindow.cpp index e0e75655..ccdf0da5 100644 --- a/src/private/indicators/ClassicIndicatorsWindow.cpp +++ b/src/private/indicators/ClassicIndicatorsWindow.cpp @@ -247,22 +247,37 @@ IndicatorWindow::IndicatorWindow(KDDockWidgets::ClassicIndicators *classicIndica void IndicatorWindow::hover(QPoint pt) { - qDebug() << "Hover" << pt; + QQuickItem *item = indicatorForPos(pt); + if (item) { + const auto loc = DropIndicatorOverlayInterface::DropLocation(item->property("indicatorType").toInt()); + classicIndicators()->setDropLocation(loc); + } else { + classicIndicators()->setDropLocation(DropIndicatorOverlayInterface::DropLocation_None); + } +} + +QQuickItem *IndicatorWindow::indicatorForPos(QPoint pt) const +{ + const QVector indicators = indicatorItems(); + Q_ASSERT(indicators.size() == 9); + + for (QQuickItem *item : indicators) { + QRect rect(0, 0, int(item->width()), int(item->height())); + rect.moveTopLeft(item->mapToGlobal(QPointF(0, 0)).toPoint()); + if (rect.contains(pt)) + return item; + } + + return nullptr; } void IndicatorWindow::updatePositions() { - qDebug() << "updatePositions"; + // Not needed to implement, the Indicators use QML anchors } QPoint IndicatorWindow::posForIndicator(KDDockWidgets::DropIndicatorOverlayInterface::DropLocation) const { - QQuickItem *root = rootObject(); - const QList items = root->childItems(); - for (QQuickItem *item : items) { - qDebug() << Q_FUNC_INFO << item; - } - qDebug() << Q_FUNC_INFO; return {}; } @@ -277,4 +292,27 @@ ClassicIndicators *IndicatorWindow::classicIndicators() const return m_classicIndicators; } +QVector IndicatorWindow::indicatorItems() const +{ + QVector indicators; + indicators.reserve(9); + + QQuickItem *root = rootObject(); + const QList items = root->childItems(); + for (QQuickItem *item : items) { + if (QString::fromLatin1(item->metaObject()->className()).startsWith(QLatin1String("ClassicIndicator_QMLTYPE"))) { + indicators.push_back(item); + } else if (item->objectName() == QLatin1String("innerIndicators")) { + const QList innerIndicators = item->childItems(); + for (QQuickItem *innerItem : innerIndicators) { + if (QString::fromLatin1(innerItem->metaObject()->className()).startsWith(QLatin1String("ClassicIndicator_QMLTYPE"))) { + indicators.push_back(innerItem); + } + } + } + } + + return indicators; +} + #endif // QtQuick diff --git a/src/private/indicators/ClassicIndicatorsWindow_p.h b/src/private/indicators/ClassicIndicatorsWindow_p.h index d4a2509b..0a2cb68f 100644 --- a/src/private/indicators/ClassicIndicatorsWindow_p.h +++ b/src/private/indicators/ClassicIndicatorsWindow_p.h @@ -97,6 +97,8 @@ public: Q_INVOKABLE QString iconName(int loc, bool active) const; KDDockWidgets::ClassicIndicators* classicIndicators() const; private: + QQuickItem *indicatorForPos(QPoint) const; + QVector indicatorItems() const; ClassicIndicators *const m_classicIndicators; }; } diff --git a/src/private/indicators/ClassicIndicators_p.h b/src/private/indicators/ClassicIndicators_p.h index 8f6f773b..024cc197 100644 --- a/src/private/indicators/ClassicIndicators_p.h +++ b/src/private/indicators/ClassicIndicators_p.h @@ -30,7 +30,7 @@ public: explicit ClassicIndicators(DropArea *dropArea); ~ClassicIndicators() override; Type indicatorType() const override; - void hover(QPoint globalPos) override; + void hover_impl(QPoint globalPos) override; QPoint posForIndicator(DropLocation) const override; bool innerIndicatorsVisible() const; diff --git a/src/private/quick/qml/ClassicIndicator.qml b/src/private/quick/qml/ClassicIndicator.qml index 7fa4b6a0..881c9595 100644 --- a/src/private/quick/qml/ClassicIndicator.qml +++ b/src/private/quick/qml/ClassicIndicator.qml @@ -5,8 +5,9 @@ Image { id: root property int indicatorType: DropIndicatorOverlayInterface.DropLocation_None + readonly property bool isHovered: _window.classicIndicators.currentDropLocation === indicatorType - source: "qrc:/img/classic_indicators/" + _window.iconName(indicatorType, true) + ".png"; + source: "qrc:/img/classic_indicators/" + _window.iconName(indicatorType, isHovered) + ".png"; width: 64 height: 64 } diff --git a/src/private/quick/qml/ClassicIndicatorsOverlay.qml b/src/private/quick/qml/ClassicIndicatorsOverlay.qml index 2d563a1b..99d99136 100644 --- a/src/private/quick/qml/ClassicIndicatorsOverlay.qml +++ b/src/private/quick/qml/ClassicIndicatorsOverlay.qml @@ -17,6 +17,7 @@ Item { anchors.fill: parent readonly property int outterMargin: 10 readonly property int innerMargin: 10 + readonly property QtObject innerIndicators: innerIndicators ClassicIndicator { visible: _window.classicIndicators.outterIndicatorsVisible @@ -60,6 +61,7 @@ Item { Item { id: innerIndicators + objectName: "innerIndicators" x: _window.classicIndicators.hoveredFrameRect.x + (_window.classicIndicators.hoveredFrameRect.width / 2) y: _window.classicIndicators.hoveredFrameRect.y + (_window.classicIndicators.hoveredFrameRect.height / 2)