qcross/libqnono/cnonogramsolver.cpp

38 lines
815 B
C++
Raw Normal View History

2010-06-16 12:53:56 +00:00
#include "cnonogramsolver.h"
#include "cnonogram.h"
#include "nonogramsolver.h"
#include <QString>
#include <QDebug>
namespace libqnono {
CNonogramSolver::CNonogramSolver(QObject * parent)
: QObject(parent), m_Nonogram(0) {
}
2012-04-11 13:01:54 +00:00
CNonogramSolver::~CNonogramSolver() {
}
2012-04-11 13:01:54 +00:00
void CNonogramSolver::setNonogram(CNonogram * nonogram) {
m_Nonogram = nonogram;
}
2012-04-11 13:01:54 +00:00
bool CNonogramSolver::solve() {
if (!m_Nonogram) return false;
QList<NonogramImage> solutions = libqnono::solve(m_Nonogram->numbers());
if (!solutions.empty()) {
NonogramImage &sol(solutions.first());
for (int i = 0; i < m_Nonogram->width(); ++i) {
for (int j = 0; j < m_Nonogram->height(); ++j) {
emit markRequested(i, j, sol.pixel(i, j) ? CMT_MARKED : CMT_CROSSED);
}
}
return TRUE;
}
2012-04-11 13:01:54 +00:00
return FALSE;
2010-06-16 12:53:56 +00:00
}
}