Index: src/filewidgets/kfileplacesmodel.h =================================================================== --- src/filewidgets/kfileplacesmodel.h +++ 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; Index: src/filewidgets/kfileplacesmodel.cpp =================================================================== --- src/filewidgets/kfileplacesmodel.cpp +++ src/filewidgets/kfileplacesmodel.cpp @@ -326,6 +326,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()) { Index: src/filewidgets/kfileplacesview.cpp =================================================================== --- src/filewidgets/kfileplacesview.cpp +++ 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,17 @@ m_disappearingItems << index; } +void KFilePlacesViewDelegate::addDisappearingItemGroup(const QModelIndex &index) +{ + const KFilePlacesModel *placesModel = static_cast(index.model()); + const QModelIndexList indexesGroup = placesModel->groupIndexes(placesModel->groupType(index)); + + m_disappearingItems.reserve(m_disappearingItems.count() + indexesGroup.count()); + for (const QModelIndex &idx : indexesGroup) { + m_disappearingItems << idx; + } +} + void KFilePlacesViewDelegate::setDisappearingItemProgress(qreal value) { value = 1.0 - value; @@ -415,7 +427,9 @@ void KFilePlacesViewDelegate::drawSectionHeader(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { - const QString category = index.data(KFilePlacesModel::GroupRole).toString(); + const KFilePlacesModel *placesModel = static_cast(index.model()); + const QString category = index.data(KFilePlacesModel::GroupRole).toString() + (placesModel->isPlaceGroupHidden(index) ? i18n(" (hidden)") : QString()); + QRect textRect(option.rect); textRect.setLeft(textRect.left() + 3); textRect.setHeight(sectionHeaderHeight()); @@ -737,8 +751,15 @@ QAction *teardown = nullptr; QAction *add = nullptr; QAction *mainSeparator = nullptr; + QAction *hideSection = nullptr; const bool clickOverHeader = delegate->pointIsHeaderArea(event->pos()); + if (clickOverHeader) { + const 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 +795,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...")); } @@ -828,9 +852,20 @@ placesModel->editPlace(index, label, url, iconName, appName); } - } else if (remove != nullptr && result == remove) { + } else if (remove && (result == remove)) { placesModel->removePlace(index); - } else if (hide != nullptr && result == hide) { + } else if (hideSection && (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 && (result == hide)) { placesModel->setPlaceHidden(index, hide->isChecked()); QModelIndex current = placesModel->closestItem(d->currentUrl);