-
Notifications
You must be signed in to change notification settings - Fork 0
/
puzzle.h
54 lines (43 loc) · 1.05 KB
/
puzzle.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
#ifndef PUZZLE_H
#define PUZZLE_H
#include <QWidget>
#include <QPoint>
#include <QVector>
#include <QPixmap>
QT_BEGIN_NAMESPACE
class QDragEnterEvent;
class QDropEvent;
class QMouseEvent;
QT_END_NAMESPACE
class Puzzle: public QWidget
{
Q_OBJECT
public:
explicit Puzzle(int size = 0, QWidget *parent = nullptr);
void clear ();
int longPiece () const;
int longImage () const;
signals:
void puzzleComplet ();
private:
struct Piece {
QPixmap pixmap;
QRect rectangle;
QPoint location;
};
int findPiece (const QRect &pieceRect ) const;
const QRect targetSquare (const QPoint &pos);
QVector<Piece> pieces;
QRect rectangleBlanc;
int inPlace;
int imageSize;
// QWidget interface
protected:
void mousePressEvent(QMouseEvent *event);
void paintEvent(QPaintEvent *event);
void dragEnterEvent(QDragEnterEvent *event);
void dragMoveEvent(QDragMoveEvent *event);
void dragLeaveEvent(QDragLeaveEvent *event);
void dropEvent(QDropEvent *event);
};
#endif // PUZZLE_H