┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Penz <[email protected]>2007-09-27 08:56:38 +0000
committerPeter Penz <[email protected]>2007-09-27 08:56:38 +0000
commitf74e17d275341c0e6a5305404feb3ff10d03939c (patch)
treeee653af77b15d73cc0ccd8882df6ef9c26feeed7
parent40691db6e78900510bdc2317d8a89509dea31f1e (diff)
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
-rw-r--r--src/dolphindetailsview.cpp51
-rw-r--r--src/dolphindetailsview.h6
2 files changed, 56 insertions, 1 deletions
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 <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();
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;