CustomItemDelegate.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #include "CustomItemDelegate.h"
  2. #include "UserInterfaceUtility.h"
  3. #include <QPainter>
  4. #include <QEvent>
  5. class CustomItemDelegatePrivate
  6. {
  7. Q_DISABLE_COPY(CustomItemDelegatePrivate)
  8. public:
  9. explicit CustomItemDelegatePrivate(CustomItemDelegate* parent);
  10. ~CustomItemDelegatePrivate();
  11. private:
  12. friend class CustomItemDelegate;
  13. CustomItemDelegate* m_Parent;
  14. };
  15. CustomItemDelegate::CustomItemDelegate(QObject *parent)
  16. : QStyledItemDelegate(parent)
  17. , m_Private(new CustomItemDelegatePrivate(this))
  18. {
  19. }
  20. CustomItemDelegate::~CustomItemDelegate()
  21. {
  22. }
  23. void CustomItemDelegate::mousePressEvent(QMouseEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
  24. {
  25. Q_UNUSED(event);
  26. Q_UNUSED(model);
  27. Q_UNUSED(option);
  28. Q_UNUSED(index);
  29. }
  30. void CustomItemDelegate::mouseMoveEvent(QMouseEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
  31. {
  32. Q_UNUSED(event);
  33. Q_UNUSED(model);
  34. Q_UNUSED(option);
  35. Q_UNUSED(index);
  36. }
  37. void CustomItemDelegate::mouseReleaseEvent(QMouseEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
  38. {
  39. Q_UNUSED(event);
  40. Q_UNUSED(model);
  41. Q_UNUSED(option);
  42. Q_UNUSED(index);
  43. }
  44. bool CustomItemDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
  45. {
  46. switch (event->type()) {
  47. case QEvent::MouseButtonPress: {
  48. QMouseEvent* mouseEvent = reinterpret_cast<QMouseEvent*>(event);
  49. if (NULL != mouseEvent) {
  50. mousePressEvent(mouseEvent, model, option, index);
  51. }
  52. break;
  53. }
  54. case QEvent::MouseMove: {
  55. QMouseEvent* mouseEvent = reinterpret_cast<QMouseEvent*>(event);
  56. if (NULL != mouseEvent) {
  57. mouseMoveEvent(mouseEvent, model, option, index);
  58. }
  59. break;
  60. }
  61. case QEvent::MouseButtonRelease: {
  62. QMouseEvent* mouseEvent = reinterpret_cast<QMouseEvent*>(event);
  63. if (NULL != mouseEvent) {
  64. mouseReleaseEvent(mouseEvent, model, option, index);
  65. }
  66. break;
  67. }
  68. default: {
  69. break;
  70. }
  71. }
  72. return QStyledItemDelegate::editorEvent(event, model, option, index);
  73. }
  74. QWidget *CustomItemDelegate::createEditor(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
  75. {
  76. return QStyledItemDelegate::createEditor(editor, option, index);
  77. }
  78. void CustomItemDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
  79. {
  80. QStyledItemDelegate::updateEditorGeometry(editor, option, index);
  81. }
  82. QSize CustomItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
  83. {
  84. return QStyledItemDelegate::sizeHint(option, index);
  85. }
  86. void CustomItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
  87. {
  88. QStyledItemDelegate::setEditorData(editor, index);
  89. }
  90. void CustomItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
  91. {
  92. QStyledItemDelegate::setModelData(editor, model, index);
  93. }
  94. void CustomItemDelegate::onCurrentIndexChange(const QModelIndex &index)
  95. {
  96. Q_UNUSED(index);
  97. }
  98. void CustomItemDelegate::onPressIndexChanged(const QModelIndex &index)
  99. {
  100. Q_UNUSED(index);
  101. }
  102. void CustomItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
  103. {
  104. Q_UNUSED(painter);
  105. Q_UNUSED(option);
  106. Q_UNUSED(index);
  107. // QItemDelegate::paint(painter, option, index);
  108. }
  109. CustomItemDelegatePrivate::CustomItemDelegatePrivate(CustomItemDelegate *parent)
  110. : m_Parent(parent)
  111. {
  112. }
  113. CustomItemDelegatePrivate::~CustomItemDelegatePrivate()
  114. {
  115. }