| 65 | } |
| 66 | |
| 67 | QWidget *QmitkPropertyDelegate::createEditor(QWidget *parent, |
| 68 | const QStyleOptionViewItem &option, |
| 69 | const QModelIndex &index) const |
| 70 | { |
| 71 | QVariant data = index.data(Qt::EditRole); |
| 72 | QVariant displayData = index.data(Qt::DisplayRole); |
| 73 | QString name = index.model()->data(index.model()->index(index.row(), index.column() - 1)).value<QString>(); |
| 74 | |
| 75 | if (data.isValid()) |
| 76 | { |
| 77 | QWidget *editorWidget = nullptr; |
| 78 | |
| 79 | if (data.typeId() == QMetaType::QColor) |
| 80 | { |
| 81 | auto colorBtn = new QPushButton(parent); |
| 82 | QColor color = data.value<QColor>(); |
| 83 | |
| 84 | QColor result = QColorDialog::getColor(color); |
| 85 | if (result.isValid()) |
| 86 | { |
| 87 | QPalette palette = colorBtn->palette(); |
| 88 | palette.setColor(QPalette::Button, result); |
| 89 | colorBtn->setPalette(palette); |
| 90 | colorBtn->setStyleSheet( |
| 91 | QString("background-color: %1;foreground-color: %1; border-style: none;").arg(result.name())); |
| 92 | } |
| 93 | // QColorDialog closed by 'Cancel' button, use the old property color |
| 94 | else |
| 95 | { |
| 96 | QPalette palette = colorBtn->palette(); |
| 97 | palette.setColor(QPalette::Button, color); |
| 98 | colorBtn->setPalette(palette); |
| 99 | colorBtn->setStyleSheet( |
| 100 | QString("background-color: %1;foreground-color: %1; border-style: none;").arg(color.name())); |
| 101 | } |
| 102 | |
| 103 | connect(colorBtn, SIGNAL(pressed()), this, SLOT(commitAndCloseEditor())); |
| 104 | |
| 105 | editorWidget = colorBtn; |
| 106 | } |
| 107 | |
| 108 | else if (data.typeId() == QMetaType::Int) |
| 109 | { |
| 110 | auto spinBox = new QSpinBox(parent); |
| 111 | spinBox->setSingleStep(1); |
| 112 | spinBox->setMinimum(std::numeric_limits<int>::min()); |
| 113 | spinBox->setMaximum(std::numeric_limits<int>::max()); |
| 114 | editorWidget = spinBox; |
| 115 | } |
| 116 | |
| 117 | else if (data.typeId() == QMetaType::Float) |
| 118 | { |
| 119 | auto spinBox = new QDoubleSpinBox(parent); |
| 120 | spinBox->setDecimals(2); |
| 121 | spinBox->setSingleStep(0.1); |
| 122 | if (name == "opacity") |
| 123 | { |
| 124 | spinBox->setMinimum(0.0); |