X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/abefc8663ac5c9dc15ad08408e224b3a3cef3b6f..6c8c052b3ffa628fd99f4e4d726017e2fc8e0e1d:/src/views/selectiontoggle.cpp diff --git a/src/views/selectiontoggle.cpp b/src/views/selectiontoggle.cpp index f5287a3dd..cbd273b11 100644 --- a/src/views/selectiontoggle.cpp +++ b/src/views/selectiontoggle.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -35,6 +36,7 @@ SelectionToggle::SelectionToggle(QWidget* parent) : QAbstractButton(parent), m_isHovered(false), m_leftMouseButtonPressed(false), + m_appliedArrowCursor(false), m_fadingValue(0), m_margin(0), m_icon(), @@ -132,6 +134,19 @@ void SelectionToggle::enterEvent(QEvent* event) { QAbstractButton::enterEvent(event); + if (!m_appliedArrowCursor) { + m_appliedArrowCursor = true; + // Apply the arrow asynchronously. This is required for + // the following usecase: + // 1. Cursor is above the viewport left beside an item + // 2. Cursor is moved above the item, so that the selection-toggle + // and the item are entered equally. + // In this situation it is not defined who gets the enter-event first. + // As the selection-toggle is above the item, it should overwrite possible + // cursor changes done by the item. + QTimer::singleShot(0, this, SLOT(applyArrowCursor())); + } + // if the mouse cursor is above the selection toggle, display // it immediately without fading timer m_isHovered = true; @@ -147,6 +162,14 @@ void SelectionToggle::enterEvent(QEvent* event) void SelectionToggle::leaveEvent(QEvent* event) { QAbstractButton::leaveEvent(event); + + if (m_appliedArrowCursor) { + // Reset the cursor asynchronously. See SelectionToggle::enterEvent() + // for a more information. + m_appliedArrowCursor = false; + QTimer::singleShot(0, this, SLOT(restoreCursor())); + } + m_isHovered = false; update(); } @@ -222,6 +245,16 @@ void SelectionToggle::refreshIcon() setIconOverlay(isChecked()); } +void SelectionToggle::applyArrowCursor() +{ + QApplication::setOverrideCursor(QCursor(Qt::ArrowCursor)); +} + +void SelectionToggle::restoreCursor() +{ + QApplication::restoreOverrideCursor(); +} + void SelectionToggle::startFading() { Q_ASSERT(m_fadingTimeLine == 0);