Initial commit

stefan-wip
Oliver Groß 12 years ago
commit 6aa6b59c88
  1. 7
      .gitignore
  2. 30
      CMakeLists.txt
  3. 8
      libqnono/.gitignore
  4. 29
      libqnono/CMakeLists.txt
  5. 269
      libqnono/ccrosspackage.cpp
  6. 55
      libqnono/ccrosspackage.h
  7. 97
      libqnono/ccrosspackagelistmodel.cpp
  8. 55
      libqnono/ccrosspackagelistmodel.h
  9. 245
      libqnono/ccrosspackagemodel.cpp
  10. 60
      libqnono/ccrosspackagemodel.h
  11. 133
      libqnono/cnonogram.cpp
  12. 84
      libqnono/cnonogram.h
  13. 65
      libqnono/cnonogramsolver.cpp
  14. 39
      libqnono/cnonogramsolver.h
  15. 28
      libqnono/constants.h
  16. 13
      qcross/.gitignore
  17. 58
      qcross/CMakeLists.txt
  18. 340
      qcross/COPYING
  19. 632
      qcross/ccrossfieldwidget.cpp
  20. 145
      qcross/ccrossfieldwidget.h
  21. 175
      qcross/cgamewindow.cpp
  22. 70
      qcross/cgamewindow.h
  23. 77
      qcross/chighscore.cpp
  24. 44
      qcross/chighscore.h
  25. 102
      qcross/cmaskedcrosspackagemodel.cpp
  26. 64
      qcross/cmaskedcrosspackagemodel.h
  27. 184
      qcross/cnewgamedialog.cpp
  28. 65
      qcross/cnewgamedialog.h
  29. 58
      qcross/common.cpp
  30. 23
      qcross/common.h
  31. 28
      qcross/constants.h
  32. 4
      qcross/debug.xbm
  33. 47
      qcross/main.cpp
  34. 9
      qcross/pic.xbm
  35. 29
      qcross/pic.xpm
  36. 5
      qcross/pic2.xbm
  37. 9
      qcross/pic_bak.xbm
  38. 150
      qcross/picselect.ui
  39. 7
      qcrossedit/.gitignore
  40. 47
      qcrossedit/CMakeLists.txt
  41. 340
      qcrossedit/COPYING
  42. 200
      qcrossedit/cmainwindow.cpp
  43. 62
      qcrossedit/cmainwindow.h
  44. 49
      qcrossedit/main.cpp

7
.gitignore vendored

@ -0,0 +1,7 @@
build
Makefile*
ui
moc_*
qcrosssuite.kde*
qcrosssuite.pro.*
Doxyfile

@ -0,0 +1,30 @@
project(qcrosssuite)
cmake_minimum_required(VERSION 2.8)
MACRO(ADD_TARGET_PROPERTIES _target _name)
SET(_properties)
FOREACH(_prop ${ARGN})
SET(_properties "${_properties} ${_prop}")
ENDFOREACH(_prop)
GET_TARGET_PROPERTY(_old_properties ${_target} ${_name})
MESSAGE(STATUS "adding property to ${_target} ${_name}:" ${_properties})
IF(NOT _old_properties)
# in case it's NOTFOUND
SET(_old_properties)
ENDIF(NOT _old_properties)
SET_TARGET_PROPERTIES(${_target} PROPERTIES ${_name} "${_old_properties} ${_properties}")
ENDMACRO(ADD_TARGET_PROPERTIES)
set(DEBUG_FLAGS "-Wall -Wno-long-long -pedantic")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${DEBUG_FLAGS}")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} ${DEBUG_FLAGS}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${DEBUG_FLAGS}")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${DEBUG_FLAGS}")
add_subdirectory(libqnono libqcross)
add_subdirectory(qcross qcross)
add_dependencies(qcross qnono)
add_subdirectory(qcrossedit qcrossedit)
add_dependencies(qcrossedit qnono)

@ -0,0 +1,8 @@
build
Makefile*
ui
moc_*
libqcross.a
libqcross.so*
Doxyfile
libqcross.pro.*

