KanoopGuiQt 1.3.0
Qt GUI utility library
Loading...
Searching...
No Matches
linegraphicsitem.h
1#ifndef LINEGRAPHICSITEM_H
2#define LINEGRAPHICSITEM_H
3#include <QGraphicsLineItem>
4#include <Kanoop/gui/libkanoopgui.h>
5
6class Line;
7
8/**
9 * @brief QGraphicsLineItem with an application-defined type integer and appearance helpers.
10 *
11 * LineGraphicsItem stores a type integer (returned by type()) that allows
12 * qgraphicsitem_cast<> and scene item-type filtering to work with custom types.
13 * It also provides helpers for changing pen width, color, and line length.
14 */
15class LIBKANOOPGUI_EXPORT LineGraphicsItem : public QGraphicsLineItem
16{
17public:
18 /**
19 * @brief Construct with a type integer and optional parent item.
20 * @param type Application-defined graphics item type
21 * @param parent Optional parent QGraphicsItem
22 */
23 LineGraphicsItem(int type, QGraphicsItem* parent = nullptr);
24
25 /**
26 * @brief Construct from a Line geometry object, with a type integer and optional parent.
27 * @param line Line geometry to display
28 * @param type Application-defined graphics item type
29 * @param parent Optional parent QGraphicsItem
30 */
31 LineGraphicsItem(const Line& line, int type, QGraphicsItem* parent = nullptr);
32
33 /**
34 * @brief Return the application-defined type integer.
35 * @return Item type value
36 */
37 virtual int type() const override { return _type; }
38
39 /**
40 * @brief Set the pen width.
41 * @param width Pen width in scene units
42 */
43 void setWidth(double width);
44
45 /**
46 * @brief Set the pen color.
47 * @param color Color to apply to the pen
48 */
49 void setColor(const QColor& color);
50
51 /**
52 * @brief Return the bounding rectangle (expanded to account for pen width).
53 * @return Bounding rect in item coordinates
54 */
55 virtual QRectF boundingRect() const override;
56
57 /**
58 * @brief Return the shape used for hit testing.
59 * @return Painter path representing the clickable area
60 */
61 virtual QPainterPath shape() const override;
62
63 /**
64 * @brief Set the length of the line, extending from its current start point.
65 * @param length New length in scene units
66 */
67 void setLength(double length);
68
69private:
70 int _type;
71};
72
73#endif // LINEGRAPHICSITEM_H
QGraphicsLineItem with an application-defined type integer and appearance helpers.
void setColor(const QColor &color)
Set the pen color.
virtual QPainterPath shape() const override
Return the shape used for hit testing.
void setLength(double length)
Set the length of the line, extending from its current start point.
virtual int type() const override
Return the application-defined type integer.
void setWidth(double width)
Set the pen width.
virtual QRectF boundingRect() const override
Return the bounding rectangle (expanded to account for pen width).
LineGraphicsItem(const Line &line, int type, QGraphicsItem *parent=nullptr)
Construct from a Line geometry object, with a type integer and optional parent.
LineGraphicsItem(int type, QGraphicsItem *parent=nullptr)
Construct with a type integer and optional parent item.