Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "QmitkNewSegmentationDialog.h"
00019
00020 #include "mitkOrganTypeProperty.h"
00021
00022 #include <itkRGBPixel.h>
00023
00024 #include <qlineedit.h>
00025 #include <qpushbutton.h>
00026 #include <qlayout.h>
00027 #include <qlabel.h>
00028 #include <QColorDialog>
00029 #include <QStringListModel>
00030 #include <QAbstractItemModel>
00031
00032 #include <mitkDataNodeFactory.h>
00033
00034 QmitkNewSegmentationDialog::QmitkNewSegmentationDialog(QWidget* parent)
00035 :QDialog(parent),
00036 selectedOrgan("undefined"),
00037 newOrganEntry(false)
00038 {
00039 QDialog::setFixedSize(250, 105);
00040
00041 QBoxLayout * verticalLayout = new QVBoxLayout( this );
00042 verticalLayout->setMargin(5);
00043 verticalLayout->setSpacing(5);
00044
00045 mitk::OrganTypeProperty::Pointer organTypes = mitk::OrganTypeProperty::New();
00046
00047
00048 lblPrompt = new QLabel( "Name and color of the segmentation", this );
00049 verticalLayout->addWidget( lblPrompt );
00050
00051
00052 btnColor = new QPushButton( "", this );
00053 btnColor->setFixedWidth(25);
00054 btnColor->setAutoFillBackground(true);
00055 btnColor->setStyleSheet("background-color:rgb(255,0,0)");
00056
00057 connect( btnColor, SIGNAL(clicked()), this, SLOT(onColorBtnClicked()) );
00058
00059 edtName = new QLineEdit( "", this );
00060 QStringList completionList;
00061 completionList << "";
00062 completer = new QCompleter(completionList);
00063 completer->setCaseSensitivity(Qt::CaseInsensitive);
00064 edtName->setCompleter(completer);
00065
00066 connect( completer, SIGNAL(activated(const QString&)), this, SLOT(onColorChange(const QString&)) );
00067
00068 QBoxLayout * horizontalLayout2 = new QHBoxLayout();
00069 verticalLayout->addLayout(horizontalLayout2);
00070 horizontalLayout2->addWidget( btnColor );
00071 horizontalLayout2->addWidget( edtName );
00072
00073
00074
00075
00076 btnOk = new QPushButton( tr("Ok"), this );
00077 btnOk->setDefault(true);
00078 connect( btnOk, SIGNAL(clicked()), this, SLOT(onAcceptClicked()) );
00079
00080 QPushButton* btnCancel = new QPushButton( tr("Cancel"), this );
00081 connect( btnCancel, SIGNAL(clicked()), this, SLOT(reject()) );
00082
00083 QBoxLayout * horizontalLayout = new QHBoxLayout();
00084 verticalLayout->addLayout(horizontalLayout);
00085 horizontalLayout->setSpacing(5);
00086 horizontalLayout->addStretch();
00087 horizontalLayout->addWidget( btnOk );
00088 horizontalLayout->addWidget( btnCancel );
00089
00090 edtName->setFocus();
00091 }
00092
00093 QmitkNewSegmentationDialog::~QmitkNewSegmentationDialog()
00094 {
00095 }
00096
00097 void QmitkNewSegmentationDialog::onAcceptClicked()
00098 {
00099 m_SegmentationName = edtName->text();
00100 this->accept();
00101 }
00102
00103 const QString QmitkNewSegmentationDialog::GetSegmentationName()
00104 {
00105 return m_SegmentationName;
00106 }
00107
00108 const char* QmitkNewSegmentationDialog::GetOrganType()
00109 {
00110 return selectedOrgan.toLocal8Bit().constData();
00111 }
00112
00113
00114 void QmitkNewSegmentationDialog::onNewOrganNameChanged(const QString& newText)
00115 {
00116 if (!newText.isEmpty())
00117 {
00118 btnOk->setEnabled( true );
00119 }
00120
00121 selectedOrgan = newText;
00122 this->setSegmentationName( newText );
00123
00124 }
00125
00126 void QmitkNewSegmentationDialog::onColorBtnClicked()
00127 {
00128 m_Color = QColorDialog::getColor();
00129 if (m_Color.spec() == 0)
00130 {
00131 m_Color.setRed(255);
00132 m_Color.setGreen(0);
00133 m_Color.setBlue(0);
00134 }
00135 btnColor->setStyleSheet(QString("background-color:rgb(%1,%2, %3)").arg(m_Color.red()).arg(m_Color.green()).arg(m_Color.blue()));
00136 }
00137
00138 void QmitkNewSegmentationDialog::setPrompt( const QString& prompt )
00139 {
00140 lblPrompt->setText( prompt );
00141 }
00142
00143 void QmitkNewSegmentationDialog::setSegmentationName( const QString& name )
00144 {
00145 edtName->setText( name );
00146 m_SegmentationName = name;
00147 }
00148
00149 mitk::Color QmitkNewSegmentationDialog::GetColor()
00150 {
00151 mitk::Color colorProperty;
00152 if (m_Color.spec() == 0)
00153 {
00154 colorProperty.SetRed(1);
00155 colorProperty.SetGreen(0);
00156 colorProperty.SetBlue(0);
00157 }
00158 else
00159 {
00160 colorProperty.SetRed(m_Color.redF());
00161 colorProperty.SetGreen(m_Color.greenF());
00162 colorProperty.SetBlue(m_Color.blueF());
00163 }
00164 return colorProperty;
00165 }
00166
00167 void QmitkNewSegmentationDialog::SetSuggestionList(QStringList organColorList)
00168 {
00169 QStringList::iterator iter;
00170 for (iter = organColorList.begin(); iter != organColorList.end(); ++iter)
00171 {
00172 QString& element = *iter;
00173 QString colorName = element.right(7);
00174 QColor color(colorName);
00175 QString organName = element.left(element.size() - 7);
00176
00177 organList.push_back(organName);
00178 colorList.push_back(color);
00179 }
00180
00181 QStringListModel* completeModel = static_cast<QStringListModel*> (completer->model());
00182 completeModel->setStringList(organList);
00183 }
00184
00185 void QmitkNewSegmentationDialog::onColorChange(const QString& completedWord)
00186 {
00187 if (organList.contains(completedWord))
00188 {
00189 int j = organList.indexOf(completedWord);
00190 m_Color = colorList.at(j);
00191 btnColor->setStyleSheet(QString("background-color:rgb(%1,%2, %3)").arg(m_Color.red()).arg(m_Color.green()).arg(m_Color.blue()));
00192 }
00193 }