Added status bar with full file path and graph zoom
[hypercube:hypercube.git] / GUI / gui.cpp
1 #include "GUI/gui.h"
2 #include "GUI/colorcombobox.h"
3 #include "GUI/numericedit.h"
4 #include "GUI/graphtab.h"
5 #include "IO/io.h"
6 #include "CORE/config.h"
7
8
9 /*!
10         \class GUI
11         \brief The application's graphical user interface.
12
13         The GUI class provides the application's graphical user interface.
14 */
15
16
17 #define TAB() ((GraphTab*) _viewTab->currentWidget())
18
19 #define BLOCK(widget, action) \
20         widget->blockSignals(true); \
21         widget->action; \
22         widget->blockSignals(false)
23
24 #define ZOOM_STRING(zoom) QString("%1%").arg((int)((zoom) * 100))
25
26
27 static QString saveFilter(OutputProvider *provider);
28 static QString errorDescription(IO::Error error);
29
30
31 /*!
32         Constructs the application's graphical user interface.
33 */
34 GUI::GUI()
35 {
36         createActions();
37         createMenus();
38         createToolBars();
39         createViews();
40         createProperties();
41         createStatusBar();
42
43         QHBoxLayout *layout = new QHBoxLayout;
44         layout->addWidget(_properties);
45         layout->addWidget(_viewTab);
46
47         QWidget *widget = new QWidget;
48         widget->setLayout(layout);
49         setCentralWidget(widget);
50
51         _masterTab = NULL;
52 }
53
54 void GUI::createActions()
55 {
56         // Action Groups
57         _fileActionGroup = new QActionGroup(this);
58         _fileActionGroup->setExclusive(false);
59         _fileActionGroup->setEnabled(false);
60         _graphActionGroup = new QActionGroup(this);
61         _graphActionGroup->setExclusive(false);
62         _graphActionGroup->setEnabled(false);
63
64
65         // General actions
66         _exitAction = new QAction(tr("Exit"), this);
67         connect(_exitAction, SIGNAL(triggered()), this, SLOT(close()));
68
69         _aboutAction = new QAction(QIcon(QPixmap(APP_ICON)),
70           tr("About Hypercube"), this);
71         connect(_aboutAction, SIGNAL(triggered()), this, SLOT(about()));
72         _aboutQtAction = new QAction(tr("About Qt"), this);
73         connect(_aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
74
75         // File related actions
76         _openFileAction = new QAction(QIcon(QPixmap(OPEN_FILE_ICON)),
77           tr("Open file"), this);
78         connect(_openFileAction, SIGNAL(triggered()), this, SLOT(openFile()));
79         _saveFileAction = new QAction(QIcon(QPixmap(SAVE_FILE_ICON)),
80           tr("Save file"), this);
81         _saveFileAction->setActionGroup(_fileActionGroup);
82         connect(_saveFileAction, SIGNAL(triggered()), this, SLOT(saveFile()));
83         _saveAsAction = new QAction(QIcon(QPixmap(SAVE_AS_ICON)),
84           tr("Save as"), this);
85         _saveAsAction->setActionGroup(_fileActionGroup);
86         connect(_saveAsAction, SIGNAL(triggered()), this, SLOT(saveAs()));
87         _saveAllAction = new QAction(QIcon(QPixmap(SAVE_ALL_ICON)),
88           tr("Save all"), this);
89         _saveAllAction->setActionGroup(_fileActionGroup);
90         connect(_saveAllAction, SIGNAL(triggered()), this, SLOT(saveAll()));
91         _closeFileAction = new QAction(QIcon(QPixmap(CLOSE_FILE_ICON)),
92           tr("Close file"), this);
93         _closeFileAction->setActionGroup(_fileActionGroup);
94         connect(_closeFileAction, SIGNAL(triggered()), this, SLOT(closeFile()));
95
96         // Graph related actions
97         _transformAction = new QAction(QIcon(QPixmap(TRANSFORM_GRAPH_ICON)),
98           tr("Transform graph"), this);
99         _transformAction->setActionGroup(_graphActionGroup);
100         connect(_transformAction, SIGNAL(triggered()), this,
101           SLOT(transformGraph()));
102         _reloadAction = new QAction(QIcon(QPixmap(RELOAD_GRAPH_ICON)),
103           tr("Reload graph"), this);
104         _reloadAction->setActionGroup(_graphActionGroup);
105         connect(_reloadAction, SIGNAL(triggered()), this, SLOT(reloadGraph()));
106         _projectAction = new QAction(QIcon(QPixmap(PROJECT_GRAPH_ICON)),
107           tr("Project this to all graphs"), this);
108         _projectAction->setActionGroup(_graphActionGroup);
109         _projectAction->setCheckable(true);
110         connect(_projectAction, SIGNAL(triggered(bool)), this,
111           SLOT(projectGraph(bool)));
112 }
113
114 void GUI::createMenus()
115 {
116         _fileMenu = menuBar()->addMenu(tr("File"));
117         _fileMenu->addAction(_openFileAction);
118         _fileMenu->addAction(_saveFileAction);
119         _fileMenu->addAction(_saveAsAction);
120         _fileMenu->addAction(_saveAllAction);
121         _fileMenu->addAction(_closeFileAction);
122         _fileMenu->addAction(_exitAction);
123
124         _graphMenu = menuBar()->addMenu(tr("Graph"));
125         _graphMenu->addAction(_transformAction);
126         _graphMenu->addAction(_reloadAction);
127         _graphMenu->addSeparator();
128         _graphMenu->addAction(_projectAction);
129
130         _aboutMenu = menuBar()->addMenu(tr("Help"));
131         _aboutMenu->addAction(_aboutAction);
132         _aboutMenu->addAction(_aboutQtAction);
133 }
134
135 void GUI::createToolBars()
136 {
137         _fileToolBar = addToolBar(tr("File"));
138         _fileToolBar->addAction(_openFileAction);
139         _fileToolBar->addAction(_saveFileAction);
140         _fileToolBar->addAction(_saveAllAction);
141         _fileToolBar->addAction(_closeFileAction);
142
143         _graphToolBar = addToolBar(tr("Graph"));
144         _graphToolBar->addAction(_transformAction);
145         _graphToolBar->addAction(_reloadAction);
146         _graphToolBar->addSeparator();
147         _graphToolBar->addAction(_projectAction);
148 }
149
150 void GUI::createProperties()
151 {
152         createGraphProperties();
153         createSAProperties();
154
155         _properties = new QToolBox;
156
157         _properties->addItem(_graphProperties, tr("Graph settings"));
158         _properties->addItem(_SAProperties, tr("SA settings"));
159
160         _properties->setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Ignored));
161         _properties->setMinimumWidth(qMax(_graphProperties->sizeHint().width(),
162           _SAProperties->sizeHint().width()));
163 }
164
165 void GUI::createSAProperties()
166 {
167         QGroupBox *graphBox = new QGroupBox(tr("Graph layout"));
168
169         _nodeDistribution = new FloatEdit(10);
170         _nodeDistribution->setValue(NODE_DISTRIBUTION);
171         _edgeLength = new FloatEdit(10);
172         _edgeLength->setValue(EDGE_LENGTH);
173         _edgeCrossings = new FloatEdit(10);
174         _edgeCrossings->setValue(EDGE_CROSSINGS);
175
176         connect(_nodeDistribution, SIGNAL(valueChanged(float)),
177           this, SLOT(setNodeDistribution(float)));
178         connect(_edgeLength, SIGNAL(valueChanged(float)),
179           this, SLOT(setEdgeLength(float)));
180         connect(_edgeCrossings, SIGNAL(valueChanged(float)),
181           this, SLOT(setEdgeCrossings(float)));
182
183         QFormLayout *graphLayout = new QFormLayout;
184         graphLayout->addRow(tr("Node distribution:"), _nodeDistribution);
185         graphLayout->addRow(tr("Edge length:"), _edgeLength);
186         graphLayout->addRow(tr("Edge crossings:"), _edgeCrossings);
187         graphBox->setLayout(graphLayout);
188
189
190         QGroupBox *SABox = new QGroupBox(tr("SA parameters"));
191
192         _initTemp = new FloatEdit(10);
193         _initTemp->setValue(INIT_TEMP);
194         _finalTemp = new FloatEdit(10);
195         _finalTemp->setValue(FINAL_TEMP);
196         _coolFactor = new FloatEdit(10);
197         _coolFactor->setValue(COOL_FACTOR);
198         _numSteps = new IntEdit(10);
199         _numSteps->setValue(NUM_STEPS);
200
201         connect(_initTemp, SIGNAL(valueChanged(float)),
202           this, SLOT(setInitTemp(float)));
203         connect(_finalTemp, SIGNAL(valueChanged(float)),
204           this, SLOT(setFinalTemp(float)));
205         connect(_coolFactor, SIGNAL(valueChanged(float)),
206           this, SLOT(setCoolFactor(float)));
207         connect(_numSteps, SIGNAL(valueChanged(int)),
208           this, SLOT(setNumSteps(int)));
209
210         QFormLayout *SAlayout = new QFormLayout;
211         SAlayout->addRow(tr("Initial temperature:"), _initTemp);
212         SAlayout->addRow(tr("Final temperature:"), _finalTemp);
213         SAlayout->addRow(tr("Cooling factor:"), _coolFactor);
214         SAlayout->addRow(tr("Steps:"), _numSteps);
215         SABox->setLayout(SAlayout);
216
217         QGroupBox *debugBox = new QGroupBox(tr("Debug"));
218         _debug = new QCheckBox("Create debug output", this);
219         QVBoxLayout *debugLayout = new QVBoxLayout;
220         debugLayout->addWidget(_debug, 0, Qt::AlignTop);
221         debugBox->setLayout(debugLayout);
222
223         connect(_debug, SIGNAL(stateChanged(int)),
224           this, SLOT(setSALogInfo(int)));
225
226
227         QVBoxLayout *layout = new QVBoxLayout;
228         layout->addWidget(graphBox);
229         layout->addWidget(SABox);
230         layout->addWidget(debugBox);
231
232         _SAProperties = new QWidget;
233         _SAProperties->setLayout(layout);
234 }
235
236 void GUI::createGraphProperties()
237 {
238         // Graph properties control widgets
239         _edgeValues = new QCheckBox(tr("Edge values"), this);
240         _vertexIDs = new QCheckBox(tr("Vertex IDs"), this);
241         _vertexIDs->setCheckState(Qt::Checked);
242
243         connect(_edgeValues, SIGNAL(stateChanged(int)),
244           this, SLOT(showEdgeValues(int)));
245         connect(_vertexIDs, SIGNAL(stateChanged(int)),
246           this, SLOT(showVertexIDs(int)));
247
248         _graphWidth = new QSpinBox();
249         _graphHeight = new QSpinBox();
250         _graphWidth->setMaximum(10000);
251         _graphHeight->setMaximum(10000);
252         _graphWidth->setValue(GRAPH_WIDTH);
253         _graphHeight->setValue(GRAPH_HEIGHT);
254
255         connect(_graphWidth, SIGNAL(valueChanged(int)),
256           this, SLOT(setGraphWidth(int)));
257         connect(_graphHeight, SIGNAL(valueChanged(int)),
258           this, SLOT(setGraphHeight(int)));
259
260         // Graph properties box layout
261         QGroupBox *propertiesBox = new QGroupBox(tr("Graph properties"));
262
263         QFormLayout *dimensions = new QFormLayout;
264         dimensions->addRow(tr("Width:"), _graphWidth);
265         dimensions->addRow(tr("Height:"), _graphHeight);
266
267         QLabel *dimensionsLabel = new QLabel(QString("<i>") + tr("Graph size")
268           + QString("</i>"));
269         QLabel *elementsLabel = new QLabel(QString("<i>") + tr("Display")
270           + QString("</i>"));
271
272         QVBoxLayout *propertiesLayout = new QVBoxLayout;
273         propertiesLayout->addWidget(dimensionsLabel);
274         propertiesLayout->addLayout(dimensions);
275         propertiesLayout->addWidget(elementsLabel);
276         propertiesLayout->addWidget(_vertexIDs);
277         propertiesLayout->addWidget(_edgeValues);
278         propertiesLayout->addStretch(1);
279         propertiesBox->setLayout(propertiesLayout);
280
281
282         // Appearance control widgets
283         _vertexSize = new QSpinBox();
284         _edgeSize = new QSpinBox();
285         _edgeFontSize = new QSpinBox();
286         _vertexFontSize = new QSpinBox();
287         _edgeColor = new ColorComboBox();
288         _vertexColor = new ColorComboBox();
289
290         _vertexSize->setValue(VERTEX_SIZE);
291         _edgeSize->setValue(EDGE_SIZE);
292         _edgeSize->setMaximum(_vertexSize->value());
293         _edgeFontSize->setValue(EDGE_FONT_SIZE);
294         _edgeFontSize->setMinimum(MIN_FONT_SIZE);
295         _vertexFontSize->setValue(VERTEX_FONT_SIZE);
296         _vertexFontSize->setMinimum(MIN_FONT_SIZE);
297         _edgeColor->setColor(QColor(EDGE_COLOR));
298         _vertexColor->setColor(QColor(VERTEX_COLOR));
299
300         connect(_edgeSize, SIGNAL(valueChanged(int)),
301           this, SLOT(setEdgeSize(int)));
302         connect(_vertexSize, SIGNAL(valueChanged(int)),
303           this, SLOT(setVertexSize(int)));
304         connect(_edgeFontSize, SIGNAL(valueChanged(int)),
305           this, SLOT(setEdgeFontSize(int)));
306         connect(_vertexFontSize, SIGNAL(valueChanged(int)),
307           this, SLOT(setVertexFontSize(int)));
308
309         connect(_edgeColor, SIGNAL(activated(const QColor&)),
310           this, SLOT(setEdgeColor(const QColor&)));
311         connect(_vertexColor, SIGNAL(activated(const QColor&)),
312           this, SLOT(setVertexColor(const QColor&)));
313
314
315         // Appearance box layout
316         QGroupBox *appearanceBox = new QGroupBox(tr("Graph appearance"));
317
318         QFormLayout *edge = new QFormLayout;
319         QFormLayout *vertex = new QFormLayout;
320
321         edge->addRow(tr("Size:"), _edgeSize);
322         edge->addRow(tr("Font size:"), _edgeFontSize);
323         edge->addRow(tr("Color:"), _edgeColor);
324
325         vertex->addRow(tr("Size:"), _vertexSize);
326         vertex->addRow(tr("Font size:"), _vertexFontSize);
327         vertex->addRow(tr("Color:"), _vertexColor);
328
329         QLabel *edgeLabel = new QLabel(QString("<i>") + tr("Edges")
330           + QString("</i>"));
331         QLabel *vertexLabel = new QLabel(QString("<i>") + tr("Vertexes")
332           + QString("</i>"));
333
334         QVBoxLayout *appearanceLayout = new QVBoxLayout();
335         appearanceLayout->addWidget(vertexLabel);
336         appearanceLayout->addLayout(vertex);
337         appearanceLayout->addWidget(edgeLabel);
338         appearanceLayout->addLayout(edge);
339         appearanceLayout->addStretch(1);
340         appearanceBox->setLayout(appearanceLayout);
341
342
343         // Graph settings tab layout
344         QVBoxLayout *layout = new QVBoxLayout;
345
346         layout->addWidget(propertiesBox);
347         layout->addWidget(appearanceBox);
348
349         _graphProperties = new QWidget;
350         _graphProperties->setLayout(layout);
351 }
352
353 void GUI::createViews()
354 {
355         _viewTab = new QTabWidget;
356
357         connect(_viewTab, SIGNAL(currentChanged(int)),
358           this, SLOT(tabChanged(int)));
359 }
360
361 void GUI::createStatusBar()
362 {
363         _fileName = new QLabel();
364         _zoom = new QLabel();
365         _zoom->setAlignment(Qt::AlignHCenter);
366
367         statusBar()->addPermanentWidget(_fileName, 9);
368         statusBar()->addPermanentWidget(_zoom, 1);
369         statusBar()->setSizeGripEnabled(false);
370 }
371
372 void GUI::tabChanged(int current)
373 {
374         if (current == -1) {
375                 _fileName->setText(QString::null);
376                 _zoom->setText(QString::null);
377                 return;
378         }
379
380         GraphTab *tab = (GraphTab*) _viewTab->widget(current);
381
382         getSAProperties(tab);
383         getGraphProperties(tab);
384
385         if (_masterTab && tab != _masterTab)
386                 tab->project(_masterTab->graph());
387
388         _graphActionGroup->setEnabled(tab->enabled());
389         _graphProperties->setEnabled(tab->enabled());
390
391         _zoom->setText(ZOOM_STRING(tab->view()->zoom()));
392         _fileName->setText(tab->fileName());
393 }
394
395 void GUI::about()
396 {
397         QMessageBox::about(this, tr("About Hypercube"),
398           QString("<h3>") + QString("Hypercube ") + QString(APP_VERSION)
399           + QString("</h3><p>") + tr("Graph visualizing tool") + QString("<p/>")
400           + QString("<p>") + tr("Hypercube is distributed under the terms of the "
401                 "GNU General Public License version 3. For more info about Hypercube "
402                 "visit the project homepage at")
403           + QString(" <a href=\""APP_HOMEPAGE"\">"APP_HOMEPAGE"</a>.</p>"));
404 }
405
406 void GUI::openFile()
407 {
408         QString fileName = QFileDialog::getOpenFileName(this);
409         if (fileName.isEmpty())
410                 return;
411
412         GraphTab *tab = new GraphTab();
413
414         setSAProperties(tab);
415         setGraphProperties(tab);
416         IO::Error error = tab->readGraph(fileName);
417
418         if (error) {
419                 QMessageBox::critical(this, tr("Error"), tr("Error loading graph")
420                   + QString(":\n") + errorDescription(error));
421                 delete tab;
422         } else {
423                 if (_masterTab)
424                         tab->setEnabled(false);
425
426                 QFileInfo fi(fileName);
427                 int index = _viewTab->addTab(tab, fi.fileName());
428
429                 connect(tab->view(), SIGNAL(zoomed(qreal)), SLOT(zoom(qreal)));
430
431                 _viewTab->setCurrentIndex(index);
432
433                 if (_viewTab->count() == 1) {
434                         _fileActionGroup->setEnabled(true);
435                         _graphActionGroup->setEnabled(true);
436                 }
437         }
438 }
439
440 void GUI::saveFile()
441 {
442         if (TAB()->writeGraph() != IO::Ok)
443                 emit saveAs();
444 }
445
446 void GUI::saveAs()
447 {
448         QString filter,  selectedFilter;
449         OutputProvider **provider = outputProviders;
450
451         while (*provider) {
452                 filter += saveFilter(*provider);
453                 provider++;
454                 if (*provider)
455                         filter += QString(";;");
456         }
457
458         QString fileName = QFileDialog::getSaveFileName(this,
459           QString::null, QString::null, filter, &selectedFilter);
460         if (!fileName.isEmpty()) {
461                 provider = outputProviders;
462                 while (*provider) {
463                         if (selectedFilter == saveFilter(*provider))
464                                 break;
465                         provider++;
466                 }
467
468                 QString suffix = QString('.') + QString((*provider)->type());
469                 if (!fileName.endsWith(suffix))
470                         fileName.append(suffix);
471
472                 IO::Error error = TAB()->writeGraph(fileName, *provider);
473                 if (error)
474                         QMessageBox::critical(this, tr("Error"),
475                           tr("Error saving graph") + QString(":\n")
476                           + errorDescription(error));
477         }
478
479 }
480
481 void GUI::saveAll()
482 {
483         int index = _viewTab->currentIndex();
484
485         for (int i = 0; i < _viewTab->count(); i++) {
486                 _viewTab->setCurrentIndex(i);
487                 saveFile();
488         }
489
490         _viewTab->setCurrentIndex(index);
491 }
492
493 void GUI::closeFile()
494 {
495         GraphTab* tab = TAB();
496
497         if (tab == _masterTab) {
498                 for (int i = 0; i < _viewTab->count(); i++)
499                         ((GraphTab*) _viewTab->widget(i))->setEnabled(true);
500
501                 _masterTab = NULL;
502                 _projectAction->setChecked(false);
503         }
504
505         _viewTab->removeTab(_viewTab->indexOf(tab));
506         delete tab;
507
508         if (_viewTab->count() == 0) {
509                 _fileActionGroup->setEnabled(false);
510                 _graphActionGroup->setEnabled(false);
511         }
512 }
513
514 void GUI::transformGraph()
515 {
516         TAB()->transformGraph();
517 }
518
519 void GUI::reloadGraph()
520 {
521         IO::Error error = TAB()->readGraph();
522         if (error) {
523                 QMessageBox::critical(this, tr("Error"),
524                   tr("Error loading graph") + QString(":\n")
525                   + errorDescription(error));
526                 closeFile();
527         }
528 }
529
530 void GUI::projectGraph(bool checked)
531 {
532         GraphTab* tab;
533
534         for (int i = 0; i < _viewTab->count(); i++) {
535                 if (_viewTab->currentIndex() == i)
536                         continue;
537                 tab = ((GraphTab*) _viewTab->widget(i));
538
539                 if (checked) {
540                         tab->project(TAB()->graph());
541                         tab->setEnabled(false);
542                 } else {
543                         tab->setEdgeColor(tab->edgeColor());
544                         tab->setEdgeSize(tab->edgeSize());
545                         tab->setEdgeFontSize(tab->edgeFontSize());
546                         tab->setEdgeZValue(-1);
547                         tab->setEnabled(true);
548                 }
549         }
550
551         _masterTab = (checked) ? TAB() : NULL;
552 }
553
554
555 void GUI::setNodeDistribution(float value)
556 {
557         if (TAB())
558                 TAB()->setNodeDistribution(value);
559 }
560
561 void GUI::setEdgeLength(float value)
562 {
563         if (TAB())
564                 TAB()->setEdgeLength(value);
565 }
566
567 void GUI::setEdgeCrossings(float value)
568 {
569         if (TAB())
570                 TAB()->setEdgeCrossings(value);
571 }
572
573 void GUI::setInitTemp(float value)
574 {
575         if (TAB())
576                 TAB()->setInitTemp(value);
577 }
578
579 void GUI::setFinalTemp(float value)
580 {
581         if (TAB())
582                 TAB()->setFinalTemp(value);
583 }
584
585 void GUI::setCoolFactor(float value)
586 {
587         if (TAB())
588                 TAB()->setCoolFactor(value);
589 }
590
591 void GUI::setNumSteps(int value)
592 {
593         if (TAB())
594                 TAB()->setNumSteps(value);
595 }
596
597 void GUI::setSALogInfo(int state)
598 {
599         if (TAB())
600                 TAB()->setLogInfo((state == Qt::Checked) ? true : false);
601 }
602
603
604 void GUI::setGraphWidth(int width)
605 {
606         if (TAB())
607                 TAB()->setDimensions(QPoint(width, TAB()->dimensions().y()));
608 }
609
610 void GUI::setGraphHeight(int height)
611 {
612         if (TAB())
613                 TAB()->setDimensions(QPoint(TAB()->dimensions().x(), height));
614 }
615
616 void GUI::setVertexColor(const QColor &color)
617 {
618         if (TAB())
619                 TAB()->setVertexColor(color);
620 }
621
622 void GUI::setEdgeColor(const QColor &color)
623 {
624         if (TAB())
625                 TAB()->setEdgeColor(color);
626 }
627
628 void GUI::setVertexSize(int size)
629 {
630         if (TAB())
631                 TAB()->setVertexSize(size);
632         _edgeSize->setMaximum(size);
633 }
634
635 void GUI::setEdgeSize(int size)
636 {
637         if (TAB())
638                 TAB()->setEdgeSize(size);
639 }
640
641 void GUI::setEdgeFontSize(int size)
642 {
643         if (TAB())
644                 TAB()->setEdgeFontSize(size);
645 }
646
647 void GUI::setVertexFontSize(int size)
648 {
649         if (TAB())
650                 TAB()->setVertexFontSize(size);
651 }
652
653 void GUI::showEdgeValues(int state)
654 {
655         if (TAB())
656                 TAB()->showEdgeValues((state == Qt::Checked) ? true : false);
657 }
658
659 void GUI::showVertexIDs(int state)
660 {
661         if (TAB())
662                 TAB()->showVertexIDs((state == Qt::Checked) ? true : false);
663 }
664
665 void GUI::setSAProperties(GraphTab *tab)
666 {
667         tab->setNodeDistribution(_nodeDistribution->value());
668         tab->setEdgeLength(_edgeLength->value());
669         tab->setEdgeCrossings(_edgeCrossings->value());
670         tab->setInitTemp(_initTemp->value());
671         tab->setFinalTemp(_finalTemp->value());
672         tab->setCoolFactor(_coolFactor->value());
673         tab->setNumSteps(_numSteps->value());
674         tab->setLogInfo((_debug->checkState() == Qt::Checked) ? true : false);
675 }
676
677 void GUI::setGraphProperties(GraphTab *tab)
678 {
679         tab->setDimensions(QPoint(_graphWidth->value(), _graphHeight->value()));
680         tab->setEdgeSize(_edgeSize->value());
681         tab->setVertexSize(_vertexSize->value());
682         tab->setEdgeColor(_edgeColor->color());
683         tab->setVertexColor(_vertexColor->color());
684         tab->setVertexFontSize(_vertexFontSize->value());
685         tab->setEdgeFontSize(_edgeFontSize->value());
686         tab->showVertexIDs((_vertexIDs->checkState() == Qt::Checked)
687           ? true : false);
688         tab->showEdgeValues((_edgeValues->checkState() == Qt::Checked)
689           ? true : false);
690 }
691
692 void GUI::getSAProperties(GraphTab *tab)
693 {
694         _nodeDistribution->setValue(tab->nodeDistribution());
695         _edgeLength->setValue(tab->edgeLength());
696         _edgeCrossings->setValue(tab->edgeCrossings());
697         _initTemp->setValue(tab->initTemp());
698         _finalTemp->setValue(tab->finalTemp());
699         _coolFactor->setValue(tab->coolFactor());
700         _numSteps->setValue(tab->numSteps());
701         BLOCK(_debug, setChecked(tab->logInfo()));
702 }
703
704 void GUI::getGraphProperties(GraphTab *tab)
705 {
706         BLOCK(_graphWidth, setValue(tab->dimensions().x()));
707         BLOCK(_graphHeight, setValue(tab->dimensions().y()));
708         BLOCK(_edgeSize, setValue(tab->edgeSize()));
709         _edgeSize->setMaximum(tab->vertexSize());
710         BLOCK(_vertexSize, setValue(tab->vertexSize()));
711         BLOCK(_edgeColor, setColor(tab->edgeColor()));
712         BLOCK(_vertexColor, setColor(tab->vertexColor()));
713         BLOCK(_vertexFontSize, setValue(tab->vertexFontSize()));
714         BLOCK(_edgeFontSize, setValue(tab->edgeFontSize()));
715         BLOCK(_vertexIDs, setChecked(tab->vertexIDs()));
716         BLOCK(_edgeValues, setChecked(tab->edgeValues()));
717 }
718
719 void GUI::zoom(qreal zoom)
720 {
721         _zoom->setText(ZOOM_STRING(zoom));
722 }
723
724
725 QString saveFilter(OutputProvider *provider)
726 {
727         return QString(provider->description()) + QString(" (*.")
728           + QString(provider->type()) + QString(")");
729 }
730
731 QString errorDescription(IO::Error error)
732 {
733         switch(error) {
734                 case IO::OpenError:
735                         return  QObject::tr("Error opening file");
736                 case IO::ReadError:
737                         return QObject::tr("Error reading file");
738                 case IO::WriteError:
739                         return QObject::tr("Error writing file");
740                 case IO::FormatError:
741                         return QObject::tr("File format error");
742                 default:
743                         return QObject::tr("Unknown error");
744         }
745 }