/*************************************************************************** * 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 #include #include class QImage; namespace libqnono { class CNonogram; class CNonogramNumbers; class CNonogramNumbers { public: typedef QVector v_num; typedef QVector vv_num; CNonogramNumbers(const vv_num & rows, const vv_num & columns); CNonogramNumbers(const CNonogram & source); CNonogramNumbers(QSize size, bool **data); CNonogramNumbers(const QImage & image); void calcFromImage(QSize size, bool **data); bool readFromStream(QDataStream & stream); void writeToStream(QDataStream & stream); bool operator==(const CNonogramNumbers &other) const; inline const vv_num & rows() const { return m_rows; } inline const vv_num & columns() const { return m_columns; } inline QSize size() const { return QSize(m_columns.count(), m_rows.count()); } inline int width() const { return m_columns.count(); } inline int height() const { return m_rows.count(); } bool check(bool **data) const; bool check(const QImage & image) const; private: vv_num m_rows, m_columns; }; class CNonogram { public: typedef QVector NumbersVector; CNonogram(); CNonogram(QSize size); CNonogram(QImage & image); CNonogram(QDataStream & stream); CNonogram(const CNonogram &other); ~CNonogram(); CNonogram& operator=(const CNonogram &other); void loadFromImage(QImage & image); void resize(QSize size); bool readFromStream(QDataStream & stream); void writeToStream(QDataStream & stream); inline QString name() const { return m_Name; } inline void setName(QString value) { m_Name = value; } inline quint16 timeout() const { return m_Timeout; } void setTimeout(quint16 value) { m_Timeout = value; } inline QSize size() const { return m_Size; } inline int width() const { return m_Size.width(); } inline int height() const { return m_Size.height(); } inline 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]; } inline int maximumNumberCount() const { return m_MaximumNumberCount; } inline 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(); }; QDataStream & operator<<(QDataStream & stream, CNonogram & nonogram); QDataStream & operator>>(QDataStream & stream, CNonogram & nonogram); } #endif