diff --git a/src/filewidgets/kfileplacesmodel.h b/src/filewidgets/kfileplacesmodel.h --- a/src/filewidgets/kfileplacesmodel.h +++ b/src/filewidgets/kfileplacesmodel.h @@ -75,6 +75,7 @@ Solid::Device deviceForIndex(const QModelIndex &index) const; KBookmark bookmarkForIndex(const QModelIndex &index) const; GroupType groupType(const QModelIndex &index) const; + QModelIndexList groupIndexes(const GroupType type) const; QAction *teardownActionForIndex(const QModelIndex &index) const; QAction *ejectActionForIndex(const QModelIndex &index) const; diff --git a/src/filewidgets/kfileplacesmodel.cpp b/src/filewidgets/kfileplacesmodel.cpp --- a/src/filewidgets/kfileplacesmodel.cpp +++ b/src/filewidgets/kfileplacesmodel.cpp @@ -328,6 +328,23 @@ return item->groupType(); } +QModelIndexList KFilePlacesModel::groupIndexes(const KFilePlacesModel::GroupType type) const +{ + if (type == UnknownType) { + return QModelIndexList(); + } + + QModelIndexList indexes; + for (int row = 0; row < rowCount(); ++row) { + const QModelIndex current = index(row, 0); + if (groupType(current) == type) { + indexes << current; + } + } + + return indexes; +} + QVariant KFilePlacesModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) { diff --git a/src/filewidgets/kfileplacesview.cpp b/src/filewidgets/kfileplacesview.cpp --- a/src/filewidgets/kfileplacesview.cpp +++ b/src/filewidgets/kfileplacesview.cpp @@ -74,6 +74,7 @@ void addAppearingItem(const QModelIndex &index); void setAppearingItemProgress(qreal value); void addDisappearingItem(const QModelIndex &index); + void addDisappearingItemGroup(const QModelIndex &index); void setDisappearingItemProgress(qreal value); void setShowHoverIndication(bool show); @@ -289,6 +290,16 @@ m_disappearingItems << index; } +void KFilePlacesViewDelegate::addDisappearingItemGroup(const QModelIndex &index) +{ + const KFilePlacesModel *placesModel = static_cast(index.model()); + const QModelIndexList indexesGroup = placesModel->groupIndexes(placesModel->groupType(index)); + + for (const QModelIndex &idx : indexesGroup) { + m_disappearingItems << idx; + } +} + void KFilePlacesViewDelegate::setDisappearingItemProgress(qreal value) { value = 1.0 - value; @@ -415,7 +426,13 @@ void KFilePlacesViewDelegate::drawSectionHeader(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { - const QString category = index.data(KFilePlacesModel::GroupRole).toString(); + QString category = index.data(KFilePlacesModel::GroupRole).toString(); + + const KFilePlacesModel *placesModel = static_cast(index.model()); + if (placesModel && placesModel->isPlaceGroupHidden(index)) { + category += i18n(" (hidden)"); + } + QRect textRect(option.rect); textRect.setLeft(textRect.left() + 3); textRect.setHeight(sectionHeaderHeight()); @@ -737,8 +754,15 @@ QAction *teardown = nullptr; QAction *add = nullptr; QAction *mainSeparator = nullptr; + QAction *hideSection = nullptr; const bool clickOverHeader = delegate->pointIsHeaderArea(event->pos()); + if (clickOverHeader) { + KFilePlacesModel::GroupType type = placesModel->groupType(index); + hideSection = menu.addAction(i18n("Hide Section")); + hideSection->setCheckable(true); + hideSection->setChecked(placesModel->isPlaceGroupHidden(type)); + } if (!clickOverHeader && index.isValid()) { if (!placesModel->isDevice(index)) { if (placesModel->url(index).toString() == QLatin1String("trash:/")) { @@ -774,6 +798,9 @@ hide = menu.addAction(i18n("&Hide Entry '%1'", label)); hide->setCheckable(true); hide->setChecked(placesModel->isHidden(index)); + // if a parent is hidden no interaction should be possible with children, show it first to do so + hide->setEnabled(!placesModel->isPlaceGroupHidden(placesModel->groupType(index))); + } else { add = menu.addAction(QIcon::fromTheme(QStringLiteral("document-new")), i18n("Add Entry...")); } @@ -830,6 +857,17 @@ } else if (remove != nullptr && result == remove) { placesModel->removePlace(index); + } else if (hideSection != nullptr && result == hideSection) { + const KFilePlacesModel::GroupType type = placesModel->groupType(index); + placesModel->setPlaceGroupHidden(type, hideSection->isChecked()); + + if (!d->showAll && hideSection->isChecked()) { + delegate->addDisappearingItemGroup(index); + if (d->itemDisappearTimeline.state() != QTimeLine::Running) { + delegate->setDisappearingItemProgress(0.0); + d->itemDisappearTimeline.start(); + } + } } else if (hide != nullptr && result == hide) { placesModel->setPlaceHidden(index, hide->isChecked()); QModelIndex current = placesModel->closestItem(d->currentUrl);