]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphincolumnwidget.cpp
hide the tooltip when the context menu is opened in the columns view
[dolphin.git] / src / dolphincolumnwidget.cpp
index 41fad2ea7148c95422e99cba95ba2f7956c90382..5ef86a29db5213c94df43830d70abcdfd5b66b83 100644 (file)
 #include "dolphincontroller.h"
 #include "dolphindirlister.h"
 #include "dolphinsortfilterproxymodel.h"
-#include "dolphinsettings.h"
+#include "settings/dolphinsettings.h"
 #include "dolphinviewautoscroller.h"
 #include "dolphin_columnmodesettings.h"
 #include "dolphin_generalsettings.h"
 #include "draganddrophelper.h"
 #include "folderexpander.h"
 #include "selectionmanager.h"
-#include "tooltipmanager.h"
+#include "tooltips/tooltipmanager.h"
 
 #include <kcolorscheme.h>
 #include <kdirlister.h>
@@ -64,6 +64,7 @@ DolphinColumnWidget::DolphinColumnWidget(QWidget* parent,
     m_dolphinModel(0),
     m_proxyModel(0),
     m_previewGenerator(0),
+    m_toolTipManager(0),
     m_dropRect()
 {
     setMouseTracking(true);
@@ -140,7 +141,7 @@ DolphinColumnWidget::DolphinColumnWidget(QWidget* parent,
     m_previewGenerator->setPreviewShown(m_view->m_controller->dolphinView()->showPreview());
 
     if (DolphinSettings::instance().generalSettings()->showToolTips()) {
-        new ToolTipManager(this, m_proxyModel);
+        m_toolTipManager = new ToolTipManager(this, m_proxyModel);
     }
 
     m_dirLister->openUrl(url, KDirLister::NoFlags);
@@ -178,16 +179,18 @@ void DolphinColumnWidget::setDecorationSize(const QSize& size)
 
 void DolphinColumnWidget::setActive(bool active)
 {
-    if (m_active == active) {
-        return;
+    if (active && (m_view->focusProxy() != this)) {
+        m_view->setFocusProxy(this);
     }
 
-    m_active = active;
+    if (m_active != active) {
+        m_active = active;
 
-    if (active) {
-        activate();
-    } else {
-        deactivate();
+        if (active) {
+            activate();
+        } else {
+            deactivate();
+        }
     }
 }
 
@@ -387,7 +390,22 @@ void DolphinColumnWidget::keyPressEvent(QKeyEvent* event)
 {
     QListView::keyPressEvent(event);
     requestActivation();
-    m_view->m_controller->handleKeyPressEvent(event);
+
+    DolphinController* controller = m_view->m_controller;
+    controller->handleKeyPressEvent(event);
+    if (event->key() == Qt::Key_Right) {
+        // Special key handling for the column: A Key_Right should
+        // open a new column for the currently selected folder.
+        const QModelIndex index = currentIndex();
+        const KFileItem item = controller->itemForIndex(index);
+        if (!item.isNull() && item.isDir()) {
+            controller->emitItemTriggered(item);
+        }
+    }
+
+    if (m_toolTipManager != 0) {
+        m_toolTipManager->hideTip();
+    }
 }
 
 void DolphinColumnWidget::contextMenuEvent(QContextMenuEvent* event)
@@ -406,6 +424,10 @@ void DolphinColumnWidget::contextMenuEvent(QContextMenuEvent* event)
         clearSelection();
     }
 
+    if (m_toolTipManager != 0) {
+        m_toolTipManager->hideTip();
+    }
+
     const QPoint pos = m_view->viewport()->mapFromGlobal(event->globalPos());
     Q_ASSERT(m_view->m_controller->itemView() == this);
     m_view->m_controller->triggerContextMenuRequest(pos);
@@ -462,6 +484,28 @@ void DolphinColumnWidget::slotEntered(const QModelIndex& index)
     m_view->m_controller->emitItemEntered(index);
 }
 
+void DolphinColumnWidget::slotClicked(const QModelIndex& index)
+{
+    DolphinController* controller = m_view->m_controller;
+    if (KGlobalSettings::singleClick()) {
+        controller->triggerItem(index);
+    } else {
+        // even when using double click, a directory should be opened
+        // after the first click
+        const KFileItem item = controller->itemForIndex(index);
+        if (!item.isNull() && item.isDir()) {
+            controller->triggerItem(index);
+        }
+    }
+}
+
+void DolphinColumnWidget::slotDoubleClicked(const QModelIndex& index)
+{
+    if (!KGlobalSettings::singleClick()) {
+        m_view->m_controller->triggerItem(index);
+    }
+}
+
 void DolphinColumnWidget::requestActivation()
 {
     m_view->m_controller->setItemView(this);
@@ -489,16 +533,14 @@ void DolphinColumnWidget::activate()
 
     connect(this, SIGNAL(clicked(const QModelIndex&)),
             m_view->m_controller, SLOT(requestTab(const QModelIndex&)));
-    if (KGlobalSettings::singleClick()) {
-        connect(this, SIGNAL(clicked(const QModelIndex&)),
-                m_view->m_controller, SLOT(triggerItem(const QModelIndex&)));
-    } else {
-        connect(this, SIGNAL(doubleClicked(const QModelIndex&)),
-                m_view->m_controller, SLOT(triggerItem(const QModelIndex&)));
-    }
+    connect(this, SIGNAL(clicked(const QModelIndex&)),
+            this, SLOT(slotClicked(const QModelIndex&)));
+    connect(this, SIGNAL(doubleClicked(const QModelIndex&)),
+            this, SLOT(slotDoubleClicked(const QModelIndex&)));
 
-    if (selectionModel() && selectionModel()->currentIndex().isValid())
+    if (selectionModel() && selectionModel()->currentIndex().isValid()) {
         selectionModel()->setCurrentIndex(selectionModel()->currentIndex(), QItemSelectionModel::SelectCurrent);
+    }
 
     updateBackground();
 }
@@ -506,17 +548,12 @@ void DolphinColumnWidget::activate()
 void DolphinColumnWidget::deactivate()
 {
     clearFocus();
-
-    // TODO: Connecting to the signal 'activated()' is not possible, as kstyle
-    // does not forward the single vs. doubleclick to it yet (KDE 4.1?). Hence it is
-    // necessary connecting the signal 'singleClick()' or 'doubleClick'.
-    if (KGlobalSettings::singleClick()) {
-        disconnect(this, SIGNAL(clicked(const QModelIndex&)),
-                   m_view->m_controller, SLOT(triggerItem(const QModelIndex&)));
-    } else {
-        disconnect(this, SIGNAL(doubleClicked(const QModelIndex&)),
-                   m_view->m_controller, SLOT(triggerItem(const QModelIndex&)));
-    }
+    disconnect(this, SIGNAL(clicked(const QModelIndex&)),
+               m_view->m_controller, SLOT(requestTab(const QModelIndex&)));
+    disconnect(this, SIGNAL(clicked(const QModelIndex&)),
+               this, SLOT(slotClicked(const QModelIndex&)));
+    disconnect(this, SIGNAL(doubleClicked(const QModelIndex&)),
+               this, SLOT(slotDoubleClicked(const QModelIndex&)));
 
     const QModelIndex current = selectionModel()->currentIndex();
     selectionModel()->clear();