File indexing completed on 2024-05-12 16:33:36
0001 /* This file is part of the KDE project 0002 0003 Copyright 2018 Dag Andersen <danders@get2net.dk> 0004 0005 This library is free software; you can redistribute it and/or 0006 modify it under the terms of the GNU Library General Public 0007 License as published by the Free Software Foundation; either 0008 version 2 of the License, or (at your option) any later version. 0009 0010 This library is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 Library General Public License for more details. 0014 0015 You should have received a copy of the GNU Library General Public License 0016 along with this library; see the file COPYING.LIB. If not, write to 0017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 Boston, MA 02110-1301, USA. 0019 */ 0020 0021 // Own 0022 #include "StockConfigWidget.h" 0023 #include "ui_StockConfigWidget.h" 0024 0025 // Qt 0026 #include <QLatin1String> 0027 0028 // KF5 0029 #include <klocalizedstring.h> 0030 0031 // Calligra 0032 #include <interfaces/KoChartModel.h> 0033 #include <KoIcon.h> 0034 0035 // KChart 0036 0037 // KoChart 0038 #include "ChartProxyModel.h" 0039 #include "PlotArea.h" 0040 #include "ChartDebug.h" 0041 0042 using namespace KoChart; 0043 0044 0045 StockConfigWidget::StockConfigWidget(QWidget *parent) 0046 : ConfigSubWidgetBase(parent) 0047 { 0048 init(); 0049 } 0050 0051 StockConfigWidget::StockConfigWidget(QList<ChartType> types, QWidget *parent) 0052 : ConfigSubWidgetBase(types, parent) 0053 { 0054 init(); 0055 } 0056 0057 StockConfigWidget::~StockConfigWidget() 0058 { 0059 } 0060 0061 void StockConfigWidget::init() 0062 { 0063 setObjectName("StockConfigWidget"); 0064 m_ui.setupUi(this); 0065 m_plotArea = 0; 0066 0067 connect(m_ui.gainMarker, SIGNAL(changed(QColor)), this, SLOT(gainClicked(QColor))); 0068 connect(m_ui.lossMarker, SIGNAL(changed(QColor)), this, SLOT(lossClicked(QColor))); 0069 } 0070 0071 void StockConfigWidget::open(ChartShape* shape) 0072 { 0073 ConfigSubWidgetBase::open(shape); 0074 m_plotArea = 0; 0075 if (!chart) { 0076 return; 0077 } 0078 m_plotArea = chart->plotArea(); 0079 m_ui.rangeLineStroke->open(shape); 0080 } 0081 0082 void StockConfigWidget::updateData(ChartType type, ChartSubtype subtype) 0083 { 0084 Q_UNUSED(subtype); 0085 0086 if (!chart || !chartTypes.contains(type)) { 0087 return; 0088 } 0089 m_ui.rangeLineStroke->updateData(); 0090 0091 m_ui.gainMarker->setColor(m_plotArea->stockGainBrush().color()); 0092 m_ui.lossMarker->setColor(m_plotArea->stockLossBrush().color()); 0093 } 0094 0095 void StockConfigWidget::gainClicked(const QColor& color) 0096 { 0097 QBrush brush = QBrush(color); 0098 brush.setStyle(Qt::SolidPattern); 0099 m_plotArea->setStockGainBrush(brush); 0100 chart->updateAll(); 0101 } 0102 0103 void StockConfigWidget::lossClicked(const QColor& color) 0104 { 0105 QBrush brush = QBrush(color); 0106 brush.setStyle(Qt::SolidPattern); 0107 m_plotArea->setStockLossBrush(brush); 0108 chart->updateAll(); 0109 }