diff --git a/src/charttheme.cpp b/src/charttheme.cpp index eaa6116..5d9fd80 100644 --- a/src/charttheme.cpp +++ b/src/charttheme.cpp @@ -197,16 +197,6 @@ void ChartTheme::decorate(PiePresenter* item, QPieSeries* series, int index) } } - -void ChartTheme::decorate(QChartAxis* axis, AxisItem* item) -{ - //TODO: dummy defults for now - axis->setLabelsBrush(Qt::black); - axis->setLabelsPen(Qt::NoPen); - axis->setShadesPen(Qt::NoPen); - axis->setShadesOpacity(0.5); -} - void ChartTheme::decorate(SplineChartItem* item, QSplineSeries* series, int index) { Q_ASSERT(item); @@ -234,6 +224,31 @@ void ChartTheme::decorate(SplineChartItem* item, QSplineSeries* series, int inde // presenter->m_markerPen = pen; } +void ChartTheme::decorate(QChartAxis* axis, AxisItem* item) +{ + Q_ASSERT(axis); + Q_ASSERT(item); + + 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 /*&& x axis ?*/ + || m_backgroundShades == BackgroundShadesHorizontal /* && y axis*/) { + axis->setShadesPen(m_backgroundShadesPen); + axis->setShadesBrush(m_backgroundShadesBrush); + } else { + // The shades not supposed to be shown for this axis, clear possible brush and pen + axis->setShadesPen(Qt::NoPen); + axis->setShadesBrush(Qt::NoBrush); + } + axis->setAxisPen(m_axisLinePen); + axis->setGridLinePen(m_gridLinePen); + axis->setLabelsFont(m_masterFont); + } +} + void ChartTheme::generateSeriesGradients() { // Generate gradients in HSV color space diff --git a/src/charttheme_p.h b/src/charttheme_p.h index 53d28c5..37972df 100644 --- a/src/charttheme_p.h +++ b/src/charttheme_p.h @@ -29,6 +29,14 @@ class QAreaSeries; class ChartTheme { +public: + enum BackgroundShadesMode { + BackgroundShadesNone = 0, + BackgroundShadesVertical, + BackgroundShadesHorizontal, + BackgroundShadesBoth + }; + protected: explicit ChartTheme(QChart::ChartTheme id = QChart::ChartThemeDefault); public: @@ -44,8 +52,8 @@ public: void decorate(AreaChartItem* item, QAreaSeries* series, int index); void decorate(ScatterChartItem* presenter, QScatterSeries* series, int index); void decorate(PiePresenter* item, QPieSeries* series, int index); - void decorate(QChartAxis* axis,AxisItem* item); void decorate(SplineChartItem* presenter, QSplineSeries* series, int index); + void decorate(QChartAxis* axis, AxisItem* item); public: // utils void generateSeriesGradients(); @@ -58,13 +66,14 @@ protected: QList m_seriesGradients; QLinearGradient m_backgroundGradient; - // TODO: Add something like the following to themes: -// QPen axisLinePen; -// QPen backgroundHorizontalGridPen; -// QPen backgroundVerticalGridPen; -// // FillAll, FillEverySecondRow, FillEverySecondColumn, FillEverySecondRowAndColumn, FillNone -// int backgroundType; -// QFont masterFont; + QFont m_masterFont; + QPen m_axisLinePen; + QBrush m_axisLabelBrush; + QPen m_axisLabelPen; + QPen m_backgroundShadesPen; + QBrush m_backgroundShadesBrush; + BackgroundShadesMode m_backgroundShades; + QPen m_gridLinePen; }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/themes/chartthemedefault_p.h b/src/themes/chartthemedefault_p.h index 267d2ff..552604a 100644 --- a/src/themes/chartthemedefault_p.h +++ b/src/themes/chartthemedefault_p.h @@ -12,17 +12,27 @@ public: ChartThemeDefault():ChartTheme(QChart::ChartThemeDefault) { #ifdef Q_OS_WIN - // First series base color from COLOR_WINDOWFRAME - DWORD colorWindowFrame; - colorWindowFrame = GetSysColor(COLOR_WINDOWFRAME); - m_seriesColors.append(QColor(GetRValue(colorWindowFrame), GetGValue(colorWindowFrame),GetBValue(colorWindowFrame))); + // TODO: use theme specific window frame color as a series base color (it would give more + // variation to the base colors in addition to the blue and black used now) + // TODO: COLOR_WINDOWTEXT for text color? + // TODO: COLOR_INFOTEXT for tooltip text color? + // TODO: COLOR_INFOBK for tooltip background color? - // Second series base color from COLOR_HIGHLIGHT + // First series base color from COLOR_HIGHLIGHT DWORD colorHighlight; colorHighlight = GetSysColor(COLOR_HIGHLIGHT); - m_seriesColors.append(QColor(GetRValue(colorHighlight), GetGValue(colorHighlight),GetBValue(colorHighlight))); + m_seriesColors.append(QColor(GetRValue(colorHighlight), + GetGValue(colorHighlight), + GetBValue(colorHighlight))); + + // Second series base color from COLOR_WINDOWFRAME + DWORD colorWindowFrame; + colorWindowFrame = GetSysColor(COLOR_WINDOWFRAME); + m_seriesColors.append(QColor(GetRValue(colorWindowFrame), + GetGValue(colorWindowFrame), + GetBValue(colorWindowFrame))); - // Thirs series base color from the middle of the COLOR_ACTIVECAPTION / + // Third series base color from the middle of the COLOR_ACTIVECAPTION / // COLOR_GRADIENTACTIVECAPTION gradient DWORD colorGradientActiveCaptionLeft; colorGradientActiveCaptionLeft = GetSysColor(COLOR_ACTIVECAPTION); @@ -52,43 +62,91 @@ public: backgroundGradient.setColorAt(1.0, QColor(GetRValue(colorWindow), GetGValue(colorWindow), GetBValue(colorWindow))); + // Axes and other + m_masterFont = QFont(); + m_masterFont.setPointSizeF(10.0); + m_axisLinePen = QPen(Qt::black); + m_axisLinePen.setWidth(2); + m_axisLabelBrush = QBrush(Qt::black); + m_axisLabelPen = Qt::NoPen; // NoPen for performance reasons + m_backgroundShadesPen = Qt::NoPen; + m_backgroundShadesBrush = QBrush(QColor(0xaf, 0xaf, 0xaf, 0x50)); + m_backgroundShades = BackgroundShadesVertical; - // TODO: COLOR_WINDOWTEXT for text color? - // TODO: COLOR_INFOTEXT for tooltip text color? - // TODO: COLOR_INFOBK for tooltip background color? #elif defined(Q_OS_LINUX) // TODO: replace this dummy theme with linux specific theme - m_seriesColors << QRgb(0xff707070); - m_seriesColors << QRgb(0xffA0A0A0); + m_seriesColors << QRgb(0x60a6e6); + m_seriesColors << QRgb(0x92ca66); + m_seriesColors << QRgb(0xeba85f); + m_seriesColors << QRgb(0xfc5751); generateSeriesGradients(); QLinearGradient backgroundGradient; - backgroundGradient.setColorAt(0.0, QRgb(0xffffffff)); - backgroundGradient.setColorAt(1.0, QRgb(0xffafafaf)); + backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); + backgroundGradient.setColorAt(1.0, QRgb(0xe9e9e9)); backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); m_backgroundGradient = backgroundGradient; -#elif Q_OS_MAC + + // Axes and other + m_masterFont = QFont(); + m_masterFont.setPointSizeF(10.0); + m_axisLinePen = QPen(Qt::black); + m_axisLinePen.setWidth(2); + m_axisLabelBrush = QBrush(Qt::black); + m_axisLabelPen = Qt::NoPen; // NoPen for performance reasons + m_backgroundShadesPen = Qt::NoPen; + m_backgroundShadesBrush = QBrush(QColor(0xaf, 0xaf, 0xaf, 0x50)); + m_backgroundShades = BackgroundShadesVertical; + +#elif defined(Q_OS_MAC) // TODO: replace this dummy theme with OSX specific theme - m_seriesColors << QRgb(0xff707070); - m_seriesColors << QRgb(0xffA0A0A0); + m_seriesColors << QRgb(0x60a6e6); + m_seriesColors << QRgb(0x92ca66); + m_seriesColors << QRgb(0xeba85f); + m_seriesColors << QRgb(0xfc5751); generateSeriesGradients(); QLinearGradient backgroundGradient; - backgroundGradient.setColorAt(0.0, QRgb(0xffffffff)); - backgroundGradient.setColorAt(1.0, QRgb(0xffafafaf)); + backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); + backgroundGradient.setColorAt(1.0, QRgb(0xe9e9e9)); backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); m_backgroundGradient = backgroundGradient; + + // Axes and other + m_masterFont = QFont(); + m_masterFont.setPointSizeF(10.0); + m_axisLinePen = QPen(Qt::black); + m_axisLinePen.setWidth(2); + m_axisLabelBrush = QBrush(Qt::black); + m_axisLabelPen = Qt::NoPen; // NoPen for performance reasons + m_backgroundShadesPen = Qt::NoPen; + m_backgroundShadesBrush = QBrush(QColor(0xaf, 0xaf, 0xaf, 0x50)); + m_backgroundShades = BackgroundShadesVertical; + #else // TODO: replace this dummy theme with generic (not OS specific) theme - m_seriesColors << QRgb(0xff707070); - m_seriesColors << QRgb(0xffA0A0A0); + m_seriesColors << QRgb(0x60a6e6); + m_seriesColors << QRgb(0x92ca66); + m_seriesColors << QRgb(0xeba85f); + m_seriesColors << QRgb(0xfc5751); generateSeriesGradients(); QLinearGradient backgroundGradient; - backgroundGradient.setColorAt(0.0, QRgb(0xffffffff)); - backgroundGradient.setColorAt(1.0, QRgb(0xffafafaf)); + backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); + backgroundGradient.setColorAt(1.0, QRgb(0xafafaf)); backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); m_backgroundGradient = backgroundGradient; + + // Axes and other + m_masterFont = QFont(); + m_masterFont.setPointSizeF(10.0); + m_axisLinePen = QPen(Qt::black); + m_axisLinePen.setWidth(2); + m_axisLabelBrush = QBrush(Qt::black); + m_axisLabelPen = Qt::NoPen; // NoPen for performance reasons + m_backgroundShadesPen = Qt::NoPen; + m_backgroundShadesBrush = QBrush(QColor(0xaf, 0xaf, 0xaf, 0x50)); + m_backgroundShades = BackgroundShadesVertical; #endif } }; diff --git a/src/themes/chartthemegrayscale_p.h b/src/themes/chartthemegrayscale_p.h index c2898a4..bf53c53 100644 --- a/src/themes/chartthemegrayscale_p.h +++ b/src/themes/chartthemegrayscale_p.h @@ -7,18 +7,29 @@ class ChartThemeGrayscale: public ChartTheme public: ChartThemeGrayscale():ChartTheme(QChart::ChartThemeGrayscale) { - m_seriesColors << QRgb(0xff869299); - m_seriesColors << QRgb(0xffa5bdcc); - m_seriesColors << QRgb(0xffe8fffc); - m_seriesColors << QRgb(0xffccc2c2); - + // Series colors + m_seriesColors << QRgb(0x869299); + m_seriesColors << QRgb(0xa5bdcc); + m_seriesColors << QRgb(0xe8fffc); + m_seriesColors << QRgb(0xccc2c2); generateSeriesGradients(); + // Background QLinearGradient backgroundGradient; - backgroundGradient.setColorAt(0.0, QRgb(0xffffffff)); - backgroundGradient.setColorAt(1.0, QRgb(0xffe0e3e5)); + backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); + backgroundGradient.setColorAt(1.0, QRgb(0xe0e3e5)); backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); m_backgroundGradient = backgroundGradient; + + // Axes and other + m_masterFont = QFont(); + m_axisLinePen = QPen(QRgb(0x0f0f0f)); + m_axisLinePen.setWidth(2); + m_axisLabelBrush = QBrush(QRgb(0x3f3f3f)); + m_axisLabelPen = Qt::NoPen; // NoPen for performance reasons + m_backgroundShadesPen = Qt::NoPen; + m_gridLinePen = QPen(QRgb(0x0f0f0f)); + m_gridLinePen.setWidth(2); } }; diff --git a/src/themes/chartthemeicy_p.h b/src/themes/chartthemeicy_p.h index b907553..f3b174f 100644 --- a/src/themes/chartthemeicy_p.h +++ b/src/themes/chartthemeicy_p.h @@ -7,18 +7,29 @@ class ChartThemeIcy: public ChartTheme public: ChartThemeIcy():ChartTheme(QChart::ChartThemeIcy) { - m_seriesColors << QRgb(0xff0d2673); - m_seriesColors << QRgb(0xff2685bf); - m_seriesColors << QRgb(0xff3dadd9); - m_seriesColors << QRgb(0xff62c3d9); - + // Series + m_seriesColors << QRgb(0x0d2673); + m_seriesColors << QRgb(0x2685bf); + m_seriesColors << QRgb(0x3dadd9); + m_seriesColors << QRgb(0x62c3d9); generateSeriesGradients(); + // Background QLinearGradient backgroundGradient; - backgroundGradient.setColorAt(0.0, QRgb(0xffebebeb)); - backgroundGradient.setColorAt(1.0, QRgb(0xfff8f9fb)); + backgroundGradient.setColorAt(0.0, QRgb(0xebebeb)); + backgroundGradient.setColorAt(1.0, QRgb(0xf8f9fb)); backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); m_backgroundGradient = backgroundGradient; + + // Axes and other + m_masterFont = QFont(); + m_axisLinePen = QPen(QRgb(0x0f0f0f)); + m_axisLinePen.setWidth(2); + m_axisLabelBrush = QBrush(QRgb(0x3f3f3f)); + m_axisLabelPen = Qt::NoPen; // NoPen for performance reasons + m_backgroundShadesPen = Qt::NoPen; + m_gridLinePen = QPen(QRgb(0x0f0f0f)); + m_gridLinePen.setWidth(2); } }; diff --git a/src/themes/chartthemescientific_p.h b/src/themes/chartthemescientific_p.h index ef35ddd..fb2cd1b 100644 --- a/src/themes/chartthemescientific_p.h +++ b/src/themes/chartthemescientific_p.h @@ -7,18 +7,29 @@ class ChartThemeScientific: public ChartTheme public: ChartThemeScientific():ChartTheme(QChart::ChartThemeScientific) { - m_seriesColors << QRgb(0xFFFFAD00); - m_seriesColors << QRgb(0xFF596A75); - m_seriesColors << QRgb(0xFF202020); - m_seriesColors << QRgb(0xFF474747); - + // Series + m_seriesColors << QRgb(0xFFAD00); + m_seriesColors << QRgb(0x596A75); + m_seriesColors << QRgb(0x202020); + m_seriesColors << QRgb(0x474747); generateSeriesGradients(); + // Background QLinearGradient backgroundGradient; - backgroundGradient.setColorAt(0.0, QRgb(0xfffffefc)); - backgroundGradient.setColorAt(1.0, QRgb(0xfffffefc)); + backgroundGradient.setColorAt(0.0, QRgb(0xfffefc)); + backgroundGradient.setColorAt(1.0, QRgb(0xfffefc)); backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); m_backgroundGradient = backgroundGradient; + + // Axes and other + m_masterFont = QFont(); + m_axisLinePen = QPen(QRgb(0x0f0f0f)); + m_axisLinePen.setWidth(2); + m_axisLabelBrush = QBrush(QRgb(0x3f3f3f)); + m_axisLabelPen = Qt::NoPen; // NoPen for performance reasons + m_backgroundShadesPen = Qt::NoPen; + m_gridLinePen = QPen(QRgb(0x0f0f0f)); + m_gridLinePen.setWidth(2); } }; diff --git a/src/themes/chartthemevanilla_p.h b/src/themes/chartthemevanilla_p.h index 65ba1ea..c085c77 100644 --- a/src/themes/chartthemevanilla_p.h +++ b/src/themes/chartthemevanilla_p.h @@ -7,19 +7,30 @@ class ChartThemeVanilla: public ChartTheme public: ChartThemeVanilla():ChartTheme(QChart::ChartThemeVanilla) { - m_seriesColors << QRgb(0xffd9c574); - m_seriesColors << QRgb(0xffd6a896); - m_seriesColors << QRgb(0xffa0a071); - m_seriesColors << QRgb(0xffd2d234); - m_seriesColors << QRgb(0xff88723a); - + // Series + m_seriesColors << QRgb(0xd9c574); + m_seriesColors << QRgb(0xd6a896); + m_seriesColors << QRgb(0xa0a071); + m_seriesColors << QRgb(0xd2d234); + m_seriesColors << QRgb(0x88723a); generateSeriesGradients(); + // Background QLinearGradient backgroundGradient; - backgroundGradient.setColorAt(0.0, QRgb(0xfffbf9f1)); - backgroundGradient.setColorAt(1.0, QRgb(0xfff5f0dc)); + backgroundGradient.setColorAt(0.0, QRgb(0xfbf9f1)); + backgroundGradient.setColorAt(1.0, QRgb(0xf5f0dc)); backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); m_backgroundGradient = backgroundGradient; + + // Axes and other + m_masterFont = QFont(); + m_axisLinePen = QPen(QRgb(0x0f0f0f)); + m_axisLinePen.setWidth(2); + m_axisLabelBrush = QBrush(QRgb(0xa0a071)); + m_axisLabelPen = Qt::NoPen; // NoPen for performance reasons + m_backgroundShadesPen = Qt::NoPen; + m_gridLinePen = QPen(QRgb(0x0f0f0f)); + m_gridLinePen.setWidth(2); } };