Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Timer enabled Image Viewer Part3 of 5
- // MD Harrington imagedialog.cpp
- // Links for others who may be interested can be found on git hub at this address
- // https://github.com/markh2016/QT_Timer_Imageviewer.git
- /* 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 */
- #include "imagedialog.h"
- #include "ui_imagedialog.h"
- #include <QImageReader>
- #include <QPixmap>
- ImageDialog::ImageDialog(QWidget *parent)
- : QDialog(parent)
- , ui(new Ui::ImageDialog)
- {
- ui->setupUi(this);
- this->setFixedSize(size());
- this->loadDir(dirOne) ;
- this->timer =new QTimer(this);
- connect(timer, SIGNAL(timeout()), this, SLOT(update()));
- connect(ui->btnStartTimer, SIGNAL(clicked()), this, SLOT(start_M_Timer()));
- }
- ImageDialog::~ImageDialog()
- {
- delete ui;
- }
- bool ImageDialog::loadDir(const QDir &path)
- {
- qDebug()<< path.exists() ;
- list = path.entryList(QDir::AllEntries);
- ui->QImageSlider->setMaximum(list.size()-1) ;
- qDebug()<< "List size = " << list.size()<< Qt::endl;
- for (int i = 2; i < list.size(); i++)
- {
- // qDebug() << "Filename " << i << " = " << path.filePath(list.at(i));
- }
- return path.exists() ;
- }
- void ImageDialog::update()
- {
- if(m_counter==list.size())
- {
- m_counter = 2;
- }
- if(m_counter <= list.size()){
- QString m_element= dirOne.filePath(list.at(m_counter));
- QPixmap pm(m_element) ;
- ui->ImageLabel->setPixmap(pm);
- ui->ImageLabel->setScaledContents(true);
- ui->QImageSlider->setValue(m_counter-1) ;
- m_counter+=1 ;
- ui->QImageSlider->setValue(m_counter-1) ;
- }
- }
- void ImageDialog::start_M_Timer()
- {
- QString btext = ui->btnStartTimer->text();
- if(btext=="Start Timer")
- {
- timer->start(3000);
- ui->btnStartTimer->setText("Stop Timer") ;
- }
- else
- {
- timer->stop();
- m_counter=2 ;
- ui->btnStartTimer->setText("Start Timer") ;
- }
- }
Add Comment
Please, Sign In to add comment