--- /dev/null
+# -------------------------------------------------
+# Project created by QtCreator 2010-02-18T12:16:41
+# -------------------------------------------------
+TARGET = Memory
+TEMPLATE = app
+SOURCES += main.cpp \
+ mainwindow.cpp \
+ crazybutton.cpp \
+ testThread.cpp
+HEADERS += mainwindow.h \
+ crazybutton.h \
+ testThread.h
+FORMS += mainwindow.ui
--- /dev/null
+#include "crazybutton.h"
+#include <QDebug>
+
+CrazyButton::CrazyButton(QWidget *p): QPushButton(p)
+{
+
+ //this->setStyleSheet("background-color:white;");
+ col=true;
+
+}
+void CrazyButton::changeColor(){
+ QPalette palettea;
+ if(col){
+
+ this->setStyleSheet("background-color:green;");
+ col=false;
+ }
+ else{
+ this->setStyleSheet("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);");
+ col=true;
+ }
+ this->setPalette(palettea);
+}
+void CrazyButton::mousePressEvent(QMouseEvent *e)
+{
+ //this->setStyleSheet("background-color:green;");
+ QPushButton::mousePressEvent(e);
+
+}
+void CrazyButton::mouseReleaseEvent(QMouseEvent *e)
+{
+ //this->setStyleSheet("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);");
+ QPushButton::mouseReleaseEvent(e);
+}
+/*
+void CrazyButton::focusInEvent(QFocusEvent *)
+{}
+void CrazyButton::focusOutEvent(QFocusEvent *)
+{}
+*/
--- /dev/null
+#ifndef CRAZYBUTTON_H
+#define CRAZYBUTTON_H
+
+#include <QPushButton>
+#include <QMouseEvent>
+
+
+class CrazyButton : public QPushButton
+{
+ Q_OBJECT
+public:
+ CrazyButton(QWidget *parent=0);
+
+public slots:
+ void changeColor();
+protected:
+ void mousePressEvent(QMouseEvent *e);
+ void mouseReleaseEvent(QMouseEvent *e);
+ /*
+ void focusInEvent(QFocusEvent *);
+ void focusOutEvent(QFocusEvent *);
+ */
+private:
+ bool col;
+
+};
+
+#endif // CRAZYBUTTON_H
--- /dev/null
+#include <QtGui/QApplication>
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+ MainWindow w;
+ w.show();
+ return a.exec();
+}
--- /dev/null
+#include "mainwindow.h"
+#include "ui_mainwindow.h"
+#include <QMessageBox>
+#include <QDebug>
+
+MainWindow::MainWindow(QWidget *parent) :
+ QMainWindow(parent),
+ ui(new Ui::MainWindow)
+{
+
+ ui->setupUi(this);
+ connect(&tread,SIGNAL(generate(int)),this,SLOT(cliccaBottone(int)));
+ connect(&tread,SIGNAL(score(int)),this,SLOT(sbagliato(int)));
+ connect(&tread,SIGNAL(disableInterface()),this,SLOT(disableAll()));
+ connect(&tread,SIGNAL(enableInterface()),this,SLOT(enableAll()));
+ connect(this,SIGNAL(cliccatoIlBottone(int)),&tread,SLOT(updateCaption(int)));
+ connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(clickA()));
+ connect(ui->pushButton_2,SIGNAL(clicked()),this,SLOT(clickB()));
+ connect(ui->pushButton_3,SIGNAL(clicked()),this,SLOT(clickC()));
+ connect(ui->pushButton_4,SIGNAL(clicked()),this,SLOT(clickD()));
+ connect(ui->pushButton_5,SIGNAL(clicked()),this,SLOT(clickE()));
+ connect(ui->pushButton_6,SIGNAL(clicked()),this,SLOT(clickF()));
+ connect(ui->pushButton_7,SIGNAL(clicked()),this,SLOT(clickG()));
+ connect(ui->pushButton_8,SIGNAL(clicked()),this,SLOT(clickH()));
+ connect(ui->pushButton_9,SIGNAL(clicked()),this,SLOT(clickI()));
+
+ tread.start();
+
+ setStyleSheet("QPushButton {"
+ "color: white;"
+ "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);"
+ "border-width: 1px;"
+ "border-color: #339;"
+ "border-style: solid;"
+ "border-radius: 7;"
+ "padding: 3px;"
+ "font-size: 50px;"
+ "padding-left: 5px;"
+ "padding-right: 5px;"
+ "min-width: 150px;"
+ "max-width: 150px;"
+ "min-height: 113px;"
+ "max-height: 113px;"
+ "}"
+ "QPushButton:pressed {"
+ "padding-top: 15px;"
+ "}");
+ //showMaximized();
+}
+void MainWindow::sbagliato(int score){
+ QString sscore("Score:");
+ sscore.append(QString::number(score));
+
+
+ QMessageBox::warning(this, tr("Sbagliato"),sscore,QMessageBox::Escape);
+ tread.genera();
+}
+void MainWindow::disableAll(){
+ ui->pushButton->setEnabled(false);
+ ui->pushButton_2->setEnabled(false);
+ ui->pushButton_3->setEnabled(false);
+ ui->pushButton_4->setEnabled(false);
+ ui->pushButton_5->setEnabled(false);
+ ui->pushButton_6->setEnabled(false);
+ ui->pushButton_7->setEnabled(false);
+ ui->pushButton_8->setEnabled(false);
+ ui->pushButton_9->setEnabled(false);
+}
+
+void MainWindow::enableAll(){
+ ui->pushButton->setEnabled(true);
+ ui->pushButton_2->setEnabled(true);
+ ui->pushButton_3->setEnabled(true);
+ ui->pushButton_4->setEnabled(true);
+ ui->pushButton_5->setEnabled(true);
+ ui->pushButton_6->setEnabled(true);
+ ui->pushButton_7->setEnabled(true);
+ ui->pushButton_8->setEnabled(true);
+ ui->pushButton_9->setEnabled(true);
+}
+
+
+void MainWindow::cliccaBottone(int id)
+{
+ switch(id){
+ case 0:
+ ui->pushButton->changeColor();
+ break;
+ case 1:
+ ui->pushButton_2->changeColor();
+ break;
+ case 2:
+ ui->pushButton_3->changeColor();
+ break;
+ case 3:
+ ui->pushButton_4->changeColor();
+ break;
+ case 4:
+ ui->pushButton_5->changeColor();
+ break;
+ case 5:
+ ui->pushButton_6->changeColor();
+ break;
+ case 6:
+ ui->pushButton_7->changeColor();
+ break;
+ case 7:
+ ui->pushButton_8->changeColor();
+ break;
+ case 8:
+ ui->pushButton_9->changeColor();
+ break;
+ }
+}
+
+MainWindow::~MainWindow()
+{
+ delete ui;
+}
+void MainWindow::clickA(){
+ emit cliccatoIlBottone(0);
+ qDebug()<< "Click 1";
+}
+
+void MainWindow::clickB(){
+ emit cliccatoIlBottone(1);
+ qDebug()<< "Click 2";
+}
+void MainWindow::clickC(){
+ emit cliccatoIlBottone(2);
+ qDebug()<< "Click 3";
+}
+void MainWindow::clickD(){
+ emit cliccatoIlBottone(3);
+ qDebug()<< "Click 4";
+}
+void MainWindow::clickE(){
+ emit cliccatoIlBottone(4);
+ qDebug()<< "Click 5";
+}
+void MainWindow::clickF(){
+ emit cliccatoIlBottone(5);
+ qDebug()<< "Click 6";
+}
+void MainWindow::clickG(){
+ emit cliccatoIlBottone(6);
+ qDebug()<< "Click 7";
+}
+void MainWindow::clickH(){
+ emit cliccatoIlBottone(7);
+ qDebug()<< "Click 8";
+}
+void MainWindow::clickI(){
+ emit cliccatoIlBottone(8);
+ qDebug()<< "Click 9";
+}
+
+
+void MainWindow::changeEvent(QEvent *e)
+{
+ QMainWindow::changeEvent(e);
+ switch (e->type()) {
+ case QEvent::LanguageChange:
+ ui->retranslateUi(this);
+ break;
+ default:
+ break;
+ }
+}
+
--- /dev/null
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+#include "testThread.h"
+
+namespace Ui {
+ class MainWindow;
+}
+
+class MainWindow : public QMainWindow {
+ Q_OBJECT
+public:
+ MainWindow(QWidget *parent = 0);
+ ~MainWindow();
+public slots:
+ void cliccaBottone(int id);
+ void clickA();
+ void clickB();
+ void clickC();
+ void clickD();
+ void clickE();
+ void clickF();
+ void clickG();
+ void clickH();
+ void clickI();
+ void sbagliato(int);
+ void disableAll();
+ void enableAll();
+
+
+signals:
+ void cliccatoIlBottone(int button);
+protected:
+ void changeEvent(QEvent *e);
+
+ Ui::MainWindow *ui;
+ QList<bool> sequenza;
+ TestThread tread;
+};
+
+#endif // MAINWINDOW_H
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>800</width>
+ <height>480</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>MainWindow</string>
+ </property>
+ <property name="autoFillBackground">
+ <bool>true</bool>
+ </property>
+ <widget class="QWidget" name="centralWidget">
+ <widget class="CrazyButton" name="pushButton_2">
+ <property name="geometry">
+ <rect>
+ <x>330</x>
+ <y>40</y>
+ <width>100</width>
+ <height>100</height>
+ </rect>
+ </property>
+ <property name="maximumSize">
+ <size>
+ <width>16777215</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>2</string>
+ </property>
+ </widget>
+ <widget class="CrazyButton" name="pushButton_3">
+ <property name="geometry">
+ <rect>
+ <x>510</x>
+ <y>40</y>
+ <width>100</width>
+ <height>100</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>3</string>
+ </property>
+ </widget>
+ <widget class="CrazyButton" name="pushButton_4">
+ <property name="geometry">
+ <rect>
+ <x>150</x>
+ <y>180</y>
+ <width>100</width>
+ <height>100</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>4</string>
+ </property>
+ </widget>
+ <widget class="CrazyButton" name="pushButton_5">
+ <property name="geometry">
+ <rect>
+ <x>330</x>
+ <y>180</y>
+ <width>100</width>
+ <height>100</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>5</string>
+ </property>
+ </widget>
+ <widget class="CrazyButton" name="pushButton_6">
+ <property name="geometry">
+ <rect>
+ <x>510</x>
+ <y>180</y>
+ <width>100</width>
+ <height>100</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>6</string>
+ </property>
+ </widget>
+ <widget class="CrazyButton" name="pushButton_7">
+ <property name="geometry">
+ <rect>
+ <x>150</x>
+ <y>320</y>
+ <width>100</width>
+ <height>100</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>7</string>
+ </property>
+ </widget>
+ <widget class="CrazyButton" name="pushButton_8">
+ <property name="geometry">
+ <rect>
+ <x>330</x>
+ <y>320</y>
+ <width>100</width>
+ <height>100</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>8</string>
+ </property>
+ </widget>
+ <widget class="CrazyButton" name="pushButton_9">
+ <property name="geometry">
+ <rect>
+ <x>510</x>
+ <y>320</y>
+ <width>100</width>
+ <height>100</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>9</string>
+ </property>
+ </widget>
+ <widget class="CrazyButton" name="pushButton">
+ <property name="geometry">
+ <rect>
+ <x>150</x>
+ <y>40</y>
+ <width>101</width>
+ <height>100</height>
+ </rect>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>0</width>
+ <height>100</height>
+ </size>
+ </property>
+ <property name="toolTip">
+ <string notr="true"/>
+ </property>
+ <property name="text">
+ <string>1</string>
+ </property>
+ </widget>
+ </widget>
+ </widget>
+ <layoutdefault spacing="6" margin="11"/>
+ <customwidgets>
+ <customwidget>
+ <class>CrazyButton</class>
+ <extends>QPushButton</extends>
+ <header>crazybutton.h</header>
+ <slots>
+ <slot>changeColor(bool)</slot>
+ </slots>
+ </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+ <slots>
+ <signal>generate(bool)</signal>
+ </slots>
+</ui>
--- /dev/null
+/****************************************************************************
+** Meta object code from reading C++ file 'crazybutton.h'
+**
+** Created: Fri Feb 26 16:31:33 2010
+** by: The Qt Meta Object Compiler version 62 (Qt 4.6.1)
+**
+** WARNING! All changes made in this file will be lost!
+*****************************************************************************/
+
+#include "crazybutton.h"
+#if !defined(Q_MOC_OUTPUT_REVISION)
+#error "The header file 'crazybutton.h' doesn't include <QObject>."
+#elif Q_MOC_OUTPUT_REVISION != 62
+#error "This file was generated using the moc from 4.6.1. It"
+#error "cannot be used with the include files from this version of Qt."
+#error "(The moc has changed too much.)"
+#endif
+
+QT_BEGIN_MOC_NAMESPACE
+static const uint qt_meta_data_CrazyButton[] = {
+
+ // content:
+ 4, // revision
+ 0, // classname
+ 0, 0, // classinfo
+ 1, 14, // methods
+ 0, 0, // properties
+ 0, 0, // enums/sets
+ 0, 0, // constructors
+ 0, // flags
+ 0, // signalCount
+
+ // slots: signature, parameters, type, tag, flags
+ 13, 12, 12, 12, 0x0a,
+
+ 0 // eod
+};
+
+static const char qt_meta_stringdata_CrazyButton[] = {
+ "CrazyButton\0\0changeColor()\0"
+};
+
+const QMetaObject CrazyButton::staticMetaObject = {
+ { &QPushButton::staticMetaObject, qt_meta_stringdata_CrazyButton,
+ qt_meta_data_CrazyButton, 0 }
+};
+
+#ifdef Q_NO_DATA_RELOCATION
+const QMetaObject &CrazyButton::getStaticMetaObject() { return staticMetaObject; }
+#endif //Q_NO_DATA_RELOCATION
+
+const QMetaObject *CrazyButton::metaObject() const
+{
+ return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject;
+}
+
+void *CrazyButton::qt_metacast(const char *_clname)
+{
+ if (!_clname) return 0;
+ if (!strcmp(_clname, qt_meta_stringdata_CrazyButton))
+ return static_cast<void*>(const_cast< CrazyButton*>(this));
+ return QPushButton::qt_metacast(_clname);
+}
+
+int CrazyButton::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
+{
+ _id = QPushButton::qt_metacall(_c, _id, _a);
+ if (_id < 0)
+ return _id;
+ if (_c == QMetaObject::InvokeMetaMethod) {
+ switch (_id) {
+ case 0: changeColor(); break;
+ default: ;
+ }
+ _id -= 1;
+ }
+ return _id;
+}
+QT_END_MOC_NAMESPACE
--- /dev/null
+/****************************************************************************
+** Meta object code from reading C++ file 'mainwindow.h'
+**
+** Created: Fri Feb 26 16:31:33 2010
+** by: The Qt Meta Object Compiler version 62 (Qt 4.6.1)
+**
+** WARNING! All changes made in this file will be lost!
+*****************************************************************************/
+
+#include "mainwindow.h"
+#if !defined(Q_MOC_OUTPUT_REVISION)
+#error "The header file 'mainwindow.h' doesn't include <QObject>."
+#elif Q_MOC_OUTPUT_REVISION != 62
+#error "This file was generated using the moc from 4.6.1. It"
+#error "cannot be used with the include files from this version of Qt."
+#error "(The moc has changed too much.)"
+#endif
+
+QT_BEGIN_MOC_NAMESPACE
+static const uint qt_meta_data_MainWindow[] = {
+
+ // content:
+ 4, // revision
+ 0, // classname
+ 0, 0, // classinfo
+ 14, 14, // methods
+ 0, 0, // properties
+ 0, 0, // enums/sets
+ 0, 0, // constructors
+ 0, // flags
+ 1, // signalCount
+
+ // signals: signature, parameters, type, tag, flags
+ 19, 12, 11, 11, 0x05,
+
+ // slots: signature, parameters, type, tag, flags
+ 45, 42, 11, 11, 0x0a,
+ 64, 11, 11, 11, 0x0a,
+ 73, 11, 11, 11, 0x0a,
+ 82, 11, 11, 11, 0x0a,
+ 91, 11, 11, 11, 0x0a,
+ 100, 11, 11, 11, 0x0a,
+ 109, 11, 11, 11, 0x0a,
+ 118, 11, 11, 11, 0x0a,
+ 127, 11, 11, 11, 0x0a,
+ 136, 11, 11, 11, 0x0a,
+ 145, 11, 11, 11, 0x0a,
+ 160, 11, 11, 11, 0x0a,
+ 173, 11, 11, 11, 0x0a,
+
+ 0 // eod
+};
+
+static const char qt_meta_stringdata_MainWindow[] = {
+ "MainWindow\0\0button\0cliccatoIlBottone(int)\0"
+ "id\0cliccaBottone(int)\0clickA()\0clickB()\0"
+ "clickC()\0clickD()\0clickE()\0clickF()\0"
+ "clickG()\0clickH()\0clickI()\0sbagliato(int)\0"
+ "disableAll()\0enableAll()\0"
+};
+
+const QMetaObject MainWindow::staticMetaObject = {
+ { &QMainWindow::staticMetaObject, qt_meta_stringdata_MainWindow,
+ qt_meta_data_MainWindow, 0 }
+};
+
+#ifdef Q_NO_DATA_RELOCATION
+const QMetaObject &MainWindow::getStaticMetaObject() { return staticMetaObject; }
+#endif //Q_NO_DATA_RELOCATION
+
+const QMetaObject *MainWindow::metaObject() const
+{
+ return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject;
+}
+
+void *MainWindow::qt_metacast(const char *_clname)
+{
+ if (!_clname) return 0;
+ if (!strcmp(_clname, qt_meta_stringdata_MainWindow))
+ return static_cast<void*>(const_cast< MainWindow*>(this));
+ return QMainWindow::qt_metacast(_clname);
+}
+
+int MainWindow::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
+{
+ _id = QMainWindow::qt_metacall(_c, _id, _a);
+ if (_id < 0)
+ return _id;
+ if (_c == QMetaObject::InvokeMetaMethod) {
+ switch (_id) {
+ case 0: cliccatoIlBottone((*reinterpret_cast< int(*)>(_a[1]))); break;
+ case 1: cliccaBottone((*reinterpret_cast< int(*)>(_a[1]))); break;
+ case 2: clickA(); break;
+ case 3: clickB(); break;
+ case 4: clickC(); break;
+ case 5: clickD(); break;
+ case 6: clickE(); break;
+ case 7: clickF(); break;
+ case 8: clickG(); break;
+ case 9: clickH(); break;
+ case 10: clickI(); break;
+ case 11: sbagliato((*reinterpret_cast< int(*)>(_a[1]))); break;
+ case 12: disableAll(); break;
+ case 13: enableAll(); break;
+ default: ;
+ }
+ _id -= 14;
+ }
+ return _id;
+}
+
+// SIGNAL 0
+void MainWindow::cliccatoIlBottone(int _t1)
+{
+ void *_a[] = { 0, const_cast<void*>(reinterpret_cast<const void*>(&_t1)) };
+ QMetaObject::activate(this, &staticMetaObject, 0, _a);
+}
+QT_END_MOC_NAMESPACE
--- /dev/null
+/****************************************************************************
+** Meta object code from reading C++ file 'testThread.h'
+**
+** Created: Fri Feb 26 16:31:34 2010
+** by: The Qt Meta Object Compiler version 62 (Qt 4.6.1)
+**
+** WARNING! All changes made in this file will be lost!
+*****************************************************************************/
+
+#include "testThread.h"
+#if !defined(Q_MOC_OUTPUT_REVISION)
+#error "The header file 'testThread.h' doesn't include <QObject>."
+#elif Q_MOC_OUTPUT_REVISION != 62
+#error "This file was generated using the moc from 4.6.1. It"
+#error "cannot be used with the include files from this version of Qt."
+#error "(The moc has changed too much.)"
+#endif
+
+QT_BEGIN_MOC_NAMESPACE
+static const uint qt_meta_data_TestThread[] = {
+
+ // content:
+ 4, // revision
+ 0, // classname
+ 0, 0, // classinfo
+ 7, 14, // methods
+ 0, 0, // properties
+ 0, 0, // enums/sets
+ 0, 0, // constructors
+ 0, // flags
+ 5, // signalCount
+
+ // signals: signature, parameters, type, tag, flags
+ 14, 12, 11, 11, 0x05,
+ 28, 11, 11, 11, 0x05,
+ 35, 11, 11, 11, 0x05,
+ 46, 11, 11, 11, 0x05,
+ 65, 11, 11, 11, 0x05,
+
+ // slots: signature, parameters, type, tag, flags
+ 93, 83, 11, 11, 0x0a,
+ 112, 11, 11, 11, 0x0a,
+
+ 0 // eod
+};
+
+static const char qt_meta_stringdata_TestThread[] = {
+ "TestThread\0\0a\0generate(int)\0exit()\0"
+ "score(int)\0disableInterface()\0"
+ "enableInterface()\0inputUser\0"
+ "updateCaption(int)\0genera()\0"
+};
+
+const QMetaObject TestThread::staticMetaObject = {
+ { &QThread::staticMetaObject, qt_meta_stringdata_TestThread,
+ qt_meta_data_TestThread, 0 }
+};
+
+#ifdef Q_NO_DATA_RELOCATION
+const QMetaObject &TestThread::getStaticMetaObject() { return staticMetaObject; }
+#endif //Q_NO_DATA_RELOCATION
+
+const QMetaObject *TestThread::metaObject() const
+{
+ return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject;
+}
+
+void *TestThread::qt_metacast(const char *_clname)
+{
+ if (!_clname) return 0;
+ if (!strcmp(_clname, qt_meta_stringdata_TestThread))
+ return static_cast<void*>(const_cast< TestThread*>(this));
+ return QThread::qt_metacast(_clname);
+}
+
+int TestThread::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
+{
+ _id = QThread::qt_metacall(_c, _id, _a);
+ if (_id < 0)
+ return _id;
+ if (_c == QMetaObject::InvokeMetaMethod) {
+ switch (_id) {
+ case 0: generate((*reinterpret_cast< int(*)>(_a[1]))); break;
+ case 1: exit(); break;
+ case 2: score((*reinterpret_cast< int(*)>(_a[1]))); break;
+ case 3: disableInterface(); break;
+ case 4: enableInterface(); break;
+ case 5: updateCaption((*reinterpret_cast< int(*)>(_a[1]))); break;
+ case 6: genera(); break;
+ default: ;
+ }
+ _id -= 7;
+ }
+ return _id;
+}
+
+// SIGNAL 0
+void TestThread::generate(int _t1)
+{
+ void *_a[] = { 0, const_cast<void*>(reinterpret_cast<const void*>(&_t1)) };
+ QMetaObject::activate(this, &staticMetaObject, 0, _a);
+}
+
+// SIGNAL 1
+void TestThread::exit()
+{
+ QMetaObject::activate(this, &staticMetaObject, 1, 0);
+}
+
+// SIGNAL 2
+void TestThread::score(int _t1)
+{
+ void *_a[] = { 0, const_cast<void*>(reinterpret_cast<const void*>(&_t1)) };
+ QMetaObject::activate(this, &staticMetaObject, 2, _a);
+}
+
+// SIGNAL 3
+void TestThread::disableInterface()
+{
+ QMetaObject::activate(this, &staticMetaObject, 3, 0);
+}
+
+// SIGNAL 4
+void TestThread::enableInterface()
+{
+ QMetaObject::activate(this, &staticMetaObject, 4, 0);
+}
+QT_END_MOC_NAMESPACE
--- /dev/null
+#include "testThread.h"
+#include <QTimer>
+#include <qdebug.h>
+#include <QMessageBox>
+#include <QDateTime>
+TestThread::TestThread(QObject *parent):QThread(parent){
+ colore=0;
+ attendiInputUtente=false;
+
+ _score=0;
+ index=0;
+
+ qsrand(QDateTime::currentDateTime().toTime_t());
+
+}
+TestThread::~TestThread(){
+
+}
+void TestThread::run()
+{
+ while(true){
+ //msleep(200);
+ qsrand(QDateTime::currentDateTime().toTime_t());
+ sequenza.append(qrand()%9);
+ int i=0;
+
+ qDebug()<<"Init Emission";
+ emit disableInterface();
+ while(i<sequenza.size())
+ {
+ qDebug()<<"Init Generate";
+ emit generate(sequenza.at(i));
+ qDebug()<<sequenza.at(i);
+ msleep(500 - (_score*5));
+ emit generate(sequenza.at(i));
+ msleep(500 - (_score*5));
+ i++;
+ }
+ i=0;
+ attendiInputUtente=true;
+ emit enableInterface();
+
+ while(attendiInputUtente){
+ msleep(1);
+ } ;
+ }
+
+
+}
+
+void TestThread::updateCaption(int inputUser)
+{
+ qDebug()<<"Entro in update Caption ="<< inputUser<< " valore aspettato" << sequenza.at(index);
+ if (attendiInputUtente){
+
+ if(sequenza.at(index) == inputUser)
+ {
+ if(index == sequenza.size() - 1){
+ qDebug()<<"Entro in if if ="<< inputUser<< " valore aspettato" << sequenza.at(index);
+ attendiInputUtente=false;
+ index=0;
+ }else
+ {
+ index++;
+ _score++;
+ }
+ }
+ else{
+ emit score(_score);
+ _score=0;
+ sequenza.clear();
+ index=0;
+ attendiInputUtente=true;
+ }
+ }
+}
+
+void TestThread::genera()
+{
+ attendiInputUtente=false;
+
+}
--- /dev/null
+#ifndef TESTTHREAD_H
+#define TESTTHREAD_H
+
+#include <QThread>
+
+
+class TestThread : public QThread
+{
+ Q_OBJECT
+
+public:
+ TestThread(QObject *parent = 0);
+ ~TestThread();
+signals:
+ void generate(int a);
+ void exit();
+ void score(int);
+ void disableInterface();
+ void enableInterface();
+protected:
+ void run();
+
+public slots:
+ void updateCaption(int inputUser);
+ void genera(void);
+
+
+private:
+ int colore;
+ int index;
+ int _score;
+ bool attendiInputUtente;
+ QList<int> sequenza;
+};
+#endif // TESTTHREAD_H
--- /dev/null
+/********************************************************************************
+** Form generated from reading UI file 'mainwindow.ui'
+**
+** Created: Fri Feb 26 16:31:30 2010
+** by: Qt User Interface Compiler version 4.6.1
+**
+** WARNING! All changes made in this file will be lost when recompiling UI file!
+********************************************************************************/
+
+#ifndef UI_MAINWINDOW_H
+#define UI_MAINWINDOW_H
+
+#include <QtCore/QVariant>
+#include <QtGui/QAction>
+#include <QtGui/QApplication>
+#include <QtGui/QButtonGroup>
+#include <QtGui/QHeaderView>
+#include <QtGui/QMainWindow>
+#include <QtGui/QWidget>
+#include "crazybutton.h"
+
+QT_BEGIN_NAMESPACE
+
+class Ui_MainWindow
+{
+public:
+ QWidget *centralWidget;
+ CrazyButton *pushButton_2;
+ CrazyButton *pushButton_3;
+ CrazyButton *pushButton_4;
+ CrazyButton *pushButton_5;
+ CrazyButton *pushButton_6;
+ CrazyButton *pushButton_7;
+ CrazyButton *pushButton_8;
+ CrazyButton *pushButton_9;
+ CrazyButton *pushButton;
+
+ void setupUi(QMainWindow *MainWindow)
+ {
+ if (MainWindow->objectName().isEmpty())
+ MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
+ MainWindow->resize(800, 480);
+ MainWindow->setAutoFillBackground(true);
+ centralWidget = new QWidget(MainWindow);
+ centralWidget->setObjectName(QString::fromUtf8("centralWidget"));
+ pushButton_2 = new CrazyButton(centralWidget);
+ pushButton_2->setObjectName(QString::fromUtf8("pushButton_2"));
+ pushButton_2->setGeometry(QRect(330, 40, 100, 100));
+ pushButton_2->setMaximumSize(QSize(16777215, 16777215));
+ pushButton_3 = new CrazyButton(centralWidget);
+ pushButton_3->setObjectName(QString::fromUtf8("pushButton_3"));
+ pushButton_3->setGeometry(QRect(510, 40, 100, 100));
+ pushButton_4 = new CrazyButton(centralWidget);
+ pushButton_4->setObjectName(QString::fromUtf8("pushButton_4"));
+ pushButton_4->setGeometry(QRect(150, 180, 100, 100));
+ pushButton_5 = new CrazyButton(centralWidget);
+ pushButton_5->setObjectName(QString::fromUtf8("pushButton_5"));
+ pushButton_5->setGeometry(QRect(330, 180, 100, 100));
+ pushButton_6 = new CrazyButton(centralWidget);
+ pushButton_6->setObjectName(QString::fromUtf8("pushButton_6"));
+ pushButton_6->setGeometry(QRect(510, 180, 100, 100));
+ pushButton_7 = new CrazyButton(centralWidget);
+ pushButton_7->setObjectName(QString::fromUtf8("pushButton_7"));
+ pushButton_7->setGeometry(QRect(150, 320, 100, 100));
+ pushButton_8 = new CrazyButton(centralWidget);
+ pushButton_8->setObjectName(QString::fromUtf8("pushButton_8"));
+ pushButton_8->setGeometry(QRect(330, 320, 100, 100));
+ pushButton_9 = new CrazyButton(centralWidget);
+ pushButton_9->setObjectName(QString::fromUtf8("pushButton_9"));
+ pushButton_9->setGeometry(QRect(510, 320, 100, 100));
+ pushButton = new CrazyButton(centralWidget);
+ pushButton->setObjectName(QString::fromUtf8("pushButton"));
+ pushButton->setGeometry(QRect(150, 40, 101, 100));
+ pushButton->setMinimumSize(QSize(0, 100));
+#ifndef QT_NO_TOOLTIP
+ pushButton->setToolTip(QString::fromUtf8(""));
+#endif // QT_NO_TOOLTIP
+ MainWindow->setCentralWidget(centralWidget);
+
+ retranslateUi(MainWindow);
+
+ QMetaObject::connectSlotsByName(MainWindow);
+ } // setupUi
+
+ void retranslateUi(QMainWindow *MainWindow)
+ {
+ MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", 0, QApplication::UnicodeUTF8));
+ pushButton_2->setText(QApplication::translate("MainWindow", "2", 0, QApplication::UnicodeUTF8));
+ pushButton_3->setText(QApplication::translate("MainWindow", "3", 0, QApplication::UnicodeUTF8));
+ pushButton_4->setText(QApplication::translate("MainWindow", "4", 0, QApplication::UnicodeUTF8));
+ pushButton_5->setText(QApplication::translate("MainWindow", "5", 0, QApplication::UnicodeUTF8));
+ pushButton_6->setText(QApplication::translate("MainWindow", "6", 0, QApplication::UnicodeUTF8));
+ pushButton_7->setText(QApplication::translate("MainWindow", "7", 0, QApplication::UnicodeUTF8));
+ pushButton_8->setText(QApplication::translate("MainWindow", "8", 0, QApplication::UnicodeUTF8));
+ pushButton_9->setText(QApplication::translate("MainWindow", "9", 0, QApplication::UnicodeUTF8));
+ pushButton->setText(QApplication::translate("MainWindow", "1", 0, QApplication::UnicodeUTF8));
+ } // retranslateUi
+
+};
+
+namespace Ui {
+ class MainWindow: public Ui_MainWindow {};
+} // namespace Ui
+
+QT_END_NAMESPACE
+
+#endif // UI_MAINWINDOW_H