00001 #include "constants.h"
00002
00003 #include "dialogs.h"
00004 #include "transforms.h"
00005 #include "commands.h"
00006 #include "state.h"
00007 #include "transition.h"
00008 #include "editor.h"
00009 #include "ialgorithm.h"
00010
00011 #include "iautomaton.h"
00012
00013
00014 #include <QGroupBox>
00015 #include <QSpinBox>
00016 #include <QComboBox>
00017 #include <QCheckBox>
00018 #include <QPushButton>
00019 #include <QLabel>
00020 #include <QLayout>
00021 #include <QLineEdit>
00022 #include <QTextEdit>
00023 #include <QTextDocumentFragment>
00024 #include <QListWidget>
00025 #include <QTableWidget>
00026 #include <QFileDialog>
00027 #include <QMessageBox>
00028 #include <QUndoStack>
00029
00030
00031
00032 GridRectDialog::GridRectDialog(QWidget *parent)
00033 : QDialog(parent)
00034 {
00035 QLabel *lblLowerLeftX = new QLabel(QString("LowerLeft x"),this);
00036 spinLowerLeftX = new QSpinBox(this);
00037 QLabel *lblLowerLeftY = new QLabel(QString("LowerLeft y"),this);
00038 spinLowerLeftY = new QSpinBox(this);
00039 QLabel *lblUpperRightX = new QLabel(QString("UpperRight x"),this);
00040 spinUpperRightX = new QSpinBox(this);
00041 QLabel *lblUpperRightY = new QLabel(QString("UpperRight y"),this);
00042 spinUpperRightY = new QSpinBox(this);
00043 QLabel *lblBorder = new QLabel(QString("Scene border"), this);
00044 spinBorder = new QSpinBox(this);
00045
00046
00047 spinLowerLeftX->setMinimum(MIN_RECT_VALUE);
00048 spinLowerLeftY->setMinimum(MIN_RECT_VALUE);
00049 spinUpperRightX->setMinimum(MIN_RECT_VALUE);
00050 spinUpperRightY->setMinimum(MIN_RECT_VALUE);
00051 spinBorder->setMinimum(MIN_BORDER_VALUE);
00052
00053 spinLowerLeftX->setMaximum(MAX_RECT_VALUE);
00054 spinLowerLeftY->setMaximum(MAX_RECT_VALUE);
00055 spinUpperRightX->setMaximum(MAX_RECT_VALUE);
00056 spinUpperRightY->setMaximum(MAX_RECT_VALUE);
00057 spinBorder->setMaximum(MAX_BORDER_VALUE);
00058
00059 spinBorder->setSingleStep(10);
00060
00061 QWidget *hBox = new QWidget(this);
00062 QPushButton *buttonOk = new QPushButton("Ok");
00063 QPushButton *buttonCancel = new QPushButton("Cancel");
00064 QHBoxLayout *hBoxLayout = new QHBoxLayout;
00065 hBoxLayout->addWidget(buttonOk);
00066 hBoxLayout->addWidget(buttonCancel);
00067 hBox->setLayout(hBoxLayout);
00068 connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
00069 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
00070
00071 QGridLayout *gridLayout = new QGridLayout(this);
00072 gridLayout->addWidget(lblLowerLeftX, 0, 0);
00073 gridLayout->addWidget(spinLowerLeftX, 0, 1);
00074 gridLayout->addWidget(lblLowerLeftY, 1, 0);
00075 gridLayout->addWidget(spinLowerLeftY, 1, 1);
00076 gridLayout->addWidget(lblUpperRightX, 2, 0);
00077 gridLayout->addWidget(spinUpperRightX, 2, 1);
00078 gridLayout->addWidget(lblUpperRightY, 3, 0);
00079 gridLayout->addWidget(spinUpperRightY, 3, 1);
00080 gridLayout->addWidget(lblBorder, 4, 0);
00081 gridLayout->addWidget(spinBorder, 4, 1);
00082 gridLayout->addWidget(hBox, 5, 0, 1, 2);
00083
00084 QString s = "GridRect dialog";
00085 setWindowTitle(s);
00086 setWindowIcon(QIcon(":images/grid.xpm"));
00087 }
00088
00089 void GridRectDialog::setLowerLeftX(int x){
00090 spinLowerLeftX->setValue(x);
00091 }
00092
00093 void GridRectDialog::setLowerLeftY(int y){
00094 spinLowerLeftY->setValue(y);
00095 }
00096
00097 void GridRectDialog::setUpperRightX(int x){
00098 spinUpperRightX->setValue(x);
00099 }
00100
00101 void GridRectDialog::setUpperRightY(int y){
00102 spinUpperRightY->setValue(y);
00103 }
00104
00105 void GridRectDialog::setBorder(int b)
00106 {
00107 spinBorder->setValue(b);
00108 }
00109
00110 int GridRectDialog::getLowerLeftX(){
00111 return spinLowerLeftX->value();
00112 }
00113
00114 int GridRectDialog::getLowerLeftY(){
00115 return spinLowerLeftY->value();
00116 }
00117
00118 int GridRectDialog::getUpperRightX(){
00119 return spinUpperRightX->value();
00120 }
00121
00122 int GridRectDialog::getUpperRightY(){
00123 return spinUpperRightY->value();
00124 }
00125
00126 int GridRectDialog::getBorder()
00127 {
00128 return spinBorder->value();
00129 }
00130
00131
00132
00133
00134
00135
00136
00137 StateStyleDialog::StateStyleDialog(Editor *parent)
00138 : QDialog(parent), editor(parent)
00139 {
00140 QStringList sls;
00141 sls.append("solid");
00142 sls.append("dashed");
00143 sls.append("dotted");
00144 sls.append("none");
00145
00146 QStringList slf;
00147 slf.append("solid");
00148 slf.append("vlines");
00149 slf.append("hlines");
00150 slf.append("crosshatch");
00151 slf.append("none");
00152
00153 QStringList sla;
00154 sla.append("Apply as new global style - to coming states");
00155 sla.append("Apply as global style - to current states with style equal with last global style");
00156 sla.append("Apply as global style - to all states");
00157
00158 QRegExp rx("^[\\-]{0,1}[0-9]{1,3}\\.[0-9]{1,3}$");
00159 QValidator *v = new QRegExpValidator(rx,this);
00160
00161
00162 QLabel *lineStyle = new QLabel(QString("StateLineStyle"),this);
00163 comboLineStyle = new QComboBox(this);
00164 comboLineStyle->addItems(sls);
00165 comboLineStyle->setCurrentIndex(0);
00166
00167 QLabel *lineWidth = new QLabel(QString("StateLineWidth"),this);
00168 edtLineWidth = new QLineEdit(this);
00169 edtLineWidth->setValidator(v);
00170
00171 QLabel *lineColor = new QLabel(QString("StateLineColor"),this);
00172 edtLineColor = new QLineEdit(this);
00173
00174 QLabel *labelColor = new QLabel(QString("StateLabelColor"),this);
00175 edtLabelColor = new QLineEdit(this);
00176
00177 QLabel *labelScale = new QLabel(QString("StateLabelScale"),this);
00178 edtLabelScale = new QLineEdit(this);
00179 edtLabelScale->setValidator(v);
00180
00181 QLabel *fillStatus = new QLabel(QString("StateFillStatus"),this);
00182 comboFillStatus = new QComboBox(this);
00183 comboFillStatus->addItems(slf);
00184 comboFillStatus->setCurrentIndex(0);
00185
00186 QLabel *fillColor = new QLabel(QString("StateFillColor"),this);
00187 edtFillColor = new QLineEdit(this);
00188
00189
00190 QLabel *dimLineStyle = new QLabel(QString("DimStateLineStyle"),this);
00191 comboDimLineStyle = new QComboBox(this);
00192 comboDimLineStyle->addItems(sls);
00193 comboDimLineStyle->setCurrentIndex(0);
00194
00195 QLabel *dimLineColor = new QLabel(QString("DimStateLineColor"),this);
00196 edtDimLineColor = new QLineEdit(this);
00197
00198 QLabel *dimLineCoef = new QLabel(QString("DimStateLineCoef"),this);
00199 edtDimLineCoef = new QLineEdit(this);
00200 edtDimLineCoef->setValidator(v);
00201
00202 QLabel *dimLabelColor = new QLabel(QString("DimStateLabelColor"),this);
00203 edtDimLabelColor = new QLineEdit(this);
00204
00205 QLabel *dimFillColor = new QLabel(QString("DimStateFillColor"),this);
00206 edtDimFillColor = new QLineEdit(this);
00207
00208
00209 QLabel *lineDblCoef = new QLabel(QString("StateLineDblCoef"),this);
00210 edtLineDblCoef = new QLineEdit(this);
00211 edtLineDblCoef->setValidator(v);
00212
00213 QLabel *lineDblSep = new QLabel(QString("StateLineDblSep"),this);
00214 edtLineDblSep= new QLineEdit(this);
00215 edtLineDblSep->setValidator(v);
00216
00217
00218 comboApply = new QComboBox(this);
00219 comboApply->addItems(sla);
00220 comboApply->setCurrentIndex(0);
00221
00222
00223 QWidget *hBox = new QWidget(this);
00224 QPushButton *buttonOk = new QPushButton("Ok");
00225 QPushButton *buttonCancel = new QPushButton("Cancel");
00226 QHBoxLayout *hBoxLayout = new QHBoxLayout;
00227 hBoxLayout->addWidget(buttonOk);
00228 hBoxLayout->addWidget(buttonCancel);
00229 hBox->setLayout(hBoxLayout);
00230 hBox->setMaximumWidth(300);
00231 connect(buttonOk, SIGNAL(clicked()), this, SLOT(myAccept()));
00232 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
00233
00234 QGroupBox *advancedGroup = new QGroupBox("Advanced parameters");
00235 QGridLayout *advancedLayout = new QGridLayout(advancedGroup);
00236 advancedLayout->addWidget(lineStyle,0,0);
00237 advancedLayout->addWidget(comboLineStyle,0,1);
00238 advancedLayout->addWidget(lineWidth,0,2);
00239 advancedLayout->addWidget(edtLineWidth,0,3);
00240 advancedLayout->addWidget(lineColor,1,0);
00241 advancedLayout->addWidget(edtLineColor,1,1);
00242 advancedLayout->addWidget(labelColor,1,2);
00243 advancedLayout->addWidget(edtLabelColor,1,3);
00244 advancedLayout->addWidget(labelScale,2,0,1,2,Qt::AlignRight);
00245 advancedLayout->addWidget(edtLabelScale,2,2,1,2,Qt::AlignLeft);
00246 advancedLayout->addWidget(fillStatus,3,0);
00247 advancedLayout->addWidget(comboFillStatus,3,1);
00248 advancedLayout->addWidget(fillColor,3,2);
00249 advancedLayout->addWidget(edtFillColor,3,3);
00250
00251 QGroupBox *presetGroup = new QGroupBox("Preset parameters (dim state)");
00252 QGridLayout* presetLayout = new QGridLayout(presetGroup);
00253 presetLayout->addWidget(dimLineStyle, 0,0);
00254 presetLayout->addWidget(comboDimLineStyle, 0,1);
00255 presetLayout->addWidget(dimLineCoef, 0,2);
00256 presetLayout->addWidget(edtDimLineCoef, 0,3);
00257 presetLayout->addWidget(dimLineColor, 1,0);
00258 presetLayout->addWidget(edtDimLineColor, 1,1);
00259 presetLayout->addWidget(dimLabelColor, 1,2);
00260 presetLayout->addWidget(edtDimLabelColor, 1,3);
00261 presetLayout->addWidget(dimFillColor, 2,0,1,2, Qt::AlignRight);
00262 presetLayout->addWidget(edtDimFillColor, 2,2,1,2, Qt::AlignLeft);
00263
00264 QGroupBox *doubleGroup = new QGroupBox("Line double parameters (final state)");
00265 QHBoxLayout *doubleLayout = new QHBoxLayout(doubleGroup);
00266 doubleLayout->addWidget(lineDblCoef);
00267 doubleLayout->addWidget(edtLineDblCoef);
00268 doubleLayout->addWidget(lineDblSep);
00269 doubleLayout->addWidget(edtLineDblSep);
00270
00271 QGroupBox *localGroup = new QGroupBox("Not storable as style (will not loaded to editor style when loading...)");
00272 QVBoxLayout *localLayout = new QVBoxLayout(localGroup);
00273 localLayout->addWidget(presetGroup);
00274 localLayout->addWidget(doubleGroup);
00275
00276 QGroupBox *applyGroup = new QGroupBox("Apply to ...");
00277 QHBoxLayout *applyLayout = new QHBoxLayout(applyGroup);
00278 applyLayout->addWidget(comboApply);
00279
00280 QVBoxLayout *dialogLayout = new QVBoxLayout(this);
00281 dialogLayout->addWidget(advancedGroup);
00282 dialogLayout->addWidget(localGroup);
00283 dialogLayout->addWidget(applyGroup);
00284 dialogLayout->addWidget(hBox, 0, Qt::AlignHCenter);
00285
00286 QString s = "State style parameters";
00287 setWindowTitle(s);
00288 setWindowIcon(QIcon(":images/state.xpm"));
00289
00290 setParams();
00291 }
00292
00293 void StateStyleDialog::setParams()
00294 {
00295 comboLineStyle->setCurrentIndex(trLineStyleI(editor->stateLineStyle));
00296 edtLineWidth->setText(QString("%1").arg(editor->stateLineWidth));
00297 edtLineColor->setText(editor->stateLineColor);
00298 edtLabelColor->setText(editor->stateLabelColor);
00299 edtLabelScale->setText(QString("%1").arg(editor->stateLabelScale));
00300 comboFillStatus->setCurrentIndex(trFillStatusI(editor->stateFillStatus));
00301 edtFillColor->setText(editor->stateFillColor);
00302
00303 comboDimLineStyle->setCurrentIndex(trLineStyleI(editor->dimStateLineStyle));
00304 edtDimLineColor->setText(editor->dimStateLineColor);
00305 edtDimLineCoef->setText(QString("%1").arg(editor->dimStateLineCoef));
00306 edtDimLabelColor->setText(editor->dimStateLabelColor);
00307 edtDimFillColor->setText(editor->dimStateFillColor);
00308
00309 edtLineDblCoef->setText(QString("%1").arg(editor->stateLineDoubleCoef));
00310 edtLineDblSep->setText(QString("%1").arg(editor->stateLineDoubleSep));
00311 }
00312
00313 void StateStyleDialog::myAccept()
00314 {
00315
00316
00317 editor->m_undoStack->push(
00318 new StateStyleChangeCommand(editor,comboApply->currentIndex() ,
00319 trLineStyle(comboLineStyle->currentIndex()),
00320 edtLineWidth->text().toFloat(), edtLineColor->text(), edtLabelColor->text(),
00321 edtLabelScale->text().toFloat(), trFillStatus(comboFillStatus->currentIndex()),
00322 edtFillColor->text(), trLineStyle(comboDimLineStyle->currentIndex()),
00323 edtDimLineColor->text(), edtDimLineCoef->text().toFloat(), edtDimLabelColor->text(),
00324 edtDimFillColor->text(), edtLineDblCoef->text().toFloat(), edtLineDblSep->text().toFloat())
00325 );
00326
00327 accept();
00328 }
00329
00330
00331
00332
00333
00334
00335
00336 TransitionStyleDialog::TransitionStyleDialog(Editor *parent)
00337 : QDialog(parent), editor(parent)
00338 {
00339 QStringList sls;
00340 sls.append("solid");
00341 sls.append("dashed");
00342 sls.append("dotted");
00343 sls.append("none");
00344
00345 QStringList sla;
00346 sla.append("Apply as new global style - to coming transitions");
00347 sla.append("Apply as global style - to current transitinos with style equal with last global style");
00348 sla.append("Apply as global style - to all transitions");
00349
00350 QRegExp rx("^[\\-]{0,1}[0-9]{1,3}\\.[0-9]{1,3}$");
00351 QValidator *v = new QRegExpValidator(rx,this);
00352
00353
00354 QLabel *lineStyle = new QLabel(QString("EdgeLineStyle"),this);
00355 comboLineStyle = new QComboBox(this);
00356 comboLineStyle->addItems(sls);
00357 comboLineStyle->setCurrentIndex(0);
00358
00359 QLabel *lineWidth = new QLabel(QString("EdgeLineWidth"),this);
00360 edtLineWidth = new QLineEdit(this);
00361 edtLineWidth->setValidator(v);
00362
00363 QLabel *lineColor = new QLabel(QString("EdgeLineColor"),this);
00364 edtLineColor = new QLineEdit(this);
00365
00366 QLabel *labelColor = new QLabel(QString("EdgeLabelColor"),this);
00367 edtLabelColor = new QLineEdit(this);
00368
00369 QLabel *labelScale = new QLabel(QString("EdgeLabelScale"),this);
00370 edtLabelScale = new QLineEdit(this);
00371 edtLabelScale->setValidator(v);
00372
00373 QLabel *dblStatus = new QLabel(QString("EdgeLineDblStatus"),this);
00374 checkDblStatus = new QCheckBox(this);
00375 checkDblStatus->setChecked(false);
00376
00377
00378 QLabel *dimLineStyle = new QLabel(QString("DimEdgeLineStyle"),this);
00379 comboDimLineStyle = new QComboBox(this);
00380 comboDimLineStyle->addItems(sls);
00381 comboDimLineStyle->setCurrentIndex(0);
00382
00383 QLabel *dimLineColor = new QLabel(QString("DimEdgeLineColor"),this);
00384 edtDimLineColor = new QLineEdit(this);
00385
00386 QLabel *dimLineCoef = new QLabel(QString("DimEdgeLineCoef"),this);
00387 edtDimLineCoef = new QLineEdit(this);
00388 edtDimLineCoef->setValidator(v);
00389
00390 QLabel *dimLabelColor = new QLabel(QString("DimEdgeLabelColor"),this);
00391 edtDimLabelColor = new QLineEdit(this);
00392
00393
00394 QLabel *lineBorderCoef = new QLabel(QString("EdgeLineBorderCoef"),this);
00395 edtLineBorderCoef = new QLineEdit(this);
00396 edtLineBorderCoef->setValidator(v);
00397
00398 QLabel *lineBorderColor = new QLabel(QString("EdgeLineBorderColor"),this);
00399 edtLineBorderColor = new QLineEdit(this);
00400
00401
00402 QLabel *lineDblCoef = new QLabel(QString("EdgeLineDblCoef"),this);
00403 edtLineDblCoef = new QLineEdit(this);
00404 edtLineDblCoef->setValidator(v);
00405
00406 QLabel *lineDblSep = new QLabel(QString("EdgeLineDblSep"),this);
00407 edtLineDblSep= new QLineEdit(this);
00408 edtLineDblSep->setValidator(v);
00409
00410
00411 comboApply = new QComboBox(this);
00412 comboApply->addItems(sla);
00413 comboApply->setCurrentIndex(0);
00414
00415
00416
00417 QWidget *hBox = new QWidget(this);
00418 QPushButton *buttonOk = new QPushButton("Ok");
00419 QPushButton *buttonCancel = new QPushButton("Cancel");
00420 QHBoxLayout *hBoxLayout = new QHBoxLayout;
00421 hBoxLayout->addWidget(buttonOk);
00422 hBoxLayout->addWidget(buttonCancel);
00423 hBox->setLayout(hBoxLayout);
00424 hBox->setMaximumWidth(300);
00425 connect(buttonOk, SIGNAL(clicked()), this, SLOT(myAccept()));
00426 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
00427
00428 QGroupBox *advancedGroup = new QGroupBox("Advanced parameters");
00429 QGridLayout *advancedLayout = new QGridLayout(advancedGroup);
00430 advancedLayout->addWidget(lineStyle,0,0);
00431 advancedLayout->addWidget(comboLineStyle,0,1);
00432 advancedLayout->addWidget(lineWidth,0,2);
00433 advancedLayout->addWidget(edtLineWidth,0,3);
00434 advancedLayout->addWidget(lineColor,1,0);
00435 advancedLayout->addWidget(edtLineColor,1,1);
00436 advancedLayout->addWidget(labelColor,1,2);
00437 advancedLayout->addWidget(edtLabelColor,1,3);
00438 advancedLayout->addWidget(labelScale,2,0);
00439 advancedLayout->addWidget(edtLabelScale,2,1);
00440 advancedLayout->addWidget(checkDblStatus,2,2,Qt::AlignRight);
00441 advancedLayout->addWidget(dblStatus,2,3,Qt::AlignLeft);
00442
00443 QGroupBox *presetGroup = new QGroupBox("Preset parameters (dim edge)");
00444 QGridLayout* presetLayout = new QGridLayout(presetGroup);
00445 presetLayout->addWidget(dimLineStyle, 0,0);
00446 presetLayout->addWidget(comboDimLineStyle, 0,1);
00447 presetLayout->addWidget(dimLineCoef, 0,2);
00448 presetLayout->addWidget(edtDimLineCoef, 0,3);
00449 presetLayout->addWidget(dimLineColor, 1,0);
00450 presetLayout->addWidget(edtDimLineColor, 1,1);
00451 presetLayout->addWidget(dimLabelColor, 1,2);
00452 presetLayout->addWidget(edtDimLabelColor, 1,3);
00453
00454 QGroupBox *borderGroup = new QGroupBox("Edge border parameters (edge line double) - unsupported in editor :+(");
00455 QHBoxLayout *borderLayout = new QHBoxLayout(borderGroup);
00456 borderLayout->addWidget(lineBorderCoef);
00457 borderLayout->addWidget(edtLineBorderCoef);
00458 borderLayout->addWidget(lineBorderColor);
00459 borderLayout->addWidget(edtLineBorderColor);
00460
00461 QGroupBox *doubleGroup = new QGroupBox("Line double parameters (final state) - unsupported in editor :+(");
00462 QHBoxLayout *doubleLayout = new QHBoxLayout(doubleGroup);
00463 doubleLayout->addWidget(lineDblCoef);
00464 doubleLayout->addWidget(edtLineDblCoef);
00465 doubleLayout->addWidget(lineDblSep);
00466 doubleLayout->addWidget(edtLineDblSep);
00467
00468 QGroupBox *localGroup = new QGroupBox("Not storable as style (will not loaded to editor style when loading...)");
00469 QVBoxLayout *localLayout = new QVBoxLayout(localGroup);
00470 localLayout->addWidget(presetGroup);
00471 localLayout->addWidget(borderGroup);
00472 localLayout->addWidget(doubleGroup);
00473
00474 QGroupBox *applyGroup = new QGroupBox("Apply to ...");
00475 QHBoxLayout *applyLayout = new QHBoxLayout(applyGroup);
00476 applyLayout->addWidget(comboApply);
00477
00478 QVBoxLayout *dialogLayout = new QVBoxLayout(this);
00479 dialogLayout->addWidget(advancedGroup);
00480 dialogLayout->addWidget(localGroup);
00481 dialogLayout->addWidget(applyGroup);
00482 dialogLayout->addWidget(hBox, 0, Qt::AlignHCenter);
00483
00484 QString s = "Transition style parameters";
00485 setWindowTitle(s);
00486 setWindowIcon(QIcon(":images/transition.xpm"));
00487
00488 setParams();
00489 }
00490
00491 void TransitionStyleDialog::setParams(){
00492 comboLineStyle->setCurrentIndex(trLineStyleI(editor->edgeLineStyle));
00493 edtLineWidth->setText(QString("%1").arg(editor->edgeLineWidth));
00494 edtLineColor->setText(editor->edgeLineColor);
00495 edtLabelColor->setText(editor->edgeLabelColor);
00496 edtLabelScale->setText(QString("%1").arg(editor->edgeLabelScale));
00497 checkDblStatus->setChecked(editor->edgeLineDblStatus);
00498
00499 comboDimLineStyle->setCurrentIndex(trLineStyleI(editor->dimEdgeLineStyle));
00500 edtDimLineColor->setText(editor->dimEdgeLineColor);
00501 edtDimLineCoef->setText(QString("%1").arg(editor->dimEdgeLineCoef));
00502 edtDimLabelColor->setText(editor->dimEdgeLabelColor);
00503
00504 edtLineBorderCoef->setText(QString("%1").arg(editor->edgeLineBorderCoef));
00505 edtLineBorderColor->setText(QString("%1").arg(editor->edgeLineBorderColor));
00506
00507 edtLineDblCoef->setText(QString("%1").arg(editor->edgeLineDblCoef));
00508 edtLineDblSep->setText(QString("%1").arg(editor->edgeLineDblSep));
00509 }
00510
00511 void TransitionStyleDialog::myAccept()
00512 {
00513
00514 editor->m_undoStack->push(
00515 new TransitionStyleChangeCommand(editor, comboApply->currentIndex(),
00516 trLineStyle(comboLineStyle->currentIndex()), edtLineWidth->text().toFloat(),
00517 edtLineColor->text(), edtLabelColor->text(), edtLabelScale->text().toFloat(),
00518 checkDblStatus->isChecked(), trLineStyle(comboDimLineStyle->currentIndex()),
00519 edtDimLineColor->text(), edtDimLineCoef->text().toFloat(),
00520 edtDimLabelColor->text(), edtLineBorderCoef->text().toFloat(),
00521 edtLineBorderColor->text(), edtLineDblCoef->text().toFloat(),
00522 edtLineDblSep->text().toFloat())
00523 );
00524
00525 accept();
00526 }
00527
00528
00529
00530
00531
00532
00533
00534 GraphGenerationDialog::GraphGenerationDialog(Editor *parent)
00535 : QDialog(parent), editor(parent)
00536 {
00537 QStringList sl;
00538 sl << "Exact string matching";
00539 sl << "Hamming distance";
00540 sl << "Levenshtein distance";
00541
00542 QLabel *labelString = new QLabel(QString("Searched string"),this);
00543 edtString = new QLineEdit(this);
00544
00545 QLabel *labelType = new QLabel(QString("Searching"),this);
00546 comboAlgorithm = new QComboBox(this);
00547 comboAlgorithm->addItems(sl);
00548
00549 connect(comboAlgorithm, SIGNAL(currentIndexChanged(int)), this, SLOT(algorithmChanged(int)));
00550
00551 QLabel *labelDistance = new QLabel(QString("Distance"), this);
00552 spinDistance = new QSpinBox(this);
00553 spinDistance->setEnabled(false);
00554
00555 QLabel *LabelLR = new QLabel(QString("x-coordinate"), this);
00556 spinX = new QSpinBox(this);
00557 spinX->setRange(MIN_RECT_VALUE,MAX_RECT_VALUE);
00558
00559 QLabel *labelY = new QLabel(QString("y-coordinate"), this);
00560 spinY = new QSpinBox(this);
00561 spinY->setRange(MIN_RECT_VALUE,MAX_RECT_VALUE);
00562
00563 spinX->setValue(editor->getGridRect().x() + 2);
00564 spinY->setValue(editor->getGridRect().y() + editor->getGridRect().height() - 2);
00565
00566 QGroupBox *pointGroup = new QGroupBox(QString("Start at point ..."));
00567 QGridLayout *pointLayout = new QGridLayout(pointGroup);
00568 pointLayout->addWidget(LabelLR, 1, 0);
00569 pointLayout->addWidget(spinX, 1, 1);
00570 pointLayout->addWidget(labelY, 2, 0);
00571 pointLayout->addWidget(spinY, 2, 1);
00572
00573 QLabel *labelExpandGrid = new QLabel(QString("Expand grid proportion"), this);
00574 checkExpandGrid = new QCheckBox(this);
00575 checkExpandGrid->setChecked(true);
00576
00577
00578 QWidget *hBox = new QWidget(this);
00579 QPushButton *buttonOk = new QPushButton("Ok");
00580 QPushButton *buttonCancel = new QPushButton("Cancel");
00581 QHBoxLayout *hBoxLayout = new QHBoxLayout;
00582 hBoxLayout->addWidget(buttonOk);
00583 hBoxLayout->addWidget(buttonCancel);
00584 hBox->setLayout(hBoxLayout);
00585 hBox->setMaximumWidth(300);
00586 connect(buttonOk, SIGNAL(clicked()), this, SLOT(myAccept()));
00587 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
00588
00589 QGridLayout *dialogLayout = new QGridLayout(this);
00590 dialogLayout->addWidget(labelString, 0, 0);
00591 dialogLayout->addWidget(edtString, 0, 1);
00592 dialogLayout->addWidget(labelType, 1, 0);
00593 dialogLayout->addWidget(comboAlgorithm, 1, 1);
00594 dialogLayout->addWidget(labelDistance, 2, 0);
00595 dialogLayout->addWidget(spinDistance, 2, 1);
00596 dialogLayout->addWidget(pointGroup, 3,0, 2, 2);
00597 dialogLayout->addWidget(labelExpandGrid, 5,0, Qt::AlignRight);
00598 dialogLayout->addWidget(checkExpandGrid, 5,1);
00599 dialogLayout->addWidget(hBox, 6, 0, 1, 2);
00600
00601 QString s = "Graph generation dialog";
00602 setWindowTitle(s);
00603 setWindowIcon(QIcon(":images/generating.png"));
00604 }
00605
00606 int GraphGenerationDialog::getType()
00607 {
00608 return comboAlgorithm->currentIndex();
00609 }
00610
00611 QString GraphGenerationDialog::getString()
00612 {
00613 return edtString->text();
00614 }
00615
00616 QPoint GraphGenerationDialog::getStartPoint()
00617 {
00618 return QPoint(spinX->value(), spinY->value());
00619 }
00620
00621 int GraphGenerationDialog::getDistance()
00622 {
00623 return spinDistance->value();
00624 }
00625
00626 bool GraphGenerationDialog::isExpandRequired()
00627 {
00628 return checkExpandGrid->isChecked();
00629 }
00630
00631
00632 void GraphGenerationDialog::myAccept()
00633 {
00634 accept();
00635 }
00636
00637 void GraphGenerationDialog::algorithmChanged(int i)
00638 {
00639 spinDistance->setEnabled(i);
00640 }
00641
00642
00643
00644
00645
00646
00647
00648 LaTeXTableDialog::LaTeXTableDialog(Editor *parent,
00649 const QSharedPointer<ITransitionTable> &table)
00650 : QDialog(parent), m_pTable(table), m_viewType(eLaTeXTable)
00651 {
00652 m_textEdit = new QTextEdit(this);
00653 m_textEdit->setFont(QFont("Courier"));
00654 m_textEdit->setReadOnly(true);
00655 m_textEdit->setLineWrapMode(QTextEdit::NoWrap);
00656
00657 m_switchButton = new QPushButton(m_viewType == eStringTable ?
00658 "LaTeX table" : "String table", this);
00659 connect(m_switchButton, SIGNAL(clicked()), this, SLOT(switchView()));
00660
00661 QPushButton *copyButton = new QPushButton("Copy to clipboard", this);
00662 connect(copyButton, SIGNAL(clicked()), this, SLOT(copyAll()));
00663
00664 QGridLayout *dialogLayout = new QGridLayout(this);
00665 dialogLayout->addWidget(m_textEdit, 0, 0, 1, 2);
00666 dialogLayout->addWidget(m_switchButton, 1, 0, 1, 1);
00667 dialogLayout->addWidget(copyButton, 1, 1, 1, 1);
00668
00669 setViewText();
00670
00671 resize(500,400);
00672
00673 QString s = "Transition table";
00674 setWindowTitle(s);
00675 setWindowIcon(QIcon(":images/table.png"));
00676 }
00677
00678 QString LaTeXTableDialog::text() const
00679 {
00680 return m_textEdit->toPlainText();
00681 }
00682
00683 void LaTeXTableDialog::setViewText()
00684 {
00685 switch (m_viewType)
00686 {
00687 case eStringTable:
00688 m_textEdit->setText(m_pTable->toStringTable());
00689 break;
00690 case eLaTeXTable:
00691 m_textEdit->setText(m_pTable->toLaTeXTable());
00692 break;
00693 }
00694 }
00695
00696
00697
00698 void LaTeXTableDialog::switchView()
00699 {
00700 m_viewType = (m_viewType == eStringTable ?
00701 eLaTeXTable : eStringTable);
00702
00703 m_switchButton->setText(m_viewType == eStringTable ?
00704 "LaTeX table" : "String table");
00705
00706 setViewText();
00707 }
00708
00709 void LaTeXTableDialog::copyAll()
00710 {
00711 if (!m_textEdit->textCursor().selection().isEmpty())
00712 {
00713 m_textEdit->copy();
00714 }
00715 else
00716 {
00717 m_textEdit->selectAll();
00718 m_textEdit->copy();
00719 m_textEdit->moveCursor(QTextCursor::Start);
00720 }
00721 }
00722
00723
00724
00725
00726
00727
00728
00729 LoadAutomataDialog::LoadAutomataDialog(Editor *editor, const QString &dialogTitle,
00730 int count, const QStringList &drawAlgorithmList,
00731 bool useCurrent, IAlgorithm *algorithm)
00732 : QDialog(editor), m_count(count), m_editorFileName(editor->getFileName()),
00733 m_lastFileName(editor->getFileName()), m_algorithm(algorithm),
00734 m_comboDrawList(NULL)
00735 {
00736 QGroupBox *fileGroup = NULL;
00737 if (count != 0)
00738 {
00739
00740 fileGroup = new QGroupBox(QString("Automata files (%1 required)").arg(count),
00741 this);
00742 QGridLayout *fileLayout = new QGridLayout(fileGroup);
00743
00744 m_checkUseCurrent = new QCheckBox("Use the current automaton", this);
00745 fileLayout->addWidget(m_checkUseCurrent, 0, 1, 1, 3, Qt::AlignRight);
00746 connect(m_checkUseCurrent, SIGNAL(stateChanged(int)), this, SLOT(checkChanged(int)));
00747
00748 for(int i=0; i<m_count; ++i)
00749 {
00750 fileLayout->addWidget(new QLabel(QString("Automata %1").arg(i+1), this), i+1, 0);
00751
00752 QLineEdit *lineEdit = new QLineEdit(this);
00753 lineEdit->setReadOnly(true);
00754 fileLayout->addWidget(lineEdit, i+1, 1);
00755 m_fileEdits << lineEdit;
00756
00757 QPushButton *button = new QPushButton("...", this);
00758 button->setMaximumWidth(20);
00759 fileLayout->addWidget(button, i+1, 2);
00760 m_fileButtons << button;
00761 connect(button, SIGNAL(clicked()), this, SLOT(buttonClicked()));
00762 }
00763 }
00764
00765
00766 QGroupBox *globalGroup = new QGroupBox("Automata settings");
00767 QGridLayout *globalLayout = new QGridLayout(globalGroup);
00768
00769 QLabel *lblAlphabet = new QLabel("Alphabet", this);
00770 QLabel *lblAlphabetSymbol = new QLabel("Alphabet symbol", this);
00771 QLabel *lblEpsilonSymbol = new QLabel("Epsilon symbol", this);
00772
00773 m_alphabetRegex = QRegExp("[^,\\[\\]]+(?:,[^,\\[\\]]+)*");
00774 QValidator *v = new QRegExpValidator(m_alphabetRegex,this);
00775
00776 m_edtAlphabet = new QLineEdit(this);
00777 m_edtAlphabet->setValidator(v);
00778 m_edtAlphabetSymbol = new QLineEdit(this);
00779 m_edtEpsilonSymbol = new QLineEdit(this);
00780
00781 const QString alphabetTip = "Alphabet syntax: '[character], [character], ...' (e.g.: 'a, b, c')";
00782 m_edtAlphabet->setToolTip(alphabetTip);
00783 m_edtAlphabet->setWhatsThis(alphabetTip);
00784 const QString aSymbTip = "Alphabet symbol syntax: '[character]' (e.g.: '\\Sigma{}')";
00785 m_edtAlphabetSymbol->setToolTip(aSymbTip);
00786 m_edtAlphabetSymbol->setWhatsThis(aSymbTip);
00787 const QString eSymbTip = "Epsilon symbol syntax: '[character]' (e.g.: '\\varepsilon{}')";
00788 m_edtEpsilonSymbol->setToolTip(eSymbTip);
00789 m_edtEpsilonSymbol->setWhatsThis(eSymbTip);
00790
00791 m_checkAlphabet = new QCheckBox("autodetect", this);
00792 m_checkAlphabet->setChecked(true);
00793 m_checkAlphabetSymbol = new QCheckBox("autodetect", this);
00794 m_checkAlphabetSymbol->setChecked(true);
00795 m_checkEpsilonSymbol = new QCheckBox("autodetect", this);
00796 m_checkEpsilonSymbol->setChecked(true);
00797
00798 checkAlphabetChanged(Qt::Checked);
00799 checkAlphabetSymbChanged(Qt::Checked);
00800 checkEpsilonSymbChanged(Qt::Checked);
00801
00802 connect(m_checkAlphabet, SIGNAL(stateChanged(int)), this, SLOT(checkAlphabetChanged(int)));
00803 connect(m_checkAlphabetSymbol, SIGNAL(stateChanged(int)), this, SLOT(checkAlphabetSymbChanged(int)));
00804 connect(m_checkEpsilonSymbol, SIGNAL(stateChanged(int)), this, SLOT(checkEpsilonSymbChanged(int)));
00805
00806 globalLayout->addWidget(lblAlphabet, 0, 0);
00807 globalLayout->addWidget(m_checkAlphabet, 0, 1, Qt::AlignRight);
00808 globalLayout->addWidget(m_edtAlphabet, 1, 0, 1, 2);
00809
00810 globalLayout->addWidget(lblAlphabetSymbol, 2, 0);
00811 globalLayout->addWidget(m_checkAlphabetSymbol, 2, 1, Qt::AlignRight);
00812 globalLayout->addWidget(m_edtAlphabetSymbol, 3, 0, 1, 2);
00813
00814 globalLayout->addWidget(lblEpsilonSymbol, 4, 0);
00815 globalLayout->addWidget(m_checkEpsilonSymbol, 4, 1, Qt::AlignRight);
00816 globalLayout->addWidget(m_edtEpsilonSymbol, 5, 0, 1, 2);
00817
00818
00819 QGroupBox *algorithmGroup = NULL;
00820 if (m_algorithm && m_algorithm->hasSettingsDialog())
00821 {
00822 algorithmGroup = new QGroupBox("Algorithm settings");
00823 QVBoxLayout *algorithmLayout = new QVBoxLayout(algorithmGroup);
00824
00825 QPushButton *btnAlgorithmSettings = new QPushButton("Settings ...", this);
00826 connect(btnAlgorithmSettings, SIGNAL(clicked()), this, SLOT(algorithmSettings()));
00827
00828 algorithmLayout->addWidget(btnAlgorithmSettings);
00829 }
00830
00831
00832 QGroupBox *drawGroup = NULL;
00833 if (!drawAlgorithmList.isEmpty())
00834 {
00835 drawGroup = new QGroupBox("Drawing algorithm");
00836 QVBoxLayout *drawLayout = new QVBoxLayout(drawGroup);
00837
00838 m_comboDrawList = new QComboBox(this);
00839 m_comboDrawList->addItems(drawAlgorithmList);
00840 m_comboDrawList->setCurrentIndex(drawAlgorithmList.size()-1);
00841
00842 drawLayout->addWidget(m_comboDrawList);
00843 }
00844
00845
00846 QWidget *hBox = new QWidget(this);
00847 QPushButton *buttonOk = new QPushButton("Ok");
00848 QPushButton *buttonCancel = new QPushButton("Cancel");
00849 QHBoxLayout *hBoxLayout = new QHBoxLayout;
00850 hBoxLayout->addWidget(buttonOk);
00851 hBoxLayout->addWidget(buttonCancel);
00852 hBox->setLayout(hBoxLayout);
00853 connect(buttonOk, SIGNAL(clicked()), this, SLOT(myAccept()));
00854 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
00855
00856 buttonOk->setFocus();
00857
00858
00859 int row = 0;
00860 QGridLayout *layout = new QGridLayout(this);
00861 if (count != 0)
00862 {
00863 layout->addWidget(fileGroup, row++, 0);
00864 m_checkUseCurrent->setChecked(useCurrent);
00865 }
00866 layout->addWidget(globalGroup, row++, 0);
00867 if (algorithmGroup)
00868 layout->addWidget(algorithmGroup, row++, 0);
00869 if (drawGroup)
00870 layout->addWidget(drawGroup, row++, 0);
00871 layout->addWidget(hBox, row++, 0);
00872
00873 setWindowTitle(dialogTitle);
00874 }
00875
00876 QStringList LoadAutomataDialog::getFileNames() const
00877 {
00878 Q_ASSERT(m_count != 0);
00879
00880 QStringList result;
00881
00882 if (m_count == 0)
00883 return result;
00884
00885 for (int i=0; i<m_count; ++i)
00886 {
00887 result << m_fileEdits[i]->text();
00888 }
00889
00890 return result;
00891 }
00892
00893 bool LoadAutomataDialog::useCurrentAutomaton() const
00894 {
00895 Q_ASSERT(m_count != 0);
00896
00897 if (m_count == 0)
00898 return true;
00899
00900 return m_checkUseCurrent->isChecked();
00901 }
00902
00903 int LoadAutomataDialog::getDrawAlgorithmIndex() const
00904 {
00905 if (!m_comboDrawList) return 0;
00906
00907 return m_comboDrawList->currentIndex();
00908 }
00909
00910 void LoadAutomataDialog::setDrawAlgorithmIndex(int index)
00911 {
00912 Q_ASSERT(m_comboDrawList && m_comboDrawList->count() > index);
00913
00914 m_comboDrawList->setCurrentIndex(index);
00915 }
00916
00917 bool LoadAutomataDialog::alphabetIsSet() const
00918 {
00919 return !m_checkAlphabet->isChecked();
00920 }
00921
00922 bool LoadAutomataDialog::alphabetSymbolIsSet() const
00923 {
00924 return !m_checkAlphabetSymbol->isChecked();
00925 }
00926
00927 bool LoadAutomataDialog::epsilonSymbolIsSet() const
00928 {
00929 return !m_checkEpsilonSymbol->isChecked();
00930 }
00931
00932 ITransition::TCharSet LoadAutomataDialog::getAlphabet() const
00933 {
00934 Q_ASSERT(!m_alphabet.empty());
00935
00936 DBGLOG(DBGPAR(m_alphabet));
00937 return m_alphabet;
00938 }
00939
00940 QString LoadAutomataDialog::getAlphabetSymbol() const
00941 {
00942 Q_ASSERT(alphabetSymbolIsSet());
00943
00944 DBGLOG(DBGPAR(m_alphabetSymbol));
00945 return m_alphabetSymbol;
00946 }
00947
00948 QString LoadAutomataDialog::getEpsilonSymbol() const
00949 {
00950 Q_ASSERT(epsilonSymbolIsSet());
00951
00952 DBGLOG(DBGPAR(m_epsilonSymbol));
00953 return m_epsilonSymbol;
00954 }
00955
00956
00957 void LoadAutomataDialog::myAccept()
00958 {
00959 bool okFiles = true;
00960 bool okSettings = true;
00961
00962 if (m_count != 0)
00963 {
00964 Q_ASSERT(!m_fileEdits.empty());
00965
00966 if (!m_checkUseCurrent->isChecked())
00967 okFiles &= (m_fileEdits[0]->text() != "");
00968
00969 for (int i=1; i<m_count; i++)
00970 {
00971 okFiles &= (m_fileEdits[i]->text() != "");
00972 }
00973 }
00974
00975 if ((!m_checkAlphabet->isChecked() && m_edtAlphabet->text() == "") ||
00976 (!m_checkAlphabetSymbol->isChecked() && m_edtAlphabetSymbol->text() == "") ||
00977 (!m_checkEpsilonSymbol->isChecked() && m_edtEpsilonSymbol->text() == ""))
00978 {
00979 okSettings = false;
00980 }
00981
00982 if (!m_checkAlphabetSymbol->isChecked())
00983 {
00984 m_alphabetSymbol = Editor::parseCharacter(m_edtAlphabetSymbol->text());
00985 DBGLOG(DBGPAR(m_alphabetSymbol));
00986 okSettings == okSettings && (m_alphabetSymbol != "");
00987 }
00988
00989 if (!m_checkEpsilonSymbol->isChecked())
00990 {
00991 m_epsilonSymbol = Editor::parseCharacter(m_edtEpsilonSymbol->text());
00992 DBGLOG(DBGPAR(m_epsilonSymbol));
00993 okSettings == okSettings && (m_epsilonSymbol != "");
00994 }
00995
00996 if (!m_checkAlphabet->isChecked())
00997 {
00998 m_alphabet = Editor::parseCharSet(m_edtAlphabet->text());
00999 DBGLOG(DBGPAR(m_alphabet));
01000 okSettings = okSettings && !m_alphabet.empty();
01001
01002 if (!m_checkAlphabetSymbol)
01003 okSettings = okSettings && !m_alphabet.contains(m_alphabetSymbol);
01004 if (!m_checkEpsilonSymbol)
01005 okSettings = okSettings && !m_alphabet.contains(m_epsilonSymbol);
01006 }
01007
01008 if (okFiles && okSettings)
01009 {
01010 accept();
01011 }
01012 else
01013 {
01014 if (!okFiles)
01015 {
01016 QMessageBox::information(this, "Select all files!",
01017 "Please select all required files or Cancel",
01018 QMessageBox::Ok);
01019 }
01020 else
01021 {
01022 QMessageBox::information(this, "Fill settings!",
01023 "Please fill required settings correctly or select autodetection.",
01024 QMessageBox::Ok);
01025 }
01026 }
01027 }
01028
01029 void LoadAutomataDialog::checkChanged(int state)
01030 {
01031 Q_ASSERT(!m_fileEdits.empty() && !m_fileButtons.empty());
01032
01033
01034
01035
01036 if (state == Qt::Checked)
01037 {
01038 m_fileEdits[0]->setEnabled(false);
01039 m_fileButtons[0]->setEnabled(false);
01040
01041 m_fileEdits[0]->setText(m_editorFileName);
01042 }
01043 else
01044 {
01045 m_fileEdits[0]->setEnabled(true);
01046 m_fileButtons[0]->setEnabled(true);
01047 }
01048 }
01049
01050 void LoadAutomataDialog::buttonClicked()
01051 {
01052 QPushButton *button = qobject_cast<QPushButton *>(sender());
01053 Q_ASSERT(button);
01054
01055 int i = m_fileButtons.indexOf(button);
01056
01057 QString fn = QFileDialog::getOpenFileName(0,"Open file", m_lastFileName,
01058 "VauCanSon-G and LaTeX (*.vcg *.tex);;All files (*.*)");
01059 if (fn != QString::null)
01060 {
01061 Q_ASSERT(m_fileEdits.count() > i);
01062 m_fileEdits[i]->setText(fn);
01063 m_lastFileName = fn.left(fn.lastIndexOf(QRegExp("[/\\\\]")));
01064 }
01065 }
01066
01067 void LoadAutomataDialog::checkAlphabetChanged(int state)
01068 {
01069 if (state == Qt::Checked)
01070 {
01071 m_edtAlphabet->setEnabled(false);
01072 }
01073 else
01074 {
01075 m_edtAlphabet->setEnabled(true);
01076 }
01077 }
01078
01079 void LoadAutomataDialog::checkAlphabetSymbChanged(int state)
01080 {
01081 if (state == Qt::Checked)
01082 {
01083 m_edtAlphabetSymbol->setEnabled(false);
01084 }
01085 else
01086 {
01087 m_edtAlphabetSymbol->setEnabled(true);
01088 }
01089 }
01090
01091 void LoadAutomataDialog::checkEpsilonSymbChanged(int state)
01092 {
01093 if (state == Qt::Checked)
01094 {
01095 m_edtEpsilonSymbol->setEnabled(false);
01096 }
01097 else
01098 {
01099 m_edtEpsilonSymbol->setEnabled(true);
01100 }
01101 }
01102
01103 void LoadAutomataDialog::algorithmSettings()
01104 {
01105 Q_ASSERT(m_algorithm);
01106 m_algorithm->runSettingsDialog();
01107 }
01108
01109
01110
01111
01112
01113
01114
01115 ReportDialog::ReportDialog(const QString &reportText, QWidget *parent)
01116 : QDialog(parent)
01117 {
01118 QTextEdit *reportEdit = new QTextEdit(reportText, this);
01119 reportEdit->setReadOnly(true);
01120 reportEdit->setMinimumSize(600,400);
01121
01122 QPushButton *closeButton = new QPushButton("&Close", this);
01123 connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
01124
01125 QVBoxLayout *dialogLayout = new QVBoxLayout(this);
01126 dialogLayout->addWidget(reportEdit);
01127 dialogLayout->addWidget(closeButton, 0, Qt::AlignHCenter);
01128
01129 setWindowTitle(QString("Report"));
01130 }
01131
01132