From f1d1a18a7169e9ad7ad4fd9cd21261d76e1c2bf0 Mon Sep 17 00:00:00 2001 From: Peter Penz Date: Tue, 6 Nov 2007 07:16:23 +0000 Subject: [PATCH] When switching from e. g. the icons view to the details view, additional information properties like 'Size' and 'Date' are added as default (showing a details-view without details does not make sense as default setting...). This fix assures that the additional information properties are removed again when switching back to the icons view. Only if the user modified the additional information properties by a GUI-interaction (e. g. by adding a 'Type'), this information is persistet also when switching back to the icon-view. BUG: 151891 svn path=/trunk/KDE/kdebase/apps/; revision=733313 --- src/dolphindetailsview.cpp | 64 +++++++++++++++++++++++++++----------- src/dolphindetailsview.h | 5 +++ src/dolphinview.cpp | 37 +++++++++++++--------- src/dolphinview.h | 2 ++ 4 files changed, 76 insertions(+), 32 deletions(-) diff --git a/src/dolphindetailsview.cpp b/src/dolphindetailsview.cpp index e55c2582d5..af79d08457 100644 --- a/src/dolphindetailsview.cpp +++ b/src/dolphindetailsview.cpp @@ -43,6 +43,7 @@ DolphinDetailsView::DolphinDetailsView(QWidget* parent, DolphinController* controller) : QTreeView(parent), m_controller(controller), + m_clearAdditionalInfo(false), m_dragging(false), m_showElasticBand(false), m_elasticBandOrigin(), @@ -349,6 +350,20 @@ void DolphinDetailsView::resizeEvent(QResizeEvent* event) } } +void DolphinDetailsView::closeEvent(QCloseEvent* event) +{ + if (m_clearAdditionalInfo) { + disconnect(m_controller->dolphinView(), SIGNAL(additionalInfoChanged(const KFileItemDelegate::InformationList&)), + this, SLOT(updateColumnVisibility())); + + KFileItemDelegate::InformationList info; + info.append(KFileItemDelegate::NoInformation); + m_controller->indicateAdditionalInfoChange(info); + m_clearAdditionalInfo = true; + } + QTreeView::closeEvent(event); +} + void DolphinDetailsView::setSortIndicatorSection(DolphinView::Sorting sorting) { QHeaderView* headerView = header(); @@ -457,17 +472,7 @@ void DolphinDetailsView::configureColumns(const QPoint& pos) const int columnIndex = activatedAction->data().toInt(); KFileItemDelegate::InformationList list = m_controller->dolphinView()->additionalInfo(); - KFileItemDelegate::Information info = KFileItemDelegate::NoInformation; - switch (columnIndex) { - case DolphinModel::Size: info = KFileItemDelegate::Size; break; - case DolphinModel::ModifiedTime: info = KFileItemDelegate::ModificationTime; break; - case DolphinModel::Permissions: info = KFileItemDelegate::Permissions; break; - case DolphinModel::Owner: info = KFileItemDelegate::Owner; break; - case DolphinModel::Group: info = KFileItemDelegate::OwnerAndGroup; break; - case DolphinModel::Type: info = KFileItemDelegate::FriendlyMimeType; break; - default: break; - } - + const KFileItemDelegate::Information info = infoForColumn(columnIndex); if (show) { Q_ASSERT(!list.contains(info)); list.append(info); @@ -485,7 +490,10 @@ void DolphinDetailsView::configureColumns(const QPoint& pos) void DolphinDetailsView::updateColumnVisibility() { KFileItemDelegate::InformationList list = m_controller->dolphinView()->additionalInfo(); - if (list.isEmpty() || list.contains(KFileItemDelegate::NoInformation)) { + const bool useDefaultColumns = !isVisible() && + (list.isEmpty() || + list.contains(KFileItemDelegate::NoInformation)); + if (useDefaultColumns) { // Using the details view without any additional information (-> additional column) // makes no sense and leads to a usability problem as no viewport area is available // anymore. Hence as fallback provide at least a size and date column. @@ -493,14 +501,17 @@ void DolphinDetailsView::updateColumnVisibility() list.append(KFileItemDelegate::Size); list.append(KFileItemDelegate::ModificationTime); m_controller->indicateAdditionalInfoChange(list); + m_clearAdditionalInfo = true; } - setColumnHidden(DolphinModel::Size, !list.contains(KFileItemDelegate::Size)); - setColumnHidden(DolphinModel::ModifiedTime, !list.contains(KFileItemDelegate::ModificationTime)); - setColumnHidden(DolphinModel::Permissions, !list.contains(KFileItemDelegate::Permissions)); - setColumnHidden(DolphinModel::Owner, !list.contains(KFileItemDelegate::Owner)); - setColumnHidden(DolphinModel::Group, !list.contains(KFileItemDelegate::OwnerAndGroup)); - setColumnHidden(DolphinModel::Type, !list.contains(KFileItemDelegate::FriendlyMimeType)); + for (int i = DolphinModel::Size; i <= DolphinModel::Type; ++i) { + const KFileItemDelegate::Information info = infoForColumn(i); + const bool hide = !list.contains(info); + if (isColumnHidden(i) != hide) { + setColumnHidden(i, hide); + m_clearAdditionalInfo = false; + } + } } bool DolphinDetailsView::isZoomInPossible() const @@ -553,4 +564,21 @@ KFileItem DolphinDetailsView::itemForIndex(const QModelIndex& index) const return dirModel->itemForIndex(dirIndex); } +KFileItemDelegate::Information DolphinDetailsView::infoForColumn(int columnIndex) const +{ + KFileItemDelegate::Information info = KFileItemDelegate::NoInformation; + + switch (columnIndex) { + case DolphinModel::Size: info = KFileItemDelegate::Size; break; + case DolphinModel::ModifiedTime: info = KFileItemDelegate::ModificationTime; break; + case DolphinModel::Permissions: info = KFileItemDelegate::Permissions; break; + case DolphinModel::Owner: info = KFileItemDelegate::Owner; break; + case DolphinModel::Group: info = KFileItemDelegate::OwnerAndGroup; break; + case DolphinModel::Type: info = KFileItemDelegate::FriendlyMimeType; break; + default: break; + } + + return info; +} + #include "dolphindetailsview.moc" diff --git a/src/dolphindetailsview.h b/src/dolphindetailsview.h index 57fb98f224..ec98b0fafc 100644 --- a/src/dolphindetailsview.h +++ b/src/dolphindetailsview.h @@ -58,6 +58,7 @@ protected: virtual void paintEvent(QPaintEvent* event); virtual void keyPressEvent(QKeyEvent* event); virtual void resizeEvent(QResizeEvent* event); + virtual void closeEvent(QCloseEvent* event); private slots: /** @@ -135,10 +136,14 @@ private: KFileItem itemForIndex(const QModelIndex& index) const; + KFileItemDelegate::Information infoForColumn(int columnIndex) const; + private: DolphinController* m_controller; QStyleOptionViewItem m_viewOptions; + bool m_clearAdditionalInfo; + bool m_dragging; // TODO: remove this property when the issue #160611 is solved in Qt 4.4 QRect m_dropRect; // TODO: remove this property when the issue #160611 is solved in Qt 4.4 diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index 004b158ed6..fabda169e2 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -194,6 +194,11 @@ void DolphinView::setMode(Mode mode) m_controller->setUrl(root); } + deleteView(); + + // It is important to read the view properties _after_ deleting the view, + // as e. g. the detail view might adjust the additional information properties + // after getting closed: const KUrl viewPropsUrl = viewPropertiesUrl(); ViewProperties props(viewPropsUrl); props.setViewMode(m_mode); @@ -770,6 +775,7 @@ void DolphinView::updateAdditionalInfo(const KFileItemDelegate::InformationList& { ViewProperties props(viewPropertiesUrl()); props.setAdditionalInfo(info); + props.save(); m_fileItemDelegate->setShowInformation(info); @@ -826,24 +832,12 @@ void DolphinView::clearHoverInformation() void DolphinView::createView() { - // delete current view - QAbstractItemView* view = itemView(); - if (view != 0) { - m_topLayout->removeWidget(view); - view->close(); - view->deleteLater(); - view = 0; - m_iconsView = 0; - m_detailsView = 0; - m_columnView = 0; - m_fileItemDelegate = 0; - } - + deleteView(); Q_ASSERT(m_iconsView == 0); Q_ASSERT(m_detailsView == 0); Q_ASSERT(m_columnView == 0); - // ... and recreate it representing the current mode + QAbstractItemView* view = 0; switch (m_mode) { case IconsView: { m_iconsView = new DolphinIconsView(this, m_controller); @@ -881,6 +875,21 @@ void DolphinView::createView() this, SLOT(emitContentsMoved())); } +void DolphinView::deleteView() +{ + QAbstractItemView* view = itemView(); + if (view != 0) { + m_topLayout->removeWidget(view); + view->close(); + view->deleteLater(); + view = 0; + m_iconsView = 0; + m_detailsView = 0; + m_columnView = 0; + m_fileItemDelegate = 0; + } +} + QAbstractItemView* DolphinView::itemView() const { if (m_detailsView != 0) { diff --git a/src/dolphinview.h b/src/dolphinview.h index 593209e064..abb82527e7 100644 --- a/src/dolphinview.h +++ b/src/dolphinview.h @@ -566,6 +566,8 @@ private: */ void createView(); + void deleteView(); + /** * Returns a pointer to the currently used item view, which is either * a ListView or a TreeView.