Преглед на файлове

Adding a timer and progress bar functionality

Rémi Synave преди 1 година
родител
ревизия
67ce2e4acd
променени са 3 файла, в които са добавени 36 реда и са изтрити 3 реда
  1. 20 0
      csl/MainWindow.cpp
  2. 8 2
      csl/MainWindow.hpp
  3. 8 1
      csl/main.cpp

+ 20 - 0
csl/MainWindow.cpp

@@ -82,7 +82,15 @@ MainWindow::MainWindow ()
   // Fourth line of the interface
   progressBar = new QProgressBar(central);
   progressBar->setFixedHeight(20);
+  progressBar->setRange(0, maxProgressBar);
+  progressBar->setValue(0);
+  connect(progressBar, SIGNAL(valueChanged(int)), this, SLOT(progressBarValueChanged(int)));
   layoutV->addWidget(progressBar);
+
+  timer = new QTimer(central);
+  timer->setSingleShot(false);
+  timer->setInterval(time);
+  connect(timer, SIGNAL(timeout()), this, SLOT(ticTimer()));
   
   setFixedSize (screenWidth, screenHeight);
 
@@ -93,6 +101,8 @@ MainWindow::MainWindow ()
   QString sl2_a_ouvrir("/home/remi/images/screenshotb.txt");
 
   openC( img_a_ouvrir, sl1_a_ouvrir, sl2_a_ouvrir);
+
+  timer->start();
 }
 
 void
@@ -131,6 +141,16 @@ void MainWindow::rightImage(){
   qDebug() << "Clic sur image droite" << Qt::endl;
 }
 
+void MainWindow::progressBarValueChanged(int value){
+  if(value == maxProgressBar ){
+    QApplication::quit();
+  }
+}
+
+void MainWindow::ticTimer(){
+  progressBar->setValue(progressBar->value()+time);
+}
+
 void
 MainWindow::openC (QString image, QString leftSL, QString rightSL){
   waLeft->loadImage (image.toStdString ());

+ 8 - 2
csl/MainWindow.hpp

@@ -1,11 +1,13 @@
 #ifndef MAINWINDOW_HPP
 #define MAINWINDOW_HPP
 
+#include <QApplication>
 #include <QMainWindow>
 #include <QAction>
 #include <QMenu>
 #include <QPushButton>
 #include <QProgressBar>
+#include <QTimer>
 
 #include "WorkArea.hpp"
 
@@ -16,7 +18,9 @@ class MainWindow: public QMainWindow
 
 
 private:
-  const int spaceInBetween = 50;
+  const int spaceInBetween = 20;
+  const int time = 100;
+  const int maxProgressBar = 5000;
   int screenWidth, screenHeight;
 
   QMenu *fileMenu;
@@ -30,6 +34,7 @@ private:
   QPushButton *leftButton, *rightButton;
 
   QProgressBar *progressBar;
+  QTimer *timer;
 
   void createActions ();
   void createMenus ();
@@ -39,7 +44,8 @@ private slots:
   void open ();
   void leftImage();
   void rightImage();
-
+  void progressBarValueChanged(int value);
+  void ticTimer();
   
 public:
   MainWindow ();

+ 8 - 1
csl/main.cpp

@@ -1,4 +1,5 @@
 #include <QApplication>
+#include <QDebug>
 
 #include "MainWindow.hpp"
 
@@ -6,7 +7,13 @@ int
 main (int argc, char *argv[])
 {
   QApplication app (argc, argv);
+  
+  QMainWindow waitingWindow;
+  waitingWindow.show();
+  app.exec();
+    
   MainWindow window;
   window.show ();
-  return app.exec ();
+  app.exec ();
+  return 0;
 }