]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphindetailsview.cpp
icon renamings:
[dolphin.git] / src / dolphindetailsview.cpp
index c26d3d5b57f5c6710b09b9cebd8bc02113555a3b..57d5eb81c3f09707701841ce26e757e54ed4392a 100644 (file)
 
 #include "dolphin_detailsmodesettings.h"
 
+#include <kdirmodel.h>
 #include <klocale.h>
 #include <kmenu.h>
 
+#include <QAbstractProxyModel>
 #include <QAction>
 #include <QApplication>
 #include <QHeaderView>
@@ -82,10 +84,10 @@ DolphinDetailsView::DolphinDetailsView(QWidget* parent, DolphinController* contr
     // RETURN-key in keyPressEvent().
     if (KGlobalSettings::singleClick()) {
         connect(this, SIGNAL(clicked(const QModelIndex&)),
-                this, SLOT(slotItemActivated(const QModelIndex&)));
+                this, SLOT(triggerItem(const QModelIndex&)));
     } else {
         connect(this, SIGNAL(doubleClicked(const QModelIndex&)),
-                this, SLOT(slotItemActivated(const QModelIndex&)));
+                this, SLOT(triggerItem(const QModelIndex&)));
     }
     connect(this, SIGNAL(entered(const QModelIndex&)),
             this, SLOT(slotEntered(const QModelIndex&)));
@@ -112,12 +114,14 @@ DolphinDetailsView::DolphinDetailsView(QWidget* parent, DolphinController* contr
 //       check avoids a division by zero happening on versions before 4.3.1.
 //       Right now KDE in theory can be shipped with Qt 4.3.0 and above.
 //       ereslibre
-#if (QT_VERSION >= QT_VERSION_CHECK(4, 3, 2))
+#if (QT_VERSION >= QT_VERSION_CHECK(4, 3, 2) || defined(QT_KDE_QT_COPY))
     setVerticalScrollMode(QTreeView::ScrollPerPixel);
     setHorizontalScrollMode(QTreeView::ScrollPerPixel);
 #endif
 
     updateDecorationSize();
+
+    setFocus();
 }
 
 DolphinDetailsView::~DolphinDetailsView()
@@ -166,7 +170,7 @@ bool DolphinDetailsView::event(QEvent* event)
 //       check avoids a division by zero happening on versions before 4.3.1.
 //       Right now KDE in theory can be shipped with Qt 4.3.0 and above.
 //       ereslibre
-#if (QT_VERSION >= QT_VERSION_CHECK(4, 3, 2))
+#if (QT_VERSION >= QT_VERSION_CHECK(4, 3, 2) || defined(QT_KDE_QT_COPY))
     else if (event->type() == QEvent::UpdateRequest) {
         // a wheel movement will scroll 4 items
         if (model()->rowCount() > 0) {
@@ -191,7 +195,7 @@ void DolphinDetailsView::contextMenuEvent(QContextMenuEvent* event)
 
 void DolphinDetailsView::mousePressEvent(QMouseEvent* event)
 {
-    m_controller->triggerActivation();
+    m_controller->requestActivation();
 
     QTreeView::mousePressEvent(event);
 
@@ -315,11 +319,11 @@ void DolphinDetailsView::keyPressEvent(QKeyEvent* 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);
+    const bool trigger = currentIndex.isValid()
+                         && (event->key() == Qt::Key_Return)
+                         && (selModel->selectedIndexes().count() <= 1);
+    if (trigger) {
+        triggerItem(currentIndex);
     }
 }
 
@@ -383,7 +387,7 @@ void DolphinDetailsView::slotEntered(const QModelIndex& index)
     const QPoint pos = viewport()->mapFromGlobal(QCursor::pos());
     const int nameColumnWidth = header()->sectionSize(DolphinModel::Name);
     if (pos.x() < nameColumnWidth) {
-        m_controller->emitItemEntered(index);
+        m_controller->emitItemEntered(itemForIndex(index));
     }
     else {
         m_controller->emitViewportEntered();
@@ -399,6 +403,13 @@ void DolphinDetailsView::updateElasticBand()
     setDirtyRegion(dirtyRegion);
 }
 
+QRect DolphinDetailsView::elasticBandRect() const
+{
+    const QPoint pos(contentsPos());
+    const QPoint topLeft(m_elasticBandOrigin.x() - pos.x(), m_elasticBandOrigin.y() - pos.y());
+    return QRect(topLeft, m_elasticBandDestination).normalized();
+}
+
 void DolphinDetailsView::zoomIn()
 {
     if (isZoomInPossible()) {
@@ -425,13 +436,14 @@ void DolphinDetailsView::zoomOut()
     }
 }
 
-void DolphinDetailsView::slotItemActivated(const QModelIndex& index)
+void DolphinDetailsView::triggerItem(const QModelIndex& index)
 {
+    const KFileItem item = itemForIndex(index);
     if (index.isValid() && (index.column() == KDirModel::Name)) {
-        m_controller->triggerItem(index);
+        m_controller->triggerItem(item);
     } else {
         clearSelection();
-        m_controller->emitItemEntered(index);
+        m_controller->emitItemEntered(item);
     }
 }
 
@@ -518,16 +530,12 @@ QPoint DolphinDetailsView::contentsPos() const
     return QPoint(0, y);
 }
 
-QRect DolphinDetailsView::elasticBandRect() const
-{
-    const QPoint pos(contentsPos());
-    const QPoint topLeft(m_elasticBandOrigin.x() - pos.x(), m_elasticBandOrigin.y() - pos.y());
-    return QRect(topLeft, m_elasticBandDestination).normalized();
-}
-
-static bool isValidNameIndex(const QModelIndex& index)
+KFileItem DolphinDetailsView::itemForIndex(const QModelIndex& index) const
 {
-    return index.isValid() && (index.column() == KDirModel::Name);
+    QAbstractProxyModel* proxyModel = static_cast<QAbstractProxyModel*>(model());
+    KDirModel* dirModel = static_cast<KDirModel*>(proxyModel->sourceModel());
+    const QModelIndex dirIndex = proxyModel->mapToSource(index);
+    return dirModel->itemForIndex(dirIndex);
 }
 
 #include "dolphindetailsview.moc"