Added some improvements
[flowchart-guider:flowchart-guider.git] / mainform.cpp
1 #include "mainform.h"\r
2 #include "ui_mainform.h"\r
3 #include "frmsettings.h"\r
4 \r
5 MainForm::MainForm(QWidget *parent) :\r
6         QMainWindow(parent),\r
7         ui(new Ui::MainForm) {\r
8         ui->setupUi(this);\r
9 \r
10         helpDialog = 0;\r
11 \r
12         // nacteni nastaveni\r
13         QSettings s(APP,APP);\r
14         restoreState(s.value("mainform/state",saveState()).toByteArray());\r
15         restoreGeometry(s.value("mainform/geometry",saveGeometry()).toByteArray());\r
16 \r
17         ui->settingsDock->setVisible(true);\r
18         lastVisible = ui->settingsDock->isVisible();\r
19 \r
20         // vytvoreni­ BASE\r
21         base = new myBase(this,ui->viewer,&s);\r
22 \r
23         // nacteni seznamu naposledy otevrenych souboru\r
24         base->MRU->setItems(s.value("mainform/mru","").toString());\r
25 \r
26         ui->canvasWidth->setMinimum(BASE_MIN_CANVAS_WIDTH);\r
27         ui->canvasHeight->setMinimum(BASE_MIN_CANVAS_HEIGHT);\r
28 \r
29         // signaly z BASE a ostatni\r
30         connect(base->scene,SIGNAL(selectionChanged()),this,SLOT(updateSelectionList()));\r
31         connect(base,SIGNAL(statusUpdated(myBaseAction)),this,SLOT(statusUpdated(myBaseAction)));\r
32         connect(base,SIGNAL(varViewerAdd(const QScriptEngine *, const QString, const QColor, const QColor, const QString )),this,SLOT(varViewerAdd(const QScriptEngine *, const QString, const QColor, const QColor, const QString )));\r
33         connect(base,SIGNAL(clearVarViewer()),this,SLOT(clearVarViewer()));\r
34         connect(base,SIGNAL(updateObjectInfo(myItem*)),this,SLOT(updateObjectInfo(myItem*)));\r
35         connect(base,SIGNAL(updateDocumentSettings()),this,SLOT(updateDocumentSettings()));\r
36         connect(base->MRU,SIGNAL(refreshMRU()),this,SLOT(refreshMRU()));\r
37         connect(ui->aUpdtPthws,SIGNAL(triggered()),base,SLOT(slotUpdatePathways()));\r
38         connect(base,SIGNAL(playActionUpdated()),this,SLOT(playActionUpdated()));\r
39         connect(base,SIGNAL(fileSaved()),this,SLOT(updateWindowTitle()));\r
40         connect(base,SIGNAL(updateWindowTitle()),this,SLOT(updateWindowTitle()));\r
41 \r
42         // nastaveni­ vlastnosti­ vybranych obj.\r
43         connect(ui->backgroundColor,SIGNAL(colorSelected(QColor)),base,SLOT(slotSetBackgroundColor(QColor)));\r
44         connect(ui->lineColor,SIGNAL(colorSelected(QColor)),base,SLOT(slotSetLineColor(QColor)));\r
45         connect(ui->circleColor,SIGNAL(colorSelected(QColor)),base,SLOT(slotSetCircleColor(QColor)));\r
46 \r
47         connect(ui->canvasWidth,SIGNAL(valueChanged(int)),base,SLOT(setCanvasWidth(int)));\r
48         connect(ui->canvasHeight,SIGNAL(valueChanged(int)),base,SLOT(setCanvasHeight(int)));\r
49 \r
50         connect(ui->defaultUserItemBorderColor,SIGNAL(colorSelected(QColor)),base,SLOT(slotSetDefaultItemBorderColor(const QColor)));\r
51         connect(ui->defaultUserItemColor1,SIGNAL(colorSelected(QColor)),base,SLOT(slotSetDefaultItemColor1(const QColor)));\r
52         connect(ui->defaultUserItemColor2,SIGNAL(colorSelected(QColor)),base,SLOT(slotSetDefaultItemColor2(const QColor)));\r
53         connect(ui->defaultUserItemTextColor,SIGNAL(colorSelected(QColor)),base,SLOT(slotSetDefaultItemTextColor(const QColor)));\r
54         connect(ui->defaultUserItemTextSize,SIGNAL(valueChanged(int)),base,SLOT(slotSetDefaultItemTextSize(const int)));\r
55 \r
56         connect(ui->userActiveItemBorderColor,SIGNAL(colorSelected(QColor)),base,SLOT(slotSetActiveItemBorderColor(const QColor)));\r
57         connect(ui->userActiveItemColor1,SIGNAL(colorSelected(QColor)),base,SLOT(slotSetActiveItemColor1(const QColor)));\r
58         connect(ui->userActiveItemColor2,SIGNAL(colorSelected(QColor)),base,SLOT(slotSetActiveItemColor2(const QColor)));\r
59         connect(ui->userActiveItemTextColor,SIGNAL(colorSelected(QColor)),base,SLOT(slotSetActiveItemTextColor(const QColor)));\r
60 \r
61         connect(ui->userSelectedItemBorderColor,SIGNAL(colorSelected(QColor)),base,SLOT(slotSetSelectedItemBorderColor(const QColor)));\r
62         connect(ui->userSelectedItemColor1,SIGNAL(colorSelected(QColor)),base,SLOT(slotSetSelectedItemColor1(const QColor)));\r
63         connect(ui->userSelectedItemColor2,SIGNAL(colorSelected(QColor)),base,SLOT(slotSetSelectedItemColor2(const QColor)));\r
64         connect(ui->userSelectedItemTextColor,SIGNAL(colorSelected(QColor)),base,SLOT(slotSetSelectedItemTextColor(const QColor)));\r
65 \r
66         connect(ui->userItemColor1,SIGNAL(colorSelected(QColor)),base->scene,SLOT(setUserItemColor1(QColor)));\r
67         connect(ui->userItemColor2,SIGNAL(colorSelected(QColor)),base->scene,SLOT(setUserItemColor2(QColor)));\r
68         connect(ui->userBorderColor,SIGNAL(colorSelected(QColor)),base->scene,SLOT(setUserBorderColor(QColor)));\r
69 \r
70         connect(ui->userTextColor,SIGNAL(colorSelected(QColor)),base->scene,SLOT(setUserTextColor(QColor)));\r
71         connect(ui->textSet,SIGNAL(textChanged(QString)),base->scene,SLOT(setTextForSelected(QString)));\r
72         connect(ui->xCoord,SIGNAL(valueChanged(int)),base->scene,SLOT(setXForSelected(int)));\r
73         connect(ui->yCoord,SIGNAL(valueChanged(int)),base->scene,SLOT(setYForSelected(int)));\r
74         connect(ui->widthSet,SIGNAL(valueChanged(int)),base->scene,SLOT(setWidthForSelected(int)));\r
75         connect(ui->heightSet,SIGNAL(valueChanged(int)),base->scene,SLOT(setHeightForSelected(int)));\r
76         connect(ui->fontSizeSet,SIGNAL(valueChanged(int)),base->scene,SLOT(setFontSizeForSelected(int)));\r
77         connect(ui->conditionTypeSet,SIGNAL(currentIndexChanged(int)),base->scene,SLOT(setConditionTypeForSelected(int)));\r
78         connect(ui->commentSet,SIGNAL(textChanged(QString)),base->scene,SLOT(setCommentForSelected(QString)));\r
79 \r
80         // zoom + / - / 1:1\r
81         connect(ui->aZoomIn,SIGNAL(triggered()),base,SLOT(zoomIn()));\r
82         connect(ui->aZoomOut,SIGNAL(triggered()),base,SLOT(zoomOut()));\r
83         connect(ui->aZoomOriginal,SIGNAL(triggered()),base,SLOT(zoomToDefault()));\r
84         connect(ui->aGotoItem,SIGNAL(triggered()),base,SLOT(gotoItem()));\r
85 \r
86         // undo / redo\r
87         connect(ui->aUndo,SIGNAL(triggered()),base,SLOT(slotUndo()));\r
88         connect(ui->aRedo,SIGNAL(triggered()),base,SLOT(slotRedo()));\r
89         connect(base,SIGNAL(checkUndoRedo()),this,SLOT(checkUndoRedo()));\r
90 \r
91         // tabulka promennych\r
92         connect(ui->aClearVarTab,SIGNAL(triggered()),this,SLOT(clearVarViewer()));\r
93         ui->clearVarTabBtn->setDefaultAction(ui->aClearVarTab);\r
94         connect(ui->aSaveVarTab,SIGNAL(triggered()),this,SLOT(exportVarTabAsCSV()));\r
95         ui->exportAsCSVBtn->setDefaultAction(ui->aSaveVarTab);\r
96         connect(ui->aSaveVarTabToHTML,SIGNAL(triggered()),this,SLOT(exportVarTabAsHTML()));\r
97         ui->exportAsHTMLBtn->setDefaultAction(ui->aSaveVarTabToHTML);\r
98 \r
99         // kopirovani, vyjmuti, ...\r
100         connect(ui->aDelete,SIGNAL(triggered()),base->scene,SLOT(slotRemoveSelected()));\r
101         connect(ui->aCopy,SIGNAL(triggered()),base->scene,SLOT(slotCopySelected()));\r
102         connect(ui->aInsert,SIGNAL(triggered()),base->scene,SLOT(slotInsertSelected()));\r
103         connect(ui->aCut,SIGNAL(triggered()),base->scene,SLOT(slotCutSelected()));\r
104 \r
105         // vybrat vse / nic\r
106         connect(ui->aSelectAll,SIGNAL(triggered()),base->scene,SLOT(selectAll()));\r
107         connect(ui->aSelectNone,SIGNAL(triggered()),base->scene,SLOT(selectNone()));\r
108 \r
109         // prace se souborem\r
110         connect(ui->aFileNew,SIGNAL(triggered()),base,SLOT(slotNewFile()));\r
111         connect(ui->aOpen,SIGNAL(triggered()),base,SLOT(slotOpenFile()));\r
112         connect(ui->aSave,SIGNAL(triggered()),base,SLOT(slotSaveFile()));\r
113         connect(ui->aSaveAs,SIGNAL(triggered()),base,SLOT(slotSaveFileAs()));\r
114         connect(ui->aPrint,SIGNAL(triggered()),base,SLOT(print()));\r
115         connect(ui->aExport,SIGNAL(triggered()),base,SLOT(exportToImage()));\r
116         connect(ui->aClose,SIGNAL(triggered()),this,SLOT(close()));\r
117 \r
118         // prehravaci tlacitka\r
119         connect(ui->aPlay,SIGNAL(triggered()),base,SLOT(slotPlay()));\r
120         connect(ui->aStop,SIGNAL(triggered()),base,SLOT(slotStop()));\r
121         connect(ui->aNextStep,SIGNAL(triggered()),base,SLOT(slotNext()));\r
122         connect(ui->aPause,SIGNAL(triggered()),base,SLOT(slotPause()));\r
123 \r
124         // pridavani objektu\r
125         connect(ui->aAddStart_2,SIGNAL(triggered()),base,SLOT(slotAddStart()));\r
126         connect(ui->aAddCommand,SIGNAL(triggered()),base,SLOT(slotAddCommand()));\r
127         connect(ui->aAddInout,SIGNAL(triggered()),base,SLOT(slotAddInout()));\r
128         connect(ui->aAddCondition,SIGNAL(triggered()),base,SLOT(slotAddCondition()));\r
129         connect(ui->aAddContinue,SIGNAL(triggered()),base,SLOT(slotAddContinue()));\r
130         connect(ui->aAddEnd,SIGNAL(triggered()),base,SLOT(slotAddEnd()));\r
131         connect(ui->aAddText,SIGNAL(triggered()),base,SLOT(slotAddText()));\r
132         connect(ui->aCancelAdding,SIGNAL(triggered()),base,SLOT(cancelAddingItem()));\r
133 \r
134         // nastaveni otevirani z MRU\r
135         connect(ui->aOpen0,SIGNAL(triggered()),this,SLOT(openFromMRU0()));\r
136         connect(ui->aOpen1,SIGNAL(triggered()),this,SLOT(openFromMRU1()));\r
137         connect(ui->aOpen2,SIGNAL(triggered()),this,SLOT(openFromMRU2()));\r
138         connect(ui->aOpen3,SIGNAL(triggered()),this,SLOT(openFromMRU3()));\r
139         connect(ui->aOpen4,SIGNAL(triggered()),this,SLOT(openFromMRU4()));\r
140         connect(ui->aOpen5,SIGNAL(triggered()),this,SLOT(openFromMRU5()));\r
141         connect(ui->aOpen6,SIGNAL(triggered()),this,SLOT(openFromMRU6()));\r
142         connect(ui->aOpen7,SIGNAL(triggered()),this,SLOT(openFromMRU7()));\r
143         connect(ui->aOpen8,SIGNAL(triggered()),this,SLOT(openFromMRU8()));\r
144         connect(ui->aOpen9,SIGNAL(triggered()),this,SLOT(openFromMRU9()));\r
145 \r
146         // zarovnani\r
147         connect(ui->aArangeToLeft,SIGNAL(triggered()),base->scene,SLOT(slotArangeToLeft()));\r
148         connect(ui->aArangeToRight,SIGNAL(triggered()),base->scene,SLOT(slotArangeToRight()));\r
149         connect(ui->aArangeToTop,SIGNAL(triggered()),base->scene,SLOT(slotArangeToTop()));\r
150         connect(ui->aArangeToBottom,SIGNAL(triggered()),base->scene,SLOT(slotArangeToBottom()));\r
151         connect(ui->aArangeToCenterH,SIGNAL(triggered()),base->scene,SLOT(slotArangeToCenterH()));\r
152         connect(ui->aArangeToCenterV,SIGNAL(triggered()),base->scene,SLOT(slotArangeToCenterV()));\r
153         connect(ui->aSetHeights,SIGNAL(triggered()),base->scene,SLOT(slotSetHeights()));\r
154         connect(ui->aSetWidths,SIGNAL(triggered()),base->scene,SLOT(slotSetWidths()));\r
155 \r
156         connect(ui->btnALeft,SIGNAL(clicked()),base->scene,SLOT(slotArangeToLeft()));\r
157         connect(ui->btnARight,SIGNAL(clicked()),base->scene,SLOT(slotArangeToRight()));\r
158         connect(ui->btnATop,SIGNAL(clicked()),base->scene,SLOT(slotArangeToTop()));\r
159         connect(ui->btnABottom,SIGNAL(clicked()),base->scene,SLOT(slotArangeToBottom()));\r
160         connect(ui->btnACenterH,SIGNAL(clicked()),base->scene,SLOT(slotArangeToCenterH()));\r
161         connect(ui->btnACenterV,SIGNAL(clicked()),base->scene,SLOT(slotArangeToCenterV()));\r
162         connect(ui->btnASetHeights,SIGNAL(clicked()),base->scene,SLOT(slotSetHeights()));\r
163         connect(ui->btnASetWidths,SIGNAL(clicked()),base->scene,SLOT(slotSetWidths()));\r
164 \r
165         ui->btnALeft->setDefaultAction(ui->aArangeToLeft);\r
166         ui->btnARight->setDefaultAction(ui->aArangeToRight);\r
167         ui->btnATop->setDefaultAction(ui->aArangeToTop);\r
168         ui->btnABottom->setDefaultAction(ui->aArangeToBottom);\r
169         ui->btnACenterH->setDefaultAction(ui->aArangeToCenterH);\r
170         ui->btnACenterV->setDefaultAction(ui->aArangeToCenterV);\r
171         ui->btnASetHeights->setDefaultAction(ui->aSetHeights);\r
172         ui->btnASetWidths->setDefaultAction(ui->aSetWidths);\r
173 \r
174         ui->btnPlay->setDefaultAction(ui->aPlay);\r
175         ui->btnPause->setDefaultAction(ui->aPause);\r
176         ui->btnNext->setDefaultAction(ui->aNextStep);\r
177         ui->btnStop->setDefaultAction(ui->aStop);\r
178 \r
179         connect(ui->aUnsetDestP,SIGNAL(triggered()),base->scene,SLOT(unsetDestP()));\r
180         connect(ui->aUnsetDestM,SIGNAL(triggered()),base->scene,SLOT(unsetDestM()));\r
181         ui->unsetPBtn->setDefaultAction(ui->aUnsetDestP);\r
182         ui->unsetMBtn->setDefaultAction(ui->aUnsetDestM);\r
183 \r
184         connect(ui->aApplyScheme,SIGNAL(triggered()),this,SLOT(schemeChanged()));\r
185         connect(ui->aEditSchemes,SIGNAL(triggered()),this,SLOT(editShemes()));\r
186         ui->applySchemeBtn->setDefaultAction(ui->aApplyScheme);\r
187         ui->editSchemesBtn->setDefaultAction(ui->aEditSchemes);\r
188 \r
189         // nastavovani rezimu\r
190         connect(ui->aEditMode,SIGNAL(triggered()),base,SLOT(slotSetEditMode()));\r
191         connect(ui->aViewMode,SIGNAL(triggered()),base,SLOT(slotSetViewMode()));\r
192         connect(ui->aToggleFullscreen,SIGNAL(triggered()),this,SLOT(toggleFullscreen()));\r
193 \r
194         // stepTimer->interval , ostatni ...\r
195         connect(ui->stepTimerDelay,SIGNAL(valueChanged(int)),base,SLOT(slotSetStepTimerInterval(int)));\r
196         ui->varTab->setEditTriggers(QAbstractItemView::NoEditTriggers);\r
197         connect(ui->aAbout,SIGNAL(triggered()),this,SLOT(showAbout()));\r
198 \r
199         // vyskakovaci menu\r
200         popupMenu = new QMenu(ui->viewer);\r
201         ui->viewer->menu = popupMenu;\r
202         popupMenu->addAction(ui->aZoomIn);\r
203         popupMenu->addAction(ui->aZoomOut);\r
204         popupMenu->addAction(ui->aZoomOriginal);\r
205         popupMenu->addSeparator();\r
206         popupMenu->addAction(ui->aCopy);\r
207         popupMenu->addAction(ui->aCut);\r
208         popupMenu->addAction(ui->aInsert);\r
209         popupMenu->addAction(ui->aDelete);\r
210         popupMenu->addSeparator();\r
211         popupMenu->addAction(ui->aSelectAll);\r
212         popupMenu->addAction(ui->aSelectNone);\r
213         popupMenu->addSeparator();\r
214         popupMenu->addAction(ui->aUnsetDestP);\r
215         popupMenu->addAction(ui->aUnsetDestM);\r
216         popupMenu->show();\r
217 \r
218         // aktualizace (zamceni) panelu\r
219         updateObjectInfo(0);\r
220         updateDocumentSettings();\r
221         updateSelectionList();\r
222         checkUndoRedo();\r
223         refreshMRU();\r
224         ui->comboBox->loadSchemes(s.value("mainform/schemes",QString("#87b5ba;#778ea4;#3d4a55;#ffffff|#ffffff;#c7c7c7;#727272;#232323|#afafaf;#636363;#464646;#ffffff|#9194b3;#5a597d;#404049;#ffffff|#a58279;#855959;#5b4040;#ffffff|#eecc9d;#c09465;#634022;#ffffff|#92a081;#6e8a6c;#51594c;#ffffff|#b8ba83;#9fa474;#52553c;#ffffff|#95ba83;#76a474;#3c553c;#ffffff|#81b8ba;#74a4a0;#3c5554;#ffffff|#ba7a7a;#a47676;#553c3c;#ffffff|#d7d7d7;#b0b0b0;#525252;#272727|#bde1e3;#a7baca;#3d4a55;#000000|#c3e3bd;#afcaa5;#3a553b;#000000|#e3e3bc;#cacaa3;#52553b;#000000|#e3b8b8;#caa2a2;#553939;#000000|#e3cfb7;#cab49b;#55483a;#000000|#e0b8e3;#c79fca;#553b54;#000000")).toString());\r
225         statusUpdated(base->status());\r
226 }\r
227 \r
228 MainForm::~MainForm() {\r
229 \r
230         QSettings s(APP,APP);\r
231         s.setValue("mainform/state",saveState());\r
232         s.setValue("mainform/geometry",saveGeometry());\r
233         s.setValue("mainform/mru",base->MRU->itemsExport());\r
234 \r
235         s.setValue("mainform/schemes",ui->comboBox->exportSchemes());\r
236 \r
237         delete base;\r
238         delete popupMenu;\r
239         delete ui;\r
240 }\r
241 \r
242 void MainForm::changeEvent(QEvent *e) {\r
243         QMainWindow::changeEvent(e);\r
244         switch (e->type()) {\r
245         case QEvent::LanguageChange:\r
246                 ui->retranslateUi(this);\r
247                 break;\r
248         default:\r
249                 break;\r
250         }\r
251 }\r
252 \r
253 void MainForm::openFromMRU(const int i) { // otevreni souboru (ze seznamu naposledy otevrenych)\r
254         if (base->changed()) if (!base->continueWithFileOp()) return;\r
255         QStringList strLst = base->MRU->items();\r
256 \r
257         if (strLst.count()>i)\r
258                 if (!base->openFile(strLst.at(i)))\r
259                         QMessageBox::warning(this,ERR,CANT_OPEN);\r
260 }\r
261 \r
262 void MainForm::closeEvent( QCloseEvent * event ) {\r
263         base->setPlayAction(mpa_stop);\r
264         if (base->changed()) {\r
265                 if (base->continueWithFileOp())\r
266                         event->accept();\r
267                 else\r
268                         event->ignore();\r
269         } else event->accept();\r
270 }\r
271 \r
272 \r
273 void MainForm::refreshMRU() { // obnoveni seznamu naposledy otevrenych souboru\r
274         QStringList strLst = base->MRU->items();\r
275 \r
276         if (strLst.count()>0) {\r
277                 ui->aOpen0->setText(strLst.at(0));\r
278                 ui->aOpen0->setVisible(true);\r
279         } else ui->aOpen0->setVisible(false);\r
280 \r
281         if (strLst.count()>1) {\r
282                 ui->aOpen1->setText(strLst.at(1));\r
283                 ui->aOpen1->setVisible(true);\r
284         } else ui->aOpen1->setVisible(false);\r
285 \r
286         if (strLst.count()>2) {\r
287                 ui->aOpen2->setText(strLst.at(2));\r
288                 ui->aOpen2->setVisible(true);\r
289         } else ui->aOpen2->setVisible(false);\r
290 \r
291         if (strLst.count()>3) {\r
292                 ui->aOpen3->setText(strLst.at(3));\r
293                 ui->aOpen3->setVisible(true);\r
294         } else ui->aOpen3->setVisible(false);\r
295 \r
296         if (strLst.count()>4) {\r
297                 ui->aOpen4->setText(strLst.at(4));\r
298                 ui->aOpen4->setVisible(true);\r
299         } else ui->aOpen4->setVisible(false);\r
300 \r
301         if (strLst.count()>5) {\r
302                 ui->aOpen5->setText(strLst.at(5));\r
303                 ui->aOpen5->setVisible(true);\r
304         } else ui->aOpen5->setVisible(false);\r
305 \r
306         if (strLst.count()>6) {\r
307                 ui->aOpen6->setText(strLst.at(6));\r
308                 ui->aOpen6->setVisible(true);\r
309         } else ui->aOpen6->setVisible(false);\r
310 \r
311         if (strLst.count()>7) {\r
312                 ui->aOpen7->setText(strLst.at(7));\r
313                 ui->aOpen7->setVisible(true);\r
314         } else ui->aOpen7->setVisible(false);\r
315 \r
316         if (strLst.count()>8) {\r
317                 ui->aOpen8->setText(strLst.at(8));\r
318                 ui->aOpen8->setVisible(true);\r
319         } else ui->aOpen8->setVisible(false);\r
320 \r
321         if (strLst.count()>9) {\r
322                 ui->aOpen9->setText(strLst.at(9));\r
323                 ui->aOpen9->setVisible(true);\r
324         } else ui->aOpen9->setVisible(false);\r
325 }\r
326 \r
327 void MainForm::varViewerAdd(const QScriptEngine * engine, const QString command, const QColor background_c, const QColor text_c, const QString comment_c) { // volani pridani polozky do tabulky promennych\r
328         QScriptValueIterator it(engine->globalObject());\r
329         QString str;\r
330 \r
331         int count = 3;\r
332         QStringList names; // hlavicka\r
333         QStringList values; // data\r
334 \r
335         names.append(QString(TABLE_COMMENT));\r
336         names.append(QString(TABLE_COMMAND));\r
337         names.append(QString(TABLE_RESULT));\r
338         values.append(comment_c);\r
339         values.append(command);\r
340         values.append(base->return_value);\r
341 \r
342         while (it.hasNext()) {\r
343                 it.next();\r
344                 str = it.name();\r
345                 if (!it.value().isFunction() &&\r
346                     str!="NaN" &&\r
347                     str!="Infinity" &&\r
348                     str!="undefined" &&\r
349                     str!="Math" &&\r
350                     str!="JSON"\r
351                     ) {\r
352                         names.append(it.name());\r
353                         values.append(it.value().toString());\r
354                         count++;\r
355                 }\r
356         }\r
357 \r
358         ui->varTab->setColumnCount(count);\r
359         ui->varTab->setRowCount(ui->varTab->rowCount()+1);\r
360         ui->varTab->setHorizontalHeaderLabels(names);\r
361 \r
362         QTableWidgetItem * prevItm;\r
363         for (int i=0; i<(values.count()); i++) {\r
364 \r
365                 QTableWidgetItem * itm = new QTableWidgetItem(values.at(i));\r
366                 itm->setBackgroundColor(TABLE_BACKGROUND);\r
367                 itm->setTextColor(TABLE_TEXT);\r
368                 if (ui->varTab->rowCount()>2) {\r
369                         prevItm = ui->varTab->item(ui->varTab->rowCount()-2,i);\r
370                         if (prevItm!=0) {\r
371                                 if (i>2)\r
372                                         if (values.at(i)!=prevItm->text())\r
373                                                 itm->setBackgroundColor(TABLE_CHANGED_VALUE);\r
374                         } else itm->setBackgroundColor(TABLE_CHANGED_VALUE);\r
375                 }\r
376 \r
377                 if (i==1) {\r
378                         itm->setBackgroundColor(background_c);\r
379                         itm->setTextColor(text_c);\r
380                 } else if (i==2) {\r
381                         if (values.at(2)=="true") itm->setBackgroundColor(TABLE_TRUE);\r
382                         else if (values.at(2)=="false") itm->setBackgroundColor(TABLE_FALSE);\r
383                 }\r
384                 ui->varTab->setItem(ui->varTab->rowCount()-1,i,itm);\r
385 \r
386         }\r
387 \r
388         // scrollovat dolu a nastaveni sirek sloupcu dle obsahu\r
389         ui->varTab->scrollToBottom();\r
390         ui->varTab->resizeColumnsToContents();\r
391 }\r
392 \r
393 void MainForm::clearVarViewer() { // volani vymazani tabulky promennych\r
394         ui->varTab->clear();\r
395         ui->varTab->setRowCount(0);\r
396 }\r
397 \r
398 void MainForm::checkUndoRedo() { // nastaveni zapnuti ci vypnuti Undo / Redo tlacitek\r
399         ui->aRedo->setEnabled(base->canRedo());\r
400         ui->aUndo->setEnabled(base->canUndo());\r
401         updateWindowTitle();\r
402 }\r
403 \r
404 void MainForm::exportVarTabAsCSV() {\r
405 \r
406     QString filename = QFileDialog::getSaveFileName(this, CSV_TITLE,"", CSV_FILTER);\r
407         if ( !filename.isEmpty() ) {\r
408                 filename = base->assignSuffix(filename,"csv");\r
409                 QFile data(filename);\r
410                 if (data.open(QFile::WriteOnly | QFile::Truncate)) {\r
411 \r
412                         QTextStream out(&data);\r
413                         out.setCodec("UTF-8");\r
414                         QString radek;\r
415                         QTableWidgetItem * itm;\r
416 \r
417                         for (int j=0; j<ui->varTab->columnCount(); j++) {\r
418                                 out << "\"";\r
419                                 itm = ui->varTab->horizontalHeaderItem(j);\r
420                                 if (itm!=NULL)\r
421                                         radek = itm->text();\r
422                                 else\r
423                                         radek = "";\r
424 \r
425                                 out << radek.replace("\"","''")  << "\"";\r
426                                 if (j!=(ui->varTab->colorCount()-1)) out << ";";\r
427                         }\r
428                         out << endl;\r
429 \r
430 \r
431                         for (int i=0; i<ui->varTab->rowCount(); i++) {\r
432 \r
433                                 for (int j=0; j<ui->varTab->columnCount(); j++) {\r
434                                         out << "\"";\r
435                                         itm = ui->varTab->item(i,j);\r
436                                         if (itm!=NULL)\r
437                                                 radek = itm->text();\r
438                                         else\r
439                                                 radek = "";\r
440 \r
441                                         out << radek.replace("\"","''")  << "\"";\r
442                                         if (j!=(ui->varTab->colorCount()-1)) out << ";";\r
443                                 }\r
444 \r
445                                 out << endl;\r
446                         }\r
447                         data.close();\r
448 \r
449                 } else QMessageBox::warning(NULL,ERR,CANT_SAVE,QMessageBox::Cancel,QMessageBox::Cancel);\r
450 \r
451         }\r
452 }\r
453 \r
454 void MainForm::exportHTML(const QString filename, const bool include_image ) {\r
455     if ( !filename.isEmpty() ) {\r
456             QString filename2 = base->assignSuffix(filename,"html");\r
457             QFile data(filename2);\r
458             if (data.open(QFile::WriteOnly | QFile::Truncate)) {\r
459                     QTextStream out(&data);\r
460 \r
461                     out.setCodec("UTF-8");\r
462                     QTableWidgetItem * itm;\r
463 \r
464                     out << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">";\r
465                     out << "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"cs\" lang=\"cs\">" << endl;\r
466                     out << "<head>" << endl;\r
467                     out << "<title>" << HTML_TITLE << "</title>" << endl;\r
468 \r
469                     out << "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>" << endl;\r
470                     out << "</head>" << endl;\r
471                     out << "<body style=\"background:" << QString(HTML_BACKGROUND) << "\">" << endl;\r
472 \r
473                     if (include_image)\r
474                         out << "<img src=\"" << QFileInfo(filename).baseName() + "_img/diagram.png\" alt=\"Flowchart Guider\" />" << endl;\r
475 \r
476                     out << "<table border=0>" << endl;\r
477 \r
478                     out << "<tr>";\r
479                     for (int j=0; j<ui->varTab->columnCount(); j++) {\r
480                             itm = ui->varTab->horizontalHeaderItem(j);\r
481                             if (itm!=NULL)\r
482                                     out << "<td style=\"color: " << itm->textColor().name() << "; font-weight: bold; border: 1px "<< QString(HTML_TABLE_BORDER) << " solid;\" >" << itm->text();\r
483                             else\r
484                                     out << "<td>&nbsp;";\r
485                            out << "</td>";\r
486                     }\r
487                     out << "</tr>" << endl;\r
488 \r
489                     for (int i=0; i<ui->varTab->rowCount(); i++) {\r
490                             out << "<tr>";\r
491                             for (int j=0; j<ui->varTab->columnCount(); j++) {\r
492                                     itm = ui->varTab->item(i,j);\r
493                                     if (itm!=NULL)\r
494                                             out << "<td style=\"background: " << itm->backgroundColor().name() << "; color: " << itm->textColor().name() << "; border: 1px "<< QString(HTML_TABLE_BORDER) << " solid;\" >" << itm->text();\r
495                                     else\r
496                                             out << "<td> ";\r
497                                     out << "</td>";\r
498                             }\r
499                             out << "</tr>" << endl;\r
500                     }\r
501                     out << "</table>" << endl;\r
502                     out << "</body>" << endl;\r
503                     out << "</html>" << endl;\r
504                     data.close();\r
505             } else\r
506                     QMessageBox::warning(NULL,ERR,CANT_SAVE,QMessageBox::Cancel,QMessageBox::Cancel);\r
507 \r
508     }\r
509 \r
510 }\r
511 \r
512 void MainForm::exportVarTabAsHTML() {\r
513         exportHTML(QFileDialog::getSaveFileName(this, HTML_SAVE_TITLE,"", HTML_FILTER),false);\r
514 }\r
515 \r
516 void MainForm::toggleFullscreen() { // prenuni rezimu cele obrazovky\r
517         if (windowState()!=Qt::WindowFullScreen)\r
518                 setWindowState(Qt::WindowFullScreen);\r
519         else\r
520                 setWindowState(Qt::WindowNoState);\r
521 }\r
522 \r
523 void MainForm::updateObjectInfo(myItem * v) { // volani­ aktualizace informaci­ o objektu\r
524         if (v!=0) {\r
525 \r
526                 if (v->itemType()==mit_endpoint) ui->otherPan->setEnabled(false);\r
527                 else  {\r
528                     ui->otherPan->setEnabled(true);\r
529                     if (v->itemType()!=mit_condition) {\r
530                           ui->conditionTypeSet->setEnabled(false);\r
531                           ui->aUnsetDestM->setEnabled(v->dest_m()>(-1) && base->scene->selectedItems().count()==1);\r
532                     } else {\r
533                         ui->conditionTypeSet->setEnabled(true);\r
534                         ui->aUnsetDestM->setEnabled(v->dest_m()>(-1) && base->scene->selectedItems().count()==1);\r
535                     }\r
536                     ui->aUnsetDestP->setEnabled(v->itemType()!=mit_endpoint && v->itemType()!=mit_continue_a && v->itemType()!=mit_endpoint && v->itemType()!=mit_text && v->dest_p()>(-1) && base->scene->selectedItems().count()==1);\r
537                     ui->textSet->setEnabled(v->itemType()==mit_command || v->itemType()==mit_condition || v->itemType()==mit_inout || v->itemType()==mit_text);\r
538 \r
539                 }\r
540                 // nastaveni policek\r
541                 ui->xCoord->setValue(v->pos().x()/10);\r
542                 ui->yCoord->setValue(v->pos().y()/10);\r
543                 ui->widthSet->setValue(v->width()/10);\r
544                 ui->heightSet->setValue(v->height()/10);\r
545                 ui->userItemColor1->setColor(v->userItemColor1());\r
546                 ui->userItemColor2->setColor(v->userItemColor2());\r
547                 ui->userBorderColor->setColor(v->userBorderColor());\r
548                 ui->userTextColor->setColor(v->userTextColor());\r
549                 ui->textSet->setText(v->text());\r
550                 ui->conditionTypeSet->setCurrentIndex(v->conditionType());\r
551                 ui->fontSizeSet->setValue(v->fontSize());\r
552                 ui->commentSet->setText(v->comment());\r
553 \r
554         } else {\r
555 \r
556                 ui->otherPan->setEnabled(false);\r
557                 ui->appearancePan->setEnabled(false);\r
558                 ui->geometryPan->setEnabled(false);\r
559 \r
560         }\r
561 \r
562 }\r
563 \r
564 void MainForm::updateDocumentSettings() { // nalneni komponent 'Nastaveni dokumentu' dle aktualniho nastaveni v objektu\r
565         base->lockCallingChange();\r
566 \r
567         ui->backgroundColor->setColor(base->userBackgroundColor());\r
568         ui->lineColor->setColor(base->userLineColor());\r
569         ui->circleColor->setColor(base->circleColor());\r
570         ui->stepTimerDelay->setValue(base->stepInterval());\r
571 \r
572         ui->userActiveItemColor1->setColor(base->activeItemColor1());\r
573         ui->userActiveItemColor2->setColor(base->activeItemColor2());\r
574         ui->userActiveItemBorderColor->setColor(base->activeItemBorderColor());\r
575         ui->userActiveItemTextColor->setColor(base->activeItemTextColor());\r
576 \r
577         ui->userSelectedItemColor1->setColor(base->selectedItemColor1());\r
578         ui->userSelectedItemColor2->setColor(base->selectedItemColor2());\r
579         ui->userSelectedItemBorderColor->setColor(base->selectedItemBorderColor());\r
580         ui->userSelectedItemTextColor->setColor(base->selectedItemTextColor());\r
581 \r
582         ui->defaultUserItemColor1->setColor(base->defaultItemColor1());\r
583         ui->defaultUserItemColor2->setColor(base->defaultItemColor2());\r
584         ui->defaultUserItemBorderColor->setColor(base->defaultItemBorderColor());\r
585         ui->defaultUserItemTextColor->setColor(base->defaultItemTextColor());\r
586         ui->defaultUserItemTextSize->setValue(base->defaultItemTextSize());\r
587 \r
588         ui->canvasWidth->setValue(base->canvasWidth());\r
589         ui->canvasHeight->setValue(base->canvasHeight());\r
590 \r
591         updateWindowTitle();\r
592 \r
593         base->unLockCallingChange();\r
594 }\r
595 \r
596 void MainForm::updateWindowTitle() { // aktualizuje popisek okna\r
597     if (base->filename()!="")\r
598         setWindowTitle(QString(MAINFORM_TITLE) + QString(" - ") + base->filename() + QString(base->changed()? QString(TITLE_CHANGED) : "") );\r
599     else\r
600         setWindowTitle(QString(MAINFORM_TITLE) + QString(TITLE_NOT_SAVED));\r
601 }\r
602 \r
603 void MainForm::updateSelectionList() { // volani aktualizace vybranych objektu\r
604         QString itm;\r
605 \r
606         bool stat = (base->scene->selectedItems().count()>1);\r
607         ui->aArangeToLeft->setEnabled(stat);\r
608         ui->aArangeToRight->setEnabled(stat);\r
609         ui->aArangeToTop->setEnabled(stat);\r
610         ui->aArangeToBottom->setEnabled(stat);\r
611         ui->aArangeToCenterH->setEnabled(stat);\r
612         ui->aArangeToCenterV->setEnabled(stat);\r
613         ui->aSetHeights->setEnabled(stat);\r
614         ui->aSetWidths->setEnabled(stat);\r
615 \r
616         stat = (base->scene->selectedItems().count()>0);\r
617         ui->aDelete->setEnabled(stat);\r
618         ui->aCopy->setEnabled(stat);\r
619         ui->aCut->setEnabled(stat);\r
620         ui->aSelectNone->setEnabled(stat);\r
621 \r
622         ui->aInsert->setEnabled(base->scene->isClipboard());\r
623         ui->appearancePan->setEnabled(base->scene->selectedItems().count()!=0);\r
624 \r
625         stat = false; // zabezpeceni volani aktualizace panelu pouze jednou\r
626         for (int i = 0; i<base->scene->selectedItems().count(); i++) {\r
627 \r
628                 myItem * v = dynamic_cast<myItem*>(base->scene->selectedItems().at(i));\r
629                 if (v!=NULL && !stat) {\r
630                         stat = true;\r
631                         base->scene->lockCallingChange();\r
632                         base->callUpdateObjectInfo(v);\r
633                         base->scene->unLockCallingChange();\r
634                 }\r
635 \r
636         }\r
637 \r
638         stat = (base->scene->selectedItems().count()==1);\r
639         if (!stat) {\r
640             ui->aUnsetDestP->setEnabled((false));\r
641             ui->aUnsetDestM->setEnabled((false));\r
642         }\r
643         ui->geometryPan->setEnabled(stat);\r
644         ui->otherPan->setEnabled(stat);\r
645 }\r
646 \r
647 void MainForm::statusUpdated(const myBaseAction i) { // volani pri zmene stavu\r
648         bool stat = (i==mba_edit && base->scene->selectedItems().count()!=0);\r
649         ui->aDelete->setEnabled(stat);\r
650         ui->aCopy->setEnabled(stat);\r
651         ui->aInsert->setEnabled((i==mba_edit) && (base->scene->isClipboard()));\r
652         ui->aCut->setEnabled(stat);\r
653         ui->aSelectNone->setEnabled(stat);\r
654         ui->aCancelAdding->setEnabled(i==mba_add);\r
655 \r
656         stat = (i==mba_edit);\r
657         ui->aSelectAll->setEnabled(stat);\r
658         ui->aAddStart_2->setEnabled(stat);\r
659         ui->aAddCommand->setEnabled(stat);\r
660         ui->aAddInout->setEnabled(stat);\r
661         ui->aAddCondition->setEnabled(stat);\r
662         ui->aAddContinue->setEnabled(stat);\r
663         ui->aAddEnd->setEnabled(stat);\r
664         ui->aAddText->setEnabled(stat);\r
665         ui->aViewMode->setEnabled(stat);\r
666         ui->aEditMode->setEnabled(!stat);\r
667         ui->documentSettingsPan->setEnabled(stat);\r
668 \r
669         if (i==mba_noEdit) { lastVisible = ui->settingsDock->isVisible(); ui->settingsDock->setVisible(false); } else ui->settingsDock->setVisible(lastVisible);\r
670 \r
671         if (stat) ui->statusbar->showMessage(MODE_EDIT);\r
672         else ui->statusbar->showMessage(MODE_VIEW);\r
673 }\r
674 \r
675 void MainForm::playActionUpdated() {\r
676 \r
677 /*    myPlayAction action = base->playAction();\r
678 \r
679     ui->aStop->setEnabled(action!=mpa_stop);\r
680     ui->aPause->setEnabled(action!=mpa_stop);\r
681     ui->aPlay->setEnabled(action!=mpa_start);\r
682     ui->aNextStep->setEnabled(action!=mpa_start);*/\r
683 \r
684 }\r
685 \r
686 void MainForm::showAbout() { // zobrazeni dialogu 'O programu'\r
687         frmAbout about(this);\r
688         about.exec();\r
689 }\r
690 \r
691 void MainForm::schemeChanged() {\r
692     int index = ui->comboBox->currentIndex();\r
693     if (index >= 0 && index < ui->comboBox->count())\r
694     {\r
695         QStringList colors = ui->comboBox->schemes.at(index).split(COLORSCHEMEBOX_COLOR_SPLITTER);\r
696         base->scene->setUserItemColor1(QColor(colors.at(0)));\r
697         base->scene->setUserItemColor2(QColor(colors.at(1)));\r
698         base->scene->setUserBorderColor(QColor(colors.at(2)));\r
699         base->scene->setUserTextColor(QColor(colors.at(3)));\r
700         updateSelectionList();\r
701     }\r
702 }\r
703 \r
704 void MainForm::editShemes() {\r
705         frmSchemes editor(this);\r
706         editor.exec();\r
707 }\r
708 \r
709 QString MainForm::getSchemes() {\r
710         return ui->comboBox->exportSchemes();\r
711 }\r
712 \r
713 void MainForm::setSchemes(const QString i) {\r
714     ui->comboBox->loadSchemes(i);\r
715 }\r
716 \r
717 void MainForm::on_acsCZ_triggered()\r
718 {\r
719      QApplication::removeTranslator(translator);\r
720 }\r
721 \r
722 void MainForm::on_aenEN_triggered()\r
723 {\r
724     QApplication::removeTranslator(translator);\r
725     translator->load("en_EN", QApplication::applicationDirPath()+"/lang");\r
726     QApplication::installTranslator(translator);\r
727 }\r
728 \r
729 void MainForm::on_aOpenDemo_triggered()\r
730 {\r
731     if (base->changed()) if (!base->continueWithFileOp()) return;\r
732 \r
733     frmDemos demos(this);\r
734     demos.exec();\r
735 }\r
736 \r
737 void MainForm::on_aExportToHTML_triggered(bool checked)\r
738 {\r
739     Q_UNUSED(checked);\r
740 \r
741     QString filename = QFileDialog::getSaveFileName(this, HTML_SAVE_TITLE,"", HTML_FILTER);\r
742     if (!filename.isEmpty()) {\r
743         exportHTML(filename,true);\r
744         QDir dir(QFileInfo(filename).absoluteDir());\r
745         dir.mkdir(QFileInfo(filename).baseName()+"_img");\r
746         dir.cd(QFileInfo(filename).baseName()+"_img");\r
747         base->exportToImage2(QDir::toNativeSeparators(dir.absolutePath()+"/diagram.png"));\r
748     }\r
749 }\r
750 \r
751 void MainForm::on_aAboutQT_triggered()\r
752 {\r
753     qApp->aboutQt();\r
754 }\r
755 \r
756 void MainForm::on_aHelp_triggered()\r
757 {\r
758     if (helpDialog==0)\r
759         helpDialog = new frmHelp(this);\r
760     helpDialog->show();\r
761 }\r