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