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 "NameDialog.h"
00025 #include "Debug.h"
00026 #include "GlobalVariables.h"
00027
00028
00029 #include <qregexp.h>
00030 #include <qvalidator.h>
00031 #include <qaccel.h>
00032 #include <qpushbutton.h>
00033 #include <qlayout.h>
00034
00035
00036 #include <iostream>
00037 using namespace std;
00038
00039
00040
00041 NameDialog::NameDialog(QString name, QWidget *parent) : QDialog(parent) {
00042
00043 QRegExp regExp( "([0-9]|[A-Z]|[a-z]|_|\\s){1,50}" );
00044 QValidator* nameValidator = new QRegExpValidator(regExp, this);
00045
00046
00047 QVBoxLayout *mainVerticalBox = new QVBoxLayout(this, 5, 10, "Main vertical Box");
00048
00049
00050 nameText = new QLineEdit(name, this);
00051 nameText->setValidator(nameValidator);
00052 mainVerticalBox->addWidget(nameText);
00053
00054
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
00066 QAccel *returnAccel = new QAccel( this );
00067 returnAccel->connectItem( returnAccel->insertItem( Key_Enter ), this, SLOT(okButtonPressed()));
00068 }
00069
00070
00071
00072 NameDialog::~ NameDialog(){
00073 #ifdef MEMORY_DEBUG
00074 cout<<"DESTROYING NAME DIALOG"<<endl;
00075 #endif//MEMORY_DEBUG
00076 }
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 QString NameDialog::getName(){
00088 QString name = nameText->text();
00089
00090
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
00097 return name;
00098 }
00099
00100
00101
00102
00103
00104
00105
00106 void NameDialog::okButtonPressed(){
00107 accept();
00108 }
00109
00110