Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkNewSegmentationDialog.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
18 
19 #include "mitkOrganTypeProperty.h"
20 
21 #include <itkRGBPixel.h>
22 
23 #include <QAbstractItemModel>
24 #include <QColorDialog>
25 #include <QStringListModel>
26 #include <qlabel.h>
27 #include <qlayout.h>
28 #include <qlineedit.h>
29 #include <qpushbutton.h>
30 
32  : QDialog(parent), // true, modal
33  selectedOrgan(tr("undefined")),
34  newOrganEntry(false)
35 {
36  QDialog::setFixedSize(250, 105);
37 
38  QBoxLayout *verticalLayout = new QVBoxLayout(this);
39  verticalLayout->setMargin(5);
40  verticalLayout->setSpacing(5);
41 
43 
44  // to enter a name for the segmentation
45  lblPrompt = new QLabel(tr("Name and color of the segmentation"), this);
46  verticalLayout->addWidget(lblPrompt);
47 
48  // to choose a color
49  btnColor = new QPushButton("", this);
50  btnColor->setFixedWidth(25);
51  btnColor->setAutoFillBackground(true);
52  btnColor->setStyleSheet("background-color:rgb(255,0,0)");
53 
54  connect(btnColor, SIGNAL(clicked()), this, SLOT(onColorBtnClicked()));
55 
56  edtName = new QLineEdit("", this);
57  QStringList completionList;
58  completionList << "";
59  completer = new QCompleter(completionList);
60  completer->setCaseSensitivity(Qt::CaseInsensitive);
61  edtName->setCompleter(completer);
62 
63  connect(completer, SIGNAL(activated(const QString &)), this, SLOT(onColorChange(const QString &)));
64 
65  QBoxLayout *horizontalLayout2 = new QHBoxLayout();
66  verticalLayout->addLayout(horizontalLayout2);
67  horizontalLayout2->addWidget(btnColor);
68  horizontalLayout2->addWidget(edtName);
69 
70  // buttons for closing the dialog
71  btnOk = new QPushButton(tr("Ok"), this);
72  btnOk->setDefault(true);
73  connect(btnOk, SIGNAL(clicked()), this, SLOT(onAcceptClicked()));
74 
75  QPushButton *btnCancel = new QPushButton(tr("Cancel"), this);
76  connect(btnCancel, SIGNAL(clicked()), this, SLOT(reject()));
77 
78  QBoxLayout *horizontalLayout = new QHBoxLayout();
79  verticalLayout->addLayout(horizontalLayout);
80  horizontalLayout->setSpacing(5);
81  horizontalLayout->addStretch();
82  horizontalLayout->addWidget(btnOk);
83  horizontalLayout->addWidget(btnCancel);
84 
85  edtName->setFocus();
86 }
87 
89 {
90 }
91 
93 {
94  m_SegmentationName = edtName->text();
95  this->accept();
96 }
97 
99 {
100  return m_SegmentationName;
101 }
102 
104 {
105  return selectedOrgan.toLocal8Bit().constData();
106 }
107 
109 {
110  if (!newText.isEmpty())
111  {
112  btnOk->setEnabled(true);
113  }
114 
115  selectedOrgan = newText;
116  this->setSegmentationName(newText);
117 }
118 
120 {
121  m_Color = QColorDialog::getColor();
122  if (m_Color.spec() == 0)
123  {
124  m_Color.setRed(255);
125  m_Color.setGreen(0);
126  m_Color.setBlue(0);
127  }
128  btnColor->setStyleSheet(
129  QString("background-color:rgb(%1,%2, %3)").arg(m_Color.red()).arg(m_Color.green()).arg(m_Color.blue()));
130 }
131 
132 void QmitkNewSegmentationDialog::setPrompt(const QString &prompt)
133 {
134  lblPrompt->setText(prompt);
135 }
136 
138 {
139  edtName->setText(name);
140  m_SegmentationName = name;
141 }
142 
144 {
145  mitk::Color colorProperty;
146  if (m_Color.spec() == 0)
147  {
148  colorProperty.SetRed(1);
149  colorProperty.SetGreen(0);
150  colorProperty.SetBlue(0);
151  }
152  else
153  {
154  colorProperty.SetRed(m_Color.redF());
155  colorProperty.SetGreen(m_Color.greenF());
156  colorProperty.SetBlue(m_Color.blueF());
157  }
158  return colorProperty;
159 }
160 
161 void QmitkNewSegmentationDialog::SetSuggestionList(QStringList organColorList)
162 {
163  QStringList::iterator iter;
164  for (iter = organColorList.begin(); iter != organColorList.end(); ++iter)
165  {
166  QString &element = *iter;
167  QString colorName = element.right(7);
168  QColor color(colorName);
169  QString organName = element.left(element.size() - 7);
170 
171  organList.push_back(organName);
172  colorList.push_back(color);
173  }
174 
175  QStringListModel *completeModel = static_cast<QStringListModel *>(completer->model());
176  completeModel->setStringList(organList);
177 }
178 
179 void QmitkNewSegmentationDialog::onColorChange(const QString &completedWord)
180 {
181  if (organList.contains(completedWord))
182  {
183  int j = organList.indexOf(completedWord);
184  m_Color = colorList.at(j);
185  btnColor->setStyleSheet(
186  QString("background-color:rgb(%1,%2, %3)").arg(m_Color.red()).arg(m_Color.green()).arg(m_Color.blue()));
187  }
188 }
void setPrompt(const QString &prompt)
void setSegmentationName(const QString &name)
static Pointer New()
void SetSuggestionList(QStringList organColorList)
void onColorChange(const QString &completedWord)
itk::RGBPixel< float > Color
Color Standard RGB color typedef (float)
QmitkNewSegmentationDialog(QWidget *parent=nullptr)