2c29cfc6a699ca424ddd544cd34ccaf97d1be221
[qmemory] / mainwindow.cpp
1 #include "mainwindow.h"
2 #include "ui_mainwindow.h"
3 #include <QMessageBox>
4 #include <QDebug>
5
6 MainWindow::MainWindow(QWidget *parent) :
7     QMainWindow(parent),
8     ui(new Ui::MainWindow)
9 {
10
11     ui->setupUi(this);
12     statusLed = new QLed(ui->verticalLayoutWidget);
13     statusLed->setLayout(ui->horizontalLayout_4);
14     statusLed->setOnColor(QLed::Red);
15     statusLed->setOffColor(QLed::Green);
16     statusLed->setGeometry(QRect(0,0,100,100));
17     setCentralWidget(ui->verticalLayoutWidget);
18     connect(&tread,SIGNAL(generate(int)),this,SLOT(cliccaBottone(int)));
19     connect(&tread,SIGNAL(score(int)),ui->lcdNumber,SLOT(display(int)));
20     connect(&tread,SIGNAL(exit(int)),this,SLOT(sbagliato(int)));
21     connect(&tread,SIGNAL(disableInterface()),this,SLOT(disableAll()));
22     connect(&tread,SIGNAL(enableInterface()),this,SLOT(enableAll()));
23     connect(this,SIGNAL(cliccatoIlBottone(int)),&tread,SLOT(updateCaption(int)));
24     connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(clickA()));
25     connect(ui->pushButton_2,SIGNAL(clicked()),this,SLOT(clickB()));
26     connect(ui->pushButton_3,SIGNAL(clicked()),this,SLOT(clickC()));
27     connect(ui->pushButton_4,SIGNAL(clicked()),this,SLOT(clickD()));
28     connect(ui->pushButton_5,SIGNAL(clicked()),this,SLOT(clickE()));
29     connect(ui->pushButton_6,SIGNAL(clicked()),this,SLOT(clickF()));
30     connect(ui->pushButton_7,SIGNAL(clicked()),this,SLOT(clickG()));
31     connect(ui->pushButton_8,SIGNAL(clicked()),this,SLOT(clickH()));
32     connect(ui->pushButton_9,SIGNAL(clicked()),this,SLOT(clickI()));
33
34     tread.start();
35
36     setStyleSheet("CrazyButton {"
37                  "color: white;"
38                  "background-color: QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #88d, stop: 0.1 #99e, stop: 0.49 #77c, stop: 0.5 #66b, stop: 1 #77c);"
39                  "border-width: 1px;"
40                  "border-color: #339;"
41                  "border-style: solid;"
42                  "border-radius: 7;"
43                  "padding: 3px;"
44                  "font-size: 50px;"
45                  "padding-left: 5px;"
46                  "padding-right: 5px;"
47                  "min-width: 15px;"
48                  "max-width: 300px;"
49                  "min-height: 11px;"
50                  "max-height: 300px;"
51                  "}"
52                  "QPushButton:pressed {"
53                  "padding-top: 15px;"
54                  "}");
55     //showMaximized();
56 }
57 void MainWindow::sbagliato(int score){
58     QString sscore("Score ");
59     sscore.append(QString::number(score));
60     QMessageBox::warning(this, tr("End Game"),sscore,QMessageBox::Escape);
61     //tread.genera();
62     exit(0);
63
64 }
65 void MainWindow::disableAll(){
66     ui->pushButton->setEnabled(false);
67     ui->pushButton_2->setEnabled(false);
68     ui->pushButton_3->setEnabled(false);
69     ui->pushButton_4->setEnabled(false);
70     ui->pushButton_5->setEnabled(false);
71     ui->pushButton_6->setEnabled(false);
72     ui->pushButton_7->setEnabled(false);
73     ui->pushButton_8->setEnabled(false);
74     ui->pushButton_9->setEnabled(false);
75     statusLed->setValue(true);
76 }
77
78 void MainWindow::enableAll(){
79     ui->pushButton->setEnabled(true);
80     ui->pushButton_2->setEnabled(true);
81     ui->pushButton_3->setEnabled(true);
82     ui->pushButton_4->setEnabled(true);
83     ui->pushButton_5->setEnabled(true);
84     ui->pushButton_6->setEnabled(true);
85     ui->pushButton_7->setEnabled(true);
86     ui->pushButton_8->setEnabled(true);
87     ui->pushButton_9->setEnabled(true);
88     statusLed->setValue(false);
89 }
90
91
92 void MainWindow::cliccaBottone(int id)
93 {
94     switch(id){
95         case 0:
96                 ui->pushButton->changeColor();
97                 break;
98         case 1:
99                 ui->pushButton_2->changeColor();
100                 break;
101         case 2:
102                 ui->pushButton_3->changeColor();
103                 break;
104         case 3:
105                 ui->pushButton_4->changeColor();
106                 break;
107         case 4:
108                 ui->pushButton_5->changeColor();
109                 break;
110         case 5:
111                 ui->pushButton_6->changeColor();
112                 break;
113         case 6:
114                 ui->pushButton_7->changeColor();
115                 break;
116         case 7:
117                 ui->pushButton_8->changeColor();
118                 break;
119         case 8:
120                 ui->pushButton_9->changeColor();
121                 break;
122     }
123 }
124
125 MainWindow::~MainWindow()
126 {
127     delete ui;
128 }
129 void MainWindow::clickA(){
130     emit cliccatoIlBottone(0);
131     qDebug()<< "Click 1";
132 }
133
134 void MainWindow::clickB(){
135     emit cliccatoIlBottone(1);
136     qDebug()<< "Click 2";
137 }
138 void MainWindow::clickC(){
139     emit cliccatoIlBottone(2);
140     qDebug()<< "Click 3";
141 }
142 void MainWindow::clickD(){
143     emit cliccatoIlBottone(3);
144     qDebug()<< "Click 4";
145 }
146 void MainWindow::clickE(){
147     emit cliccatoIlBottone(4);
148     qDebug()<< "Click 5";
149 }
150 void MainWindow::clickF(){
151     emit cliccatoIlBottone(5);
152     qDebug()<< "Click 6";
153 }
154 void MainWindow::clickG(){
155     emit cliccatoIlBottone(6);
156     qDebug()<< "Click 7";
157 }
158 void MainWindow::clickH(){
159     emit cliccatoIlBottone(7);
160     qDebug()<< "Click 8";
161 }
162 void MainWindow::clickI(){
163     emit cliccatoIlBottone(8);
164     qDebug()<< "Click 9";
165 }
166
167
168 void MainWindow::changeEvent(QEvent *e)
169 {
170     QMainWindow::changeEvent(e);
171     switch (e->type()) {
172     case QEvent::LanguageChange:
173         ui->retranslateUi(this);
174         break;
175     default:
176         break;
177     }
178 }
179