Skip to content
This repository has been archived by the owner on Dec 8, 2018. It is now read-only.

Commit

Permalink
Switch to use the coding style similar to Qt.
Browse files Browse the repository at this point in the history
  • Loading branch information
ariya committed May 16, 2010
1 parent 352c472 commit 22a3be4
Show file tree
Hide file tree
Showing 3 changed files with 919 additions and 964 deletions.
187 changes: 90 additions & 97 deletions pictureflow-qt/main.cpp
Expand Up @@ -31,123 +31,116 @@

QStringList findFiles(const QString& path = QString())
{
QStringList files;
QStringList files;

QDir dir = QDir::current();
if(!path.isEmpty())
dir = QDir(path);
QDir dir = QDir::current();
if (!path.isEmpty())
dir = QDir(path);

dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
QFileInfoList list = dir.entryInfoList();
for (int i = 0; i < list.size(); ++i)
files += dir.absoluteFilePath(list.at(i).fileName());
dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
QFileInfoList list = dir.entryInfoList();
for (int i = 0; i < list.size(); ++i)
files += dir.absoluteFilePath(list.at(i).fileName());

return files;
return files;
}

class Browser: public PictureFlow
{
public:
Browser(): PictureFlow()
{
setWindowTitle("PictureFlow");
}

void keyPressEvent(QKeyEvent* event)
{
if(event->key() == Qt::Key_Escape || event->key() == Qt::Key_Enter ||
event->key() == Qt::Key_Return)
{
event->accept();
close();
}

// checking the speed of rendering
if(event->key() == Qt::Key_F10)
if(event->modifiers() == Qt::AltModifier)
{
qDebug("benchmarking.... please wait");
const int blit_count = 10;

QTime stopwatch;
stopwatch.start();
for(int i = 0; i < blit_count; i++)
{
render(); repaint(); QApplication::flush(); QApplication::syncX();
render(); repaint(); QApplication::flush(); QApplication::syncX();
render(); repaint(); QApplication::flush(); QApplication::syncX();
render(); repaint(); QApplication::flush(); QApplication::syncX();
render(); repaint(); QApplication::flush(); QApplication::syncX();
render(); repaint(); QApplication::flush(); QApplication::syncX();
render(); repaint(); QApplication::flush(); QApplication::syncX();
render(); repaint(); QApplication::flush(); QApplication::syncX();
render(); repaint(); QApplication::flush(); QApplication::syncX();
render(); repaint(); QApplication::flush(); QApplication::syncX();
}
QString msg;
int elapsed = stopwatch.elapsed();
if( elapsed > 0 )
msg = QString("FPS: %1").arg( blit_count*10*1000.0/elapsed );
else
msg = QString("Too fast. Increase blit_count");
setWindowTitle( msg );
event->accept();
return;
Browser(): PictureFlow() {
setWindowTitle("PictureFlow");
}

// for debugging only: Alt+F11 cycles the reflection effect
if(event->key() == Qt::Key_F11)
if(event->modifiers() == Qt::AltModifier)
{
qDebug("changing reflection effect...");
switch(reflectionEffect())
{
//case NoReflection: setReflectionEffect(PlainReflection); break;
case PlainReflection: setReflectionEffect(BlurredReflection); break;
case BlurredReflection: setReflectionEffect(PlainReflection); break;
default: setReflectionEffect(PlainReflection); break;
}
event->accept();
return;
void keyPressEvent(QKeyEvent* event) {
if (event->key() == Qt::Key_Escape || event->key() == Qt::Key_Enter ||
event->key() == Qt::Key_Return) {
event->accept();
close();
}

// checking the speed of rendering
if (event->key() == Qt::Key_F10)
if (event->modifiers() == Qt::AltModifier) {
qDebug("benchmarking.... please wait");
const int blit_count = 10;

QTime stopwatch;
stopwatch.start();
for (int i = 0; i < blit_count; i++) {
render(); repaint(); QApplication::flush(); QApplication::syncX();
render(); repaint(); QApplication::flush(); QApplication::syncX();
render(); repaint(); QApplication::flush(); QApplication::syncX();
render(); repaint(); QApplication::flush(); QApplication::syncX();
render(); repaint(); QApplication::flush(); QApplication::syncX();
render(); repaint(); QApplication::flush(); QApplication::syncX();
render(); repaint(); QApplication::flush(); QApplication::syncX();
render(); repaint(); QApplication::flush(); QApplication::syncX();
render(); repaint(); QApplication::flush(); QApplication::syncX();
render(); repaint(); QApplication::flush(); QApplication::syncX();
}
QString msg;
int elapsed = stopwatch.elapsed();
if (elapsed > 0)
msg = QString("FPS: %1").arg(blit_count * 10 * 1000.0 / elapsed);
else
msg = QString("Too fast. Increase blit_count");
setWindowTitle(msg);
event->accept();
return;
}

// for debugging only: Alt+F11 cycles the reflection effect
if (event->key() == Qt::Key_F11)
if (event->modifiers() == Qt::AltModifier) {
qDebug("changing reflection effect...");
switch (reflectionEffect()) {
//case NoReflection: setReflectionEffect(PlainReflection); break;
case PlainReflection: setReflectionEffect(BlurredReflection); break;
case BlurredReflection: setReflectionEffect(PlainReflection); break;
default: setReflectionEffect(PlainReflection); break;
}
event->accept();
return;
}

PictureFlow::keyPressEvent(event);
}
};

PictureFlow::keyPressEvent(event);
}
};

int main( int argc, char ** argv )
int main(int argc, char ** argv)
{
QApplication* app = new QApplication( argc, argv );
Browser* w = new Browser;
QApplication* app = new QApplication(argc, argv);
Browser* w = new Browser;

#if defined(_WS_QWS) || defined(Q_WS_QWS)
w->showFullScreen();
int ww = w->width();
int wh = w->height();
int dim = (ww > wh) ? wh : ww;
dim = dim * 3 / 4;
w->setSlideSize(QSize(3*dim/5, dim));
#else
w->setSlideSize(QSize(3*40, 5*40));
w->resize(750, 270);
w->showFullScreen();
int ww = w->width();
int wh = w->height();
int dim = (ww > wh) ? wh : ww;
dim = dim * 3 / 4;
w->setSlideSize(QSize(3*dim / 5, dim));
#else
w->setSlideSize(QSize(3*40, 5*40));
w->resize(750, 270);
#endif

QStringList files = (argc > 1) ? findFiles(QString(argv[1])) : findFiles();
QStringList files = (argc > 1) ? findFiles(QString(argv[1])) : findFiles();

QImage img;
for(int i = 0; i < (int)files.count(); i++)
if(img.load(files[i]))
w->addSlide(img);
QImage img;
for (int i = 0; i < (int)files.count(); i++)
if (img.load(files[i]))
w->addSlide(img);

w->setCenterIndex(w->slideCount()/2);
w->setBackgroundColor(Qt::white);
w->show();
w->setCenterIndex(w->slideCount() / 2);
w->setBackgroundColor(Qt::white);
w->show();

app->connect( app, SIGNAL(lastWindowClosed()), app, SLOT(quit()) );
int result = app->exec();
app->connect(app, SIGNAL(lastWindowClosed()), app, SLOT(quit()));
int result = app->exec();

delete w;
delete app;
delete w;
delete app;

return result;
return result;
}

0 comments on commit 22a3be4

Please sign in to comment.