@ -0,0 +1,29 @@
project(qnono)
cmake_minimum_required(VERSION 2.8)
find_package(Qt4 COMPONENTS QtCore QtGui REQUIRED)
include_directories(${QT_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR})
include(${QT_USE_FILE})
set(SOURCES_MOC_H
cnonogramsolver.h
ccrosspackagemodel.h
ccrosspackagelistmodel.h
)
set(SOURCES_CPP
cnonogram.cpp
cnonogramsolver.cpp
ccrosspackage.cpp
ccrosspackagemodel.cpp
ccrosspackagelistmodel.cpp
)
qt4_wrap_cpp(SOURCES_MOC_CPP ${SOURCES_MOC_H})
add_library(${PROJECT_NAME} STATIC ${SOURCES_CPP} ${SOURCES_MOC_CPP})
target_link_libraries(${PROJECT_NAME}
${QT_LIBRARIES}
)

@ -0,0 +1,269 @@
/***************************************************************************
* 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. *
***************************************************************************/
#include "ccrosspackage.h"
#include "cnonogram.h"
#include <QDataStream>
#include <QFile>
namespace libqcross {
//public:
CCrossPackage::CCrossPackage() {}
CCrossPackage::CCrossPackage(QString fileName) : m_FileName(fileName) {}
CCrossPackage::~CCrossPackage() {
foreach (CNonogram * i, m_PictureList) {
delete i;
}
}
bool CCrossPackage::open() {
if (m_FileName.isEmpty())
return false;
qDebug("opening file: %s", m_FileName.toAscii().data());
QFile file(m_FileName);
if (!file.open(QIODevice::ReadOnly))
return false;
QDataStream in(&file);
in.setVersion(QDataStream::Qt_4_0);
QString stringBuffer;
// qint32 intBuffer;
QSize sizeBuffer;
// CNonogram * newPicture = NULL;
// qint32 pictureCount = 0;
if (in.atEnd()) {
qCritical("invalid package file - no header");
file.close();
return false;
}
in >> stringBuffer;
if ((stringBuffer != "QCROSSPACKAGE")) {
qCritical("invalid package file - invalid header: %s", stringBuffer.toAscii().data());
file.close();
return false;
}
if (in.atEnd()) {
qCritical("invalid package file - no package name");
file.close();
return false;
}
in >> m_Name;
file.close();
return true;
}
bool CCrossPackage::readAll() {
if (m_FileName.isEmpty())
return false;
qDebug("reading file: %s", m_FileName.toAscii().data());
QFile file(m_FileName);
if (!file.open(QIODevice::ReadOnly))
return false;
m_PictureList.clear();
QDataStream in(&file);
in.setVersion(QDataStream::Qt_4_0);
QString stringBuffer;
qint32 intBuffer;
QSize sizeBuffer;
CNonogram * newPicture = NULL;
qint32 pictureCount = 0;
if (in.atEnd()) {
qCritical("invalid package file - no header");
file.close();
return false;
}
in >> stringBuffer;
if ((stringBuffer != "QCROSSPACKAGE")) {
qCritical("invalid package file - invalid header: %s", stringBuffer.toAscii().data());
file.close();
return false;
}
if (in.atEnd()) {
qCritical("invalid package file - no package name");
file.close();
return false;
}
in >> stringBuffer;
if (in.atEnd()) {
qCritical("invalid package file - no picture count");
file.close();
return false;
}
in >> pictureCount;
unsigned char data;
int i;
for (i = 0; i < pictureCount && !in.atEnd(); i++) {
in >> stringBuffer;
qDebug("reading image: %s", stringBuffer.toAscii().data());
if (in.atEnd()) {
qCritical("invalid package file - no picture name");
file.close();
return false;
}
in >> intBuffer;
qDebug("width %i", intBuffer);
if (in.atEnd()) {
qCritical("invalid package file - no picture width");
file.close();
return false;
}
sizeBuffer.setWidth(intBuffer);
in >> intBuffer;
qDebug("height %i", intBuffer);
if (in.atEnd()) {
qCritical("invalid package file - no picture height");
file.close();
return false;
}
sizeBuffer.setHeight(intBuffer);
newPicture = new CNonogram(sizeBuffer);
newPicture->setName(stringBuffer);
in >> intBuffer;
qDebug("timeout %i", intBuffer);
if (in.atEnd()) {
qCritical("invalid package file - no picture timeout");
delete newPicture;
file.close();
return false;
}
newPicture->setTimeout(intBuffer);
for (int x = 0; x < sizeBuffer.width(); x++) {
int y = 0;
while (y < sizeBuffer.height()) {
if (in.atEnd()) {
qCritical("invalid package file - data");
delete newPicture;
file.close();
return false;
}
in.readRawData((char *)&data, 1);
int b;
for (b = 0; b < 8; b++) {
if (y < sizeBuffer.height())
newPicture->setPixel(x, y, (bool)(data & 0x80));
data = data << 1;
y++;
}
// out.writeRawData((char *)&data, 1);
// newPicture->setPixel(x, y, (bool)(data & 0x80));
// data = data << 1;
// y++;
// if (!(y % 8))
// in.readRawData((char *)&data, 1);
}
}
m_PictureList << newPicture;
}
if (i < pictureCount)
qWarning("damaged package file - invalid picture count");
file.close();
return true;
}
bool CCrossPackage::save() {
QFile file(m_FileName);
if (!file.open(QIODevice::WriteOnly))
return false;
QDataStream out(&file);
out.setVersion(QDataStream::Qt_4_0);
out << QString("QCROSSPACKAGE");
out << m_Name;
out << (qint32)(m_PictureList.size());
unsigned char data = 0;
foreach (CNonogram * i, m_PictureList) {
out << i->name();
out << (qint32)i->width();
out << (qint32)i->height();
out << (qint32)i->timeout();
for (int x = 0; x < i->width(); x++) {
data = 0x00;
int y = 0;
while (y < i->height()) {
int b;
for (b = 0; b < 8; b++) {
data = data << 1;
if (y < i->height() && i->pixel(x, y))
data |= 0x01;
y++;
}
out.writeRawData((char *)&data, 1);
// if (i->pixel(x, y))
// data |= 0x01;
//
// y++;
// if (!(y % 8)) {
// out.writeRawData((char *)&data, 1);
// data = 0x00;
// }
//
// data = data << 1;
}
// if (y % 8)
// out.writeRawData((char *)&data, 1);
}
}
file.close();
return true;
}
}

