From f74e17d275341c0e6a5305404feb3ff10d03939c Mon Sep 17 00:00:00 2001 From: Peter Penz Date: Thu, 27 Sep 2007 08:56:38 +0000 Subject: [PATCH] allow to show/hide the columns of the details-view by a context menu for the header (-> no need to go into the settings menu) svn path=/trunk/KDE/kdebase/apps/; revision=717627 --- src/dolphindetailsview.cpp | 51 +++++++++++++++++++++++++++++++++++++- src/dolphindetailsview.h | 6 +++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/dolphindetailsview.cpp b/src/dolphindetailsview.cpp index dce2ab5ce..0bad0b0c9 100644 --- a/src/dolphindetailsview.cpp +++ b/src/dolphindetailsview.cpp @@ -28,6 +28,10 @@ #include "dolphin_detailsmodesettings.h" +#include +#include + +#include #include #include #include @@ -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(); diff --git a/src/dolphindetailsview.h b/src/dolphindetailsview.h index 862a49613..a0ef0eedf 100644 --- a/src/dolphindetailsview.h +++ b/src/dolphindetailsview.h @@ -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; -- 2.47.3