2022-05-10 10:06:48 +00:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
#ifndef PUZZLEWIDGET_H
|
|
|
|
#define PUZZLEWIDGET_H
|
|
|
|
|
|
|
|
#include <QPoint>
|
|
|
|
#include <QPixmap>
|
2020-06-22 08:12:38 +00:00
|
|
|
#include <QList>
|
2011-04-27 10:05:43 +00:00
|
|
|
#include <QWidget>
|
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
class QDragEnterEvent;
|
|
|
|
class QDropEvent;
|
|
|
|
class QMouseEvent;
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
|
|
|
class PuzzleWidget : public QWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2017-08-24 09:19:21 +00:00
|
|
|
explicit PuzzleWidget(int imageSize, QWidget *parent = nullptr);
|
2011-04-27 10:05:43 +00:00
|
|
|
void clear();
|
|
|
|
|
2011-04-27 17:16:41 +00:00
|
|
|
int pieceSize() const;
|
|
|
|
int imageSize() const;
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
signals:
|
|
|
|
void puzzleCompleted();
|
|
|
|
|
|
|
|
protected:
|
2016-06-15 08:12:35 +00:00
|
|
|
void dragEnterEvent(QDragEnterEvent *event) override;
|
|
|
|
void dragLeaveEvent(QDragLeaveEvent *event) override;
|
|
|
|
void dragMoveEvent(QDragMoveEvent *event) override;
|
|
|
|
void dropEvent(QDropEvent *event) override;
|
|
|
|
void mousePressEvent(QMouseEvent *event) override;
|
|
|
|
void paintEvent(QPaintEvent *event) override;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
private:
|
2017-08-24 09:19:21 +00:00
|
|
|
struct Piece {
|
|
|
|
QPixmap pixmap;
|
|
|
|
QRect rect;
|
|
|
|
QPoint location;
|
|
|
|
};
|
|
|
|
|
|
|
|
int findPiece(const QRect &pieceRect) const;
|
2011-04-27 10:05:43 +00:00
|
|
|
const QRect targetSquare(const QPoint &position) const;
|
|
|
|
|
2020-06-22 08:12:38 +00:00
|
|
|
QList<Piece> pieces;
|
2011-04-27 10:05:43 +00:00
|
|
|
QRect highlightedRect;
|
|
|
|
int inPlace;
|
2011-04-27 17:16:41 +00:00
|
|
|
int m_ImageSize;
|
2011-04-27 10:05:43 +00:00
|
|
|
};
|
|
|
|
|
2012-11-23 13:27:50 +00:00
|
|
|
#endif // PUZZLEWIDGET_H
|