@ -0,0 +1,55 @@
/***************************************************************************
* 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_CCROSSPACKAGE_H
#define LIBQCROSS_CCROSSPACKAGE_H
#include <QString>
#include <QList>
namespace libqcross {
class CNonogram;
typedef QList<CNonogram *> QMonoPictureList;
class CCrossPackage {
public:
CCrossPackage();
CCrossPackage(QString fileName);
~CCrossPackage();
virtual void setFileName(QString & value) { m_FileName = value; }
QString fileName() const { return m_FileName; }
void setName(QString value) { m_Name = value; }
QString name() const { return m_Name; }
virtual bool open();
virtual bool readAll();
virtual bool save();
QMonoPictureList & pictures() { return m_PictureList; }
private:
QMonoPictureList m_PictureList;
QString m_FileName;
QString m_Name;
};
}
#endif

@ -0,0 +1,97 @@
/***************************************************************************
* 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. *
***************************************************************************/
#include <QDir>
#include "ccrosspackage.h"
#include "cnonogram.h"
#include "ccrosspackagelistmodel.h"
namespace libqcross {
//public:
CCrossPackageListModel::CCrossPackageListModel(QString dataPath, QObject * parent) : QAbstractItemModel(parent),
m_DataPath(dataPath) {
update();
}
CCrossPackageListModel::~CCrossPackageListModel() {
foreach (CCrossPackage * i, m_PackageList)
delete i;
}
void CCrossPackageListModel::update() {
foreach (CCrossPackage * i, m_PackageList)
delete i;
m_PackageList.clear();
CCrossPackage * newPackage;
QDir workDir(m_DataPath);
QStringList fileNames = workDir.entryList(QStringList("*.cpk"), QDir::Files | QDir::NoDotAndDotDot, QDir::Name);
foreach (QString fileName, fileNames) {
newPackage = new CCrossPackage(workDir.filePath(fileName));
if (newPackage->open())
m_PackageList << newPackage;
else
delete newPackage;
}
reset();
}
QModelIndex CCrossPackageListModel::index(int row, int column, const QModelIndex & /*parent*/) const {
return (column > 0) || (row < 0) || (row >= m_PackageList.size()) ?
QModelIndex() :
createIndex(row, column, static_cast<void *>(m_PackageList[row]));
}
QVariant CCrossPackageListModel::data(const QModelIndex & index, int role) const {
if (!index.isValid())
return QVariant();
if (role == Qt::DisplayRole)
return static_cast<CCrossPackage *>(index.internalPointer())->name();
else
return QVariant();
}
int CCrossPackageListModel::rowCount(const QModelIndex & /*parent*/) const {
return m_PackageList.size();
}
int CCrossPackageListModel::columnCount(const QModelIndex & /*parent*/) const {
return 1;
}
QVariant CCrossPackageListModel::headerData(int /*section*/, Qt::Orientation /*orientation*/, int /*role*/) const {
return QVariant();
}
// Qt::ItemFlags CCrossPackageListModel::flags(const QModelIndex & index) const {
// return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
// }
QModelIndex CCrossPackageListModel::parent(const QModelIndex &) const {
return QModelIndex();
}
bool CCrossPackageListModel::hasChildren(const QModelIndex & parent) const {
return !parent.isValid();
}
}

