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; 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; QEventLoop loop3; QTimer::singleShot(cfg.preferences.slideShowTimer, &loop3, SLOT(quit())); loop3.exec(); updateShow(); if(slideShowQuit)break; } while( !fileStream.atEnd() ); file.close(); }} void MainWindow::updateShow(){ if(slideshowPopup->isChecked())slidePopup->slideTranslationFor( trimmedStr ); if(slideshowGrand->isChecked())showTranslationFor( trimmedStr );}
C++ (Qt) do { 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; QTimer::singleShot(cfg.preferences.slideShowTimer, this, SLOT(updateShow())); if(slideShowQuit)break; } while( !fileStream.atEnd() );
C++ (Qt)enum states { fristState, secondState, nState}; void MainWindowtete::onButtonPushed(){ switch (state) { // первоначальное состояние case fristState: { doWork1(); // ... некоторая работа state = secondState; // в сл. раз при вызове этого слота уже на выполнится блок в сл. case } break; case secondState: { doWork2(); // .. некоторая другая работа... state = nState; } break; case nState: { doWorkN(); // завершающая работа state = fristState; // переходим к первоначальному состоянию } break; default: break; }}
C++ (Qt)while(!asleep()) sheep++;
C++ (Qt)void MainWindow::slideshowOn(bool on){ if(!on) { slideShowPause = true; return; } else if(slideShowPlay && slideShowPause) { slideShowPause = false; return; } else { slideShowPlay = true; slideShowPause = false; QString importPath; if( cfg.historyExportPath.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; 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(slideShowPause); // Play itemStr = fileStream.readLine(); if( fileStream.status() >= QTextStream::ReadCorruptData ) break; trimmedStr = itemStr.trimmed(); if( trimmedStr.isEmpty() ) continue; QEventLoop loop3; QTimer::singleShot(cfg.preferences.slideShowTimer, &loop3, SLOT(quit())); loop3.exec(); updateShow(); if(slideShowQuit)break; } while( !fileStream.atEnd() ); file.close(); }}
C++ (Qt) connect( ui.quit, SIGNAL( triggered() ), this, SLOT( quitApp() ) ); void MainWindow::quitApp(){ slideShowStop = true; qApp->quit();}