#define GAME_VERSION 0.3
-#define EASY_PIECE_COUNT 12
-#define HARD_PIECE_COUNT 20
+#define EASY_PIECE_COUNT 9
+#define EASY_HORIZONTAL_COUNT 3
+#define HARD_PIECE_COUNT 16
+#define HARD_HORIZONTAL_COUNT 4
#define DEFAULT_IMAGE_TXT "Default image"
#define RANDOM_IMAGE_TXT "Random image"
int horizontalCount = 0;
// Find out board size
- if(pieces_.count() == 12) {
- horizontalCount = 4;
+ if(pieces_.count() == EASY_PIECE_COUNT) {
+ horizontalCount = EASY_HORIZONTAL_COUNT;
}
- else if(pieces_.count() == 20) {
- horizontalCount = 5;
+ else if(pieces_.count() == HARD_PIECE_COUNT) {
+ horizontalCount = HARD_HORIZONTAL_COUNT;
}
else {
qDebug() << "Invalid piece count @ GameView::setPieces";
pieces_.at(pieceNumber)->setPos(point);
pieces_.at(pieceNumber)->setCorrectPlace(point);
pieces_.at(pieceNumber)->setCurrentPlace(point);
+ pieces_.at(pieceNumber)->setDrawNumber(true);
pieceNumber++;
}
}
- // Wait a second
+ // Wait
QTimer::singleShot(750, this, SLOT(shufflePieces()));
}
pieces_.at(hiddenIndex_)->show();
pieces_.at(hiddenIndex_)->moveMeTo(emptyPlace_);
- // Set all pieces not movable
+ // Set all pieces not movable and hide numbers
for(int i = 0; i < pieces_.count(); ++i) {
pieces_.at(i)->setMovable(false);
+ pieces_.at(i)->setDrawNumber(false);
}
// Show dialog with move count
int horizontalCount = 0;
- if(count == 12) {
- horizontalCount = 4;
+ if(count == EASY_PIECE_COUNT) {
+ horizontalCount = EASY_HORIZONTAL_COUNT;
}
- else if(count == 20) {
- horizontalCount = 5;
+ else if(count == HARD_PIECE_COUNT) {
+ horizontalCount = HARD_HORIZONTAL_COUNT;
}
else {
+ qDebug() << QString("Bad piece count ( %1 ) @ ImageImporter::newPieces").arg(count);
return list;
}
#include <QObject>
+#include "defines.h"
+
class QPixmap;
class PuzzleItem;
public:
static ImageImporter *instance();
- QList<PuzzleItem *> newPieces(const QPixmap &pixmap, const int count = 12);
+ QList<PuzzleItem *> newPieces(const QPixmap &pixmap, const int count = EASY_PIECE_COUNT);
private:
ImageImporter(QObject *parent = 0);
movable_ = true;
moveAnimation_ = new QPropertyAnimation(this, "pos", this);
pieceNumber_ = 0;
+ drawNumber_ = true;
}
QPointF PuzzleItem::correctPlace() const
{
QGraphicsPixmapItem::paint(painter, option, widget);
- painter->save();
+ if(drawNumber_) {
+ painter->save();
- QFont font = painter->font();
- QFontMetrics metrics(font);
- QRect numberRect(0, 0, metrics.height(), metrics.height());
+ QFont font = painter->font();
+ QFontMetrics metrics(font);
+ QRect numberRect(0, 0, metrics.height(), metrics.height());
- painter->setPen(Qt::NoPen);
+ painter->setPen(Qt::NoPen);
- painter->setBrush(QColor(255, 255, 255, 192));
- painter->drawRect(numberRect);
+ painter->setBrush(QColor(255, 255, 255, 192));
+ painter->drawRect(numberRect);
- painter->setPen(Qt::black);
+ painter->setPen(Qt::black);
- QTextOption textOption;
- textOption.setAlignment(Qt::AlignCenter);
+ QTextOption textOption;
+ textOption.setAlignment(Qt::AlignCenter);
- painter->drawText(numberRect, QString::number(pieceNumber_), textOption);
+ painter->drawText(numberRect, QString::number(pieceNumber_), textOption);
- painter->restore();
+ painter->restore();
+ }
}
int PuzzleItem::pieceNumber() const
{
pieceNumber_ = pieceNumber;
}
+
+void PuzzleItem::setDrawNumber(bool value)
+{
+ if(value != drawNumber_) {
+ drawNumber_ = value;
+ update();
+ }
+}
+
+bool PuzzleItem::drawNumber() const
+{
+ return drawNumber_;
+}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
void setPieceNumber(const int pieceNumber);
int pieceNumber() const;
+ void setDrawNumber(bool value);
+ bool drawNumber() const;
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event);
QPropertyAnimation *moveAnimation_;
static int moveCount_;
int pieceNumber_;
+ bool drawNumber_;
};
#endif
#include "settings.h"
+#include "defines.h"
Settings *Settings::instance_ = 0;
Settings::Settings(QObject *parent) :
QObject(parent)
{
- pieceCount_ = 12;
+ pieceCount_ = EASY_PIECE_COUNT;
image_ = 0;
}