diff --git a/cuttlefish/package/contents/ui/IconGridDelegate.qml b/cuttlefish/package/contents/ui/IconGridDelegate.qml index 3eef48e..010238b 100644 --- a/cuttlefish/package/contents/ui/IconGridDelegate.qml +++ b/cuttlefish/package/contents/ui/IconGridDelegate.qml @@ -1,100 +1,100 @@ /*************************************************************************** * * * Copyright 2014-2017 Sebastian Kügler * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * * * ***************************************************************************/ import QtQuick 2.5 import QtQuick.Controls 2.5 as QQC2 import QtQuick.Layouts 1.0 import org.kde.kirigami 2.8 as Kirigami // for smallestFont import org.kde.plasma.core 2.0 as PlasmaCore MouseArea { id: delegateRoot width: iconSize + Kirigami.Units.gridUnit height: cellWidth + Math.round(Kirigami.Units.gridUnit * 2) acceptedButtons: Qt.LeftButton | Qt.RightButton function setAsPreview() { preview.fullPath = fullPath preview.iconName = iconName preview.fileName = fileName preview.category = category preview.type = type preview.iconTheme = iconTheme preview.sizes = sizes preview.scalable = scalable; } Rectangle { color: Kirigami.Theme.highlightColor opacity: iconGrid.currentIndex == index ? 0.5 : 0.0 visible: opacity != 0.0 Behavior on opacity { NumberAnimation { duration: Kirigami.Units.shortDuration } } anchors { fill: parent } } Kirigami.Icon { id: delegateIcon width: iconSize height: width source: iconName anchors { top: parent.top horizontalCenter: parent.horizontalCenter } } QQC2.Label { font.pointSize: iconSize > 96 ? Kirigami.Theme.defaultFont.pointSize : theme.smallestFont.pointSize text: iconName wrapMode: Text.Wrap maximumLineCount: 3 horizontalAlignment: Text.AlignHCenter opacity: iconGrid.currentIndex == index ? 1.0 : 0.7 anchors { left: parent.left right: parent.right top: delegateIcon.bottom topMargin: 0 margins: Math.round(-Kirigami.Units.gridUnit / 4) } } Connections { target: iconGrid - onCurrentIndexChanged: { + onCurrentItemChanged: { if (delegateRoot.GridView.isCurrentItem) { delegateRoot.setAsPreview(); } } } onClicked: (mouse) => { proxyModel.currentIndex = index iconGrid.forceActiveFocus(); if (mouse.button == Qt.RightButton) { cuttlefish.itemRightClicked() } } } diff --git a/cuttlefish/src/sortfiltermodel.cpp b/cuttlefish/src/sortfiltermodel.cpp index 29c44cd..515337c 100644 --- a/cuttlefish/src/sortfiltermodel.cpp +++ b/cuttlefish/src/sortfiltermodel.cpp @@ -1,106 +1,106 @@ /*************************************************************************** * * * Copyright 2020 David Redondo * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * * * ***************************************************************************/ #include "iconmodel.h" #include "sortfiltermodel.h" using namespace CuttleFish; SortFilterModel::SortFilterModel(QObject *parent) : QSortFilterProxyModel(parent) { setSortRole(IconModel::IconName); setSortCaseSensitivity(Qt::CaseInsensitive); } bool SortFilterModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const { const QModelIndex sourceIndex = sourceModel()->index(source_row, 0, source_parent); if (!(m_category.isEmpty() || m_category == QLatin1String("all")) && (m_category != sourceIndex.data(IconModel::Category))) { return false; } if (!m_filter.isEmpty()) { return sourceIndex.data(IconModel::IconName).toString().contains(m_filter, Qt::CaseInsensitive); } return true; } int SortFilterModel::currentIndex() { const QModelIndex index = mapFromSource(m_currentSourceIndex); if (index.isValid()) { return index.row(); - } - m_currentSourceIndex = mapFromSource(this->index(0, 0)); + } + m_currentSourceIndex = mapToSource(this->index(0, 0)); return 0; } void SortFilterModel::setCurrentIndex(int index) { if (mapFromSource(m_currentSourceIndex).row() != index) { m_currentSourceIndex = mapToSource(this->index(index, 0)); emit currentIndexChanged(); } } QString SortFilterModel::category() const { return m_category; } void SortFilterModel::setCategory(const QString &category) { if (category == m_category) { return; } int oldIndex = currentIndex(); m_category = category; invalidateFilter(); emit categoryChanged(); if (currentIndex() != oldIndex) { emit currentIndexChanged(); } } QString SortFilterModel::filter() const { return m_filter; } void SortFilterModel::setFilter(const QString& filter) { if (filter == m_filter) { return; } int oldIndex = currentIndex(); m_filter = filter; invalidateFilter(); emit filterChanged(); if (currentIndex() != oldIndex) { emit currentIndexChanged(); } }