vstyleditemdelegate.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #ifndef VSTYLEDITEMDELEGATE_H
  2. #define VSTYLEDITEMDELEGATE_H
  3. #include <QStyledItemDelegate>
  4. #include <QBrush>
  5. #include <QSet>
  6. class VStyledItemDelegate : public QStyledItemDelegate
  7. {
  8. public:
  9. explicit VStyledItemDelegate(QObject *p_parent = Q_NULLPTR);
  10. virtual void paint(QPainter *p_painter,
  11. const QStyleOptionViewItem &p_option,
  12. const QModelIndex &p_index) const Q_DECL_OVERRIDE;
  13. void setHitItems(const QSet<QModelIndex> &p_hitItems);
  14. void clearHitItems();
  15. private:
  16. bool isHit(const QModelIndex &p_index) const;
  17. QBrush m_itemHitBg;
  18. QBrush m_itemHitFg;
  19. QSet<QModelIndex> m_hitItems;
  20. };
  21. inline void VStyledItemDelegate::setHitItems(const QSet<QModelIndex> &p_hitItems)
  22. {
  23. m_hitItems = p_hitItems;
  24. }
  25. inline void VStyledItemDelegate::clearHitItems()
  26. {
  27. m_hitItems.clear();
  28. }
  29. inline bool VStyledItemDelegate::isHit(const QModelIndex &p_index) const
  30. {
  31. if (m_hitItems.isEmpty()) {
  32. return false;
  33. }
  34. return m_hitItems.contains(p_index);
  35. }
  36. #endif // VSTYLEDITEMDELEGATE_H