mirror of
https://invent.kde.org/system/dolphin
synced 2024-11-05 18:47:12 +00:00
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
This commit is contained in:
parent
40691db6e7
commit
f74e17d275
2 changed files with 56 additions and 1 deletions
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue