qt6windows7/examples/widgets/itemviews/puzzle/piecesmodel.h

46 lines
1.3 KiB
C
Raw Normal View History

2023-10-30 06:33:08 +08:00
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifndef PIECESLIST_H
#define PIECESLIST_H
#include <QAbstractListModel>
#include <QPixmap>
#include <QPoint>
#include <QStringList>
#include <QList>
QT_BEGIN_NAMESPACE
class QMimeData;
QT_END_NAMESPACE
class PiecesModel : public QAbstractListModel
{
Q_OBJECT
public:
explicit PiecesModel(int pieceSize, QObject *parent = nullptr);
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
Qt::ItemFlags flags(const QModelIndex &index) const override;
bool removeRows(int row, int count, const QModelIndex &parent) override;
bool dropMimeData(const QMimeData *data, Qt::DropAction action,
int row, int column, const QModelIndex &parent) override;
QMimeData *mimeData(const QModelIndexList &indexes) const override;
QStringList mimeTypes() const override;
int rowCount(const QModelIndex &parent) const override;
Qt::DropActions supportedDropActions() const override;
void addPiece(const QPixmap &pixmap, const QPoint &location);
void addPieces(const QPixmap &pixmap);
private:
QList<QPoint> locations;
QList<QPixmap> pixmaps;
int m_PieceSize;
};
#endif // PIECESLIST_H