Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support freeform-sort drop animation #434

Merged
merged 1 commit into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions qml/windowed/FreeSortListView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ Item {
anchors.fill: parent
highlightFollowsCurrentItem: true

displaced: Transition { NumberAnimation { properties: "y"; duration: 150 } }
move: displaced
moveDisplaced: displaced

clip: true
highlight: Item {
FocusBoxBorder {
Expand Down Expand Up @@ -84,7 +88,19 @@ Item {
}
}

model: freeSortProxyModel
model: FreeSortProxyModel {
id: freeSortProxyModel
sourceModel: MultipageSortFilterProxyModel {
filterOnlyMode: true
sourceModel: ItemArrangementProxyModel
pageId: -1
folderId: 0
}
sortRole: ItemArrangementProxyModel.IndexInPageRole
Component.onCompleted: {
freeSortProxyModel.sort(0)
}
}
delegate: DropArea {
width: listView.width
height: itemDelegate.height
Expand Down Expand Up @@ -264,9 +280,4 @@ Item {
Keys.onSpacePressed: launchItem()
}
}

FreeSortProxyModel {
id: freeSortProxyModel
sourceModel: ItemArrangementProxyModel
}
}
19 changes: 1 addition & 18 deletions src/models/freesortproxymodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,8 @@
#include "itemarrangementproxymodel.h"

FreeSortProxyModel::FreeSortProxyModel(QObject *parent)
: QSortFilterProxyModel(parent)
: SortProxyModel(parent)
{
setSortRole(ItemArrangementProxyModel::FolderIdNumberRole);
setDynamicSortFilter(true);
}

void FreeSortProxyModel::setModel(QAbstractItemModel *model)
{
if (model == sourceModel()) {
return;
}

setSourceModel(model);
sort(0);
}

bool FreeSortProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
{
return sourceModel()->data(sourceModel()->index(source_row, 0, source_parent), ItemArrangementProxyModel::FolderIdNumberRole).toInt() == 0;
}

bool FreeSortProxyModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const
Expand Down
16 changes: 4 additions & 12 deletions src/models/freesortproxymodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,18 @@
#ifndef FREE_SORT_PROXY_MODEL_H
#define FREE_SORT_PROXY_MODEL_H

#include <QtQml/qqml.h>
#include <QSortFilterProxyModel>
#include <QQmlEngine>

class FreeSortProxyModel : public QSortFilterProxyModel
#include "sortproxymodel.h"

class FreeSortProxyModel : public SortProxyModel
{
Q_OBJECT

Q_PROPERTY(QAbstractItemModel *sourceModel READ sourceModel WRITE setModel NOTIFY sourceModelChanged)
QML_NAMED_ELEMENT(FreeSortProxyModel)

public:
explicit FreeSortProxyModel(QObject *parent = nullptr);

void setModel(QAbstractItemModel *model);

signals:
void sourceModelChanged(QObject *);

protected:
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override;
};

Expand Down
2 changes: 1 addition & 1 deletion src/models/multipagesortfilterproxymodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void MultipageSortFilterProxyModel::setModel(QAbstractItemModel *model)
bool MultipageSortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
{
return sourceModel()->data(sourceModel()->index(source_row, 0, source_parent), ItemArrangementProxyModel::FolderIdNumberRole).toInt() == m_folderId &&
sourceModel()->data(sourceModel()->index(source_row, 0, source_parent), ItemArrangementProxyModel::PageRole).toInt() == m_pageId;
(m_pageId == -1 || sourceModel()->data(sourceModel()->index(source_row, 0, source_parent), ItemArrangementProxyModel::PageRole).toInt() == m_pageId);
}

bool MultipageSortFilterProxyModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const
Expand Down
2 changes: 1 addition & 1 deletion src/models/sortproxymodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class SortProxyModel : public QAbstractProxyModel
void sortOrderChanged();

protected:
bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const;
virtual bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const;
tsic404 marked this conversation as resolved.
Show resolved Hide resolved

protected Q_SLOTS:
void resetInternalData() override;
Expand Down
Loading