X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/bad99f25fee78ccf36971da00e3ef18d493c22fe..c40ed6564e8cd0d58c19f099c1aee6b5f3bcbb69:/src/selectiontoggle.cpp diff --git a/src/selectiontoggle.cpp b/src/selectiontoggle.cpp index eb02edcb2..01cfed0f3 100644 --- a/src/selectiontoggle.cpp +++ b/src/selectiontoggle.cpp @@ -19,9 +19,11 @@ #include "selectiontoggle.h" +#include #include #include #include +#include #include #include @@ -36,11 +38,14 @@ SelectionToggle::SelectionToggle(QWidget* parent) : m_icon(), m_fadingTimeLine(0) { + setFocusPolicy(Qt::NoFocus); parent->installEventFilter(this); resize(sizeHint()); setIconOverlay(isChecked()); connect(this, SIGNAL(toggled(bool)), this, SLOT(setIconOverlay(bool))); + connect(KGlobalSettings::self(), SIGNAL(iconChanged(int)), + this, SLOT(refreshIcon())); } SelectionToggle::~SelectionToggle() @@ -84,9 +89,27 @@ void SelectionToggle::setVisible(bool visible) bool SelectionToggle::eventFilter(QObject* obj, QEvent* event) { - if ((obj == parent()) && (event->type() == QEvent::Leave)) { - hide(); + if (obj == parent()) { + switch (event->type()) { + case QEvent::Leave: + hide(); + break; + + case QEvent::MouseMove: + if (m_isHovered) { + // Don't forward mouse move events to the viewport, + // otherwise a rubberband selection will be shown when + // clicking on the selection toggle and moving the mouse + // above the viewport. + return true; + } + break; + + default: + break; + } } + return QAbstractButton::eventFilter(obj, event); } @@ -101,6 +124,8 @@ void SelectionToggle::enterEvent(QEvent* event) m_fadingTimeLine->stop(); } m_fadingValue = 255; + setToolTip(isChecked() ? i18nc("@info:tooltip", "Deselect Item") : + i18nc("@info:tooltip", "Select Item")); update(); } @@ -172,11 +197,19 @@ void SelectionToggle::setIconOverlay(bool checked) update(); } +void SelectionToggle::refreshIcon() +{ + setIconOverlay(isChecked()); +} + void SelectionToggle::startFading() { Q_ASSERT(m_fadingTimeLine == 0); - m_fadingTimeLine = new QTimeLine(1500, this); + const bool animate = KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects; + const int duration = animate ? 600 : 1; + + m_fadingTimeLine = new QTimeLine(duration, this); connect(m_fadingTimeLine, SIGNAL(frameChanged(int)), this, SLOT(setFadingValue(int))); m_fadingTimeLine->setFrameRange(0, 255);