aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2019-11-07 12:15:54 +0100
committerMitch Curtis <mitch.curtis@qt.io>2019-11-15 13:57:33 +0100
commitd04c7121acf66af75f557147ce8d055c62262608 (patch)
tree1e6442d182d0bc63af03c5a08d215f4bba84ba99
parent19976fd5db1f2fb4925831c5f7a708c090e4a70e (diff)
SplitView: refactor hover handling code
- Don't unset the hovered flag only to potentially set it again. - Generally simplify the code. - Move it into a new updateHoveredHandle() function so that follow up patches can call it from other places. - Add more logging to debug hover issues. Change-Id: Iaf06cfe1f556a3f30bd0e883ef504b3df2dbc8e2 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
-rw-r--r--src/quicktemplates2/qquicksplitview.cpp77
-rw-r--r--src/quicktemplates2/qquicksplitview_p_p.h1
2 files changed, 36 insertions, 42 deletions
diff --git a/src/quicktemplates2/qquicksplitview.cpp b/src/quicktemplates2/qquicksplitview.cpp
index 56392e9a..ba7644a1 100644
--- a/src/quicktemplates2/qquicksplitview.cpp
+++ b/src/quicktemplates2/qquicksplitview.cpp
@@ -909,6 +909,40 @@ void QQuickSplitViewPrivate::updateHandleVisibilities()
}
}
+void QQuickSplitViewPrivate::updateHoveredHandle(QQuickItem *hoveredItem)
+{
+ Q_Q(QQuickSplitView);
+ const int oldHoveredHandleIndex = m_hoveredHandleIndex;
+ m_hoveredHandleIndex = m_handleItems.indexOf(hoveredItem);
+ if (m_hoveredHandleIndex == oldHoveredHandleIndex)
+ return;
+
+ // First, clear the hovered flag of any previously-hovered handle.
+ if (oldHoveredHandleIndex != -1) {
+ QQuickItem *oldHoveredHandle = m_handleItems.at(oldHoveredHandleIndex);
+ QQuickSplitHandleAttached *oldHoveredHandleAttached = qobject_cast<QQuickSplitHandleAttached*>(
+ qmlAttachedPropertiesObject<QQuickSplitHandleAttached>(oldHoveredHandle, true));
+ QQuickSplitHandleAttachedPrivate::get(oldHoveredHandleAttached)->setHovered(false);
+ qCDebug(qlcQQuickSplitViewMouse) << "handle item at index" << oldHoveredHandleIndex << "is no longer hovered";
+ }
+
+ if (m_hoveredHandleIndex != -1) {
+ QQuickSplitHandleAttached *handleAttached = qobject_cast<QQuickSplitHandleAttached*>(
+ qmlAttachedPropertiesObject<QQuickSplitHandleAttached>(hoveredItem, true));
+ QQuickSplitHandleAttachedPrivate::get(handleAttached)->setHovered(true);
+ qCDebug(qlcQQuickSplitViewMouse) << "handle item at index" << m_hoveredHandleIndex << "is now hovered";
+ } else {
+ qCDebug(qlcQQuickSplitViewMouse) << "either there is no hovered item or" << hoveredItem << "is not a handle";
+ }
+
+#if QT_CONFIG(cursor)
+ if (m_hoveredHandleIndex != -1)
+ q->setCursor(m_orientation == Qt::Horizontal ? Qt::SplitHCursor : Qt::SplitVCursor);
+ else
+ q->setCursor(Qt::ArrowCursor);
+#endif
+}
+
void QQuickSplitViewPrivate::setResizing(bool resizing)
{
Q_Q(QQuickSplitView);
@@ -1327,48 +1361,7 @@ void QQuickSplitView::hoverMoveEvent(QHoverEvent *event)
QQuickContainer::hoverMoveEvent(event);
QQuickItem *hoveredItem = childAt(event->pos().x(), event->pos().y());
- if (!hoveredItem) {
- // No handle is hovered.
- if (d->m_hoveredHandleIndex != -1) {
- // The previously-hovered handle is no longer hovered.
- QQuickItem *oldHoveredHandle = d->m_handleItems.at(d->m_hoveredHandleIndex);
- QQuickSplitHandleAttached *handleAttached = qobject_cast<QQuickSplitHandleAttached*>(
- qmlAttachedPropertiesObject<QQuickSplitHandleAttached>(oldHoveredHandle, true));
- QQuickSplitHandleAttachedPrivate::get(handleAttached)->setHovered(false);
- }
-
- qCDebug(qlcQQuickSplitViewMouse) << "handle item at index" << d->m_hoveredHandleIndex << "is no longer hovered";
-
- d->m_hoveredHandleIndex = -1;
- } else {
- // A child item of ours is hovered.
-
- // First, clear the hovered flag of any previously-hovered handle.
- if (d->m_hoveredHandleIndex != -1) {
- QQuickItem *oldHoveredHandle = d->m_handleItems.at(d->m_hoveredHandleIndex);
- QQuickSplitHandleAttached *handleAttached = qobject_cast<QQuickSplitHandleAttached*>(
- qmlAttachedPropertiesObject<QQuickSplitHandleAttached>(oldHoveredHandle, true));
- QQuickSplitHandleAttachedPrivate::get(handleAttached)->setHovered(false);
- }
-
- // Now check if the newly hovered item is actually a handle.
- d->m_hoveredHandleIndex = d->m_handleItems.indexOf(hoveredItem);
-
- if (d->m_hoveredHandleIndex != -1) {
- QQuickSplitHandleAttached *handleAttached = qobject_cast<QQuickSplitHandleAttached*>(
- qmlAttachedPropertiesObject<QQuickSplitHandleAttached>(hoveredItem, true));
- QQuickSplitHandleAttachedPrivate::get(handleAttached)->setHovered(true);
-
- qCDebug(qlcQQuickSplitViewMouse) << "handle item at index" << d->m_hoveredHandleIndex << "is now hovered";
- }
- }
-
-#if QT_CONFIG(cursor)
- if (d->m_hoveredHandleIndex != -1)
- setCursor(d->m_orientation == Qt::Horizontal ? Qt::SplitHCursor : Qt::SplitVCursor);
- else
- setCursor(Qt::ArrowCursor);
-#endif
+ d->updateHoveredHandle(hoveredItem);
}
void QQuickSplitView::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
diff --git a/src/quicktemplates2/qquicksplitview_p_p.h b/src/quicktemplates2/qquicksplitview_p_p.h
index 5d71d461..ccefe5ec 100644
--- a/src/quicktemplates2/qquicksplitview_p_p.h
+++ b/src/quicktemplates2/qquicksplitview_p_p.h
@@ -74,6 +74,7 @@ public:
void resizeHandle(QQuickItem *handleItem);
void resizeHandles();
void updateHandleVisibilities();
+ void updateHoveredHandle(QQuickItem *hoveredItem);
void setResizing(bool resizing);
bool isHorizontal() const;