@ -0,0 +1,55 @@
/***************************************************************************
* 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 LIBCCROSS_CCROSSPACKAGELISTMODEL_H
#define LIBCCROSS_CCROSSPACKAGELISTMODEL_H
#include <QAbstractItemModel>
#include <QList>
namespace libqcross {
class CCrossPackage;
/**
@author Oliver Groß <z.o.gross@gmx.de>
*/
class CCrossPackageListModel : public QAbstractItemModel {
Q_OBJECT
public:
CCrossPackageListModel(QString dataPath, QObject * parent = 0);
~CCrossPackageListModel();
void update();
virtual QModelIndex index(int row, int column = 0, const QModelIndex & parent = QModelIndex()) const;
virtual QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
virtual int rowCount(const QModelIndex & parent = QModelIndex()) const;
virtual int columnCount(const QModelIndex & parent = QModelIndex()) const;
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
// virtual Qt::ItemFlags flags(const QModelIndex & index) const;
virtual QModelIndex parent(const QModelIndex & index) const;
virtual bool hasChildren(const QModelIndex & parent = QModelIndex()) const;
private:
QString m_DataPath;
QList<libqcross::CCrossPackage *> m_PackageList;
};
}
#endif

@ -0,0 +1,245 @@
/***************************************************************************
* 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. *
***************************************************************************/
#include <QImage>
#include <QIcon>
#include "ccrosspackage.h"
#include "cnonogram.h"
#include "ccrosspackagemodel.h"
#include "constants.h"
#define COL_NAME 0
#define COL_TIME 1
namespace libqcross {
QString formatedTime(quint32 seconds, bool showSeconds = false) {
quint32 strippedSeconds = seconds % 60;
quint8 minutes = seconds / 60;
quint8 hours = minutes / 60;
QString result;
if (hours) {
if (hours < 10)
result += '0';
result += QString::number(hours);
result += ':';
}
minutes %= 60;
if (minutes < 10)
result += '0';
result += QString::number(minutes);
if (showSeconds) {
result += ':';
if (strippedSeconds < 10)
result += '0';
result += QString::number(strippedSeconds);
}
return result;
}
//public:
CCrossPackageModel::CCrossPackageModel(QObject * parent) : QAbstractItemModel(parent),
m_Package(NULL) {
}
CCrossPackageModel::~CCrossPackageModel() {
setPackage(NULL);
}
void CCrossPackageModel::setPackage(libqcross::CCrossPackage * package) {
if (m_Package)
m_Package->pictures().clear();
m_Package = package;
if (m_Package && m_Package->pictures().isEmpty())
m_Package->readAll();
reset();
}
QModelIndex CCrossPackageModel::index(int row, int column, const QModelIndex & /*parent*/) const {
return (m_Package) && (column >= 0) && (row >= 0) && (row < m_Package->pictures().size()) ?
createIndex(row, column, static_cast<void *>(m_Package->pictures()[row])) :
QModelIndex();
}
QVariant CCrossPackageModel::data(const QModelIndex & index, int role) const {
if (!index.isValid())
return QVariant();
switch (index.column()) {
case COL_NAME:
switch (role) {
case Qt::DecorationRole:
return static_cast<CNonogram *>(index.internalPointer())->timeout() ?
QIcon(LIBQCROSS_ICON_TIMEOUT) :
QIcon(LIBQCROSS_ICON_TIMETRIAL);
case Qt::EditRole:
case Qt::DisplayRole:
return static_cast<CNonogram *>(index.internalPointer())->name();
default:
break;
}
break;
case COL_TIME:
if (role == Qt::DisplayRole)
return formatedTime(static_cast<CNonogram *>(index.internalPointer())->timeout());
break;
default:
break;
}
return QVariant();
}
int CCrossPackageModel::rowCount(const QModelIndex & parent) const {
if (m_Package && !parent.isValid())
return m_Package->pictures().size();
else
return 0;
}
int CCrossPackageModel::columnCount(const QModelIndex & /*parent*/) const {
return 2;
}
QVariant CCrossPackageModel::headerData(int section, Qt::Orientation /*orientation*/, int role) const {
if (role == Qt::DisplayRole) {
switch (section) {
case COL_NAME:
return tr("Nonogram");
case COL_TIME:
return tr("Time");
default:
break;
}
}
return QVariant();
}
Qt::ItemFlags CCrossPackageModel::flags(const QModelIndex & index) const {
if (index.column() == COL_NAME)
return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
else
return QAbstractItemModel::flags(index);
}
QModelIndex CCrossPackageModel::parent(const QModelIndex &) const {
return QModelIndex();
}
bool CCrossPackageModel::hasChildren(const QModelIndex & parent) const {
return m_Package && !parent.isValid();
}
bool CCrossPackageModel::setData(const QModelIndex & index, const QVariant & value, int role) {
if (index.isValid() && role == Qt::EditRole) {
QString name = value.toString();
if (name.isEmpty())
return false;
foreach (CNonogram * i, m_Package->pictures()) {
if (i->name() == name)
return false;
}
m_Package->pictures()[index.row()]->setName(name);
emit dataChanged(index, index);
return true;
}
return false;
}
bool CCrossPackageModel::appendEmpty(QString name, QSize size, bool fillValue) {
if (!m_Package)
return false;
beginInsertRows(QModelIndex(), m_Package->pictures().size(), 1);
CNonogram * newNonogram = new CNonogram(size);
newNonogram->fill(fillValue);
newNonogram->setName(name);
m_Package->pictures() << newNonogram;
endInsertRows();
return true;
}
bool CCrossPackageModel::appendImage(QString name, QImage image) {
if (!m_Package)
return false;
CNonogram * newNonogram = new CNonogram();
newNonogram->loadFromImage(image);
newNonogram->setName(name);
newNonogram->setTimeout(60*60); // set an hour as default timeout
if (newNonogram->isValid()) {
beginInsertRows(QModelIndex(), m_Package->pictures().size(), 1);
m_Package->pictures() << newNonogram;
endInsertRows();
return true;
}
else {
delete newNonogram;
return false;
}
}
bool CCrossPackageModel::insertRows(int row, int count, const QModelIndex & parent) {
if (!m_Package)
return false;
beginInsertRows(parent, row, count);
CNonogram * newNonogram;
for (int i = row; i < row+count; ++i) {
newNonogram = new CNonogram();
newNonogram->fill(false);
m_Package->pictures() << newNonogram;
}
endInsertRows();
return true;
}
bool CCrossPackageModel::removeRows(int row, int count, const QModelIndex & parent) {
if (!m_Package)
return false;
beginRemoveRows(parent, row, row+count-1);
for (int i = row; i < row+count; ++i)
delete m_Package->pictures().takeAt(i);
endRemoveRows();
return true;
}
}

