32 #ifndef CUSTOMITEMDELEGATE_H
33 #define CUSTOMITEMDELEGATE_H
35 #include <QStyledItemDelegate>
36 #include <QFileSystemModel>
41 #include "CustomFileSystemModel.h"
43 #include <QItemSelectionModel>
44 #include <QStandardItemModel>
45 #include "CustomFileIconProvider.h"
46 #include <QAbstractProxyModel>
51 DelegatePositionRole = Qt::UserRole + 1
72 explicit CustomItemDelegate(QObject* parent =
nullptr, QAbstractProxyModel* fileSystemModel =
nullptr);
83 void paint(QPainter *painter,
const QStyleOptionViewItem &option,
84 const QModelIndex &index)
const override;
112 QSize
sizeHint(
const QStyleOptionViewItem& option,
const QModelIndex& index)
const override {
114 QSize size = QStyledItemDelegate::sizeHint(option, index);
115 return QSize(option.rect.width(), size.height());
157 QWidget*
createEditor(QWidget* parent,
const QStyleOptionViewItem& option,
const QModelIndex& index)
const override;
165 void setModelData(QWidget* editor, QAbstractItemModel* model,
const QModelIndex& index)
const override;
173 void fileDropped(
const QString& filePath,
const QPoint& iconPosition);
177 bool editorEvent(QEvent *event, QAbstractItemModel *model,
const QStyleOptionViewItem &option,
178 const QModelIndex &index)
override;
182 QAbstractProxyModel *m_fileSystemModel;
185 bool iconShown =
false;
186 bool iconVisible =
false;
196 QTimeLine* animationTimeline;
198 qreal currentAnimationValue;
201 mutable QModelIndex m_currentIndex;
202 QModelIndex m_animatedIndex;
203 mutable QStyleOptionViewItem m_currentOption;
205 QItemSelectionModel* m_selectionModel;
CustomItemDelegateRole
Add a custom role to store the delegate position.
Definition: CustomItemDelegate.h:50
A custom delegate for rendering items in views.
Definition: CustomItemDelegate.h:63
bool isAnimationRunning() const
Checks if an animation is currently running.
Definition: CustomItemDelegate.cpp:485
void animationFinished()
Slot called when the animation has finished.
Definition: CustomItemDelegate.cpp:432
void fileDropped(const QString &filePath, const QPoint &iconPosition)
Signal emitted when a file is dropped onto the delegate item.
void animationValueChanged(double value)
Animates the value change for the animation.
Definition: CustomItemDelegate.cpp:414
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Creates and returns a custom editor widget.
Definition: CustomItemDelegate.cpp:491
void setSelectionModel(QItemSelectionModel *selectionModel)
Installs event filters on the specified view to intercept events.
Definition: CustomItemDelegate.cpp:480
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override
Overrides the sizeHint method to set the size of the delegate items.
Definition: CustomItemDelegate.h:112
void stopAnimation()
Stops the currently running animation.
Definition: CustomItemDelegate.cpp:455
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override
Sets the model data based on the edited data in the editor.
Definition: CustomItemDelegate.cpp:520
void startAnimation(const QModelIndex &index)
Starts an animation for the specified index.
Definition: CustomItemDelegate.cpp:462
CustomItemDelegate(QObject *parent=nullptr, QAbstractProxyModel *fileSystemModel=nullptr)
Constructs a CustomItemDelegate object.
Definition: CustomItemDelegate.cpp:50
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Renders the item's appearance using a QPainter.
Definition: CustomItemDelegate.cpp:85