@@ -1,99 +1,100 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "chartbackground_p.h" |
|
22 | 22 | #include "chartconfig_p.h" |
|
23 | 23 | #include <QPen> |
|
24 | 24 | #include <QBrush> |
|
25 | 25 | #include <QPainter> |
|
26 | 26 | #include <QGraphicsDropShadowEffect> |
|
27 | 27 | |
|
28 | 28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | 29 | |
|
30 | 30 | ChartBackground::ChartBackground(QGraphicsItem* parent) : |
|
31 | 31 | QGraphicsRectItem(parent), |
|
32 | 32 | m_diameter(15), |
|
33 | 33 | m_dropShadow(0) |
|
34 | 34 | { |
|
35 | 35 | } |
|
36 | 36 | |
|
37 | 37 | ChartBackground::~ChartBackground() |
|
38 | 38 | { |
|
39 | 39 | |
|
40 | 40 | } |
|
41 | 41 | |
|
42 | 42 | void ChartBackground::setDropShadowEnabled(bool enabled) |
|
43 | 43 | { |
|
44 | 44 | if (enabled) { |
|
45 | 45 | if (!m_dropShadow) { |
|
46 | 46 | m_dropShadow = new QGraphicsDropShadowEffect(); |
|
47 | 47 | #ifdef Q_OS_MAC |
|
48 | 48 | m_dropShadow->setBlurRadius(15); |
|
49 | 49 | m_dropShadow->setOffset(0, 0); |
|
50 | 50 | #elif defined(Q_OS_WIN) |
|
51 | 51 | m_dropShadow->setBlurRadius(10); |
|
52 | 52 | m_dropShadow->setOffset(0, 0); |
|
53 | 53 | #else |
|
54 | 54 | m_dropShadow->setBlurRadius(10); |
|
55 | 55 | m_dropShadow->setOffset(5, 5); |
|
56 | 56 | #endif |
|
57 | 57 | setGraphicsEffect(m_dropShadow); |
|
58 | 58 | } |
|
59 | 59 | } else { |
|
60 | 60 | delete m_dropShadow; |
|
61 | 61 | m_dropShadow = 0; |
|
62 | 62 | } |
|
63 | 63 | } |
|
64 | 64 | |
|
65 | 65 | void ChartBackground::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
66 | 66 | { |
|
67 | 67 | Q_UNUSED(option); |
|
68 | 68 | Q_UNUSED(widget); |
|
69 | 69 | painter->save(); |
|
70 | 70 | painter->setPen(pen()); |
|
71 | 71 | painter->setBrush(brush()); |
|
72 | 72 | painter->drawRoundRect(rect(),roundness(rect().width()),roundness(rect().height())); |
|
73 | 73 | #ifndef QT_NO_DEBUG |
|
74 | 74 | painter->setPen(Qt::black); |
|
75 | 75 | QFont font; |
|
76 | 76 | QString build("build %1"); |
|
77 | 77 | font.setPointSize(6); |
|
78 | 78 | painter->setFont(font); |
|
79 | 79 | painter->drawText(rect().bottomLeft(),build.arg(ChartConfig::instance()->compilationTime())); |
|
80 | 80 | #endif |
|
81 | 81 | painter->restore(); |
|
82 | 82 | } |
|
83 | 83 | |
|
84 | 84 | int ChartBackground::roundness(qreal size) const |
|
85 | 85 | { |
|
86 | if(qFuzzyIsNull(size)) return 0; | |
|
86 | 87 | return 100*m_diameter/int(size); |
|
87 | 88 | } |
|
88 | 89 | |
|
89 | 90 | int ChartBackground::diameter() const |
|
90 | 91 | { |
|
91 | 92 | return m_diameter; |
|
92 | 93 | } |
|
93 | 94 | |
|
94 | 95 | void ChartBackground::setDimeter(int dimater) |
|
95 | 96 | { |
|
96 | 97 | m_diameter=dimater; |
|
97 | 98 | } |
|
98 | 99 | |
|
99 | 100 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now