@ -0,0 +1,60 @@
/***************************************************************************
* 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_CCROSSPACKAGEMODEL_H
#define LIBQCROSS_CCROSSPACKAGEMODEL_H
#include <QAbstractItemModel>
namespace libqcross {
class CCrossPackage;
/**
@author Oliver Groß <z.o.gross@gmx.de>
*/
class CCrossPackageModel : public QAbstractItemModel {
Q_OBJECT
public:
CCrossPackageModel(QObject * parent = 0);
~CCrossPackageModel();
void setPackage(libqcross::CCrossPackage * package);
virtual QModelIndex index(int row, int column = 0, const QModelIndex & parent = QModelIndex()) const;
virtual QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
virtual int rowCount(const QModelIndex & parent = QModelIndex()) const;
virtual int columnCount(const QModelIndex & parent = QModelIndex()) const;
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
virtual Qt::ItemFlags flags(const QModelIndex & index) const;
virtual QModelIndex parent(const QModelIndex & index) const;
virtual bool hasChildren(const QModelIndex & parent = QModelIndex()) const;
virtual bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole);
bool appendEmpty(QString name, QSize size, bool fillValue);
bool appendImage(QString name, QImage image);
virtual bool insertRows(int row, int count, const QModelIndex & parent = QModelIndex());
virtual bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex());
protected:
libqcross::CCrossPackage * m_Package;
};
}
#endif

