diff --git a/Plugins/ZShell/Components/carouselview.cpp b/Plugins/ZShell/Components/carouselview.cpp index 027b0aa..9428c1a 100644 --- a/Plugins/ZShell/Components/carouselview.cpp +++ b/Plugins/ZShell/Components/carouselview.cpp @@ -89,6 +89,8 @@ void CarouselView::setModel(const QVariantList& m) { if (newCount == 0) { m_currentRealIndex = -1; + m_currentItem = nullptr; + emit currentItemChanged(); releaseAllItems(); rebuildArrangement(); @@ -248,6 +250,22 @@ void CarouselView::setCurrentIndex(int idx) { goToIndex(idx); } +void CarouselView::updateCurrentItem() { + QQuickItem* item = nullptr; + + for (const Slot& s : std::as_const(m_slots)) { + if (s.active && s.virtualIndex == m_currentVirtualIndex) { + item = s.item; + break; + } + } + + if (item == m_currentItem) return; + + m_currentItem = item; + emit currentItemChanged(); +} + void CarouselView::geometryChange(const QRectF& newGeo, const QRectF& oldGeo) { QQuickItem::geometryChange(newGeo, oldGeo); @@ -844,6 +862,7 @@ void CarouselView::relayout() { if (s.item) s.item->setVisible(false); } + updateCurrentItem(); return; } @@ -918,6 +937,8 @@ void CarouselView::relayout() { for (const Slot& s : std::as_const(m_slots)) { positionSlot(s); } + + updateCurrentItem(); } void CarouselView::cancelAnimations() { diff --git a/Plugins/ZShell/Components/carouselview.hpp b/Plugins/ZShell/Components/carouselview.hpp index a5b2ef9..d822c79 100644 --- a/Plugins/ZShell/Components/carouselview.hpp +++ b/Plugins/ZShell/Components/carouselview.hpp @@ -40,6 +40,10 @@ class CarouselView : public QQuickItem { Q_PROPERTY( int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) + + Q_PROPERTY( + QQuickItem* currentItem READ currentItem NOTIFY currentItemChanged) + Q_PROPERTY( int glideDuration READ glideDuration WRITE setGlideDuration NOTIFY glideDurationChanged) @@ -79,6 +83,8 @@ class CarouselView : public QQuickItem { int currentIndex() const { return m_currentRealIndex; } void setCurrentIndex(int idx); + QQuickItem* currentItem() const { return m_currentItem; } + int glideDuration() const { return m_glideDuration; } void setGlideDuration(int v); @@ -103,6 +109,7 @@ class CarouselView : public QQuickItem { void tileHeightChanged(); void maxWidthChanged(); void currentIndexChanged(); + void currentItemChanged(); void glideDurationChanged(); void glideEasingTypeChanged(); void delegatePropertiesChanged(); @@ -173,6 +180,8 @@ class CarouselView : public QQuickItem { void updateCurrentIndexFromContentX(bool emitPreview); + void updateCurrentItem(); + void wrapContentIfNeeded(); void centerInstantlyOnReal(int realIndex); @@ -198,6 +207,8 @@ class CarouselView : public QQuickItem { int m_currentRealIndex = -1; int m_previewRealIndex = -1; + QQuickItem* m_currentItem = nullptr; + int m_centerBlockStart = 0; QList m_slots;