kchart

kchartColorConfigPage.cpp
1/* This file is part of the KDE project
2 Copyright (C) 1999 Matthias Kalle Dalheimer <kalle@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include "kchartColorConfigPage.h"
21#include "kchartColorConfigPage.moc"
22
23#include <tdeapplication.h>
24#include <kdialog.h>
25#include <tdelocale.h>
26#include <kcolorbutton.h>
27#include <tqlayout.h>
28#include <tqlabel.h>
29#include <tqbuttongroup.h>
30#include <tqwhatsthis.h>
31#include <tqhbox.h>
32#include <tdelistbox.h>
33#include "kchart_params.h"
34#include <kdebug.h>
35
36namespace KChart
37{
38
39KChartColorConfigPage::KChartColorConfigPage( KChartParams* params,
40 TQWidget* parent,
41 KDChartTableData *dat ) :
42 TQWidget( parent ),
43 m_params( params ),
44 m_data( dat ),
45 index( 0 )
46{
47 TQWhatsThis::add( this, i18n( "This page lets you configure the colors "
48 "in which your chart is displayed. Each "
49 "part of the chart can be assigned a "
50 "different color." ) );
51
52 TQVBoxLayout* toplevel = new TQVBoxLayout( this, 14 );
53 TQButtonGroup* gb = new TQButtonGroup( 0, TQt::Vertical, i18n("Colors"), this );
54 gb->layout()->setSpacing(KDialog::spacingHint());
55 gb->layout()->setMargin(KDialog::marginHint());
56 toplevel->addWidget( gb);
57 TQString wtstr;
58 TQGridLayout* grid = new TQGridLayout( gb->layout(), 8, 3 );
59
60 const int labelAlign = AlignRight | AlignVCenter;
61 int row = -1;
62#define ADD_COLOR_BTN(btn,title,whatsthis) \
63{ \
64 ++row; \
65 TQLabel* l = new TQLabel( title, gb ); \
66 l->setAlignment( labelAlign ); \
67 grid->addWidget( l, row, 0 ); \
68 btn = new KColorButton( gb ); \
69 l->setBuddy( btn ); \
70 grid->addWidget( btn, row, 1 ); \
71 TQWhatsThis::add( l, whatsthis ); \
72 TQWhatsThis::add( btn, whatsthis ); \
73}
74 ADD_COLOR_BTN(_lineCB, i18n( "&Line color:" ),
75 i18n( "This is the color that is used for drawing lines like axes." ))
76 ADD_COLOR_BTN(_gridCB, i18n( "&Grid color:" ),
77 i18n( "Here you can configure the color that is used for the "
78 "chart grid. Of course, this setting will only "
79 "take effect if grid drawing is turned on." ))
80 ADD_COLOR_BTN(_xtitleCB, i18n( "&X-title color:" ),
81 i18n( "This color is used for displaying titles for the "
82 "X (horizontal) axis." ))
83 ADD_COLOR_BTN(_ytitleCB, i18n( "&Y-title color:" ),
84 i18n( "This color is used for displaying titles for the "
85 "Y (vertical) axis." ))
86#if 0
87 ADD_COLOR_BTN(_ytitle2CB, i18n( "Y-title color (2nd axis):" ),
88 i18n( "This color is used for displaying titles for the "
89 "second Y (vertical) axis. It only takes effect if the "
90 "chart is configured to have a second Y axis." ))
91#endif
92 ADD_COLOR_BTN(_xlabelCB, i18n( "X-label color:" ),
93 i18n( "Here you can configure the color that is used for "
94 "labeling the X (horizontal) axis" ))
95 ADD_COLOR_BTN(_ylabelCB, i18n( "Y-label color:" ),
96 i18n( "Here you can configure the color that is used for "
97 "labeling the Y (vertical) axis" ))
98#if 0
99 ADD_COLOR_BTN(_ylabel2CB, i18n( "Y-label color (2nd axis):" ),
100 i18n( "Here you can configure the color that is used for "
101 "labeling the second Y (vertical) axis. Of course, "
102 "this setting only takes effect if the chart is "
103 "configured to have two vertical axes." ))
104#endif
105 ADD_COLOR_BTN(_xlineCB, i18n( "X-line color:" ),
106 i18n( "Here you can configure the line color of the X (horizontal) axis" ))
107 ADD_COLOR_BTN(_ylineCB, i18n( "Y-line color:" ),
108 i18n( "Here you can configure the line color of the Y (vertical) axis" ))
109#if 0
110 ADD_COLOR_BTN(_yline2CB, i18n( "Y-line color (2nd axis):" ),
111 i18n( "Here you can configure the line color of "
112 "the second Y (vertical) axis. Of course, "
113 "this setting only takes effect if the chart is "
114 "configured to have two vertical axes." ))
115#endif
116 ADD_COLOR_BTN(_xzerolineCB, i18n( "X-Zero-line color:" ),
117 i18n( "Here you can configure the zero-line's color of the X "
118 "(horizontal) axis. Of course, this setting only takes "
119 "effect if the abscissa is displaying a Zero-line." ))
120 ADD_COLOR_BTN(_yzerolineCB, i18n( "Y-Zero-line color:" ),
121 i18n( "Here you can configure the zero-line's color of the Y (vertical) axis" ))
122#if 0
123 ADD_COLOR_BTN(_yzeroline2CB, i18n( "Y-Zero-line color (2nd axis):" ),
124 i18n( "Here you can configure the color that is used for "
125 "the Zero-line of the second Y (vertical) axis. Of course, "
126 "this setting only takes effect if the chart is "
127 "configured to have two vertical axes." ))
128#endif
129
130 TQHBox* dataColorHB = new TQHBox( gb );
131 grid->addMultiCellWidget( dataColorHB, 0, row, 2, 2 );
132 _dataColorLB = new TDEListBox(dataColorHB);
133 _dataColorCB = new KColorButton( dataColorHB);
134 wtstr = i18n( "Choose a row/column in the list on the left and change its color using this button.");
135 TQWhatsThis::add( _dataColorCB, wtstr );
136 initDataColorList();
137 connect( _dataColorLB, TQ_SIGNAL(highlighted(int )), this, TQ_SLOT(changeIndex(int)));
138 connect( _dataColorLB, TQ_SIGNAL(doubleClicked ( TQListBoxItem * )), this, TQ_SLOT(activeColorButton()));
139
140
141
142 /*TQLabel* edgeLA = new TQLabel( i18n( "Edge color (pies only)" ), this );
143 edgeLA->setAlignment( AlignRight | AlignVCenter );
144 grid->addWidget( edgeLA, 6, 0 );
145 _edgeCB = new KColorButton( this );
146 grid->addWidget( _edgeCB, 6, 1 );*/
147
148// for( int i = 0; i < NUMDATACOLORS; i++ ) {
149// TQString labeltext;
150// labeltext.sprintf( i18n( "Data color #%d:"), i );
151// TQLabel* dataLA = new TQLabel( labeltext, this );
152// dataLA->setAlignment(AlignRight | AlignVCenter);
153// dataLA->resize( dataLA->sizeHint() );
154// grid->addWidget( dataLA, i, 2 );
155// _dataCB[i] = new KColorButton( this );
156// _dataCB[i]->resize( _dataCB[i]->sizeHint() );
157// grid->addWidget( _dataCB[i], i, 3 );
158// grid->addRowSpacing(i,_textCB->height());
159// grid->setRowStretch(i,0);
160// grid->addColSpacing(2,dataLA->width() + 20);
161// }
162}
163
164
165void KChartColorConfigPage::changeIndex(int newindex)
166{
167 if(index > m_params->maxDataColor())
168 _dataColorLB->setEnabled(false);
169 else
170 {
171 if(!_dataColorCB->isEnabled())
172 _dataColorCB->setEnabled(true);
173 extColor[index] = _dataColorCB->color();
174 _dataColorCB->setColor(extColor[newindex]);
175 index=newindex;
176 }
177}
178
179
180void KChartColorConfigPage::activeColorButton()
181{
182 _dataColorCB->animateClick();
183}
184
185
186void KChartColorConfigPage::initDataColorList()
187{
188 TQStringList lst;
189 for(uint i = 0; i < m_data->rows(); i++)
190 {
191 extColor.resize( m_params->maxDataColor() );
192 if(i<m_params->maxDataColor())
193 {
194 _dataColorLB->insertItem(m_params->legendText( i ).isEmpty() ? i18n("Series %1").arg(i+1) :m_params->legendText( i ) );
195 extColor[i] =m_params->dataColor(i);
196 }
197 }
198 _dataColorLB->setCurrentItem(0);
199
200 //Fix crash when we didn't create data
201 if ( m_data->rows() == 0 )
202 _dataColorCB->setEnabled(false);
203 else
204 _dataColorCB->setColor( extColor[index]);
205}
206
207
208void KChartColorConfigPage::apply()
209{
210 //Nothing to save
211 if ( m_data->rows() == 0 )
212 return;
213
214 extColor[index] = _dataColorCB->color();
215 for(uint i =0;i<m_data->rows();i++)
216 if(i<m_params->maxDataColor())
217 m_params->setDataColor(i,extColor[i]);
218}
219
220} //KChart namespace