@ -0,0 +1,133 @@
/***************************************************************************
* 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. *
***************************************************************************/
#include "cnonogram.h"
#include <QImage>
namespace libqcross {
CNonogram::CNonogram()
: m_Size(0, 0),
m_Data(NULL),
m_Timeout(0),
m_MaximumNumberCount(0) {
}
CNonogram::CNonogram(QSize size) : m_Size(size), m_MaximumNumberCount(0) {
init();
}
CNonogram::~CNonogram() {
cleanup();
}
void CNonogram::loadFromImage(QImage & image) {
if (image.isNull())
return;
resize(image.size());
for (int i = 0; i < m_Size.width(); i++)
for (int j = 0; j < m_Size.height(); j++)
m_Data[i][j] = !(image.pixel(i, j) & 0x00FFFFFF);
}
void CNonogram::resize(QSize size) {
if (m_Data)
cleanup();
m_Size = size;
init();
}
void CNonogram::setPixel(int x, int y, bool value) {
m_Data[x][y] = value;
}
void CNonogram::updateNumbers() {
m_BlackPixels = 0;
int pixelCount;
m_MaximumNumberCount = 0;
for (int i = 0; i < m_Size.height(); i++) {
m_RowNumbers[i].clear();
pixelCount = 0;
for (int j = 0; j < m_Size.width(); j++) {
if (m_Data[j][i]) {
pixelCount++;
m_BlackPixels++;
}
else if (pixelCount) {
m_RowNumbers[i] << pixelCount;
pixelCount = 0;
}
}
if (pixelCount || m_RowNumbers[i].empty())
m_RowNumbers[i] << pixelCount;
if (m_RowNumbers[i].count() > m_MaximumNumberCount)
m_MaximumNumberCount = m_RowNumbers[i].count();
}
for (int j = 0; j < m_Size.width(); j++) {
m_ColumnNumbers[j].clear();
pixelCount = 0;
for (int i = 0; i < m_Size.height(); i++) {
if (m_Data[j][i]) {
pixelCount++;
}
else if (pixelCount) {
m_ColumnNumbers[j] << pixelCount;
pixelCount = 0;
}
}
if (pixelCount || m_ColumnNumbers[j].empty())
m_ColumnNumbers[j] << pixelCount;
if (m_ColumnNumbers[j].count() > m_MaximumNumberCount)
m_MaximumNumberCount = m_ColumnNumbers[j].count();
}
}
void CNonogram::fill(bool value) {
for (int i = 0; i < m_Size.width(); i++)
for (int j = 0; j < m_Size.height(); j++)
m_Data[i][j] = value;
}
void CNonogram::cleanup() {
delete[] m_RowNumbers;
delete[] m_ColumnNumbers;
for (int i = 0; i < m_Size.width(); i++)
delete[] m_Data[i];
delete[] m_Data;
m_Data = NULL;
}
void CNonogram::init() {
m_Data = new bool *[m_Size.width()];
for (int i = 0; i < m_Size.width(); i++)
m_Data[i] = new bool[m_Size.height()];
m_RowNumbers = new NumbersVector[m_Size.height()];
m_ColumnNumbers = new NumbersVector[m_Size.width()];
}
}

