]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphindetailsview.cpp
use KGlobal::config() instead of parsing kdeglobals each time (thanks to David for...
[dolphin.git] / src / dolphindetailsview.cpp
index 61919c140e72d6c6ff7047d5f36f48396697c3f5..8e8eec2ec1624b88c38efcb780e7c4fa34089827 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&)));
@@ -108,6 +110,15 @@ DolphinDetailsView::DolphinDetailsView(QWidget* parent, DolphinController* contr
     m_viewOptions.font = font;
     m_viewOptions.showDecorationSelected = true;
 
+// TODO: Remove this check when 4.3.2 is released and KDE requires it... this
+//       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) || defined(QT_KDE_QT_COPY))
+    setVerticalScrollMode(QTreeView::ScrollPerPixel);
+    setHorizontalScrollMode(QTreeView::ScrollPerPixel);
+#endif
+
     updateDecorationSize();
 }
 
@@ -153,6 +164,18 @@ bool DolphinDetailsView::event(QEvent* event)
         hideColumn(DolphinModel::Rating);
         hideColumn(DolphinModel::Tags);
     }
+// TODO: Remove this check when 4.3.2 is released and KDE requires it... this
+//       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) || defined(QT_KDE_QT_COPY))
+    else if (event->type() == QEvent::UpdateRequest) {
+        // a wheel movement will scroll 4 items
+        if (model()->rowCount() > 0) {
+            verticalScrollBar()->setSingleStep((sizeHintForRow(0) / 3) * 4);
+        }
+    }
+#endif
 
     return QTreeView::event(event);
 }
@@ -170,7 +193,7 @@ void DolphinDetailsView::contextMenuEvent(QContextMenuEvent* event)
 
 void DolphinDetailsView::mousePressEvent(QMouseEvent* event)
 {
-    m_controller->triggerActivation();
+    m_controller->requestActivation();
 
     QTreeView::mousePressEvent(event);
 
@@ -294,11 +317,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);
     }
 }
 
@@ -362,7 +385,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();
@@ -378,6 +401,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()) {
@@ -404,13 +434,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);
     }
 }
 
@@ -497,16 +528,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"