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

NameDialog.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 "NameDialog.h"
00025 #include "Debug.h"
00026 #include "GlobalVariables.h"
00027 
00028 //Qt includes
00029 #include <qregexp.h>
00030 #include <qvalidator.h>
00031 #include <qaccel.h>
00032 #include <qpushbutton.h>
00033 #include <qlayout.h>
00034 
00035 //Other includes
00036 #include <iostream>
00037 using namespace std;
00038 
00039 
00040 /*! Constructor. */
00041 NameDialog::NameDialog(QString name, QWidget *parent) : QDialog(parent) {
00042         //Create a validators
00043         QRegExp regExp( "([0-9]|[A-Z]|[a-z]|_|\\s){1,50}" );
00044     QValidator* nameValidator = new QRegExpValidator(regExp, this);
00045 
00046         //Create box to organise vertical layout of dialog
00047         QVBoxLayout *mainVerticalBox = new QVBoxLayout(this, 5, 10, "Main vertical Box");
00048         
00049         //Add text field to receive name
00050         nameText = new QLineEdit(name, this);
00051         nameText->setValidator(nameValidator);
00052         mainVerticalBox->addWidget(nameText);
00053 
00054         //Set up ok and cancel buttons
00055         QHBoxLayout *okCanButtonBox = new QHBoxLayout();
00056         QPushButton *okPushButton = new QPushButton("Ok", this, "okButton");
00057         QPushButton *cancelPushButton = new QPushButton("Cancel", this, "cancelButton");        
00058         okCanButtonBox->addWidget(okPushButton);
00059         okCanButtonBox->addWidget(cancelPushButton);
00060         mainVerticalBox->addLayout(okCanButtonBox);
00061         
00062         connect (okPushButton, SIGNAL(clicked()), this, SLOT(okButtonPressed()));
00063         connect (cancelPushButton, SIGNAL(clicked()), this, SLOT(reject()));
00064 
00065         //Set up accelerator for return button
00066         QAccel *returnAccel = new QAccel( this );
00067     returnAccel->connectItem( returnAccel->insertItem( Key_Enter ), this, SLOT(okButtonPressed()));
00068 }
00069 
00070 
00071 /*! Destructor. */
00072 NameDialog::~ NameDialog(){
00073         #ifdef MEMORY_DEBUG
00074                 cout<<"DESTROYING NAME DIALOG"<<endl;
00075         #endif//MEMORY_DEBUG
00076 }
00077 
00078 
00079 //--------------------------------------------------------------------------------
00080 //------------------------------ PUBLIC METHODS ----------------------------------
00081 //--------------------------------------------------------------------------------
00082 
00083 /*! Returns the name that has been entered
00084         Checks that archive name is sensible and it is the right length
00085                 These are the same checks as are run in Simulation Widget where
00086                 the name is first set. Any changes there should be matched here. */
00087 QString NameDialog::getName(){
00088         QString name = nameText->text();
00089 
00090         //Check length of name is ok
00091         if(name.length() == 0)
00092                 name = "Untitled";
00093         else if(name.length() > MAX_DATABASE_NAME_LENGTH)
00094                 name.truncate(MAX_DATABASE_NAME_LENGTH);
00095 
00096         //Return the name
00097         return name;
00098 }
00099 
00100 
00101 //-------------------------------------------------------------------------------
00102 //----------------------------- SLOTS -------------------------------------------
00103 //-------------------------------------------------------------------------------
00104 
00105 /*! Slot for when ok button is pressed. */
00106 void NameDialog::okButtonPressed(){
00107         accept();
00108 }
00109 
00110 

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