@ -0,0 +1,84 @@
/***************************************************************************
* 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 <QSize>
#include <QVector>
#include <QString>
class QImage;
namespace libqcross {
class CNonogram {
public:
typedef QVector<quint16> NumbersVector;
CNonogram();
CNonogram(QSize size);
~CNonogram();
void loadFromImage(QImage & image);
void resize(QSize size);
QString name() const { return m_Name; }
void setName(QString value) { m_Name = value; }
quint16 timeout() const { return m_Timeout; }
void setTimeout(quint16 value) { m_Timeout = value; }
int width() const { return m_Size.width(); }
int height() const { return m_Size.height(); }
bool pixel(int x, int y) const { return m_Data[x][y]; }
void setPixel(int x, int y, bool value);
NumbersVector & rowNumbers(int index) const { return m_RowNumbers[index]; }
NumbersVector & columnNumbers(int index) const { return m_ColumnNumbers[index]; }
int maximumNumberCount() const { return m_MaximumNumberCount; }
quint32 blackPixels() const { return m_BlackPixels; }
void updateNumbers();
void fill(bool value);
bool isValid() const { return m_Data; }
protected:
QSize m_Size;
bool ** m_Data;
QString m_Name;
quint16 m_Timeout;
NumbersVector * m_RowNumbers;
NumbersVector * m_ColumnNumbers;
quint32 m_BlackPixels;
int m_MaximumNumberCount;
void cleanup();
void init();
};
}
#endif

@ -0,0 +1,65 @@
#include "cnonogramsolver.h"
#include "cnonogram.h"
namespace libqcross {
CNonogramSolver::CNonogramSolver(QObject * parent) : QObject(parent), m_Nonogram(NULL), m_OverlayData(NULL) {
}
CNonogramSolver::~CNonogramSolver() {
cleanup();
}
bool CNonogramSolver::solve() {
if (!m_Nonogram)
return false;
cleanup();
m_OverlayData = new int *[m_Nonogram->width()];
for (int i = 0; i < m_Nonogram->width(); i++) {
m_OverlayData[i] = new int[m_Nonogram->height()];
for (int j = 0; j < m_Nonogram->height(); j++)
m_OverlayData[i][j] = 0;
}
for (int i = 0; i < m_Nonogram->height(); i++)
solveRow(i);
return false;
}
void CNonogramSolver::cleanup() {
if (m_OverlayData && m_Nonogram) {
for (int i = 0; i < m_Nonogram->width(); i++)
delete[] m_OverlayData[i];
delete[] m_OverlayData;
}
}
bool CNonogramSolver::solveRow(int /*y*/) {
return false;
// int left = 0;
// int right = m_Nonogram->width()-1;
//
// foreach (int k, m_Nonogram->rowNumbers(y)) {
// if (k == m_Nonogram->width())
// for (int i = 0; )
// m_OverlayData[i][y] = 1;
// }
//
// while (m_OverlayData[right][y] && left < right)
// right++;
//
// if (left == right)
// return true;
//
// if (m_Nonogram->rowNumbers(y)[0] == 0)
// for (int i = left; i <= right; i++)
// m_OverlayData[i][y] = MT_CROSSED;
//
// foreach (int k, m_Nonogram->rowNumbers(y)) {
//
// }
}
}

