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 "QmitkInfoDialog.h"
00019
00020 #include "QmitkDataStorageComboBox.h"
00021
00022 #include <sstream>
00023
00024 #include <QGridLayout>
00025 #include <QTextBrowser>
00026 #include <QPushButton>
00027 #include <QLineEdit>
00028 #include <QEvent>
00029 #include <QKeyEvent>
00030
00031 QmitkInfoDialog::QmitkInfoDialog( std::vector<mitk::DataNode*> _Nodes, QWidget * parent , Qt::WindowFlags f )
00032 : QDialog(parent, f)
00033 {
00034
00035 QGridLayout* parentLayout = new QGridLayout;
00036 QmitkDataStorageComboBox* _QmitkDataStorageComboBox = new QmitkDataStorageComboBox(this, true);
00037 m_KeyWord = new QLineEdit;
00038 m_KeyWord->installEventFilter(this);
00039 m_SearchButton = new QPushButton("Search (F3)", this);
00040 m_SearchButton->installEventFilter(this);
00041 m_TextBrowser = new QTextBrowser(this);
00042 QPushButton* _CancelButton = new QPushButton("Cancel", this);
00043
00044
00045 this->setMinimumSize(512, 512);
00046 this->setLayout(parentLayout);
00047 this->setSizeGripEnabled(true);
00048 this->setModal(true);
00049
00050 parentLayout->addWidget(_QmitkDataStorageComboBox, 0, 0, 1, 2);
00051 parentLayout->addWidget(m_KeyWord, 1, 0);
00052 parentLayout->addWidget(m_SearchButton, 1, 1);
00053 parentLayout->addWidget(m_TextBrowser, 2, 0, 1, 2);
00054 parentLayout->addWidget(_CancelButton, 3, 0, 1, 2);
00055
00056 QObject::connect( _QmitkDataStorageComboBox, SIGNAL( OnSelectionChanged( const mitk::DataNode* ) )
00057 , this, SLOT( OnSelectionChanged( const mitk::DataNode* ) ) );
00058
00059 for (std::vector<mitk::DataNode*>::iterator it = _Nodes.begin()
00060 ; it != _Nodes.end(); it++)
00061 {
00062 _QmitkDataStorageComboBox->AddNode(*it);
00063 }
00064
00065 QObject::connect( m_KeyWord, SIGNAL( textChanged ( const QString & ) )
00066 , this, SLOT( KeyWordTextChanged(const QString &) ) );
00067
00068 QObject::connect( m_SearchButton, SIGNAL( clicked ( bool ) )
00069 , this, SLOT( OnSearchButtonClicked( bool ) ) );
00070
00071 QObject::connect( _CancelButton, SIGNAL( clicked ( bool ) )
00072 , this, SLOT( OnCancelButtonClicked( bool ) ) );
00073
00074 _CancelButton->setDefault(true);
00075
00076 }
00077
00078 void QmitkInfoDialog::OnSelectionChanged( const mitk::DataNode* node )
00079 {
00080 std::ostringstream s;
00081 itk::Indent i(2);
00082 mitk::BaseData* _BaseData = node->GetData();
00083 if(_BaseData)
00084 _BaseData->Print(s, i);
00085 m_TextBrowser->setPlainText(QString::fromStdString(s.str()));
00086 }
00087
00088 void QmitkInfoDialog::OnSearchButtonClicked( bool )
00089 {
00090 QString keyWord = m_KeyWord->text();
00091 QString text = m_TextBrowser->toPlainText();
00092
00093 if(keyWord.isEmpty() || text.isEmpty())
00094 return;
00095
00096 m_TextBrowser->find(keyWord);
00097 m_SearchButton->setText("Search Next(F3)");
00098 }
00099
00100 void QmitkInfoDialog::OnCancelButtonClicked( bool )
00101 {
00102 this->done(0);
00103 }
00104
00105 bool QmitkInfoDialog::eventFilter( QObject *obj, QEvent *event )
00106 {
00107 if (event->type() == QEvent::KeyPress)
00108 {
00109 QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
00110 if(keyEvent->key() == Qt::Key_F3 || keyEvent->key() == Qt::Key_Return)
00111 {
00112
00113 this->OnSearchButtonClicked(true);
00114
00115 return true;
00116 }
00117 }
00118
00119 return QObject::eventFilter(obj, event);
00120 }
00121
00122 void QmitkInfoDialog::KeyWordTextChanged(const QString & )
00123 {
00124 QTextCursor textCursor = m_TextBrowser->textCursor();
00125 textCursor.setPosition(0);
00126 m_TextBrowser->setTextCursor(textCursor);
00127 m_SearchButton->setText("Search (F3)");
00128 }