diff --git a/src/charttheme.cpp b/src/charttheme.cpp index 20304b6..606dd1a 100644 --- a/src/charttheme.cpp +++ b/src/charttheme.cpp @@ -1,5 +1,6 @@ #include "charttheme_p.h" #include "qchart.h" +#include "qchartview.h" #include "qlegend.h" #include "qchartaxis.h" #include @@ -34,6 +35,7 @@ #include "chartthemegrayscale_p.h" #include "chartthemescientific_p.h" #include "chartthemebluecerulean_p.h" +#include "chartthemelight_p.h" QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -58,6 +60,8 @@ ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme) return new ChartThemeScientific(); case QChart::ChartThemeBlueCerulean: return new ChartThemeBlueCerulean(); + case QChart::ChartThemeLight: + return new ChartThemeLight(); default: return new ChartThemeDefault(); } @@ -65,16 +69,17 @@ ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme) void ChartTheme::decorate(QChart* chart) { - if (m_backgroundShades == BackgroundShadesNone) - chart->setChartBackgroundBrush(m_backgroundGradient); - else + if (m_backgroundShades == BackgroundShadesNone) { + chart->setChartBackgroundBrush(m_chartBackgroundGradient); + } else { chart->setChartBackgroundBrush(Qt::NoBrush); + } chart->setChartTitleFont(m_masterFont); } void ChartTheme::decorate(QLegend* legend) { - legend->setBackgroundBrush(m_backgroundGradient); + legend->setBackgroundBrush(m_chartBackgroundGradient); } void ChartTheme::decorate(QAreaSeries* series, int index) @@ -210,7 +215,6 @@ void ChartTheme::decorate(QChartAxis* axis,bool axisX) if (axis->isAxisVisible()) { axis->setLabelsBrush(m_axisLabelBrush); axis->setLabelsPen(m_axisLabelPen); - // TODO: check the axis type (x or y) should define whether to show the shades or not if (m_backgroundShades == BackgroundShadesBoth || (m_backgroundShades == BackgroundShadesVertical && axisX) || (m_backgroundShades == BackgroundShadesHorizontal && !axisX)) { diff --git a/src/charttheme_p.h b/src/charttheme_p.h index 89e465c..398b052 100644 --- a/src/charttheme_p.h +++ b/src/charttheme_p.h @@ -64,7 +64,7 @@ protected: QChart::ChartTheme m_id; QList m_seriesColors; QList m_seriesGradients; - QLinearGradient m_backgroundGradient; + QLinearGradient m_chartBackgroundGradient; QFont m_masterFont; QPen m_axisLinePen; diff --git a/src/qchart.cpp b/src/qchart.cpp index eefcf19..45dd3c2 100644 --- a/src/qchart.cpp +++ b/src/qchart.cpp @@ -20,6 +20,7 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE \value ChartThemeGrayscale \value ChartThemeScientific \value ChartThemeBlueCerulean + \value ChartThemeLight \value ChartThemeCount Not really a theme; the total count of themes. */ diff --git a/src/qchart.h b/src/qchart.h index e48907e..d6006c6 100644 --- a/src/qchart.h +++ b/src/qchart.h @@ -33,6 +33,7 @@ public: ChartThemeGrayscale, ChartThemeScientific, ChartThemeBlueCerulean, + ChartThemeLight, ChartThemeCount }; diff --git a/src/qchartview.cpp b/src/qchartview.cpp index 853196c..a285b62 100644 --- a/src/qchartview.cpp +++ b/src/qchartview.cpp @@ -36,12 +36,12 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE Constructs a chartView object which is a child of a\a parent. */ QChartView::QChartView(QWidget *parent) : -QGraphicsView(parent), -m_scene(new QGraphicsScene(this)), -m_chart(new QChart()), -m_rubberBand(0), -m_verticalRubberBand(false), -m_horizonalRubberBand(false) + QGraphicsView(parent), + m_scene(new QGraphicsScene(this)), + m_chart(new QChart()), + m_rubberBand(0), + m_verticalRubberBand(false), + m_horizonalRubberBand(false) { setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); @@ -328,6 +328,15 @@ void QChartView::keyPressEvent(QKeyEvent *event) */ void QChartView::setChartTheme(QChart::ChartTheme theme) { + if (theme == QChart::ChartThemeBlueCerulean) { + QLinearGradient backgroundGradient; + backgroundGradient.setColorAt(0.0, QRgb(0x056188)); + backgroundGradient.setColorAt(1.0, QRgb(0x101a33)); + backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); + setBackgroundBrush(backgroundGradient); + } else { + setBackgroundBrush(Qt::NoBrush); + } m_chart->setChartTheme(theme); } @@ -385,4 +394,6 @@ void QChartView::scroll(int dx,int dy) m_chart->scroll(dx,dy); } +#include "moc_qchartview.cpp" + QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/qchartview.h b/src/qchartview.h index 8a3db3d..2f113f7 100644 --- a/src/qchartview.h +++ b/src/qchartview.h @@ -16,6 +16,8 @@ class QChart; class QTCOMMERCIALCHART_EXPORT QChartView : public QGraphicsView { + Q_OBJECT + public: enum RubberBandPolicy { NoRubberBand, VerticalRubberBand, HorizonalRubberBand, RectangleRubberBand }; @@ -64,7 +66,6 @@ protected: void mouseReleaseEvent(QMouseEvent *event); void keyPressEvent(QKeyEvent *event); - private: QGraphicsScene *m_scene; QChart* m_chart; @@ -73,8 +74,6 @@ private: bool m_verticalRubberBand; bool m_horizonalRubberBand; Q_DISABLE_COPY(QChartView) - - }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/src.pro b/src/src.pro index d3147b6..91cdfcf 100644 --- a/src/src.pro +++ b/src/src.pro @@ -45,7 +45,9 @@ THEMES += themes/chartthemedefault_p.h \ themes/chartthemegrayscale_p.h \ themes/chartthemescientific_p.h \ themes/chartthemevanilla_p.h \ - themes/chartthemebluecerulean_p.h + themes/chartthemebluecerulean_p.h \ + themes/chartthemelight_p.h + HEADERS += $$PUBLIC_HEADERS HEADERS += $$PRIVATE_HEADERS HEADERS += $$THEMES diff --git a/src/themes/chartthemebluecerulean_p.h b/src/themes/chartthemebluecerulean_p.h index 4976843..93e8703 100644 --- a/src/themes/chartthemebluecerulean_p.h +++ b/src/themes/chartthemebluecerulean_p.h @@ -13,23 +13,19 @@ public: m_seriesColors << QRgb(0x4fbef3); generateSeriesGradients(); - // Background - QLinearGradient backgroundGradient; - backgroundGradient.setColorAt(0.0, QRgb(0x056188)); - backgroundGradient.setColorAt(1.0, QRgb(0x101a33)); - backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); - m_backgroundGradient = backgroundGradient; + // No chart background, chart view specifies a background + // TODO: what if the chart is drawn on custom graphics scene instead of QChartView? // Axes and other m_masterFont = QFont(); - m_axisLinePen = QPen(QRgb(0x0f0f0f)); + m_axisLinePen = QPen(QRgb(0xf7f7ff)); m_axisLinePen.setWidth(2); - m_axisLabelBrush = QBrush(QRgb(0x3f3f3f)); + m_axisLabelBrush = QBrush(QRgb(0xf7f7ff)); m_axisLabelPen = Qt::NoPen; // NoPen for performance reasons m_backgroundShadesPen = Qt::NoPen; m_backgroundShades = BackgroundShadesNone; - m_gridLinePen = QPen(QRgb(0x0f0f0f)); - m_gridLinePen.setWidth(2); + m_gridLinePen = QPen(QRgb(0xf7f7ff)); + m_gridLinePen.setWidth(1); } }; diff --git a/src/themes/chartthemedefault_p.h b/src/themes/chartthemedefault_p.h index 552604a..2e9635b 100644 --- a/src/themes/chartthemedefault_p.h +++ b/src/themes/chartthemedefault_p.h @@ -110,7 +110,7 @@ public: backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); backgroundGradient.setColorAt(1.0, QRgb(0xe9e9e9)); backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); - m_backgroundGradient = backgroundGradient; + m_chartBackgroundGradient = backgroundGradient; // Axes and other m_masterFont = QFont(); diff --git a/src/themes/chartthemegrayscale_p.h b/src/themes/chartthemegrayscale_p.h index bf53c53..6ae2c7f 100644 --- a/src/themes/chartthemegrayscale_p.h +++ b/src/themes/chartthemegrayscale_p.h @@ -19,7 +19,7 @@ public: backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); backgroundGradient.setColorAt(1.0, QRgb(0xe0e3e5)); backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); - m_backgroundGradient = backgroundGradient; + m_chartBackgroundGradient = backgroundGradient; // Axes and other m_masterFont = QFont(); @@ -28,6 +28,7 @@ public: m_axisLabelBrush = QBrush(QRgb(0x3f3f3f)); m_axisLabelPen = Qt::NoPen; // NoPen for performance reasons m_backgroundShadesPen = Qt::NoPen; + m_backgroundShades = BackgroundShadesNone; m_gridLinePen = QPen(QRgb(0x0f0f0f)); m_gridLinePen.setWidth(2); } diff --git a/src/themes/chartthemeicy_p.h b/src/themes/chartthemeicy_p.h index f3b174f..78b873f 100644 --- a/src/themes/chartthemeicy_p.h +++ b/src/themes/chartthemeicy_p.h @@ -19,7 +19,7 @@ public: backgroundGradient.setColorAt(0.0, QRgb(0xebebeb)); backgroundGradient.setColorAt(1.0, QRgb(0xf8f9fb)); backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); - m_backgroundGradient = backgroundGradient; + m_chartBackgroundGradient = backgroundGradient; // Axes and other m_masterFont = QFont(); @@ -28,6 +28,7 @@ public: m_axisLabelBrush = QBrush(QRgb(0x3f3f3f)); m_axisLabelPen = Qt::NoPen; // NoPen for performance reasons m_backgroundShadesPen = Qt::NoPen; + m_backgroundShades = BackgroundShadesNone; m_gridLinePen = QPen(QRgb(0x0f0f0f)); m_gridLinePen.setWidth(2); } diff --git a/src/themes/chartthemelight_p.h b/src/themes/chartthemelight_p.h new file mode 100644 index 0000000..f15fca5 --- /dev/null +++ b/src/themes/chartthemelight_p.h @@ -0,0 +1,36 @@ +#include "charttheme_p.h" + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +class ChartThemeLight: public ChartTheme +{ +public: + ChartThemeLight() : ChartTheme(QChart::ChartThemeLight) + { + // Series colors + m_seriesColors << QRgb(0x1c9dde); + m_seriesColors << QRgb(0xf7a015); + m_seriesColors << QRgb(0x8dc444); + generateSeriesGradients(); + + // Background + QLinearGradient backgroundGradient; + backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); + backgroundGradient.setColorAt(1.0, QRgb(0xffffff)); + backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); + m_chartBackgroundGradient = backgroundGradient; + + // Axes and other + m_masterFont = QFont(); + m_axisLinePen = QPen(QRgb(0x424242)); + m_axisLinePen.setWidth(1); + m_axisLabelBrush = QBrush(QRgb(0x424242)); + m_axisLabelPen = Qt::NoPen; // NoPen for performance reasons + m_backgroundShadesPen = Qt::NoPen; + m_backgroundShades = BackgroundShadesNone; + m_gridLinePen = QPen(QRgb(0x424242)); + m_gridLinePen.setWidth(1); + } +}; + +QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/themes/chartthemescientific_p.h b/src/themes/chartthemescientific_p.h index 69184f3..67b9c99 100644 --- a/src/themes/chartthemescientific_p.h +++ b/src/themes/chartthemescientific_p.h @@ -19,7 +19,7 @@ public: backgroundGradient.setColorAt(0.0, QRgb(0xfffefc)); backgroundGradient.setColorAt(1.0, QRgb(0xfffefc)); backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); - m_backgroundGradient = backgroundGradient; + m_chartBackgroundGradient = backgroundGradient; // Axes and other m_masterFont = QFont(); diff --git a/src/themes/chartthemevanilla_p.h b/src/themes/chartthemevanilla_p.h index c085c77..ecd149b 100644 --- a/src/themes/chartthemevanilla_p.h +++ b/src/themes/chartthemevanilla_p.h @@ -20,7 +20,7 @@ public: backgroundGradient.setColorAt(0.0, QRgb(0xfbf9f1)); backgroundGradient.setColorAt(1.0, QRgb(0xf5f0dc)); backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); - m_backgroundGradient = backgroundGradient; + m_chartBackgroundGradient = backgroundGradient; // Axes and other m_masterFont = QFont(); @@ -29,6 +29,7 @@ public: m_axisLabelBrush = QBrush(QRgb(0xa0a071)); m_axisLabelPen = Qt::NoPen; // NoPen for performance reasons m_backgroundShadesPen = Qt::NoPen; + m_backgroundShades = BackgroundShadesNone; m_gridLinePen = QPen(QRgb(0x0f0f0f)); m_gridLinePen.setWidth(2); }