/
Sheet.h
72 lines (51 loc) · 1.68 KB
/
Sheet.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#ifndef SHEET_H_INCLUDED
#define SHEET_H_INCLUDED
#include "CellControl.h"
#include "Puzzle.h"
#include <QWidget>
#include <QGridLayout>
#include <QList>
#include <QUndoStack>
#include <memory>
class Sheet : public QWidget
{
Q_OBJECT
signals:
void modified(int index);
public:
static const int cell_size;
Sheet(QUndoStack &undo_stack, QSize grid_size = QSize(1, 1), QWidget *parent = 0);
Sheet(QUndoStack &undo_stack, const Puzzle &puzzle, QWidget *parent = 0);
const QSize &gridSize() { return grid_size; }
void setGridSize(const QSize &size);
std::unique_ptr<Puzzle> toPuzzle() const;
void fromPuzzle(const Puzzle &puzzle);
bool empty();
QUndoStack &undoStack() { return undo_stack; }
CellControl &cellAt(int n) {
return *reinterpret_cast<CellControl*>(layout()->itemAt(n)->widget()); };
const CellControl &cellAt(int n) const {
return *reinterpret_cast<CellControl*>(layout()->itemAt(n)->widget()); };
CellControl &cellAt(int r, int c) {
return cellAt(r*grid_size.width() + c); };
CellControl &cellAt(QPoint &p) {
return cellAt(p.y(), p.x()); };
void setName(QString name) { m_name = name; }
QString name() { return m_name; }
void paint(QPainter &painter);
QRect paintRect();
void setIndex(int index) { m_index = index; }
int index() { return m_index; }
void modified() { emit modified(m_index); }
protected:
void initialize();
void clear();
void setPuzzle(const Puzzle &puzzle);
private:
QString m_name;
QUndoStack &undo_stack;
QSize grid_size;
int m_index;
friend class SetPuzzleCommand;
};
#endif /* SHEET_H_INCLUDED */