Mark2020H

Timer enabled Image Viewer Part3 of 5

Nov 4th, 2020 (edited)
393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.18 KB | None | 0 0
  1. // Timer enabled Image Viewer Part3 of 5
  2. // MD Harrington imagedialog.cpp
  3. // Links for others who may be interested can be found on  git hub at this address
  4. // https://github.com/markh2016/QT_Timer_Imageviewer.git
  5.  
  6.  
  7. /* Special word of thanks to Brian  Cairns  Voidrealms  facebook who put tutorials together for us whom  cant afford much  right now  Working version   / desktop  recording  available  at this link https://www.facebook.com/groups/1400884323467285 */
  8.  
  9.  
  10. #include "imagedialog.h"
  11. #include "ui_imagedialog.h"
  12.  
  13. #include <QImageReader>
  14. #include <QPixmap>
  15.  
  16. ImageDialog::ImageDialog(QWidget *parent)
  17.     : QDialog(parent)
  18.     , ui(new Ui::ImageDialog)
  19. {
  20.     ui->setupUi(this);
  21.     this->setFixedSize(size());
  22.     this->loadDir(dirOne)  ;
  23.     this->timer =new QTimer(this);
  24.     connect(timer, SIGNAL(timeout()), this, SLOT(update()));
  25.     connect(ui->btnStartTimer, SIGNAL(clicked()), this, SLOT(start_M_Timer()));
  26. }
  27.  
  28. ImageDialog::~ImageDialog()
  29. {
  30.     delete ui;
  31. }
  32.  
  33. bool ImageDialog::loadDir(const QDir &path)
  34. {
  35.  
  36.  
  37.  
  38.  
  39.      qDebug()<< path.exists() ;
  40.      list = path.entryList(QDir::AllEntries);
  41.  
  42.      ui->QImageSlider->setMaximum(list.size()-1) ;
  43.      qDebug()<< "List size = " << list.size()<< Qt::endl;
  44.      for (int i = 2; i < list.size(); i++)
  45.      {
  46.         // qDebug() << "Filename " << i << " = " << path.filePath(list.at(i));
  47.      }
  48.  
  49.      return path.exists() ;
  50.  
  51. }
  52.  
  53. void ImageDialog::update()
  54. {
  55.  
  56.     if(m_counter==list.size())
  57.     {
  58.         m_counter = 2;
  59.     }
  60.  
  61.     if(m_counter <= list.size()){
  62.         QString m_element=  dirOne.filePath(list.at(m_counter));
  63.         QPixmap pm(m_element) ;
  64.         ui->ImageLabel->setPixmap(pm);
  65.         ui->ImageLabel->setScaledContents(true);
  66.         ui->QImageSlider->setValue(m_counter-1) ;
  67.         m_counter+=1 ;
  68.  
  69.         ui->QImageSlider->setValue(m_counter-1) ;
  70.    }
  71.  
  72.  
  73.  
  74.  
  75. }
  76.  
  77. void ImageDialog::start_M_Timer()
  78. {
  79.    QString btext = ui->btnStartTimer->text();
  80.    if(btext=="Start Timer")
  81.    {
  82.    timer->start(3000);
  83.    ui->btnStartTimer->setText("Stop  Timer") ;
  84.    }
  85.    else
  86.    {
  87.        timer->stop();
  88.        m_counter=2 ;
  89.  
  90.         ui->btnStartTimer->setText("Start Timer") ;
  91.    }
  92. }
  93.  
  94.  
  95.  
  96.  
Add Comment
Please, Sign In to add comment