Warning, file /graphics/kdiagram/examples/demo/datasetsettings.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /** 0002 * Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved. 0003 * 0004 * This file is part of the KD Chart library. 0005 * 0006 * This program is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU General Public License as 0008 * published by the Free Software Foundation; either version 2 of 0009 * the License, or (at your option) any later version. 0010 * 0011 * This program is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0014 * GNU General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU General Public License 0017 * along with this program. If not, see <https://www.gnu.org/licenses/>. 0018 */ 0019 0020 #include "datasetsettings.h" 0021 #include "ui_datasetsettings.h" 0022 0023 #include <KChartAbstractCoordinatePlane> 0024 #include <KChartChart> 0025 0026 #include <QColorDialog> 0027 #include <QFileDialog> 0028 0029 #include <QStyleFactory> 0030 0031 #include <QImage> 0032 0033 #include <QObject> 0034 0035 #include <QDebug> 0036 0037 #include "gradientdialog.h" 0038 0039 using namespace KChart; 0040 0041 class DatasetSettings::Private : public QObject 0042 { 0043 Q_OBJECT 0044 public: 0045 Private( Chart *chart, DatasetSettings *q, QObject *parent ); 0046 ~Private(); 0047 0048 Ui::DatasetSettings *ui; 0049 int m_dataset; 0050 int m_datasetCount; 0051 KChart::Chart *m_chart; 0052 DatasetSettings *qq; 0053 public Q_SLOTS: 0054 void changeColor(); 0055 void changeOutline(); 0056 }; 0057 0058 DatasetSettings::Private::Private( Chart *chart, DatasetSettings *q, QObject *parent ) 0059 : QObject( parent ) 0060 , ui( new Ui::DatasetSettings ) 0061 , m_dataset( 0 ) 0062 , m_datasetCount( 0 ) 0063 , m_chart( chart ) 0064 , qq( q ) 0065 { 0066 0067 } 0068 0069 DatasetSettings::Private::~Private() 0070 { 0071 delete ui; 0072 } 0073 0074 void DatasetSettings::Private::changeColor() 0075 { 0076 const int index = ui->datasetSelector->currentIndex(); 0077 if ( ui->Color->isChecked() ) 0078 { 0079 QBrush setBrush = m_chart->coordinatePlane()->diagram()->brush( index ); 0080 const QColor color = QColorDialog::getColor( setBrush.color(), qq, tr( "Choose new color" ) ); 0081 if ( !color.isValid() ) 0082 return; 0083 m_chart->coordinatePlane()->diagram()->setBrush( index, color ); 0084 QPalette palette = ui->colorDisplay->palette(); 0085 palette.setBrush( QPalette::Button, color ); 0086 ui->colorDisplay->setPalette( palette ); 0087 } 0088 else if ( ui->textureBtn->isChecked() ) 0089 { 0090 //QBrush setBrush = m_chart->coordinatePlane()->diagram()->brush( index ); 0091 QImage texture; 0092 0093 const QString filename = QFileDialog::getOpenFileName( qq, tr( "Choose Texture" ), QString(), tr( "Images (*.png *.xpm *.jpg)" ) ); 0094 if ( filename.isEmpty() ) 0095 return; 0096 texture = QImage( filename ); 0097 m_chart->coordinatePlane()->diagram()->setBrush( index, texture ); 0098 QPalette palette = ui->colorDisplay->palette(); 0099 palette.setBrush( QPalette::Button, QBrush( texture ) ); 0100 ui->colorDisplay->setPalette( palette ); 0101 } 0102 else 0103 { 0104 QBrush setBrush = m_chart->coordinatePlane()->diagram()->brush( index ); 0105 QGradient grad; 0106 QLinearGradient lGrad; 0107 lGrad.setColorAt( 0, Qt::black ); 0108 lGrad.setColorAt( 1, setBrush.color() ); 0109 grad = lGrad; 0110 0111 if ( setBrush.gradient() ) 0112 grad = *setBrush.gradient(); 0113 const QGradient &color = GradientDialog::getGradient( grad, qq, tr( "Choose new color" ) ); 0114 m_chart->coordinatePlane()->diagram()->setBrush( index, color ); 0115 QPalette palette = ui->colorDisplay->palette(); 0116 palette.setBrush( QPalette::Button, QBrush( color ) ); 0117 ui->colorDisplay->setPalette( palette ); 0118 } 0119 } 0120 0121 void DatasetSettings::Private::changeOutline() 0122 { 0123 const int index = ui->datasetSelector->currentIndex(); 0124 if ( ui->Color->isChecked() ) 0125 { 0126 QPen pen = m_chart->coordinatePlane()->diagram()->pen( index ); 0127 const QColor color = QColorDialog::getColor( pen.color(), qq, tr( "Choose new color" ) ); 0128 if ( !color.isValid() ) 0129 return; 0130 pen.setColor( color ); 0131 m_chart->coordinatePlane()->diagram()->setPen( index, pen ); 0132 QPalette palette = ui->outlineBtn->palette(); 0133 palette.setBrush( QPalette::Button, color ); 0134 ui->outlineBtn->setPalette( palette ); 0135 } 0136 } 0137 0138 DatasetSettings::DatasetSettings( Chart *chart, QWidget *parent ) 0139 : QWidget( parent ) 0140 , d( new Private( chart, this, this ) ) 0141 { 0142 d->ui->setupUi(this); 0143 #ifdef Q_OS_LINUX 0144 d->ui->colorDisplay->setStyle( QStyleFactory::create( QStringLiteral( "cleanlooks" ) ) ); 0145 d->ui->outlineBtn->setStyle( QStyleFactory::create( QStringLiteral( "cleanlooks" ) ) ); 0146 #endif 0147 connect( d->ui->datasetSelector, SIGNAL(currentIndexChanged(int)), this, SLOT(indexChanged(int)) ); 0148 connect( d->ui->colorDisplay, SIGNAL(clicked()), d, SLOT(changeColor()) ); 0149 connect( d->ui->outlineBtn, SIGNAL(clicked()), d, SLOT(changeOutline()) ); 0150 } 0151 0152 DatasetSettings::~DatasetSettings() 0153 { 0154 delete d; 0155 } 0156 0157 int DatasetSettings::datasetCount() const 0158 { 0159 return d->m_datasetCount; 0160 } 0161 void DatasetSettings::setDatasetCount( int value ) 0162 { 0163 if ( d->m_datasetCount != value ) 0164 { 0165 d->m_datasetCount = value; 0166 QStringList list; 0167 for ( int i = 0; i < value; ++i ) 0168 { 0169 list << tr( "Dataset %1" ).arg( i ); 0170 } 0171 d->ui->datasetSelector->clear(); 0172 d->ui->datasetSelector->addItems( list ); 0173 Q_EMIT datasetCountChanged(); 0174 } 0175 } 0176 0177 void DatasetSettings::indexChanged( int index ) 0178 { 0179 if ( d->m_chart && index >= 0 ) 0180 { 0181 const QBrush setBrush = d->m_chart->coordinatePlane()->diagram()->brush( index ); 0182 QPalette palette = d->ui->colorDisplay->palette(); 0183 if ( setBrush.gradient() ) 0184 d->ui->radioButton_2->setChecked( true ); 0185 else if ( !setBrush.textureImage().isNull() ) 0186 d->ui->textureBtn->setChecked( true ); 0187 else 0188 d->ui->Color->setChecked( true ); 0189 palette.setBrush( QPalette::Button, setBrush ); 0190 d->ui->colorDisplay->setPalette( palette ); 0191 const QPen pen = d->m_chart->coordinatePlane()->diagram()->pen( index ); 0192 QPalette penPalette = d->ui->outlineBtn->palette(); 0193 penPalette.setBrush( QPalette::Button, pen.color() ); 0194 d->ui->outlineBtn->setPalette( penPalette ); 0195 } 0196 } 0197 0198 void DatasetSettings::diagramTypeChanged() 0199 { 0200 0201 } 0202 0203 #include "datasetsettings.moc"