Advertisement
Guest User

window.cpp

a guest
May 5th, 2012
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.77 KB | None | 0 0
  1. #include "window.h"
  2. #include <Qsound>
  3.  
  4. int tempsMinutes=0;
  5. int tempsSecondes=0;
  6. bool enCours=false;
  7. double i=0;
  8.  
  9. MaFenetre::MaFenetre() : QWidget()
  10. {
  11.     setFixedSize(250, 300);
  12.  
  13.     m_bouton = new QPushButton("Commencer", this);
  14.     m_bouton->setCursor(Qt::PointingHandCursor);
  15.     m_bouton->setGeometry(35, 250, 180, 50);
  16.     connect(m_bouton, SIGNAL(clicked()), this, SLOT(start()));
  17.  
  18.  
  19.  
  20.     m_progressbar= new QProgressBar(this);
  21.     m_progressbar->setGeometry(50, 180, 180, 30);
  22.  
  23.     m_spinbox = new QSpinBox(this);
  24.     m_spinbox -> setGeometry(35, 30, 180, 30);
  25.     m_spinbox-> setMaximum(3600);
  26.     m_spinbox-> setAccelerated(true);
  27.     m_spinbox-> setMaximum(120);
  28.     m_spinbox-> setMinimum(1);
  29.     m_spinbox-> setSuffix (" minute(s)");
  30.  
  31.     QLabel *label = new QLabel("Avancement vers le prochain TR: ", this);
  32.     label->move(50,155);
  33.  
  34.     QLabel *label2 = new QLabel("Temps entre les TRs:", this);
  35.     label2->move(35,15);
  36.  
  37.     QTimer *timer = new QTimer(this);
  38.     connect(timer, SIGNAL(timeout()), this, SLOT(update()));
  39.     timer->start(100);
  40. }
  41.  
  42.  
  43. void MaFenetre::start()
  44. {
  45.     static bool dejaClique =false;
  46.     if(dejaClique==false)
  47.     {
  48.     enCours=true;
  49.     tempsMinutes = m_spinbox->value();
  50.     tempsSecondes = tempsMinutes*60;
  51.     dejaClique=true;
  52.     m_bouton->setText("Reset");
  53.     }
  54.     else
  55.     {
  56.     enCours=false;
  57.     dejaClique=false;
  58.     m_progressbar->setValue(0);
  59.     i=0;
  60.     m_bouton->setText("Recommencer");
  61.     }
  62.  
  63.  
  64.  
  65. }
  66.  
  67. void MaFenetre::update()
  68. {
  69.     static int prct;
  70.  
  71.     if(enCours)
  72.     {
  73.     prct = (i*100)/tempsSecondes;
  74.     m_progressbar->setValue(prct);
  75.     i+=0.1;
  76.     }
  77.  
  78.     if(prct>100)
  79.     {
  80.       m_progressbar->setValue(0);
  81.       i=0;
  82.       QSound::play("sounds/firealarm.wav");
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement