C++ (Qt)void MainWindow::slideshowOn(bool on){ if(!on)return; slideShowQuit = false; slideShowStop = false; QString importPath; if( cfg.contentExportPath.isEmpty() ) importPath = QDir::homePath(); else { importPath = QDir::fromNativeSeparators( cfg.contentExportPath ); if( !QDir( importPath ).exists() ) importPath = QDir::homePath(); } QString fileName = QFileDialog::getOpenFileName( this, tr( "Slideshow content from file" ), importPath, tr( "Text files (*.txt);;All files (*.*)" ) ); if( fileName.size() == 0) { slideshowButton->setChecked(false); return; } QFileInfo fileInfo( fileName ); QString contentName = fileInfo.baseName(); QFile file( fileName ); int n(0); // Count slides if ( file.open( QFile::ReadOnly ) ) { char buf[1024]; qint64 lineLength; forever { lineLength = file.readLine(buf, sizeof(buf)); if (lineLength > 0) { ++n; } else if (lineLength == -1) { break; } } file.close(); } if ( file.open( QFile::ReadOnly | QIODevice::Text ) ) { QTextStream fileStream( & file ); QString itemStr, trimmedStr; QString str; str.setNum(n); slidePopup->setWindowTitle( contentName + "/" + str ); // slide Show do { // Pause do { QEventLoop loop; QTimer::singleShot(0, &loop, SLOT(quit())); loop.exec(); } while(slideShowStop); itemStr = fileStream.readLine(); if( fileStream.status() >= QTextStream::ReadCorruptData ) break; trimmedStr = itemStr.trimmed(); if( trimmedStr.isEmpty() ) continue; if(slideshowPopup->isChecked())slidePopup->slideTranslationFor( trimmedStr ); if(slideshowGrand->isChecked())showTranslationFor( trimmedStr ); QEventLoop loop3; QTimer::singleShot(cfg.preferences.slideShowTimer, &loop3, SLOT(quit())); loop3.exec(); if(slideShowQuit)break; } while( !fileStream.atEnd() ); file.close(); }}
C++ (Qt)void MainWindow::slideshowOff( bool ){ slideShowQuit = true;}
C++ (Qt) connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(slideshowOff( bool )));
C++ (Qt)void MainWindow::slideshowOff(){ slideShowQuit = true;}
C++ (Qt) connect( slideshowButton, SIGNAL( toggled( bool ) ), this, SLOT( slideshowOn( bool ) ) );
C++ (Qt)slideShowQuit = false;
C++ (Qt) QEventLoop loop3; QTimer::singleShot(cfg.preferences.slideShowTimer, &loop3, SLOT(quit())); loop3.exec();
C++ (Qt)while(!asleep()) sheep++;