KanoopGuiQt 1.3.0
Qt GUI utility library
Loading...
Searching...
No Matches
rectanglegraphicsitem.h
1#ifndef RECTANGLEGRAPHICSITEM_H
2#define RECTANGLEGRAPHICSITEM_H
3#include <QGraphicsRectItem>
4
5#include <Kanoop/gui/libkanoopgui.h>
6#include <Kanoop/geometry/point.h>
7
8class Rectangle;
9
10/**
11 * @brief QGraphicsRectItem with an application-defined type integer and center-point helpers.
12 *
13 * RectangleGraphicsItem stores a type integer (returned by type()) that allows
14 * qgraphicsitem_cast<> and scene item-type filtering to work with custom types.
15 * It also provides centerPoint() and sceneCenterPoint() convenience accessors.
16 */
17class LIBKANOOPGUI_EXPORT RectangleGraphicsItem : public QGraphicsRectItem
18{
19public:
20 /**
21 * @brief Construct with a type integer and optional parent item.
22 * @param type Application-defined graphics item type
23 * @param parent Optional parent QGraphicsItem
24 */
25 explicit RectangleGraphicsItem(int type, QGraphicsItem* parent = nullptr);
26
27 /**
28 * @brief Construct from a Rectangle geometry object.
29 * @param rect Rectangle geometry to display
30 * @param type Application-defined graphics item type
31 * @param parent Optional parent QGraphicsItem
32 */
33 explicit RectangleGraphicsItem(const Rectangle& rect, int type, QGraphicsItem* parent = nullptr);
34
35 /**
36 * @brief Return the application-defined type integer.
37 * @return Item type value
38 */
39 virtual int type() const override { return _type; }
40
41 /**
42 * @brief Return the center of the item's bounding rect in item coordinates.
43 * @return Center point in item coordinates
44 */
45 Point centerPoint() const;
46
47 /**
48 * @brief Return the center of the item's bounding rect in scene coordinates.
49 * @return Center point in scene coordinates
50 */
51 Point sceneCenterPoint() const;
52
53protected:
54 /** @brief Handle graphics item change notifications. */
55 virtual QVariant itemChange(GraphicsItemChange change, const QVariant& value) override;
56
57private:
58 int _type;
59};
60
61#endif // RECTANGLEGRAPHICSITEM_H
QGraphicsRectItem with an application-defined type integer and center-point helpers.
RectangleGraphicsItem(const Rectangle &rect, int type, QGraphicsItem *parent=nullptr)
Construct from a Rectangle geometry object.
Point centerPoint() const
Return the center of the item's bounding rect in item coordinates.
Point sceneCenterPoint() const
Return the center of the item's bounding rect in scene coordinates.
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value) override
Handle graphics item change notifications.
RectangleGraphicsItem(int type, QGraphicsItem *parent=nullptr)
Construct with a type integer and optional parent item.
virtual int type() const override
Return the application-defined type integer.