File indexing completed on 2024-05-19 04:07:48

0001 /*
0002     SPDX-FileCopyrightText: 2009 Stefan Majewsky <majewsky@gmx.net>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef PALAPELI_ENGINE_BASICS_H
0008 #define PALAPELI_ENGINE_BASICS_H
0009 
0010 #include <QGraphicsObject>
0011 
0012 namespace Palapeli
0013 {
0014     //A simple QGraphicsObject subclass with the following features:
0015     //* automatically enabled qgraphicsitem_cast (template parameters are defined by the GraphicsObjectUserTypes enum)
0016     //* empty QGraphicsItem reimplementation (i.e. item does not paint anything by default)
0017     template<int userType> class GraphicsObject : public QGraphicsObject
0018     {
0019         public:
0020             GraphicsObject(bool noPainting = true)
0021             { if (noPainting) setFlag(QGraphicsItem::ItemHasNoContents); }
0022 
0023             //empty QGraphicsItem reimplementation
0024             QRectF boundingRect() const override { return QRectF(); }
0025             void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*) override {}
0026             //enable qgraphicsitem_cast
0027             enum { Type = QGraphicsItem::UserType + userType };
0028             int type() const override { return Type; }
0029     };
0030 
0031     enum GraphicsObjectUserTypes
0032     {
0033         GeneralUserType = 0,
0034         PieceUserType = 1,
0035         ConstraintVisualizerUserType = 11
0036     };
0037 
0038     typedef Palapeli::GraphicsObject<Palapeli::GeneralUserType> EmptyGraphicsObject;
0039 }
0040 
0041 #endif // PALAPELI_ENGINE_BASICS_H