Kirigami2

paintedrectangleitem.cpp
1/*
2 * SPDX-FileCopyrightText: 2020 Arjen Hiemstra <ahiemstra@heimr.nl>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
7#include "paintedrectangleitem.h"
8
9#include <QPainter>
10#include <cmath>
11
12PaintedRectangleItem::PaintedRectangleItem(QQuickItem *parent)
13 : QQuickPaintedItem(parent)
14{
15}
16
17void PaintedRectangleItem::setColor(const QColor &color)
18{
19 m_color = color;
20 update();
21}
22
23void PaintedRectangleItem::setRadius(qreal radius)
24{
25 m_radius = radius;
26 update();
27}
28
29void PaintedRectangleItem::setBorderColor(const QColor &color)
30{
31 m_borderColor = color;
32 update();
33}
34
35void PaintedRectangleItem::setBorderWidth(qreal width)
36{
37 m_borderWidth = width;
38 update();
39}
40
41void PaintedRectangleItem::paint(QPainter *painter)
42{
44 painter->setPen(Qt::transparent);
45
46 auto radius = std::min(m_radius, std::min(width(), height()) / 2);
47 auto borderWidth = std::floor(m_borderWidth);
48
49 if (borderWidth > 0.0) {
50 painter->setBrush(m_borderColor);
51 painter->drawRoundedRect(0, 0, width(), height(), radius, radius);
52 }
53
54 painter->setBrush(m_color);
55 painter->drawRoundedRect(borderWidth, borderWidth, width() - borderWidth * 2, height() - borderWidth * 2, radius, radius);
56}
57
58#include "moc_paintedrectangleitem.cpp"
void drawRoundedRect(const QRect &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode)
void setBrush(Qt::BrushStyle style)
void setPen(Qt::PenStyle style)
void setRenderHint(RenderHint hint, bool on)
void update()
transparent
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:56:52 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.