1
1
#include " algorithmwidget.h"
2
2
#include " ui_algorithmwidget.h"
3
3
4
- AlgorithmWidget::AlgorithmWidget (QWidget *parent) :
5
- QWidget(parent),
4
+ AlgorithmWidget::AlgorithmWidget (Algorithm::modes _mode, QWidget *parent) :
5
+ QWidget(parent), mode(_mode),
6
6
ui(new Ui::AlgorithmWidget)
7
7
{
8
8
ui->setupUi (this );
9
+
10
+ showSolution = false ;
11
+
9
12
connect (this ->ui ->nextButton ,SIGNAL (clicked ()),this ,SIGNAL (nextPressed ()));
10
13
connect (this ->ui ->prewButton ,SIGNAL (clicked ()),this ,SIGNAL (prewPressed ()));
11
14
connect (this ->ui ->playButton ,SIGNAL (clicked ()),this ,SLOT (emitPlay ()));
12
15
connect (this ->ui ->stopButton ,SIGNAL (clicked ()),this ,SIGNAL (stopPressed ()));
16
+ connect (this ->ui ->checkButton ,SIGNAL (clicked ()),this ,SIGNAL (checkSolutionPressed ()));
17
+ setWidgets (mode);
13
18
}
14
19
15
20
AlgorithmWidget::~AlgorithmWidget ()
@@ -22,7 +27,78 @@ AlgorithmView *AlgorithmWidget::getAlgorithmView()
22
27
return ui->treeView ;
23
28
}
24
29
30
+
31
+
32
+ void AlgorithmWidget::hideWidgets (QList<QWidget *> widgets)
33
+ {
34
+ foreach (QWidget* w,widgets)
35
+ w->hide ();
36
+ }
37
+
38
+ void AlgorithmWidget::showWidgets (QList<QWidget *> widgets)
39
+ {
40
+ foreach (QWidget* w,widgets)
41
+ w->show ();
42
+ }
43
+
44
+ void AlgorithmWidget::setWidgets (Algorithm::modes mode)
45
+ {
46
+ switch (mode) {
47
+ case Algorithm::CHECK_MODE:
48
+ showWidgets (QList<QWidget*>() << ui->checkButton << ui->showButton );
49
+ showSpacer (ui->checkSpacer );
50
+ hideWidgets (QList<QWidget*>()
51
+ << ui->prewButton << ui->nextButton << ui->playButton << ui->stopButton << ui->spinBox << ui->delay_label
52
+ << ui->prew_stepButton << ui->next_stepButton );
53
+ hideSpacer (ui->stepSpacer );
54
+ break ;
55
+ case Algorithm::PLAY_MODE:
56
+ showWidgets (QList<QWidget*>() << ui->prewButton << ui->nextButton << ui->playButton << ui->stopButton << ui->spinBox << ui->delay_label );
57
+ hideWidgets (QList<QWidget*>()
58
+ << ui->checkButton << ui->showButton
59
+ << ui->prew_stepButton << ui->next_stepButton );
60
+ hideSpacer (ui->stepSpacer );
61
+ hideSpacer (ui->checkSpacer );
62
+ break ;
63
+ case Algorithm::STEP_MODE:
64
+ showWidgets (QList<QWidget*>()<< ui->prew_stepButton << ui->next_stepButton );
65
+ hideWidgets (QList<QWidget*>()
66
+ << ui->checkButton << ui->showButton
67
+ << ui->prewButton << ui->nextButton << ui->playButton << ui->stopButton << ui->spinBox << ui->delay_label );
68
+ showSpacer (ui->stepSpacer );
69
+ hideSpacer (ui->checkSpacer );
70
+ break ;
71
+ default :
72
+ break ;
73
+ }
74
+ }
75
+
76
+ void AlgorithmWidget::hideSpacer (QSpacerItem *s)
77
+ {
78
+ s->changeSize (0 ,0 , QSizePolicy::Fixed, QSizePolicy::Fixed);
79
+ }
80
+
81
+ void AlgorithmWidget::showSpacer (QSpacerItem *s)
82
+ {
83
+ s->changeSize (1 ,1 , QSizePolicy::Expanding, QSizePolicy::Fixed);
84
+ }
85
+
25
86
void AlgorithmWidget::emitPlay ()
26
87
{
27
88
emit playPressed (this ->ui ->spinBox ->value ());
28
89
}
90
+
91
+ void AlgorithmWidget::on_showButton_clicked ()
92
+ {
93
+ showSolution=!showSolution;
94
+ if (showSolution)
95
+ {
96
+ ui->showButton ->setText (" Show solution." );
97
+ emit showCorrectSolutionPressed ();
98
+ }
99
+ else
100
+ {
101
+ ui->showButton ->setText (" Back." );
102
+ emit showUserSolutionPressed ();
103
+ }
104
+ }
0 commit comments