Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

HighlightDialog.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   SpikeStream Application                                               *
00003  *   Copyright (C) 2007 by David Gamez                                     *
00004  *   david@davidgamez.eu                                                   *
00005  *   Version 0.1                                                           *
00006  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  *                                                                         *
00012  *   This program is distributed in the hope that it will be useful,       *
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015  *   GNU General Public License for more details.                          *
00016  *                                                                         *
00017  *   You should have received a copy of the GNU General Public License     *
00018  *   along with this program; if not, write to the                         *
00019  *   Free Software Foundation, Inc.,                                       *
00020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00021  ***************************************************************************/
00022 
00023 //SpikeStream includes
00024 #include "HighlightDialog.h"
00025 #include "Utilities.h"
00026 
00027 //Qt includes
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 /*! Constructor. */
00037 HighlightDialog::HighlightDialog(QWidget* parent, NetworkViewer* nwViewer) : QDialog(parent) {
00038         //Store references
00039         networkViewer = nwViewer;
00040 
00041         //Create a vertical box to organise the layout
00042         QVBoxLayout* mainVBox = new QVBoxLayout(this, 5, 10, "vertical");
00043 
00044         //Add controls to select the colour of the highlight
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         //Add text area for the neuron ids.
00062         neuronIDText = new QTextEdit(this);
00063         mainVBox->addWidget(neuronIDText);
00064 
00065         //Set up buttons
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         //Create keyboard accelerator
00082         keyboardAccelerator = new QAccel( this );
00083         
00084         //Add accelerator to select all neurons
00085         keyboardAccelerator->insertItem(CTRL + Key_A);
00086          
00087          //Connect up accelerator with the method that will process the key events
00088          connect (keyboardAccelerator, SIGNAL(activated(int)), this, SLOT(acceleratorKeyPressed(int)));
00089 
00090         //Set size      
00091         this->resize(600, 400);
00092 
00093 }
00094 
00095 
00096 /*! Destructor. */
00097 HighlightDialog::~HighlightDialog(){
00098 
00099 }
00100 
00101 
00102 //-------------------------------------------------------------------------
00103 //---------                  PRIVATE SLOTS                        ---------
00104 //-------------------------------------------------------------------------
00105 
00106 /*! Handles keyboard accelerator events. */
00107 void HighlightDialog::acceleratorKeyPressed(int acceleratorID){
00108         //Get the key sequence
00109         int keySequence = keyboardAccelerator->key(acceleratorID);
00110         
00111         //Do different actions dependingo
00112         switch(keySequence){
00113                 case (CTRL + Key_A)://Select all neurons
00114                         neuronIDText->selectAll();
00115                 break;
00116         }
00117 }
00118 
00119 
00120 /*! Adds a highlight to the network viewer. */
00121 void HighlightDialog::addHighlightButtonPressed(){
00122         //Convert the colour to a suitable form for open gl painting
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         //Extract the neuron ids and add them to the network viewer
00129         QString neurIDStr = neuronIDText->text();
00130 
00131         //Get rid of all white space
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         //Add neuron IDs to the highlight map in the network viewer
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){// Catch-all for std exceptions
00149                 QString errorString = "HighlightDialog: STD EXCEPTION THROWN EXTRACTING NEURON IDS: \"";
00150                 errorString += ex.what();
00151                 errorString += "\"";
00152                 showError(errorString);
00153         }
00154 
00155         //Refresh the display
00156         networkViewer->refresh();
00157 }
00158 
00159 
00160 /*! Clears all of the current highlights. */
00161 void HighlightDialog::clearButtonPressed(){
00162         networkViewer->clearHighlights();
00163         neuronIDText->clear();
00164 }
00165 
00166 
00167 /*! Closes the dialog. */
00168 void HighlightDialog::closeButtonPressed(){
00169         this->hide();
00170 }
00171 
00172 
00173 /*! Sets the highlight colour. */
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 //---------                  PRIVATE METHODS                      ---------
00186 //-------------------------------------------------------------------------
00187 
00188 /*! Displays an error message. */
00189 void HighlightDialog::showError(const QString& errMsg){
00190         cerr<<errMsg<<endl;
00191         QMessageBox::critical(this, "Highlight Dialog Error", errMsg);
00192 }
00193 
00194 

Generated on Mon Sep 3 22:29:04 2007 for SpikeStream Application by  doxygen 1.4.4