75 lines
1.9 KiB
C++
75 lines
1.9 KiB
C++
// BCItemDelegate.h
|
|
#ifndef BCITEMDELEGATE_H
|
|
#define BCITEMDELEGATE_H
|
|
|
|
#include <QStyledItemDelegate>
|
|
|
|
class QPropertyAnimation;
|
|
class QVariantAnimation;
|
|
class QListView;
|
|
|
|
class BCItemDelegate : public QStyledItemDelegate
|
|
{
|
|
Q_OBJECT
|
|
Q_PROPERTY(qreal highlightOpacity READ highlightOpacity WRITE setHighlightOpacity)
|
|
|
|
public:
|
|
|
|
explicit BCItemDelegate(QListView *view );
|
|
|
|
QString displayText(const QVariant& dataValue, const QLocale& locale) const override;
|
|
|
|
// Zuständig für den Edit-Modus (Doppelklick)
|
|
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
|
void setEditorData(QWidget *editor, const QModelIndex &index) const override;
|
|
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
|
|
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
|
|
|
QSize sizeHint(const QStyleOptionViewItem &option,const QModelIndex &index) const override;
|
|
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
|
|
|
qreal highlightOpacity() const
|
|
{
|
|
return _opacity;
|
|
}
|
|
|
|
void setHighlightOpacity(qreal opacity)
|
|
{
|
|
_opacity = opacity;
|
|
//qDebug() << " --- opa: " << opacity;
|
|
emit viewUpdateNeeded();
|
|
}
|
|
|
|
|
|
void clearAllHighlights();
|
|
|
|
public slots:
|
|
|
|
void onHighlightRow(int row);
|
|
|
|
|
|
signals:
|
|
|
|
void viewUpdateNeeded();
|
|
|
|
private:
|
|
|
|
void updateRow(int row);
|
|
QString formatDisplayString(const QModelIndex &index) const;
|
|
void paintHighlightRow(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
|
|
|
|
int _highlightedRow{-1};
|
|
qreal _opacity{1.0};
|
|
QListView* _view{};
|
|
QPropertyAnimation *_animation{};
|
|
|
|
private:
|
|
|
|
QHash<int, qreal> m_rowOpacities;
|
|
QHash<int, QVariantAnimation*> m_rowAnimations;
|
|
|
|
};
|
|
|
|
|
|
#endif // BCITEMDELEGATE_H
|