00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "PromptSettings.hpp"
00023
00024 #include <QGridLayout>
00025 #include <QLabel>
00026 #include <QSpinBox>
00027 #include <QPushButton>
00028
00029 #include "global.hpp"
00030
00031 #ifndef QT_NO_DEBUG
00032 #include <iostream>
00033 #endif
00034
00035 extern short unsigned int nbCore;
00036
00037 PromptSettings :: PromptSettings(QWidget* parent )
00038 :QDialog(parent),
00039
00040 pMainGrid(NULL),
00041 pNbCoreLabel(NULL), pNbCore(NULL),
00042 pCancelButton(NULL), pValidateButton(NULL)
00043 {
00044 pMainGrid = new QGridLayout(this);
00045
00046 pNbCoreLabel = new QLabel(tr("Number of core that you have:"));
00047 pNbCore = new QSpinBox();
00048
00049 pNbCore->setRange(1, NB_MAX_CORE);
00050
00051 pNbCore->setValue(nbCore);
00052 oldNbCore = nbCore;
00053
00054
00055 connect(pNbCore, SIGNAL(valueChanged(int )), this, SLOT(nbCoreChanged(int )));
00056
00057 pMainGrid->addWidget(pNbCoreLabel,0,0);
00058 pMainGrid->addWidget(pNbCore,0,1);
00059
00060 pValidateButton = new QPushButton(tr("Ok"), this);
00061 pCancelButton = new QPushButton(tr("Cancel"), this);
00062
00063 connect(pValidateButton, SIGNAL(clicked()), this, SLOT(validateSettings()));
00064 connect(pCancelButton, SIGNAL(clicked()), this, SLOT(cancelSettings()));
00065
00066 pMainGrid->addWidget(pValidateButton,1,0);
00067 pMainGrid->addWidget(pCancelButton,1,1);
00068
00069 #ifndef QT_NO_DEBUG
00070 std::cout << "PromptSettings created" << std::endl;
00071 #endif
00072 }
00073
00074 PromptSettings :: ~PromptSettings(void)
00075 {
00076 delete pCancelButton;
00077 delete pValidateButton;
00078
00079 delete pNbCoreLabel;
00080 delete pNbCore;
00081
00082 delete pMainGrid;
00083
00084 #ifndef QT_NO_DEBUG
00085 std::cout << "PromptSettings deleted" << std::endl;
00086 #endif
00087 }
00088
00089 void PromptSettings :: validateSettings(void)
00090 {
00091
00092 nbCore = pNbCore->value();
00093
00094 this->done(0);
00095 #ifndef QT_NO_DEBUG
00096 std::cout << "SLOT - PromptSettings::validateSettings (changed to: " << nbCore << ")" << std::endl;
00097 #endif
00098 }
00099
00100 void PromptSettings :: cancelSettings(void)
00101 {
00102
00103
00104 this->done(1);
00105 #ifndef QT_NO_DEBUG
00106 std::cout << "SLOT - PromptSettings::cancelSettings" << std::endl;
00107 #endif
00108 }
00109
00110 void PromptSettings :: nbCoreChanged(int newNbCore)
00111 {
00112
00113
00114
00115
00116 if ( newNbCore < oldNbCore )
00117 {
00118 pNbCore->setValue(oldNbCore / 2);
00119 }
00120 else if ( newNbCore > oldNbCore )
00121 {
00122 pNbCore->setValue(oldNbCore * 2);
00123 }
00124
00125 oldNbCore = pNbCore->value();
00126 }