1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 or (at your option) any later version |
20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
22 | ** included in the packaging of this file. Please review the following |
23 | ** information to ensure the GNU General Public License requirements will |
24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
25 | ** |
26 | ** $QT_END_LICENSE$ |
27 | ** |
28 | ****************************************************************************/ |
29 | |
30 | #include <private/chartbackground_p.h> |
31 | #include <private/chartconfig_p.h> |
32 | #include <QtGui/QPen> |
33 | #include <QtGui/QBrush> |
34 | #include <QtGui/QPainter> |
35 | #include <QGraphicsDropShadowEffect> |
36 | |
37 | QT_CHARTS_BEGIN_NAMESPACE |
38 | |
39 | ChartBackground::ChartBackground(QGraphicsItem *parent) |
40 | : QGraphicsRectItem(parent), |
41 | m_diameter(5), |
42 | m_dropShadow(0) |
43 | { |
44 | } |
45 | |
46 | ChartBackground::~ChartBackground() |
47 | { |
48 | |
49 | } |
50 | |
51 | void ChartBackground::setDropShadowEnabled(bool enabled) |
52 | { |
53 | #ifdef QT_NO_GRAPHICSEFFECT |
54 | Q_UNUSED(enabled) |
55 | #else |
56 | if (enabled) { |
57 | if (!m_dropShadow) { |
58 | m_dropShadow = new QGraphicsDropShadowEffect(); |
59 | #ifdef Q_OS_MAC |
60 | m_dropShadow->setBlurRadius(15); |
61 | m_dropShadow->setOffset(0, 0); |
62 | #elif defined(Q_OS_WIN) |
63 | m_dropShadow->setBlurRadius(10); |
64 | m_dropShadow->setOffset(0, 0); |
65 | #else |
66 | m_dropShadow->setBlurRadius(10); |
67 | m_dropShadow->setOffset(dx: 5, dy: 5); |
68 | #endif |
69 | setGraphicsEffect(m_dropShadow); |
70 | } |
71 | } else { |
72 | delete m_dropShadow; |
73 | m_dropShadow = 0; |
74 | } |
75 | #endif |
76 | } |
77 | |
78 | void ChartBackground::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
79 | { |
80 | Q_UNUSED(option); |
81 | Q_UNUSED(widget); |
82 | painter->save(); |
83 | painter->setPen(pen()); |
84 | painter->setBrush(brush()); |
85 | painter->drawRoundedRect(rect: rect(), xRadius: m_diameter, yRadius: m_diameter); |
86 | painter->restore(); |
87 | } |
88 | |
89 | qreal ChartBackground::diameter() const |
90 | { |
91 | return m_diameter; |
92 | } |
93 | |
94 | void ChartBackground::setDiameter(qreal diameter) |
95 | { |
96 | m_diameter = diameter; |
97 | update(); |
98 | } |
99 | |
100 | QT_CHARTS_END_NAMESPACE |
101 | |