| 64 | } |
| 65 | |
| 66 | bool ProjectItemDelegate::editorEvent(QEvent *event, |
| 67 | QAbstractItemModel *model, |
| 68 | const QStyleOptionViewItem &option, |
| 69 | const QModelIndex &index) |
| 70 | { |
| 71 | if (event->type() == QEvent::MouseButtonRelease || event->type() == QEvent::MouseButtonDblClick) { |
| 72 | QStyleOptionViewItem opt = option; |
| 73 | opt.rect.adjust(10, 0, -10, 0); |
| 74 | QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event); |
| 75 | |
| 76 | int depth = itemDepth(index); |
| 77 | if (index.model()->flags(index).testFlag(Qt::ItemIsUserCheckable)) { |
| 78 | const QRect checkRect = checkBoxRect(depth, opt.rect); |
| 79 | if (checkRect.contains(mouseEvent->pos())) { |
| 80 | Qt::CheckState state = static_cast<Qt::CheckState>(index.data(Qt::CheckStateRole).toInt()); |
| 81 | Qt::CheckState newState = state == Qt::Checked ? Qt::Unchecked : Qt::Checked; |
| 82 | |
| 83 | updateChildrenCheckState(model, index, newState); |
| 84 | updateParentCheckState(model, index); |
| 85 | return true; |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | const QRect arRect = arrowRect(depth, opt.rect); |
| 90 | if (arRect.contains(mouseEvent->pos())) { |
| 91 | if (view->isExpanded(index)) { |
| 92 | view->collapse(index); |
| 93 | } else { |
| 94 | view->expand(index); |
| 95 | } |
| 96 | return true; |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | return false; |
| 101 | } |
| 102 | |
| 103 | bool ProjectItemDelegate::helpEvent(QHelpEvent *event, |
| 104 | QAbstractItemView *view, |