X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/2872b35f4b4af9ab3c934da6c48834ba1dfca64a..b1c9b5126d:/src/dolphindetailsview.cpp diff --git a/src/dolphindetailsview.cpp b/src/dolphindetailsview.cpp index 2d18c8e18..dd58e5842 100644 --- a/src/dolphindetailsview.cpp +++ b/src/dolphindetailsview.cpp @@ -23,7 +23,7 @@ #include "dolphinmodel.h" #include "dolphincontroller.h" #include "dolphinfileitemdelegate.h" -#include "dolphinsettings.h" +#include "settings/dolphinsettings.h" #include "dolphinsortfilterproxymodel.h" #include "dolphinviewautoscroller.h" #include "draganddrophelper.h" @@ -56,6 +56,7 @@ DolphinDetailsView::DolphinDetailsView(QWidget* parent, DolphinController* contr m_controller(controller), m_selectionManager(0), m_autoScroller(0), + m_expandableFoldersAction(0), m_font(), m_decorationSize(), m_band() @@ -88,7 +89,7 @@ DolphinDetailsView::DolphinDetailsView(QWidget* parent, DolphinController* contr this, SLOT(synchronizeSortingState(int))); headerView->setContextMenuPolicy(Qt::CustomContextMenu); connect(headerView, SIGNAL(customContextMenuRequested(const QPoint&)), - this, SLOT(configureColumns(const QPoint&))); + this, SLOT(configureSettings(const QPoint&))); connect(headerView, SIGNAL(sectionResized(int, int, int)), this, SLOT(slotHeaderSectionResized(int, int, int))); connect(headerView, SIGNAL(sectionHandleDoubleClicked(int)), @@ -149,10 +150,15 @@ DolphinDetailsView::DolphinDetailsView(QWidget* parent, DolphinController* contr setFocus(); viewport()->installEventFilter(this); - connect(KGlobalSettings::self(), SIGNAL(kdisplayFontChanged()), - this, SLOT(updateFont())); + connect(KGlobalSettings::self(), SIGNAL(settingsChanged(int)), + this, SLOT(slotGlobalSettingsChanged(int))); m_useDefaultIndexAt = false; + + m_expandableFoldersAction = new QAction(i18nc("@option:check", "Expandable Folders"), this); + m_expandableFoldersAction->setCheckable(true); + connect(m_expandableFoldersAction, SIGNAL(toggled(bool)), + this, SLOT(setFoldersExpandable(bool))); } DolphinDetailsView::~DolphinDetailsView() @@ -187,7 +193,11 @@ QStyleOptionViewItem DolphinDetailsView::viewOptions() const void DolphinDetailsView::contextMenuEvent(QContextMenuEvent* event) { QTreeView::contextMenuEvent(event); - m_controller->triggerContextMenuRequest(event->pos()); + + DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings(); + m_expandableFoldersAction->setChecked(settings->expandableFolders()); + m_controller->triggerContextMenuRequest(event->pos(), + QList() << m_expandableFoldersAction); } void DolphinDetailsView::mousePressEvent(QMouseEvent* event) @@ -555,11 +565,12 @@ void DolphinDetailsView::slotShowPreviewChanged() updateDecorationSize(view->showPreview()); } -void DolphinDetailsView::configureColumns(const QPoint& pos) +void DolphinDetailsView::configureSettings(const QPoint& pos) { KMenu popup(this); popup.addTitle(i18nc("@title:menu", "Columns")); + // add checkbox items for each column QHeaderView* headerView = header(); for (int i = DolphinModel::Size; i <= DolphinModel::Type; ++i) { const int logicalIndex = headerView->logicalIndex(i); @@ -569,6 +580,7 @@ void DolphinDetailsView::configureColumns(const QPoint& pos) action->setChecked(!headerView->isSectionHidden(logicalIndex)); action->setData(i); } + popup.addSeparator(); QAction* activatedAction = popup.exec(header()->mapToGlobal(pos)); if (activatedAction != 0) { @@ -636,14 +648,23 @@ void DolphinDetailsView::requestActivation() m_controller->requestActivation(); } -void DolphinDetailsView::updateFont() +void DolphinDetailsView::slotGlobalSettingsChanged(int category) { + Q_UNUSED(category); + const DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings(); Q_ASSERT(settings != 0); - if (settings->useSystemFont()) { m_font = KGlobalSettings::generalFont(); } + //Disconnect then reconnect, since the settings have been changed, the connection requirements may have also. + disconnect(this, SIGNAL(clicked(QModelIndex)), m_controller, SLOT(triggerItem(QModelIndex))); + disconnect(this, SIGNAL(doubleClicked(QModelIndex)), m_controller, SLOT(triggerItem(QModelIndex))); + if (KGlobalSettings::singleClick()) { + connect(this, SIGNAL(clicked(QModelIndex)), m_controller, SLOT(triggerItem(QModelIndex))); + } else { + connect(this, SIGNAL(doubleClicked(QModelIndex)), m_controller, SLOT(triggerItem(QModelIndex))); + } } void DolphinDetailsView::updateElasticBandSelection() @@ -829,6 +850,22 @@ void DolphinDetailsView::updateElasticBandSelection() m_band.ignoreOldInfo = false; } +void DolphinDetailsView::setFoldersExpandable(bool expandable) +{ + if (!expandable) { + // collapse all expanded folders, as QTreeView::setItemsExpandable(false) + // does not do this task + const int rowCount = model()->rowCount(); + for (int row = 0; row < rowCount; ++row) { + setExpanded(model()->index(row, 0), false); + } + } + DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings(); + settings->setExpandableFolders(expandable); + setRootIsDecorated(expandable); + setItemsExpandable(expandable); +} + void DolphinDetailsView::updateDecorationSize(bool showPreview) { DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings(); @@ -900,7 +937,7 @@ void DolphinDetailsView::resizeColumns() // reasons the exact necessary width for full visible names is // only checked for up to 200 items: const int rowCount = model()->rowCount(); - if (rowCount < 200) { + if (rowCount > 0 && rowCount < 200) { const int nameWidth = sizeHintForColumn(DolphinModel::Name); if (nameWidth + requiredWidth <= viewport()->width()) { columnWidth[KDirModel::Name] = viewport()->width() - requiredWidth;