Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Select random picture.
  • Loading branch information
cornelius committed Dec 9, 2008
1 parent 6f47ad6 commit 3e95b55
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
30 changes: 26 additions & 4 deletions src/resultviewpic.cpp
Expand Up @@ -29,9 +29,11 @@
#include <kdebug.h>
#include <klocale.h>
#include <kstandarddirs.h>
#include <kmessagebox.h>

#include <qlayout.h>
#include <qlabel.h>
#include <qdir.h>

#include <math.h>

Expand All @@ -48,18 +50,38 @@ ResultViewPic::ResultViewPic( QWidget *parent )
topLayout->addWidget( mPicLabel, 1 );
mPicLabel->setAlignment( AlignCenter );

QString picPath = locate( "appdata", "pics/funny_bunny.jpg" );
setSummary();
}

void ResultViewPic::selectPicture()
{
QStringList paths;

paths.append( locate( "appdata", "pics/funny_bunny.jpg" ) );

QString dirPath = locateLocal( "appdata", "progress_pictures/" );
QDir dir( dirPath );
QStringList entries = dir.entryList( QDir::Files );

QStringList::ConstIterator it;
for( it = entries.begin(); it != entries.end(); ++it ) {
paths.append( dirPath + *it );
}

QString picPath = paths[ KRandom::number( paths.size() ) ];

mFullPic = QPixmap( picPath );

mCurrentPic.resize( mFullPic.size() );
mCurrentPic.fill();

mPicLabel->setPixmap( mCurrentPic );

setSummary();
mPicLabel->setPixmap( mCurrentPic );
}

void ResultViewPic::calculatePieces()
{
selectPicture();

mPieces.clear();

float aspectRatio = float( mFullPic.width() ) / float( mFullPic.height() );
Expand Down
1 change: 1 addition & 0 deletions src/resultviewpic.h
Expand Up @@ -46,6 +46,7 @@ class ResultViewPic : public ResultView

void setSummary();

void selectPicture();
void calculatePieces();

void showPiece( const QRect & );
Expand Down

0 comments on commit 3e95b55

Please sign in to comment.