qcross/libqnono/cnonogram.h

112 lines
3.8 KiB
C++

/***************************************************************************
* Copyright (C) 2008 by Oliver Groß *
* z.o.gross@gmx.de *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef LIBQCROSS_CMONOPICTURE_H
#define LIBQCROSS_CMONOPICTURE_H
#include <QObject>
#include <QSize>
#include <QVector>
#include <QString>
#include <QBasicTimer>
#include "nonogramproblem.h"
#include "nonogrammarker.h"
class QImage;
namespace libqnono {
class CNonogram : public QObject {
Q_OBJECT
public:
typedef QVector<quint16> NumbersVector;
explicit CNonogram(QObject *parent = 0);
void start(const NonogramProblem & problem);
const NonogramProblem & problem() const { return m_problem; }
QString name() const { return m_problem.name(); }
quint16 timeout() const { return m_problem.timeout(); }
const NonogramImage & solution() const { return m_problem.solution(); }
const NonogramNumbers & numbers() const { return m_problem.numbers(); }
const NonogramMarker & marker() const { return m_marker; }
bool valid() const { return (!size().isEmpty()) && (0 != m_problem.solution().blackPixels()); }
QSize size() const { return m_problem.size(); }
int width() const { return size().width(); }
int height() const { return size().height(); }
int time() const { return m_time; }
bool isPaused() const { return m_paused; }
bool isFinished() const { return m_finished; }
bool saveGame(QString fileName);
bool loadGame(QString fileName);
bool readFromStream(QDataStream & stream);
void writeToStream(QDataStream& stream) const;
public slots:
void setMark(int x, int y, NonogramMarker::Mark mark);
void restart();
void pause();
void resume();
void solve();
signals:
void loaded(); /* new problem/loaded savegame */
void won(int score); /* score is the current time */
void timeup();
void wrongMark(int x, int y, int penaltyTime);
void changedMark(int x, int y);
void restarted();
void paused(int time);
void resumed(int time);
void tick(int time);
protected:
virtual void timerEvent(QTimerEvent * event);
void internRestart(bool newGame);
QBasicTimer m_timer;
NonogramProblem m_problem;
NonogramMarker m_marker;
int m_markedPixels;
int m_time; /* timeout() == 0: used time, timeout() > 0: remaining time */
int m_errorCount;
bool m_preventErrors; /* (timeout() > 0) for now - must be false if timeout() == 0 */
bool m_finished, m_paused;
};
QDataStream & operator<<(QDataStream & stream, const CNonogram & nonogram);
QDataStream & operator>>(QDataStream & stream, CNonogram & nonogram);
}
#endif