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