| 38 | } |
| 39 | |
| 40 | bool QmitkLabelColorItemDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &, |
| 41 | const QModelIndex &index) |
| 42 | { |
| 43 | Q_ASSERT(event); |
| 44 | Q_ASSERT(model); |
| 45 | |
| 46 | // make sure that the item is checkable |
| 47 | Qt::ItemFlags flags = model->flags(index); |
| 48 | if (!(flags & Qt::ItemIsEditable) || !(flags & Qt::ItemIsEnabled)) |
| 49 | { |
| 50 | return false; |
| 51 | } |
| 52 | |
| 53 | // make sure that we have the right event type |
| 54 | QMouseEvent* mouseEvent = dynamic_cast<QMouseEvent*>(event); |
| 55 | if (nullptr == mouseEvent || mouseEvent->type() != QEvent::MouseButtonRelease || mouseEvent->button() != Qt::LeftButton) |
| 56 | { |
| 57 | return false; |
| 58 | } |
| 59 | |
| 60 | QColor oldColor = index.data(Qt::EditRole).value<QColor>(); |
| 61 | QColor newColor = QColorDialog::getColor(oldColor, nullptr); |
| 62 | |
| 63 | if (newColor.isValid()) |
| 64 | { |
| 65 | return model->setData(index, QVariant(newColor), Qt::EditRole); |
| 66 | } |
| 67 | |
| 68 | return false; |
| 69 | }; |