1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#include <private/chartbackground_p.h>
5#include <private/chartconfig_p.h>
6#include <QtGui/QPen>
7#include <QtGui/QBrush>
8#include <QtGui/QPainter>
9#include <QGraphicsDropShadowEffect>
10
11QT_BEGIN_NAMESPACE
12
13ChartBackground::ChartBackground(QGraphicsItem *parent)
14 : QGraphicsRectItem(parent),
15 m_diameter(5),
16 m_dropShadow(0)
17{
18 setAcceptedMouseButtons({});
19}
20
21ChartBackground::~ChartBackground()
22{
23
24}
25
26void ChartBackground::setDropShadowEnabled(bool enabled)
27{
28#ifdef QT_NO_GRAPHICSEFFECT
29 Q_UNUSED(enabled);
30#else
31 if (enabled) {
32 if (!m_dropShadow) {
33 m_dropShadow = new QGraphicsDropShadowEffect();
34#ifdef Q_OS_MAC
35 m_dropShadow->setBlurRadius(15);
36 m_dropShadow->setOffset(0, 0);
37#elif defined(Q_OS_WIN)
38 m_dropShadow->setBlurRadius(10);
39 m_dropShadow->setOffset(0, 0);
40#else
41 m_dropShadow->setBlurRadius(10);
42 m_dropShadow->setOffset(dx: 5, dy: 5);
43#endif
44 setGraphicsEffect(m_dropShadow);
45 }
46 } else {
47 delete m_dropShadow;
48 m_dropShadow = 0;
49 }
50#endif
51}
52
53void ChartBackground::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
54{
55 Q_UNUSED(option);
56 Q_UNUSED(widget);
57 painter->save();
58 painter->setPen(pen());
59 painter->setBrush(brush());
60 painter->drawRoundedRect(rect: rect(), xRadius: m_diameter, yRadius: m_diameter);
61 painter->restore();
62}
63
64qreal ChartBackground::diameter() const
65{
66 return m_diameter;
67}
68
69void ChartBackground::setDiameter(qreal diameter)
70{
71 m_diameter = diameter;
72 update();
73}
74
75QT_END_NAMESPACE
76

source code of qtcharts/src/charts/chartbackground.cpp