Initial commit

This commit is contained in:
Oliver Groß 2010-06-16 14:53:56 +02:00
commit 6aa6b59c88
44 changed files with 4240 additions and 0 deletions

7
.gitignore vendored Normal file
View File

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

30
CMakeLists.txt Normal file
View File

@ -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)

8
libqnono/.gitignore vendored Normal file
View File

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

29
libqnono/CMakeLists.txt Normal file
View File

@ -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}
)

269
libqnono/ccrosspackage.cpp Normal file
View File

@ -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;
}
}

55
libqnono/ccrosspackage.h Normal file
View File

@ -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

View File

@ -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();
}
}

View File

@ -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

View File

@ -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;
}
}

View File

@ -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

133
libqnono/cnonogram.cpp Normal file
View File

@ -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()];
}
}

84
libqnono/cnonogram.h Normal file
View File

@ -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

View File

@ -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)) {
//
// }
}
}

View File

@ -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

28
libqnono/constants.h Normal file
View File

@ -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 Normal file
View File

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

58
qcross/CMakeLists.txt Normal file
View File

@ -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)

340
qcross/COPYING Normal file
View File

@ -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 that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of