]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/selectiontoggle.cpp
The feature freeze is near: Add video support to the Information Panel. Phonon is...
[dolphin.git] / src / selectiontoggle.cpp
index a2abc49c26786579350490175bfaab83adac03df..5c573811e7654c8a352607e6f4f61961cb7ad444 100644 (file)
@@ -23,6 +23,7 @@
 #include <kicon.h>
 #include <kiconloader.h>
 #include <kiconeffect.h>
+#include <klocale.h>
 
 #include <QPainter>
 #include <QPaintEvent>
@@ -33,6 +34,7 @@
 SelectionToggle::SelectionToggle(QWidget* parent) :
     QAbstractButton(parent),
     m_isHovered(false),
+    m_leftMouseButtonPressed(false),
     m_fadingValue(0),
     m_icon(),
     m_fadingTimeLine(0)
@@ -43,6 +45,8 @@ SelectionToggle::SelectionToggle(QWidget* parent) :
     setIconOverlay(isChecked());
     connect(this, SIGNAL(toggled(bool)),
             this, SLOT(setIconOverlay(bool)));
+    connect(KGlobalSettings::self(), SIGNAL(iconChanged(int)),
+            this, SLOT(refreshIcon()));
 }
 
 SelectionToggle::~SelectionToggle()
@@ -86,9 +90,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_leftMouseButtonPressed) {
+                // 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);
 }
 
@@ -103,6 +125,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();
 }
 
@@ -113,6 +137,18 @@ void SelectionToggle::leaveEvent(QEvent* event)
     update();
 }
 
+void SelectionToggle::mousePressEvent(QMouseEvent* event)
+{
+    QAbstractButton::mousePressEvent(event);
+    m_leftMouseButtonPressed = (event->buttons() & Qt::LeftButton);
+}
+
+void SelectionToggle::mouseReleaseEvent(QMouseEvent* event)
+{
+    QAbstractButton::mouseReleaseEvent(event);
+    m_leftMouseButtonPressed = (event->buttons() & Qt::LeftButton);
+}
+
 void SelectionToggle::paintEvent(QPaintEvent* event)
 {
     QPainter painter(this);
@@ -174,12 +210,17 @@ void SelectionToggle::setIconOverlay(bool checked)
     update();
 }
 
+void SelectionToggle::refreshIcon()
+{
+    setIconOverlay(isChecked());
+}
+
 void SelectionToggle::startFading()
 {
     Q_ASSERT(m_fadingTimeLine == 0);
 
     const bool animate = KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects;
-    const int duration = animate ? 1500 : 1;
+    const int duration = animate ? 600 : 1;
 
     m_fadingTimeLine = new QTimeLine(duration, this);
     connect(m_fadingTimeLine, SIGNAL(frameChanged(int)),