/
visual.h
109 lines (82 loc) · 1.89 KB
/
visual.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
* visual.h
*
* Created on: 23.08.2009
* Author: dmitry
*/
#ifndef VISUAL_H_
#define VISUAL_H_
#include <vector>
#include <list>
#include <QtGui>
#include "scorepanelitem.h"
#include "cell_item.h"
struct MoveLog
{
enum MovePhase
{
MOVE_PHASE_NOT_STARTED,
MOVE_PHASE_STARTED,
MOVE_PHASE_WAIT_FOR_CHAR,
MOVE_PHASE_ENTER_WORD,
MOVE_PHASE_CLOSE_WORD
};
// Current phase
MovePhase phase;
// The list of items in the order they are added
QList<CellItem*> cells;
// Added char
CellItem* added_char;
};
class TextWidget : public QGraphicsWidget
{
Q_OBJECT
public:
TextWidget(const QString& text, QGraphicsItem* parent);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
void mousePressEvent (QGraphicsSceneMouseEvent * event );
public slots:
void addChar(QChar c);
void setText(const QString& s);
signals:
void clicked();
private:
QString text;
QColor color;
};
class BoardItem: public QGraphicsWidget
{
Q_OBJECT
public:
BoardItem(QGraphicsItem* parent_item);
~BoardItem();
QList<CellItem*> getAjacentsCells(CellItem* cell);
QString getCurrentWord();
bool validateWord(const QString& str);
public slots:
void prepareBeforeMove();
void markBeforeSelect();
void makeMove();
void makeAutoMove();
void reMove();
void closeMove();
void setCenterWord(QString str);
void setHelpText();
signals:
void tryComplete();
void currentWordChanged(const QString& str);
void stateChanged();
private:
bool eventFilter(QObject *obj, QEvent *event);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
// Visual settings
qreal opacity;
QPixmap image;
TextWidget* help_test;
int rows, columns;
// Cells
QVector< QVector<CellItem *> > cells;
ScorePanelItem *score;
MoveLog log;
};
#endif /* VISUAL_H_ */