@ -0,0 +1,39 @@
#ifndef LIBQCROSS_CNONOGRAMSOLVER_H
#define LIBQCROSS_CNONOGRAMSOLVER_H
#include <QObject>
namespace libqcross {
class CNonogram;
class CNonogramSolver : public QObject {
Q_OBJECT
public:
CNonogramSolver(QObject * parent = 0);
~CNonogramSolver();
void setNonogram(CNonogram * nonogram) { m_Nonogram = nonogram; }
bool solve();
signals:
void markRequested(int x, int y, int type);
protected:
// struct Range {
// int left;
// int right;
//
// Range() : left(-1), right(-1) {}
// bool isNULL() { return left == -1; }
// };
CNonogram * m_Nonogram;
int ** m_OverlayData;
void cleanup();
bool solveRow(int y);
bool solveColumn(int x);
};
}
#endif

@ -0,0 +1,28 @@
/***************************************************************************
* 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_CONSTANTS_H
#define LIBQCROSS_CONSTANTS_H
#define LIBQCROSS_STRING_ICONPATH "/usr/share/qcross/icons/"
#define LIBQCROSS_ICON_TIMEOUT LIBQCROSS_STRING_ICONPATH "timeout.png"
#define LIBQCROSS_ICON_TIMETRIAL LIBQCROSS_STRING_ICONPATH "timetrial.png"
#endif // CONSTANTS_H

13
qcross/.gitignore vendored

@ -0,0 +1,13 @@
build
Makefile*
ui
moc_*
fp
qnut
qnut_debug
qnut.kde*
Doxyfile
qnut.log
qnut.conf
.qnut
backup

@ -0,0 +1,58 @@
project(qcross)
cmake_minimum_required(VERSION 2.8)
find_package(Qt4 COMPONENTS QtCore QtGui REQUIRED)
include_directories(${QT_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR})
include(${QT_USE_FILE})
set(INSTALL_SHARE_PREFIX ${CMAKE_INSTALL_PREFIX}/share)
set(INSTALL_SHARE_TARGET_PREFIX ${INSTALL_SHARE_PREFIX}/${PROJECT_NAME})
set(FORMS
picselect.ui
)
set(SOURCES_MOC_H
ccrossfieldwidget.h
cgamewindow.h
cnewgamedialog.h
cmaskedcrosspackagemodel.h
)
set(SOURCES_CPP main.cpp
ccrossfieldwidget.cpp
cgamewindow.cpp
cnewgamedialog.cpp
cmaskedcrosspackagemodel.cpp
common.cpp
chighscore.cpp
)
# set(TRANSLATIONS_TS ${PROJECT_NAME}_de.ts)
qt4_wrap_ui(FORMS_H ${FORMS})
qt4_wrap_cpp(SOURCES_MOC_CPP ${SOURCES_MOC_H})
# qt4_add_translation(TRANSLATIONS_QM ${TRANSLATIONS_TS})
add_executable(${PROJECT_NAME}
${SOURCES_CPP}
${SOURCES_MOC_CPP}
${SOURCES_H}
${FORMS_H}
# ${TRANSLATIONS_QM}
)
target_link_libraries(${PROJECT_NAME}
${qnono_BINARY_DIR}/libqnono.a
${QT_QTCORE_LIBRARY}
${QT_QTGUI_LIBRARY}
${QT_QTNETWORK_LIBRARY}
)
# file(GLOB RES_ICONS res/*.png res/qnut.svg res/qnut_small.svg)
install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
# install(FILES ${TRANSLATIONS_QM} DESTINATION ${INSTALL_SHARE_TARGET_PREFIX}/lang)
# install(FILES ${RES_ICONS} DESTINATION ${INSTALL_SHARE_TARGET_PREFIX}/icons)
# install(FILES ${PROJECT_NAME}.desktop DESTINATION ${INSTALL_SHARE_PREFIX}/applications)

@ -0,0 +1,340 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure