summaryrefslogtreecommitdiffstats
path: root/kchart/kchartColorConfigPage.cc
blob: 9e4123b3f17c667a22a1925a61f5bfd98ccec4d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/* This file is part of the KDE project
   Copyright (C) 1999 Matthias Kalle Dalheimer <kalle@kde.org>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

#include "kchartColorConfigPage.h"
#include "kchartColorConfigPage.moc"

#include <kapplication.h>
#include <kdialog.h>
#include <klocale.h>
#include <kcolorbutton.h>
#include <layout.h>
#include <tqlabel.h>
#include <tqbuttongroup.h>
#include <tqwhatsthis.h>
#include <tqhbox.h>
#include <klistbox.h>
#include "kchart_params.h"
#include <kdebug.h>

namespace KChart
{

KChartColorConfigPage::KChartColorConfigPage( KChartParams* params,
                                              TQWidget* parent, 
					      KDChartTableData *dat ) :
    TQWidget( parent ),
    m_params( params ),
    m_data( dat ),
    index( 0 )
{
    TQWhatsThis::add( this, i18n( "This page lets you configure the colors "
                                 "in which your chart is displayed. Each "
                                 "part of the chart can be assigned a "
                                 "different color." ) );

    TQVBoxLayout* toplevel = new TQVBoxLayout( this, 14 );
    TQButtonGroup* gb = new TQButtonGroup( 0, Qt::Vertical, i18n("Colors"), this );
    gb->layout()->setSpacing(KDialog::spacingHint());
    gb->layout()->setMargin(KDialog::marginHint());
    toplevel->addWidget( gb);
    TQString wtstr;
    TQGridLayout* grid = new TQGridLayout( gb->layout(), 8, 3 );

    const int labelAlign = AlignRight | AlignVCenter;
    int row = -1;
#define ADD_COLOR_BTN(btn,title,whatsthis) \
{                                          \
    ++row;                                 \
    TQLabel* l = new TQLabel( title, gb );   \
    l->setAlignment( labelAlign );         \
    grid->addWidget( l, row, 0 );          \
    btn = new KColorButton( gb );          \
    l->setBuddy( btn );                    \
    grid->addWidget( btn, row, 1 );        \
    TQWhatsThis::add( l, whatsthis );       \
    TQWhatsThis::add( btn, whatsthis );     \
}
    ADD_COLOR_BTN(_lineCB, i18n( "&Line color:" ),
        i18n( "This is the color that is used for drawing lines like axes." ))
    ADD_COLOR_BTN(_gridCB, i18n( "&Grid color:" ),
        i18n( "Here you can configure the color that is used for the "
              "chart grid. Of course, this setting will only "
              "take effect if grid drawing is turned on." ))
    ADD_COLOR_BTN(_xtitleCB, i18n( "&X-title color:" ),
        i18n( "This color is used for displaying titles for the "
              "X (horizontal) axis." ))
    ADD_COLOR_BTN(_ytitleCB, i18n( "&Y-title color:" ),
        i18n( "This color is used for displaying titles for the "
              "Y (vertical) axis." ))
#if 0
    ADD_COLOR_BTN(_ytitle2CB, i18n( "Y-title color (2nd axis):" ),
        i18n( "This color is used for displaying titles for the "
              "second Y (vertical) axis. It only takes effect if the "
              "chart is configured to have a second Y axis." ))
#endif
    ADD_COLOR_BTN(_xlabelCB, i18n( "X-label color:" ),
        i18n( "Here you can configure the color that is used for "
              "labeling the X (horizontal) axis" ))
    ADD_COLOR_BTN(_ylabelCB, i18n( "Y-label color:" ),
        i18n( "Here you can configure the color that is used for "
              "labeling the Y (vertical) axis" ))
#if 0
    ADD_COLOR_BTN(_ylabel2CB, i18n( "Y-label color (2nd axis):" ),
        i18n( "Here you can configure the color that is used for "
              "labeling the second Y (vertical) axis. Of course, "
              "this setting only takes effect if the chart is "
              "configured to have two vertical axes." ))
#endif
    ADD_COLOR_BTN(_xlineCB, i18n( "X-line color:" ),
        i18n( "Here you can configure the line color of the X (horizontal) axis" ))
    ADD_COLOR_BTN(_ylineCB, i18n( "Y-line color:" ),
        i18n( "Here you can configure the line color of the Y (vertical) axis" ))
#if 0
    ADD_COLOR_BTN(_yline2CB, i18n( "Y-line color (2nd axis):" ),
        i18n( "Here you can configure the line color of "
              "the second Y (vertical) axis. Of course, "
              "this setting only takes effect if the chart is "
              "configured to have two vertical axes." ))
#endif
    ADD_COLOR_BTN(_xzerolineCB, i18n( "X-Zero-line color:" ),
        i18n( "Here you can configure the zero-line's color of the X "
              "(horizontal) axis. Of course, this setting only takes "
              "effect if the abscissa is displaying a Zero-line." ))
    ADD_COLOR_BTN(_yzerolineCB, i18n( "Y-Zero-line color:" ),
        i18n( "Here you can configure the zero-line's color of the Y (vertical) axis" ))
#if 0
    ADD_COLOR_BTN(_yzeroline2CB, i18n( "Y-Zero-line color (2nd axis):" ),
        i18n( "Here you can configure the color that is used for "
              "the Zero-line of the second Y (vertical) axis. Of course, "
              "this setting only takes effect if the chart is "
              "configured to have two vertical axes." ))
#endif

    TQHBox* dataColorHB = new TQHBox( gb );
    grid->addMultiCellWidget( dataColorHB,  0, row, 2, 2 );
    _dataColorLB = new KListBox(dataColorHB);
    _dataColorCB = new KColorButton( dataColorHB);
    wtstr = i18n( "Choose a row/column in the list on the left and change its color using this button.");
    TQWhatsThis::add( _dataColorCB, wtstr );
    initDataColorList();
    connect( _dataColorLB, TQT_SIGNAL(highlighted(int )), this, TQT_SLOT(changeIndex(int)));
    connect( _dataColorLB, TQT_SIGNAL(doubleClicked ( TQListBoxItem * )), this, TQT_SLOT(activeColorButton()));



    /*TQLabel* edgeLA = new TQLabel( i18n( "Edge color (pies only)" ), this );
      edgeLA->setAlignment( AlignRight | AlignVCenter );
      grid->addWidget( edgeLA, 6, 0 );
      _edgeCB = new KColorButton( this );
      grid->addWidget( _edgeCB, 6, 1 );*/

//     for( int i = 0; i < NUMDATACOLORS; i++ ) {
// 	TQString labeltext;
// 	labeltext.sprintf( i18n( "Data color #%d:"), i );
// 	TQLabel* dataLA = new TQLabel( labeltext, this );
// 	dataLA->setAlignment(AlignRight | AlignVCenter);
// 	dataLA->resize( dataLA->sizeHint() );
// 	grid->addWidget( dataLA, i, 2 );
// 	_dataCB[i] = new KColorButton( this );
// 	_dataCB[i]->resize( _dataCB[i]->sizeHint() );
// 	grid->addWidget( _dataCB[i], i, 3 );
// 	grid->addRowSpacing(i,_textCB->height());
// 	grid->setRowStretch(i,0);
// 	grid->addColSpacing(2,dataLA->width() + 20);
//     }
}


void KChartColorConfigPage::changeIndex(int newindex)
{
    if(index > m_params->maxDataColor())
        _dataColorLB->setEnabled(false);
    else
    {
        if(!_dataColorCB->isEnabled())
            _dataColorCB->setEnabled(true);
        extColor[index] = _dataColorCB->color();
        _dataColorCB->setColor(extColor[newindex]);
        index=newindex;
    }
}


void KChartColorConfigPage::activeColorButton()
{
    _dataColorCB->animateClick();
}


void KChartColorConfigPage::initDataColorList()
{
    TQStringList lst;
    for(uint i = 0; i < m_data->rows(); i++)
    {
        extColor.resize( m_params->maxDataColor() );
        if(i<m_params->maxDataColor())
        {
            _dataColorLB->insertItem(m_params->legendText( i ).isEmpty() ? i18n("Series %1").arg(i+1) :m_params->legendText( i ) );
            extColor[i] =m_params->dataColor(i);
        }
    }
    _dataColorLB->setCurrentItem(0);

	 //Fix crash when we didn't create data
	if ( m_data->rows() == 0 )
		_dataColorCB->setEnabled(false);
	else
    	_dataColorCB->setColor( extColor[index]);
}


void KChartColorConfigPage::apply()
{
	//Nothing to save
	if ( m_data->rows() == 0 )
		return;

    extColor[index] = _dataColorCB->color();
    for(uint i =0;i<m_data->rows();i++)
        if(i<m_params->maxDataColor())
            m_params->setDataColor(i,extColor[i]);
}

}  //KChart namespace