1 /* 2 SPDX-FileCopyrightText: 2011 Graeme Gott <graeme@gottcode.org> 3 4 SPDX-License-Identifier: GPL-3.0-or-later 5 */ 6 7 #ifndef TANGLET_BEVELED_RECT_H 8 #define TANGLET_BEVELED_RECT_H 9 10 #include <QGraphicsItem> 11 12 /** 13 * @brief The BeveledRect class displays a rounded square with the appearance of depth. 14 */ 15 class BeveledRect: public QGraphicsItem 16 { 17 public: 18 /** 19 * Constructs a beveled rectangle instance. 20 * @param size how big the rectangle should be 21 * @param parent the item that owns the rectangle 22 */ 23 explicit BeveledRect(int size, QGraphicsItem* parent = nullptr); 24 25 /** 26 * @return the size of the beveled rectangle 27 */ 28 QRectF boundingRect() const override; 29 30 /** 31 * Draws the beveled rectangle. 32 * @param painter the painter used to draw the rectangle 33 */ 34 void paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*) override; 35 36 /** 37 * Sets the color of the beveled rectangle. 38 * @param color what color to draw in the paint event 39 * @param bevel if the rectangle should have the appearance of depth 40 */ 41 void setColor(const QColor& color, bool bevel = true); 42 43 private: 44 int m_size; /**< width of the square */ 45 int m_steps; /**< how many levels deep to draw */ 46 QRectF m_rects[5]; /**< regions to draw at each depth */ 47 QColor m_colors[5]; /**< colors to draw at each depth */ 48 }; 49 50 #endif // TANGLET_BEVELED_RECT_H 51