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