kchart

kchartColorConfigPage.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 1999 Matthias Kalle Dalheimer <kalle@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
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, 14 );
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     const int labelAlign = AlignRight | AlignVCenter;
00061     int row = -1;
00062 #define ADD_COLOR_BTN(btn,title,whatsthis) \
00063 {                                          \
00064     ++row;                                 \
00065     QLabel* l = new QLabel( title, gb );   \
00066     l->setAlignment( labelAlign );         \
00067     grid->addWidget( l, row, 0 );          \
00068     btn = new KColorButton( gb );          \
00069     l->setBuddy( btn );                    \
00070     grid->addWidget( btn, row, 1 );        \
00071     QWhatsThis::add( l, whatsthis );       \
00072     QWhatsThis::add( btn, whatsthis );     \
00073 }
00074     ADD_COLOR_BTN(_lineCB, i18n( "&Line color:" ),
00075         i18n( "This is the color that is used for drawing lines like axes." ))
00076     ADD_COLOR_BTN(_gridCB, i18n( "&Grid color:" ),
00077         i18n( "Here you can configure the color that is used for the "
00078               "chart grid. Of course, this setting will only "
00079               "take effect if grid drawing is turned on." ))
00080     ADD_COLOR_BTN(_xtitleCB, i18n( "&X-title color:" ),
00081         i18n( "This color is used for displaying titles for the "
00082               "X (horizontal) axis." ))
00083     ADD_COLOR_BTN(_ytitleCB, i18n( "&Y-title color:" ),
00084         i18n( "This color is used for displaying titles for the "
00085               "Y (vertical) axis." ))
00086 #if 0
00087     ADD_COLOR_BTN(_ytitle2CB, i18n( "Y-title color (2nd axis):" ),
00088         i18n( "This color is used for displaying titles for the "
00089               "second Y (vertical) axis. It only takes effect if the "
00090               "chart is configured to have a second Y axis." ))
00091 #endif
00092     ADD_COLOR_BTN(_xlabelCB, i18n( "X-label color:" ),
00093         i18n( "Here you can configure the color that is used for "
00094               "labeling the X (horizontal) axis" ))
00095     ADD_COLOR_BTN(_ylabelCB, i18n( "Y-label color:" ),
00096         i18n( "Here you can configure the color that is used for "
00097               "labeling the Y (vertical) axis" ))
00098 #if 0
00099     ADD_COLOR_BTN(_ylabel2CB, i18n( "Y-label color (2nd axis):" ),
00100         i18n( "Here you can configure the color that is used for "
00101               "labeling the second Y (vertical) axis. Of course, "
00102               "this setting only takes effect if the chart is "
00103               "configured to have two vertical axes." ))
00104 #endif
00105     ADD_COLOR_BTN(_xlineCB, i18n( "X-line color:" ),
00106         i18n( "Here you can configure the line color of the X (horizontal) axis" ))
00107     ADD_COLOR_BTN(_ylineCB, i18n( "Y-line color:" ),
00108         i18n( "Here you can configure the line color of the Y (vertical) axis" ))
00109 #if 0
00110     ADD_COLOR_BTN(_yline2CB, i18n( "Y-line color (2nd axis):" ),
00111         i18n( "Here you can configure the line color of "
00112               "the second Y (vertical) axis. Of course, "
00113               "this setting only takes effect if the chart is "
00114               "configured to have two vertical axes." ))
00115 #endif
00116     ADD_COLOR_BTN(_xzerolineCB, i18n( "X-Zero-line color:" ),
00117         i18n( "Here you can configure the zero-line's color of the X "
00118               "(horizontal) axis. Of course, this setting only takes "
00119               "effect if the abscissa is displaying a Zero-line." ))
00120     ADD_COLOR_BTN(_yzerolineCB, i18n( "Y-Zero-line color:" ),
00121         i18n( "Here you can configure the zero-line's color of the Y (vertical) axis" ))
00122 #if 0
00123     ADD_COLOR_BTN(_yzeroline2CB, i18n( "Y-Zero-line color (2nd axis):" ),
00124         i18n( "Here you can configure the color that is used for "
00125               "the Zero-line of the second Y (vertical) axis. Of course, "
00126               "this setting only takes effect if the chart is "
00127               "configured to have two vertical axes." ))
00128 #endif
00129 
00130     QHBox* dataColorHB = new QHBox( gb );
00131     grid->addMultiCellWidget( dataColorHB,  0, row, 2, 2 );
00132     _dataColorLB = new KListBox(dataColorHB);
00133     _dataColorCB = new KColorButton( dataColorHB);
00134     wtstr = i18n( "Choose a row/column in the list on the left and change its color using this button.");
00135     QWhatsThis::add( _dataColorCB, wtstr );
00136     initDataColorList();
00137     connect( _dataColorLB, SIGNAL(highlighted(int )), this, SLOT(changeIndex(int)));
00138     connect( _dataColorLB, SIGNAL(doubleClicked ( QListBoxItem * )), this, SLOT(activeColorButton()));
00139 
00140 
00141 
00142     /*QLabel* edgeLA = new QLabel( i18n( "Edge color (pies only)" ), this );
00143       edgeLA->setAlignment( AlignRight | AlignVCenter );
00144       grid->addWidget( edgeLA, 6, 0 );
00145       _edgeCB = new KColorButton( this );
00146       grid->addWidget( _edgeCB, 6, 1 );*/
00147 
00148 //     for( int i = 0; i < NUMDATACOLORS; i++ ) {
00149 //  QString labeltext;
00150 //  labeltext.sprintf( i18n( "Data color #%d:"), i );
00151 //  QLabel* dataLA = new QLabel( labeltext, this );
00152 //  dataLA->setAlignment(AlignRight | AlignVCenter);
00153 //  dataLA->resize( dataLA->sizeHint() );
00154 //  grid->addWidget( dataLA, i, 2 );
00155 //  _dataCB[i] = new KColorButton( this );
00156 //  _dataCB[i]->resize( _dataCB[i]->sizeHint() );
00157 //  grid->addWidget( _dataCB[i], i, 3 );
00158 //  grid->addRowSpacing(i,_textCB->height());
00159 //  grid->setRowStretch(i,0);
00160 //  grid->addColSpacing(2,dataLA->width() + 20);
00161 //     }
00162 }
00163 
00164 
00165 void KChartColorConfigPage::changeIndex(int newindex)
00166 {
00167     if(index > m_params->maxDataColor())
00168         _dataColorLB->setEnabled(false);
00169     else
00170     {
00171         if(!_dataColorCB->isEnabled())
00172             _dataColorCB->setEnabled(true);
00173         extColor[index] = _dataColorCB->color();
00174         _dataColorCB->setColor(extColor[newindex]);
00175         index=newindex;
00176     }
00177 }
00178 
00179 
00180 void KChartColorConfigPage::activeColorButton()
00181 {
00182     _dataColorCB->animateClick();
00183 }
00184 
00185 
00186 void KChartColorConfigPage::initDataColorList()
00187 {
00188     QStringList lst;
00189     for(uint i = 0; i < m_data->rows(); i++)
00190     {
00191         extColor.resize( m_params->maxDataColor() );
00192         if(i<m_params->maxDataColor())
00193         {
00194             _dataColorLB->insertItem(m_params->legendText( i ).isEmpty() ? i18n("Series %1").arg(i+1) :m_params->legendText( i ) );
00195             extColor[i] =m_params->dataColor(i);
00196         }
00197     }
00198     _dataColorLB->setCurrentItem(0);
00199 
00200      //Fix crash when we didn't create data
00201     if ( m_data->rows() == 0 )
00202         _dataColorCB->setEnabled(false);
00203     else
00204         _dataColorCB->setColor( extColor[index]);
00205 }
00206 
00207 
00208 void KChartColorConfigPage::apply()
00209 {
00210     //Nothing to save
00211     if ( m_data->rows() == 0 )
00212         return;
00213 
00214     extColor[index] = _dataColorCB->color();
00215     for(uint i =0;i<m_data->rows();i++)
00216         if(i<m_params->maxDataColor())
00217             m_params->setDataColor(i,extColor[i]);
00218 }
00219 
00220 }  //KChart namespace
KDE Home | KDE Accessibility Home | Description of Access Keys