qcross/qcross/ccrossfieldwidget.h

150 lines
4.2 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 CCROSSFIELDWIDGET_H
#define CCROSSFIELDWIDGET_H
#include <QWidget>
#include <QQueue>
class QLCDNumber;
class QFrame;
class QLabel;
namespace libqnono {
class CNonogram;
class CNonogramSolver;
}
namespace qcross {
enum MarkerType {CMT_UNMARKED = 0, CMT_MARKED = 1, CMT_CROSSED = 2, CMT_NONE = 3};
class CCrossFieldWidget : public QWidget {
Q_OBJECT
public:
enum MessageType {Information = 1, Warning = 2, Critical = 3, Invalid = 0};
bool isPaused() const { return m_Paused; }
bool isSolved() const { return m_Solved; }
bool isErrorAware() const { return m_ErrorAware; }
int time() const { return m_Time; }
qint32 errorCount() const { return m_ErrorCount; }
CCrossFieldWidget(libqnono::CNonogram * picture, QWidget * parent = 0);
~CCrossFieldWidget();
QPoint lastErrorMark() const { return m_LastErrorMark; }
void setPicture(libqnono::CNonogram * picture);
void showMessage(const QString message = QString(), int timeout = 0, MessageType type = Information);
void applyState(QDataStream & stream);
void dumpState(QDataStream & stream);
public slots:
void mark(int x, int y, int type);
void setTime(int value);
void setErrorAware(bool value);
void setNumbersMarkable(bool value);
void start();
void pause();
void resume();
signals:
void markError();
void solved();
void timeUp();
void timeChanged(int value);
protected:
struct Message {
MessageType type;
QString text;
int timeout;
Message() : type(Invalid), timeout(0) {}
};
QQueue<Message> m_Messages;
libqnono::CNonogram * m_Picture;
MarkerType ** m_OverlayData;
quint32 m_RemainingPixels;
int m_BoxSize;
qreal m_MarkerSize;
qreal m_MarkerOffset;
int m_OffsetX;
int m_OffsetY;
int m_HeaderWidth;
int m_HeaderHeight;
int m_RasterWidth;
int m_RasterHeight;
MarkerType m_MouseMark;
bool m_ErrorAware;
bool m_NumbersMarkable;
int m_Time;
bool m_Paused;
bool m_Solved;
int m_TimerId;
int m_MessageTimeoutId;
QLCDNumber * m_Clock;
// QFrame * m_Notifier;
// QLabel * m_NotifierIcon;
// QLabel * m_NotifierText;
qint32 m_ErrorCount;
QPoint m_LastErrorMark;
Message m_Message;
void nextMessage();
inline void initialize();
inline void cleanup();
inline void reset();
inline bool checkNoError(int x, int y);
void timerEvent(QTimerEvent * event);
inline void updateTimeDisplay();
inline void execMark(int x, int y, MarkerType & marker);
void paintEvent(QPaintEvent * event);
/* void updateCell(int x, int y);
*/
void resizeEvent(QResizeEvent * event);
void updateMetrics();
void mousePressEvent(QMouseEvent * event);
void mouseMoveEvent(QMouseEvent * event);
void mouseReleaseEvent(QMouseEvent * event);
};
}
#endif