Medical Imaging Interaction Toolkit  2018.4.99-389bf124
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 (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
14 
15 #include <itkRGBPixel.h>
16 
17 #include <QAbstractItemModel>
18 #include <QColorDialog>
19 #include <QStringListModel>
20 #include <qlabel.h>
21 #include <qlayout.h>
22 #include <qlineedit.h>
23 #include <qpushbutton.h>
24 
26  : QDialog(parent) // true, modal
27  , selectedOrgan(tr("undefined"))
28  , newOrganEntry(false)
29 {
30  QDialog::setFixedSize(250, 105);
31 
32  QBoxLayout *verticalLayout = new QVBoxLayout(this);
33  verticalLayout->setMargin(5);
34  verticalLayout->setSpacing(5);
35 
36  // to enter a name for the segmentation
37  lblPrompt = new QLabel(tr("Name and color of the segmentation"), this);
38  verticalLayout->addWidget(lblPrompt);
39 
40  // to choose a color
41  btnColor = new QPushButton("", this);
42  btnColor->setFixedWidth(25);
43  btnColor->setAutoFillBackground(true);
44  btnColor->setStyleSheet("background-color:rgb(255,0,0)");
45 
46  connect(btnColor, SIGNAL(clicked()), this, SLOT(onColorBtnClicked()));
47 
48  lineEditName = new QLineEdit("", this);
49  QStringList completionList;
50  completionList << "";
51  completer = new QCompleter(completionList);
52  completer->setCaseSensitivity(Qt::CaseInsensitive);
53  lineEditName->setCompleter(completer);
54 
55  connect(completer, SIGNAL(activated(const QString &)), this, SLOT(onColorChange(const QString &)));
56 
57  QBoxLayout *horizontalLayout2 = new QHBoxLayout();
58  verticalLayout->addLayout(horizontalLayout2);
59  horizontalLayout2->addWidget(btnColor);
60  horizontalLayout2->addWidget(lineEditName);
61 
62  // buttons for closing the dialog
63  btnOk = new QPushButton(tr("Ok"), this);
64  btnOk->setDefault(true);
65  connect(btnOk, SIGNAL(clicked()), this, SLOT(onAcceptClicked()));
66 
67  QPushButton *btnCancel = new QPushButton(tr("Cancel"), this);
68  connect(btnCancel, SIGNAL(clicked()), this, SLOT(reject()));
69 
70  QBoxLayout *horizontalLayout = new QHBoxLayout();
71  verticalLayout->addLayout(horizontalLayout);
72  horizontalLayout->setSpacing(5);
73  horizontalLayout->addStretch();
74  horizontalLayout->addWidget(btnOk);
75  horizontalLayout->addWidget(btnCancel);
76 
77  lineEditName->setFocus();
78 }
79 
81 {
82 }
83 
85 {
86  return m_SegmentationName;
87 }
88 
90 {
91  mitk::Color colorProperty;
92  if (m_Color.spec() == 0)
93  {
94  colorProperty.SetRed(1);
95  colorProperty.SetGreen(0);
96  colorProperty.SetBlue(0);
97  }
98  else
99  {
100  colorProperty.SetRed(m_Color.redF());
101  colorProperty.SetGreen(m_Color.greenF());
102  colorProperty.SetBlue(m_Color.blueF());
103  }
104  return colorProperty;
105 }
106 
108 {
109  return selectedOrgan.toLocal8Bit().constData();
110 }
111 
112 void QmitkNewSegmentationDialog::SetSegmentationName(const QString &segmentationName)
113 {
114  lineEditName->setText(segmentationName);
115 }
116 
118 {
119  m_Color.setRedF(color.GetRed());
120  m_Color.setGreenF(color.GetGreen());
121  m_Color.setBlueF(color.GetBlue());
122 
123  btnColor->setStyleSheet(QString("background-color:rgb(%1, %2, %3)").arg(m_Color.red()).arg(m_Color.green()).arg(m_Color.blue()));
124 }
125 
126 void QmitkNewSegmentationDialog::SetSuggestionList(QStringList organColorList)
127 {
128  QStringList::iterator iter;
129  for (iter = organColorList.begin(); iter != organColorList.end(); ++iter)
130  {
131  QString &element = *iter;
132  QString colorName = element.right(7);
133  QColor color(colorName);
134  QString organName = element.left(element.size() - 7);
135 
136  organList.push_back(organName);
137  colorList.push_back(color);
138  }
139 
140  QStringListModel *completeModel = static_cast<QStringListModel *>(completer->model());
141  completeModel->setStringList(organList);
142 }
143 
144 void QmitkNewSegmentationDialog::setPrompt(const QString &prompt)
145 {
146  lblPrompt->setText(prompt);
147 }
148 
150 {
152  accept();
153 }
154 
156 {
157  if (!newText.isEmpty())
158  {
159  btnOk->setEnabled(true);
160  }
161 
162  selectedOrgan = newText;
163  SetSegmentationName(newText);
164 }
165 
167 {
168  m_Color = QColorDialog::getColor();
169  if (m_Color.spec() == 0)
170  {
171  m_Color.setRed(255);
172  m_Color.setGreen(0);
173  m_Color.setBlue(0);
174  }
175  btnColor->setStyleSheet(QString("background-color:rgb(%1, %2, %3)").arg(m_Color.red()).arg(m_Color.green()).arg(m_Color.blue()));
176 }
177 
178 void QmitkNewSegmentationDialog::onColorChange(const QString &completedWord)
179 {
180  if (organList.contains(completedWord))
181  {
182  int j = organList.indexOf(completedWord);
183  m_Color = colorList.at(j);
184  btnColor->setStyleSheet(QString("background-color:rgb(%1, %2, %3)").arg(m_Color.red()).arg(m_Color.green()).arg(m_Color.blue()));
185  }
186 }
void setPrompt(const QString &prompt)
void SetSuggestionList(QStringList organColorList)
void onColorChange(const QString &completedWord)
itk::RGBPixel< float > Color
Color Standard RGB color typedef (float)
void SetColor(const mitk::Color &color)
void SetSegmentationName(const QString &segmentationName)
QmitkNewSegmentationDialog(QWidget *parent=nullptr)