##// END OF EJS Templates
Added drop shadow effect for light themes
Tero Ahola -
r1001:81238c98c2aa
parent child
Show More
@@ -23,11 +23,14
23 23 #include <QPen>
24 24 #include <QBrush>
25 25 #include <QPainter>
26 #include <QGraphicsDropShadowEffect>
26 27
27 28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 29
29 ChartBackground::ChartBackground(QGraphicsItem* parent):QGraphicsRectItem(parent),
30 m_diameter(15)
30 ChartBackground::ChartBackground(QGraphicsItem* parent) :
31 QGraphicsRectItem(parent),
32 m_diameter(15),
33 m_dropShadow(0)
31 34 {
32 35 }
33 36
@@ -36,6 +39,21 ChartBackground::~ChartBackground()
36 39
37 40 }
38 41
42 void ChartBackground::setDropShadowEnabled(bool enabled)
43 {
44 if (enabled) {
45 if (!m_dropShadow) {
46 m_dropShadow = new QGraphicsDropShadowEffect();
47 m_dropShadow->setBlurRadius(10);
48 m_dropShadow->setOffset(5, 5);
49 setGraphicsEffect(m_dropShadow);
50 }
51 } else {
52 delete m_dropShadow;
53 m_dropShadow = 0;
54 }
55 }
56
39 57 void ChartBackground::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
40 58 {
41 59 Q_UNUSED(option);
@@ -24,6 +24,7
24 24 #include "qchartglobal.h"
25 25 #include <QGraphicsRectItem>
26 26
27 class QGraphicsDropShadowEffect;
27 28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 29
29 30 class ChartBackground: public QGraphicsRectItem
@@ -34,7 +35,8 public:
34 35
35 36 void setDimeter(int dimater);
36 37 int diameter() const;
37
38 void setDropShadowEnabled(bool enabled);
39 bool isDropShadowEnabled() {return m_dropShadow != 0;}
38 40
39 41 protected:
40 42 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
@@ -44,8 +46,8 private:
44 46 int roundness(qreal size) const;
45 47
46 48 private:
47 int m_diameter;
48
49 int m_diameter;
50 QGraphicsDropShadowEffect *m_dropShadow;
49 51 };
50 52
51 53 QTCOMMERCIALCHART_END_NAMESPACE
@@ -20,6 +20,7
20 20
21 21 #include "charttheme_p.h"
22 22 #include "qchart.h"
23 #include "qchart_p.h"
23 24 #include "qchartview.h"
24 25 #include "qlegend.h"
25 26 #include "qchartaxis.h"
@@ -69,6 +70,7 ChartTheme::ChartTheme(QChart::ChartTheme id) :
69 70 m_backgroundShadesPen(Qt::NoPen),
70 71 m_backgroundShadesBrush(Qt::NoBrush),
71 72 m_backgroundShades(BackgroundShadesNone),
73 m_backgroundDropShadowEnabled(false),
72 74 m_gridLinePen(QPen(QRgb(0x000000))),
73 75 m_force(false)
74 76 {
@@ -107,6 +109,7 void ChartTheme::decorate(QChart *chart)
107 109 chart->setBackgroundBrush(m_chartBackgroundGradient);
108 110 chart->setTitleFont(m_masterFont);
109 111 chart->setTitleBrush(m_titleBrush);
112 chart->setBackgroundDropShadowEnabled(m_backgroundDropShadowEnabled);
110 113 }
111 114
112 115 void ChartTheme::decorate(QLegend *legend)
@@ -118,7 +121,6 void ChartTheme::decorate(QLegend *legend)
118 121 legend->setPen(Qt::NoPen);
119 122 }
120 123
121
122 124 if (brush == legend->brush() || m_force) {
123 125 legend->setBrush(m_chartBackgroundGradient);
124 126 }
@@ -92,6 +92,7 protected:
92 92 QPen m_backgroundShadesPen;
93 93 QBrush m_backgroundShadesBrush;
94 94 BackgroundShadesMode m_backgroundShades;
95 bool m_backgroundDropShadowEnabled;
95 96 QPen m_gridLinePen;
96 97 bool m_force;
97 98 };
@@ -379,10 +379,26 void QChart::setBackgroundVisible(bool visible)
379 379 bool QChart::isBackgroundVisible() const
380 380 {
381 381 //TODO: refactor me
382 if (!d_ptr->m_presenter->m_backgroundItem) return false;
382 if (!d_ptr->m_presenter->m_backgroundItem)
383 return false;
384
383 385 return d_ptr->m_presenter->m_backgroundItem->isVisible();
384 386 }
385 387
388 void QChart::setBackgroundDropShadowEnabled(bool enabled)
389 {
390 d_ptr->m_presenter->createChartBackgroundItem();
391 d_ptr->m_presenter->m_backgroundItem->setDropShadowEnabled(enabled);
392 }
393
394 bool QChart::isBackgroundDropShadowEnabled() const
395 {
396 if (!d_ptr->m_presenter->m_backgroundItem)
397 return false;
398
399 return d_ptr->m_presenter->m_backgroundItem->isDropShadowEnabled();
400 }
401
386 402 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
387 403
388 404 QChartPrivate::QChartPrivate():
@@ -81,9 +81,10 public:
81 81 QBrush backgroundBrush() const;
82 82 void setBackgroundPen(const QPen &pen);
83 83 QPen backgroundPen() const;
84
85 84 void setBackgroundVisible(bool visible = true);
86 85 bool isBackgroundVisible() const;
86 void setBackgroundDropShadowEnabled(bool enabled = true);
87 bool isBackgroundDropShadowEnabled() const;
87 88
88 89 void setAnimationOptions(AnimationOptions options);
89 90 AnimationOptions animationOptions() const;
@@ -44,6 +44,7 public:
44 44 backgroundGradient.setColorAt(1.0, QRgb(0xffffff));
45 45 backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode);
46 46 m_chartBackgroundGradient = backgroundGradient;
47 m_backgroundDropShadowEnabled = true;
47 48
48 49 // Axes and other
49 50 m_titleBrush = QBrush(QRgb(0x404044));
@@ -44,6 +44,7 public:
44 44 backgroundGradient.setColorAt(1.0, QRgb(0xffffff));
45 45 backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode);
46 46 m_chartBackgroundGradient = backgroundGradient;
47 m_backgroundDropShadowEnabled = true;
47 48
48 49 // Axes and other
49 50 m_titleBrush = QBrush(QRgb(0x181818));
@@ -44,6 +44,7 public:
44 44 backgroundGradient.setColorAt(1.0, QRgb(0xffffff));
45 45 backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode);
46 46 m_chartBackgroundGradient = backgroundGradient;
47 m_backgroundDropShadowEnabled = true;
47 48
48 49 // Axes and other
49 50 m_axisLinePen = QPen(0xd6d6d6);
General Comments 0
You need to be logged in to leave comments. Login now