]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Implemented support for hide/show groups
authorRenato Araujo Oliveira Filho <renato.araujo@kdab.com>
Thu, 7 Dec 2017 14:36:00 +0000 (11:36 -0300)
committerRenato Araujo Oliveira Filho <renato.araujo@kdab.com>
Thu, 14 Dec 2017 12:42:13 +0000 (09:42 -0300)
Summary:
Added an option on PlacesPanel context menu to show or hide the entire
group of places.

Depends on D8855

Test Plan: Open Donlphin and use PlacesPanel context menu to hide and show groups

Reviewers: franckarrecot, mlaurent, mwolff, elvisangelaccio

Reviewed By: franckarrecot, mlaurent, mwolff, elvisangelaccio

Subscribers: rkflx, mwolff, elvisangelaccio, ngraham, #dolphin

Differential Revision: https://phabricator.kde.org/D9242

src/kitemviews/kitemlistcontroller.cpp
src/kitemviews/kitemlistcontroller.h
src/panels/places/placesitem.cpp
src/panels/places/placesitem.h
src/panels/places/placesitemlistwidget.cpp
src/panels/places/placesitemmodel.cpp
src/panels/places/placesitemmodel.h
src/panels/places/placespanel.cpp
src/panels/places/placespanel.h

index 61f520641cf0b2fc9e9322fbf5c36a63d71a2de9..1309364884ee5fa708492c50c7e15fc26b5a0850 100644 (file)
@@ -179,6 +179,20 @@ KItemListController::MouseDoubleClickAction KItemListController::mouseDoubleClic
     return m_mouseDoubleClickAction;
 }
 
