00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kchartColorConfigPage.h"
00021 #include "kchartColorConfigPage.moc"
00022
00023 #include <kapplication.h>
00024 #include <kdialog.h>
00025 #include <klocale.h>
00026 #include <kcolorbutton.h>
00027 #include <qlayout.h>
00028 #include <qlabel.h>
00029 #include <qbuttongroup.h>
00030 #include <qwhatsthis.h>
00031 #include <qhbox.h>
00032 #include <klistbox.h>
00033 #include "kchart_params.h"
00034 #include <kdebug.h>
00035
00036 namespace KChart
00037 {
00038
00039 KChartColorConfigPage::KChartColorConfigPage( KChartParams* params,
00040 QWidget* parent,
00041 KDChartTableData *dat ) :
00042 QWidget( parent ),
00043 m_params( params ),
00044 m_data( dat ),
00045 index( 0 )
00046 {
00047 QWhatsThis::add( this, i18n( "This page lets you configure the colors "
00048 "in which your chart is displayed. Each "
00049 "part of the chart can be assigned a "
00050 "different color." ) );
00051
00052 QVBoxLayout* toplevel = new QVBoxLayout( this, 10 );
00053 QButtonGroup* gb = new QButtonGroup( 0, Qt::Vertical, i18n("Colors"), this );
00054 gb->layout()->setSpacing(KDialog::spacingHint());
00055 gb->layout()->setMargin(KDialog::marginHint());
00056 toplevel->addWidget( gb);
00057 QString wtstr;
00058 QGridLayout* grid = new QGridLayout( gb->layout(), 8, 3 );
00059
00060 QLabel* lineLA = new QLabel( i18n( "&Line color:" ), gb );
00061 lineLA->setAlignment( AlignRight | AlignVCenter );
00062 grid->addWidget( lineLA, 0, 0 );
00063 _lineCB = new KColorButton( gb );
00064 lineLA->setBuddy( _lineCB );
00065 grid->addWidget( _lineCB, 0, 1 );
00066 wtstr = i18n( "This is the color that is used for drawing lines like axes." );
00067 QWhatsThis::add( lineLA, wtstr );
00068 QWhatsThis::add( _lineCB, wtstr );
00069
00070 QLabel* gridLA = new QLabel( i18n( "&Grid color:" ), gb );
00071 gridLA->setAlignment( AlignRight | AlignVCenter );
00072 grid->addWidget( gridLA, 1, 0 );
00073 _gridCB = new KColorButton( gb );
00074 gridLA->setBuddy( _gridCB );
00075 grid->addWidget( _gridCB, 1, 1 );
00076 wtstr = i18n( "Here you can configure the color that is used for the "
00077 "chart grid. Of course, this setting will only "
00078 "take effect if grid drawing is turned on." );
00079 QWhatsThis::add( gridLA, wtstr );
00080 QWhatsThis::add( _gridCB, wtstr );
00081
00082 QLabel* xtitleLA = new QLabel( i18n("&X-title color:" ), gb );
00083 xtitleLA->setAlignment( AlignRight | AlignVCenter );
00084 grid->addWidget( xtitleLA, 2, 0 );
00085 _xtitleCB = new KColorButton( gb );
00086 xtitleLA->setBuddy( _xtitleCB );
00087 grid->addWidget( _xtitleCB, 2, 1 );
00088 wtstr = i18n( "This color is used for displaying titles for the "
00089 "X (horizontal) axis. This setting overrides the setting "
00090 "<i>Title Color</i>." );
00091 QWhatsThis::add( xtitleLA, wtstr );
00092 QWhatsThis::add( _xtitleCB, wtstr );
00093
00094 QLabel* ytitleLA = new QLabel( i18n("&Y-title color:" ), gb );
00095 ytitleLA->setAlignment( AlignRight | AlignVCenter );
00096 grid->addWidget( ytitleLA, 3, 0 );
00097 _ytitleCB = new KColorButton( gb );
00098 ytitleLA->setBuddy( _ytitleCB );
00099 grid->addWidget( _ytitleCB, 3, 1 );
00100 wtstr = i18n( "This color is used for displaying titles for the "
00101 "Y (vertical) axis. This setting overrides the setting "
00102 "<i>Title Color</i>." );
00103 QWhatsThis::add( ytitleLA, wtstr );
00104 QWhatsThis::add( _ytitleCB, wtstr );
00105
00106 #if 0
00107 QLabel* ytitle2LA = new QLabel( i18n( "Y-title color (2nd axis):" ), gb );
00108 ytitle2LA->setAlignment( AlignRight | AlignVCenter );
00109 grid->addWidget( ytitle2LA, 4, 0 );
00110 _ytitle2CB = new KColorButton( gb );
00111 ytitle2LA->setBuddy( _ytitle2CB );
00112 grid->addWidget( _ytitle2CB, 4, 1 );
00113 wtstr = i18n( "This color is used for displaying titles for the "
00114 "second Y (vertical) axis. It only takes effect if the "
00115 "chart is configured to have a second Y axis. This setting "
00116 "overrides the setting <i>Title Color</i>." );
00117 QWhatsThis::add( ytitle2LA, wtstr );
00118 QWhatsThis::add( _ytitle2CB, wtstr );
00119 #endif
00120
00121 QLabel* xlabelLA = new QLabel( i18n( "X-label color:" ), gb );
00122 xlabelLA->setAlignment( AlignRight | AlignVCenter );
00123 grid->addWidget( xlabelLA, 4, 0 );
00124 _xlabelCB = new KColorButton( gb );
00125 xlabelLA->setBuddy( _xlabelCB );
00126 grid->addWidget( _xlabelCB, 4, 1 );
00127 wtstr = i18n( "Here you can configure the color that is used for "
00128 "labeling the X (horizontal) axis" );
00129 QWhatsThis::add( xlabelLA, wtstr );
00130 QWhatsThis::add( _xlabelCB, wtstr );
00131
00132 QLabel* ylabelLA = new QLabel( i18n( "Y-label color:" ), gb );
00133 ylabelLA->setAlignment( AlignRight | AlignVCenter );
00134 grid->addWidget( ylabelLA, 5, 0 );
00135 _ylabelCB = new KColorButton( gb );
00136 ylabelLA->setBuddy( _ylabelCB );
00137 grid->addWidget( _ylabelCB, 5, 1 );
00138 wtstr = i18n( "Here you can configure the color that is used for "
00139 "labeling the Y (vertical) axis" );
00140 QWhatsThis::add( ylabelLA, wtstr );
00141 QWhatsThis::add( _ylabelCB, wtstr );
00142
00143 #if 0
00144 QLabel* ylabel2LA = new QLabel( i18n( "Y-label color (2nd axis):" ), gb );
00145 ylabel2LA->setAlignment( AlignRight | AlignVCenter );
00146 grid->addWidget( ylabel2LA, 7, 0 );
00147 _ylabel2CB = new KColorButton( gb );
00148 ylabel2LA->setBuddy( _ylabel2CB );
00149 grid->addWidget( _ylabel2CB, 7, 1 );
00150 wtstr = i18n( "Here you can configure the color that is used for "
00151 "labeling the second Y (vertical) axis. Of course, "
00152 "this setting only takes effect if the chart is "
00153 "configured to have two vertical axes." );
00154 QWhatsThis::add( ylabel2LA, wtstr );
00155 QWhatsThis::add( _ylabel2CB, wtstr );
00156 #endif
00157
00158 QHBox* dataColorHB = new QHBox( gb );
00159 grid->addMultiCellWidget( dataColorHB, 0, 7, 2, 2 );
00160 _dataColorLB = new KListBox(dataColorHB);
00161 _dataColorCB = new KColorButton( dataColorHB);
00162 wtstr = i18n( "Choose a row/column in the list on the left and change its color using this button.");
00163 QWhatsThis::add( _dataColorCB, wtstr );
00164 initDataColorList();
00165 connect( _dataColorLB, SIGNAL(highlighted(int )), this, SLOT(changeIndex(int)));
00166 connect( _dataColorLB, SIGNAL(doubleClicked ( QListBoxItem * )), this, SLOT(activeColorButton()));
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190 }
00191
00192
00193 void KChartColorConfigPage::changeIndex(int newindex)
00194 {
00195 if(index > m_params->maxDataColor())
00196 _dataColorLB->setEnabled(false);
00197 else
00198 {
00199 if(!_dataColorCB->isEnabled())
00200 _dataColorCB->setEnabled(true);
00201 extColor[index] = _dataColorCB->color();
00202 _dataColorCB->setColor(extColor[newindex]);
00203 index=newindex;
00204 }
00205 }
00206
00207
00208 void KChartColorConfigPage::activeColorButton()
00209 {
00210 _dataColorCB->animateClick();
00211 }
00212
00213
00214 void KChartColorConfigPage::initDataColorList()
00215 {
00216 QStringList lst;
00217 for(uint i = 0; i < m_data->rows(); i++)
00218 {
00219 extColor.resize( m_params->maxDataColor() );
00220 if(i<m_params->maxDataColor())
00221 {
00222 _dataColorLB->insertItem(m_params->legendText( i ).isEmpty() ? i18n("Series %1").arg(i+1) :m_params->legendText( i ) );
00223 extColor[i] =m_params->dataColor(i);
00224 }
00225 }
00226 _dataColorLB->setCurrentItem(0);
00227
00228
00229 if ( m_data->rows() == 0 )
00230 _dataColorCB->setEnabled(false);
00231 else
00232 _dataColorCB->setColor( extColor[index]);
00233 }
00234
00235
00236 void KChartColorConfigPage::apply()
00237 {
00238
00239 if ( m_data->rows() == 0 )
00240 return;
00241
00242 extColor[index] = _dataColorCB->color();
00243 for(uint i =0;i<m_data->rows();i++)
00244 if(i<m_params->maxDataColor())
00245 m_params->setDataColor(i,extColor[i]);
00246 }
00247
00248 }