| 48 | } |
| 49 | |
| 50 | bool ItemDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) |
| 51 | { |
| 52 | if (event->type() == QEvent::MouseMove || event->type() == QEvent::MouseButtonPress) { |
| 53 | Q_EMIT model->layoutChanged({ QPersistentModelIndex(index) }); |
| 54 | return false; |
| 55 | } else if (event->type() == QEvent::MouseButtonRelease) { |
| 56 | const QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event); |
| 57 | if (mouseEvent->button() == Qt::LeftButton) { |
| 58 | auto entity = index.data(kEntityRole).value<EntityPtr>(); |
| 59 | QPoint mousePos = view->mapFromGlobal(QCursor::pos()); |
| 60 | const auto &closeRect = closeButtonRect(option.rect); |
| 61 | if (closeRect.contains(mousePos)) { |
| 62 | Q_EMIT view->processed(entity); |
| 63 | return true; |
| 64 | } |
| 65 | |
| 66 | const auto &actInfoList = actionInfoList(option, index); |
| 67 | for (const auto &info : actInfoList) { |
| 68 | if (info.rect.contains(mousePos)) { |
| 69 | Q_EMIT view->actionInvoked(entity, info.id); |
| 70 | Q_EMIT view->processed(entity); |
| 71 | return true; |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | return false; |
| 78 | } |
| 79 | |
| 80 | QSize ItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const |
| 81 | { |