00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "HighlightDialog.h"
00025 #include "Utilities.h"
00026
00027
00028 #include <qlayout.h>
00029 #include <qlabel.h>
00030 #include <qpushbutton.h>
00031 #include <qiconset.h>
00032 #include <qmessagebox.h>
00033 #include <qcolordialog.h>
00034
00035
00036
00037 HighlightDialog::HighlightDialog(QWidget* parent, NetworkViewer* nwViewer) : QDialog(parent) {
00038
00039 networkViewer = nwViewer;
00040
00041
00042 QVBoxLayout* mainVBox = new QVBoxLayout(this, 5, 10, "vertical");
00043
00044
00045 QHBoxLayout* colorBox = new QHBoxLayout();
00046 colorBox->addWidget(new QLabel("Highlight colour:", this));
00047 colorPixmap = new QPixmap(40, 20);
00048 highlightColor = Qt::yellow;
00049 colorPixmap->fill(highlightColor);
00050 colorButt = new QPushButton("", this);
00051 colorButt->setPixmap(*colorPixmap);
00052 colorButt->setBaseSize(40, 20);
00053 colorButt->setMinimumSize(40, 20);
00054 colorButt->setMaximumSize(40, 20);
00055 colorButt->setFlat(true);
00056 connect (colorButt, SIGNAL(clicked()), this, SLOT(colorButtonPressed()));
00057 colorBox->addWidget(colorButt);
00058 colorBox->addStretch(5);
00059 mainVBox->addLayout(colorBox);
00060
00061
00062 neuronIDText = new QTextEdit(this);
00063 mainVBox->addWidget(neuronIDText);
00064
00065
00066 QHBoxLayout *buttonBox = new QHBoxLayout();
00067 QPushButton *addHighlightButt = new QPushButton("Add Highlight", this);
00068 buttonBox->addWidget(addHighlightButt);
00069 connect (addHighlightButt, SIGNAL(clicked()), this, SLOT(addHighlightButtonPressed()));
00070
00071 QPushButton *clearButton = new QPushButton("Clear Highlights", this);
00072 buttonBox->addWidget(clearButton);
00073 connect (clearButton, SIGNAL(clicked()), this, SLOT(clearButtonPressed()));
00074
00075 QPushButton *closeButton = new QPushButton("Close", this);
00076 buttonBox->addWidget(closeButton);
00077 connect (closeButton, SIGNAL(clicked()), this, SLOT(closeButtonPressed()));
00078
00079 mainVBox->addLayout(buttonBox);
00080
00081
00082 keyboardAccelerator = new QAccel( this );
00083
00084
00085 keyboardAccelerator->insertItem(CTRL + Key_A);
00086
00087
00088 connect (keyboardAccelerator, SIGNAL(activated(int)), this, SLOT(acceleratorKeyPressed(int)));
00089
00090
00091 this->resize(600, 400);
00092
00093 }
00094
00095
00096
00097 HighlightDialog::~HighlightDialog(){
00098
00099 }
00100
00101
00102
00103
00104
00105
00106
00107 void HighlightDialog::acceleratorKeyPressed(int acceleratorID){
00108
00109 int keySequence = keyboardAccelerator->key(acceleratorID);
00110
00111
00112 switch(keySequence){
00113 case (CTRL + Key_A):
00114 neuronIDText->selectAll();
00115 break;
00116 }
00117 }
00118
00119
00120
00121 void HighlightDialog::addHighlightButtonPressed(){
00122
00123 RGBColor* tmpColor = new RGBColor;
00124 tmpColor->red = highlightColor.red() / 255.0;
00125 tmpColor->green = highlightColor.green() / 255.0;
00126 tmpColor->blue = highlightColor.blue() / 255.0;
00127
00128
00129 QString neurIDStr = neuronIDText->text();
00130
00131
00132 for(unsigned int i=0; i<neurIDStr.length(); ++i){
00133 if(neurIDStr.at(i).isSpace()){
00134 neurIDStr.remove(i, 1);
00135 --i;
00136 }
00137 }
00138 QStringList tempStringList = QStringList::split(",", neurIDStr);
00139
00140
00141 try{
00142 unsigned int tmpNeuronID;
00143 for(unsigned int i=0; i< tempStringList.size(); ++i){
00144 tmpNeuronID = Utilities::getUInt(tempStringList[i].ascii());
00145 networkViewer->addHighlight(tmpNeuronID, tmpColor);
00146 }
00147 }
00148 catch(std::exception& ex){
00149 QString errorString = "HighlightDialog: STD EXCEPTION THROWN EXTRACTING NEURON IDS: \"";
00150 errorString += ex.what();
00151 errorString += "\"";
00152 showError(errorString);
00153 }
00154
00155
00156 networkViewer->refresh();
00157 }
00158
00159
00160
00161 void HighlightDialog::clearButtonPressed(){
00162 networkViewer->clearHighlights();
00163 neuronIDText->clear();
00164 }
00165
00166
00167
00168 void HighlightDialog::closeButtonPressed(){
00169 this->hide();
00170 }
00171
00172
00173
00174 void HighlightDialog::colorButtonPressed(){
00175 QColor tmpColor = QColorDialog::getColor(highlightColor, this, "color dialog" );
00176 if ( tmpColor.isValid() ) {
00177 colorPixmap->fill(tmpColor);
00178 colorButt->setPixmap(*colorPixmap);
00179 highlightColor = tmpColor;
00180 }
00181 }
00182
00183
00184
00185
00186
00187
00188
00189 void HighlightDialog::showError(const QString& errMsg){
00190 cerr<<errMsg<<endl;
00191 QMessageBox::critical(this, "Highlight Dialog Error", errMsg);
00192 }
00193
00194