Skip to content

Commit 86aff25

Browse files
authored
Merge pull request #45 from javierBarandiaran/master
Improve color selection with right button
2 parents 8a11664 + 13efd74 commit 86aff25

1 file changed

Lines changed: 14 additions & 12 deletions

File tree

src/image_canvas.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -175,20 +175,22 @@ void ImageCanvas::mouseReleaseEvent(QMouseEvent * e) {
175175
}
176176

177177
if (e->button() == Qt::RightButton) { // selection of label
178-
QColor color = _mask.id.pixel(_mouse_pos / _scale);
179-
const LabelInfo * label = _ui->id_labels[color.red()];
180-
181-
if (!_watershed.id.isNull() && _ui->checkbox_watershed_mask->isChecked()) {
182-
QColor color = QColor(_watershed.id.pixel(_mouse_pos / _scale));
183-
QMap<int, const LabelInfo*>::const_iterator it = _ui->id_labels.find(color.red());
184-
if (it != _ui->id_labels.end()) {
185-
label = it.value();
178+
QColor maskColor = _mask.id.pixel(_mouse_pos / _scale);
179+
QColor watershedColor = _watershed.id.pixel(_mouse_pos / _scale);
180+
const LabelInfo * label = _ui->id_labels[maskColor.red()] != NULL? _ui->id_labels[maskColor.red()] : _ui->id_labels[watershedColor.red()];
181+
if (label != NULL)
182+
{
183+
if (!_watershed.id.isNull() && _ui->checkbox_watershed_mask->isChecked()) {
184+
QColor color = QColor(_watershed.id.pixel(_mouse_pos / _scale));
185+
QMap<int, const LabelInfo*>::const_iterator it = _ui->id_labels.find(color.red());
186+
if (it != _ui->id_labels.end()) {
187+
label = it.value();
188+
}
186189
}
190+
if (label->item != NULL)
191+
emit(_ui->list_label->currentItemChanged(label->item, NULL));
192+
refresh();
187193
}
188-
if(label->item != NULL)
189-
emit(_ui->list_label->currentItemChanged(label->item, NULL));
190-
191-
refresh();
192194
}
193195

194196
if (e->button() == Qt::MiddleButton)

0 commit comments

Comments
 (0)