]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphindetailsview.cpp
use inline keyword as suggested at http://www.parashift.com/c%2B%2B-faq-lite/inline...
[dolphin.git] / src / dolphindetailsview.cpp
index defe93192fc6cc377405fd1253f3ea4368fcbb95..0bad0b0c9342fb8ddd546eab8cf95bc9b73f8ac6 100644 (file)
 
 #include "dolphin_detailsmodesettings.h"
 
+#include <klocale.h>
+#include <kmenu.h>
+
+#include <QAction>
 #include <QApplication>
 #include <QHeaderView>
 #include <QRubberBand>
@@ -60,8 +64,12 @@ DolphinDetailsView::DolphinDetailsView(QWidget* parent, DolphinController* contr
     setSortIndicatorSection(props.sorting());
     setSortIndicatorOrder(props.sortOrder());
 
-    connect(header(), SIGNAL(sectionClicked(int)),
+    QHeaderView* headerView = header();
+    connect(headerView, SIGNAL(sectionClicked(int)),
             this, SLOT(synchronizeSortingState(int)));
+    headerView->setContextMenuPolicy(Qt::CustomContextMenu);
+    connect(headerView, SIGNAL(customContextMenuRequested(const QPoint&)),
+            this, SLOT(configureColumns(const QPoint&)));
 
     connect(parent, SIGNAL(sortingChanged(DolphinView::Sorting)),
             this, SLOT(setSortIndicatorSection(DolphinView::Sorting)));
@@ -139,6 +147,9 @@ bool DolphinDetailsView::event(QEvent* event)
         if (!settings->showType()) {
             hideColumn(DolphinModel::Type);
         }
+
+        hideColumn(DolphinModel::Rating);
+        hideColumn(DolphinModel::Tags);
     }
 
     return QTreeView::event(event);
@@ -241,6 +252,7 @@ void DolphinDetailsView::dropEvent(QDropEvent* event)
     if (!urls.isEmpty()) {
         event->acceptProposedAction();
         m_controller->indicateDroppedUrls(urls,
+                                          m_controller->url(),
                                           indexAt(event->pos()),
                                           event->source());
     }
@@ -288,6 +300,39 @@ void DolphinDetailsView::keyPressEvent(QKeyEvent* event)
     }
 }
 
+void DolphinDetailsView::resizeEvent(QResizeEvent* event)
+{
+    QTreeView::resizeEvent(event);
+
+    // assure that the width of the name-column does not get too small
+    const int minWidth = 120;
+    QHeaderView* headerView = header();
+    bool useFixedWidth = (headerView->sectionSize(KDirModel::Name) <= minWidth)
+                         && (headerView->resizeMode(0) != QHeaderView::Fixed);
+    if (useFixedWidth) {
+        // the current width of the name-column is too small, hence
+        // use a fixed size
+        headerView->setResizeMode(QHeaderView::Fixed);
+        headerView->setResizeMode(0, QHeaderView::Fixed);
+        headerView->resizeSection(KDirModel::Name, minWidth);
+    } else if (headerView->resizeMode(0) != QHeaderView::Stretch) {
+        // check whether there is enough available viewport width
+        // to automatically resize the columns
+        const int availableWidth = viewport()->width();
+
+        int headerWidth = 0;
+        const int count = headerView->count();
+        for (int i = 0; i < count; ++i) {
+            headerWidth += headerView->sectionSize(i);
+        }
+
+        if (headerWidth < availableWidth) {
+            headerView->setResizeMode(QHeaderView::ResizeToContents);
+            headerView->setResizeMode(0, QHeaderView::Stretch);
+        }
+    }
+}
+
 void DolphinDetailsView::setSortIndicatorSection(DolphinView::Sorting sorting)
 {
     QHeaderView* headerView = header();
@@ -359,6 +404,57 @@ void DolphinDetailsView::zoomOut()
     }
 }
 
+void DolphinDetailsView::slotItemActivated(const QModelIndex& index)
+{
+    if (index.isValid() && (index.column() == KDirModel::Name)) {
+        m_controller->triggerItem(index);
+    } else {
+        clearSelection();
+        m_controller->emitItemEntered(index);
+    }
+}
+
+void DolphinDetailsView::configureColumns(const QPoint& pos)
+{
+    KMenu popup(this);
+    popup.addTitle(i18nc("@title:menu", "Columns"));
+
+    QHeaderView* headerView = header();
+    for (int i = DolphinModel::ModifiedTime; i <= DolphinModel::Type; ++i) {
+        const int logicalIndex = headerView->logicalIndex(i);
+        const QString text = model()->headerData(i, Qt::Horizontal).toString();
+        QAction* action = popup.addAction(text);
+        action->setCheckable(true);
+        action->setChecked(!headerView->isSectionHidden(logicalIndex));
+        action->setData(i);
+    }
+
+    QAction* activatedAction = popup.exec(header()->mapToGlobal(pos));
+    if (activatedAction != 0) {
+        const bool show = activatedAction->isChecked();
+        DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
+        Q_ASSERT(settings != 0);
+
+        // remember the changed column visibility in the settings
+        const int columnIndex = activatedAction->data().toInt();
+        switch (columnIndex) {
+        case DolphinModel::ModifiedTime: settings->setShowDate(show); break;
+        case DolphinModel::Permissions:  settings->setShowPermissions(show); break;
+        case DolphinModel::Owner:        settings->setShowOwner(show); break;
+        case DolphinModel::Group:        settings->setShowGroup(show); break;
+        case DolphinModel::Type:         settings->setShowType(show); break;
+        default: break;
+        }
+
+        // apply the changed column visibility
+        if (show) {
+            showColumn(columnIndex);
+        } else {
+            hideColumn(columnIndex);
+        }
+    }
+}
+
 bool DolphinDetailsView::isZoomInPossible() const
 {
     DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
@@ -413,14 +509,4 @@ static bool isValidNameIndex(const QModelIndex& index)
     return index.isValid() && (index.column() == KDirModel::Name);
 }
 
-void DolphinDetailsView::slotItemActivated(const QModelIndex& index)
-{
-    if (!isValidNameIndex(index)) {
-        clearSelection();
-        m_controller->emitItemEntered(index);
-    } else {
-        m_controller->triggerItem(index);
-    }
-}
-
 #include "dolphindetailsview.moc"