]> cloud.milkyroute.net Git - dolphin.git/commitdiff
allow to show/hide the columns of the details-view by a context menu for the header...
authorPeter Penz <peter.penz19@gmail.com>
Thu, 27 Sep 2007 08:56:38 +0000 (08:56 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Thu, 27 Sep 2007 08:56:38 +0000 (08:56 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=717627

src/dolphindetailsview.cpp
src/dolphindetailsview.h

index dce2ab5ce50f816706434b7d323e765aafcb8b94..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)));
@@ -406,6 +414,47 @@ void DolphinDetailsView::slotItemActivated(const QModelIndex& 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();
index 862a4961344e15cc9f9c14b09b8ff45f6534985f..a0ef0eedf3832733c33ae3b123e422115c09b0be 100644 (file)
@@ -110,6 +110,12 @@ private slots:
      */
     void slotItemActivated(const QModelIndex& index);
 
+    /**
+     * Opens a context menu at the position \a pos and allows to
+     * configure the visibility of the header columns.
+     */
+    void configureColumns(const QPoint& pos);
+
 private:
     bool isZoomInPossible() const;
     bool isZoomOutPossible() const;