+int KItemListController::indexCloseToMousePressedPosition() const
+{
+    QHashIterator<KItemListWidget*, KItemListGroupHeader*> it(m_view->m_visibleGroups);
+    while (it.hasNext()) {
+        it.next();
+        KItemListGroupHeader *groupHeader = it.value();
+        const QPointF mappedToGroup = groupHeader->mapFromItem(nullptr, m_pressedMousePos);
+        if (groupHeader->contains(mappedToGroup)) {
+            return it.key()->index();
+        }
+    }
+    return -1;
+}
+
 void KItemListController::setAutoActivationDelay(int delay)
 {
     m_autoActivationTimer->setInterval(delay);
index 7c48fb18c14b51ba12fa15f540284191a7ea7be1..3de5edece9e79913abad5a18e4b85f09557ad65a 100644 (file)
@@ -108,6 +108,8 @@ public:
     void setMouseDoubleClickAction(MouseDoubleClickAction action);
     MouseDoubleClickAction mouseDoubleClickAction() const;
 
+    int indexCloseToMousePressedPosition() const;
+
     /**
      * Sets the delay in milliseconds when dragging an object above an item
      * until the item gets activated automatically. A value of -1 indicates
index c473856565f4961107d70cc1673d32053399938c..d7e87cf7a9e41944f2992fef09cbc966997c9b62 100644 (file)
@@ -102,6 +102,16 @@ bool PlacesItem::isHidden() const
     return dataValue("isHidden").toBool();
 }
 
+bool PlacesItem::isGroupHidden() const
+{
+    return dataValue("isGroupHidden").toBool();
+}
+
+void PlacesItem::setGroupHidden(bool hidden)
+{
+    setDataValue("isGroupHidden", hidden);
+}
+
 void PlacesItem::setSystemItem(bool isSystemItem)
 {
     setDataValue("isSystemItem", isSystemItem);
index d32c616db860393e98df2ed1ee7baaca3c260507..733265d468c8ade9bfbe912af6da694b3dd30e86 100644 (file)
@@ -52,6 +52,9 @@ public:
     void setHidden(bool hidden);
     bool isHidden() const;
 
+    void setGroupHidden(bool hidden);
+    bool isGroupHidden() const;
+
     void setSystemItem(bool isSystemItem);
     bool isSystemItem() const;
 
index 18e5618640cc6e29d94d19772afbf37d5ba158eb..b0b3fb2aa288bd2858cb8b598b3fc7af38fe83bb 100644 (file)
@@ -30,7 +30,8 @@ PlacesItemListWidget::~PlacesItemListWidget()
 
 bool PlacesItemListWidget::isHidden() const
 {
-    return data().value("isHidden").toBool();
+    return data().value("isHidden").toBool() ||
+           data().value("isGroupHidden").toBool();
 }
 
 QPalette::ColorRole PlacesItemListWidget::normalTextColorRole() const
index 074b7ab452689dce4b19c14b8da8ea5af40f9fdb..577596c7422beb7807ce13404dbdf4db98c71c8a 100644 (file)
@@ -73,6 +73,7 @@ PlacesItemModel::PlacesItemModel(QObject* parent) :
     connect(m_sourceModel.data(), &KFilePlacesModel::dataChanged, this, &PlacesItemModel::onSourceModelDataChanged);
     connect(m_sourceModel.data(), &KFilePlacesModel::rowsAboutToBeMoved, this, &PlacesItemModel::onSourceModelRowsAboutToBeMoved);
     connect(m_sourceModel.data(), &KFilePlacesModel::rowsMoved, this, &PlacesItemModel::onSourceModelRowsMoved);
+    connect(m_sourceModel.data(), &KFilePlacesModel::groupHiddenChanged, this, &PlacesItemModel::onSourceModelGroupHiddenChanged);
 }
 
 PlacesItemModel::~PlacesItemModel()
@@ -195,11 +196,13 @@ void PlacesItemModel::onItemChanged(int index, const QSet<QByteArray>& changedRo
         qWarning() << "invalid item changed signal";
         return;
     }
-
     if (changedRoles.contains("isHidden")) {
-        m_sourceModel->setPlaceHidden(sourceIndex, changedItem->isHidden());
+        if (m_sourceModel->isHidden(sourceIndex) != changedItem->isHidden()) {
+            m_sourceModel->setPlaceHidden(sourceIndex, changedItem->isHidden());
+        } else {
+            m_sourceModel->refresh();
+        }
     }
-
     KStandardItemModel::onItemChanged(index, changedRoles);
 }
 
@@ -470,6 +473,7 @@ void PlacesItemModel::updateItem(PlacesItem *item, const QModelIndex &index)
 {
     item->setGroup(index.data(KFilePlacesModel::GroupRole).toString());
     item->setIcon(index.data(KFilePlacesModel::IconNameRole).toString());
+    item->setGroupHidden(index.data(KFilePlacesModel::GroupHiddenRole).toBool());
 }
 
 void PlacesItemModel::slotStorageTearDownDone(Solid::ErrorType error, const QVariant& errorData)
@@ -590,6 +594,16 @@ void PlacesItemModel::onSourceModelDataChanged(const QModelIndex &topLeft, const
     }
 }
 
+void PlacesItemModel::onSourceModelGroupHiddenChanged(KFilePlacesModel::GroupType group, bool hidden)
+{
+    for(const QModelIndex &sourceIndex : m_sourceModel->groupIndexes(group)) {
+        PlacesItem *item = placesItem(mapFromSource(sourceIndex));
+        if (item) {
+            item->setGroupHidden(hidden);
+        }
+    }
+}
+
 void PlacesItemModel::loadBookmarks()
 {
     for(int r = 0, rMax = m_sourceModel->rowCount(); r < rMax; r++) {
@@ -730,6 +744,21 @@ bool PlacesItemModel::isDir(int index) const
     return true;
 }
 
+KFilePlacesModel::GroupType PlacesItemModel::groupType(int row) const
+{
+    return m_sourceModel->groupType(mapToSource(row));
+}
+
+bool PlacesItemModel::isGroupHidden(KFilePlacesModel::GroupType type) const
+{
+    return m_sourceModel->isGroupHidden(type);
+}
+
+void PlacesItemModel::setGroupHidden(KFilePlacesModel::GroupType type, bool hidden)
+{
+    return m_sourceModel->setGroupHidden(type, hidden);
+}
+
 QModelIndex PlacesItemModel::mapToSource(int row) const
 {
     return m_indexMap.value(row);
index b701c8ea9b43fcabb235eb2ddeeb3f2e70a05d4a..c8830ee6f4c54f19453bbb16fa42c37ef672de0e 100644 (file)
@@ -21,6 +21,7 @@
 #define PLACESITEMMODEL_H
 
 #include <kitemviews/kstandarditemmodel.h>
+#include <KFilePlacesModel>
 
 #include <QUrl>
 #include <QHash>
@@ -31,7 +32,6 @@
 
 class KBookmark;
 class KBookmarkManager;
-class KFilePlacesModel;
 class PlacesItem;
 class QAction;
 
@@ -137,6 +137,12 @@ public:
     void refresh();
 
     bool isDir(int index) const override;
+
+
+    KFilePlacesModel::GroupType groupType(int row) const;
+    bool isGroupHidden(KFilePlacesModel::GroupType type) const;
+    void setGroupHidden(KFilePlacesModel::GroupType type, bool hidden);
+
 signals:
     void errorMessage(const QString& message);
     void storageSetupDone(int index, bool success);
@@ -158,6 +164,7 @@ private slots:
     void onSourceModelRowsAboutToBeMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row);
     void onSourceModelRowsMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row);
     void onSourceModelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles);
+    void onSourceModelGroupHiddenChanged(KFilePlacesModel::GroupType group, bool hidden);
 
 private:
     /**
index d8eab7dd928a443a078d710c4f333e995bba394a..f7ca7d010dea5487c91d4fdc9e17dd3c711dd3de 100644 (file)
@@ -223,6 +223,8 @@ void PlacesPanel::slotItemContextMenuRequested(int index, const QPointF& pos)
     hideAction->setCheckable(true);
     hideAction->setChecked(item->isHidden());
 
+    buildGroupContextMenu(&menu, index);
+
     QAction* action = menu.exec(pos.toPoint());
     if (action) {
         if (action == emptyTrashAction) {
@@ -273,6 +275,8 @@ void PlacesPanel::slotViewContextMenuRequested(const QPointF& pos)
         showAllAction->setChecked(m_model->hiddenItemsShown());
     }
 
+    buildGroupContextMenu(&menu, m_controller->indexCloseToMousePressedPosition());
+
     QMenu* iconSizeSubMenu = new QMenu(i18nc("@item:inmenu", "Icon Size"), &menu);
 
     struct IconSizeInfo
@@ -326,6 +330,24 @@ void PlacesPanel::slotViewContextMenuRequested(const QPointF& pos)
     selectClosestItem();
 }
 
+QAction *PlacesPanel::buildGroupContextMenu(QMenu *menu, int index)
+{
+    if (index == -1) {
+        return nullptr;
+    }
+
+    KFilePlacesModel::GroupType groupType = m_model->groupType(index);
+    QAction *hideGroupAction = menu->addAction(i18nc("@item:inmenu", "Hide Section '%1'", m_model->item(index)->group()));
+    hideGroupAction->setCheckable(true);
+    hideGroupAction->setChecked(m_model->isGroupHidden(groupType));
+
+    connect(hideGroupAction, &QAction::triggered, this, [this, groupType, hideGroupAction]{
+        m_model->setGroupHidden(groupType, hideGroupAction->isChecked());
+    });
+
+    return hideGroupAction;
+}
+
 void PlacesPanel::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* event)
 {
     if (index < 0) {
index f5c90b1f9d075e3e134491f56d75f22d09f6cfa6..444785888ec0cfce0fb80b0d4f1a4875980987d6 100644 (file)
@@ -31,6 +31,7 @@ class PlacesItemModel;
 class PlacesView;
 class QGraphicsSceneDragDropEvent;
 class KJob;
+class QMenu;
 /**
  * @brief Combines bookmarks and mounted devices as list.
  */
@@ -82,6 +83,8 @@ private:
 
     void triggerItem(int index, Qt::MouseButton button);
 
+    QAction* buildGroupContextMenu(QMenu* menu, int index);
+
 private:
     KItemListController* m_controller;
     PlacesItemModel* m_model;