mirror of
https://invent.kde.org/system/dolphin
synced 2024-07-04 17:30:55 +00:00
Implemented support for hide/show groups
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
This commit is contained in:
parent
da6f8fe086
commit
5f1df43b87
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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:
|
||||
/**
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue
Block a user