|
@@ -0,0 +1,125 @@ |
|
|
|
|
|
// Code de la classe Loterie |
|
|
|
|
|
|
|
|
|
|
|
// #include <QWidgets> |
|
|
|
|
|
#include <QtGlobal> |
|
|
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) |
|
|
|
|
|
# include <QtWidgets> |
|
|
|
|
|
#else |
|
|
|
|
|
# include <QtGui> |
|
|
|
|
|
#endif |
|
|
|
|
|
#include "Loterie.h" |
|
|
|
|
|
|
|
|
|
|
|
Loterie::Loterie(int Taille, QWidget *parent) : QWidget(parent) |
|
|
|
|
|
{ |
|
|
|
|
|
taille = Taille; |
|
|
|
|
|
dep=30; |
|
|
|
|
|
savsec=-1; |
|
|
|
|
|
QTimer *monTimer = new QTimer(this); |
|
|
|
|
|
// monTimer->setTimerType(Qt::PreciseTimer); |
|
|
|
|
|
connect(monTimer, SIGNAL(timeout()), this, SLOT(update())); |
|
|
|
|
|
monTimer->start(1000); // Timeout toutes les secondes |
|
|
|
|
|
setWindowTitle(tr("Loterie E2L")); |
|
|
|
|
|
resize(taille, taille); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Loterie::lance(void) |
|
|
|
|
|
{ |
|
|
|
|
|
dep=30; |
|
|
|
|
|
savsec++; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Loterie::paintEvent(QPaintEvent *) |
|
|
|
|
|
{ |
|
|
|
|
|
int x = (taille/2) - 4; |
|
|
|
|
|
|
|
|
|
|
|
// Les polygones (aiguille) |
|
|
|
|
|
// On suppose que l'origine est au centre !! |
|
|
|
|
|
static const QPoint AigS[4] = { |
|
|
|
|
|
QPoint(2, 2), |
|
|
|
|
|
QPoint(0,4), |
|
|
|
|
|
QPoint(-2, 2), |
|
|
|
|
|
QPoint(0, 10-x) |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// Quelques couleurs predefinies |
|
|
|
|
|
QColor HCoul(255, 0, 0); |
|
|
|
|
|
QColor ACoul(250, 0, 250); |
|
|
|
|
|
QColor MCoul(250, 250, 0); |
|
|
|
|
|
QColor SCoul(150, 150, 150); |
|
|
|
|
|
// QColor SCoul(52, 152, 219); |
|
|
|
|
|
QColor XCoul(152, 219, 52); |
|
|
|
|
|
|
|
|
|
|
|
QPainter painter(this); // Espace du dessin |
|
|
|
|
|
painter.setRenderHint(QPainter::Antialiasing); // Meilleure image |
|
|
|
|
|
|
|
|
|
|
|
int cote = qMin(width(), height()); |
|
|
|
|
|
painter.translate(width() / 2, height() / 2); // changt origine |
|
|
|
|
|
painter.scale(cote / (double)taille, cote / (double)taille); |
|
|
|
|
|
|
|
|
|
|
|
painter.setPen(Qt::NoPen); |
|
|
|
|
|
painter.setBrush(HCoul); |
|
|
|
|
|
|
|
|
|
|
|
// Marques des quartiers de la roue |
|
|
|
|
|
for (int i = 0; i < 30; ++i) { |
|
|
|
|
|
if ((i % 6) == 0) { |
|
|
|
|
|
if (i==0) painter.setBrush(HCoul); |
|
|
|
|
|
else painter.setBrush(ACoul); |
|
|
|
|
|
} else { |
|
|
|
|
|
if ((i % 2) == 0) painter.setBrush(XCoul); |
|
|
|
|
|
else painter.setBrush(MCoul); |
|
|
|
|
|
} |
|
|
|
|
|
// painter.fillRect(-x,0,x,x, Qt::green); |
|
|
|
|
|
QRectF rectangle(-x, -x, 2*x, 2*x); |
|
|
|
|
|
int startAngle = 84 * 16; |
|
|
|
|
|
int spanAngle = 12 * 16; |
|
|
|
|
|
painter.drawPie(rectangle, startAngle, spanAngle); |
|
|
|
|
|
painter.rotate(12.0); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Marques des minutes du cadran |
|
|
|
|
|
painter.setPen(SCoul); |
|
|
|
|
|
|
|
|
|
|
|
for (int j = 0; j < 60; ++j) { |
|
|
|
|
|
painter.drawLine(x-4, 0, x, 0); |
|
|
|
|
|
painter.rotate(6.0); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Texte de fond |
|
|
|
|
|
painter.setPen(Qt::blue); |
|
|
|
|
|
painter.setFont(QFont("Arial", 30)); |
|
|
|
|
|
QRectF rectT(-x, -x, 2*x, 2*x); |
|
|
|
|
|
painter.drawText(rectT,Qt::AlignCenter,"E2L\nLoterie\n\nIvry en Fete\n2025"); |
|
|
|
|
|
QTime Heure = QTime::currentTime(); |
|
|
|
|
|
int coef=1; |
|
|
|
|
|
int nsec, sec; |
|
|
|
|
|
if (savsec==-1) sec = Heure.second(); |
|
|
|
|
|
else sec = savsec; |
|
|
|
|
|
if (dep > 0) { |
|
|
|
|
|
if (dep > 15) coef=5; |
|
|
|
|
|
else { |
|
|
|
|
|
if (dep > 10) coef=3; |
|
|
|
|
|
else { |
|
|
|
|
|
if (dep > 5) coef=2; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
nsec = sec + coef; |
|
|
|
|
|
while (nsec > 59) nsec -= 60; |
|
|
|
|
|
savsec=nsec; |
|
|
|
|
|
dep--; |
|
|
|
|
|
// if (dep==0) printf("val = %d\n",nsec); |
|
|
|
|
|
painter.fillRect(x-10,x-10,x,x, Qt::red); |
|
|
|
|
|
} else { |
|
|
|
|
|
nsec = savsec; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Aiguille |
|
|
|
|
|
painter.setPen(Qt::black); |
|
|
|
|
|
painter.setBrush(SCoul); |
|
|
|
|
|
|
|
|
|
|
|
painter.save(); |
|
|
|
|
|
painter.rotate(6.0 * (nsec + .5)); |
|
|
|
|
|
painter.drawConvexPolygon(AigS, 4); |
|
|
|
|
|
painter.restore(); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|