]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphindetailsview.cpp
check whether the current index is valid and whether no other items are selected
[dolphin.git] / src / dolphindetailsview.cpp
index 1aec30cca05fd4edb1289776bec04d1b7b3d9612..d7c8c5ab138cbf63c99eb914a0f7c5994ee6873f 100644 (file)
@@ -69,6 +69,10 @@ DolphinDetailsView::DolphinDetailsView(QWidget* parent, DolphinController* contr
     connect(parent, SIGNAL(sortOrderChanged(Qt::SortOrder)),
             this, SLOT(setSortIndicatorOrder(Qt::SortOrder)));
 
+    // 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' and to handle the
+    // RETURN-key in keyPressEvent().
     if (KGlobalSettings::singleClick()) {
         connect(this, SIGNAL(clicked(const QModelIndex&)),
                 this, SLOT(slotItemActivated(const QModelIndex&)));
@@ -271,6 +275,20 @@ void DolphinDetailsView::paintEvent(QPaintEvent* event)
     }
 }
 
+void DolphinDetailsView::keyPressEvent(QKeyEvent* event)
+{
+    QTreeView::keyPressEvent(event);
+
+    const QItemSelectionModel* selModel = selectionModel();
+    const QModelIndex currentIndex = selModel->currentIndex();
+    const bool triggerItem = currentIndex.isValid()
+                             && (event->key() == Qt::Key_Return)
+                             && (selModel->selectedIndexes().count() <= 1);
+    if (triggerItem) {
+        m_controller->triggerItem(currentIndex);
+    }
+}
+
 void DolphinDetailsView::setSortIndicatorSection(DolphinView::Sorting sorting)
 {
     QHeaderView* headerView = header();