summaryrefslogtreecommitdiffstats
path: root/kchart/kchartWizardSelectChartTypePage.cc
blob: 8ea02100b9da3905fee15f78c2d2cbd5f48698c6 (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

#include "kchartWizardSelectChartTypePage.h"
#include "kchart_params.h"
#include "kchart_view.h"
#include "kchart_factory.h"
#include "kchart_part.h"

#include <tqbuttongroup.h>
#include <tqframe.h>
#include <tqpushbutton.h>
#include <tqlabel.h>

#include <tdelocale.h>
#include <tdeglobal.h>
#include <kiconloader.h>

namespace KChart
{


KChartButton::KChartButton(TQWidget *parent, const TQString & _text, const TQPixmap &_pixmap)
  : TQVBox(parent)
{
  // The button
  m_button = new TQPushButton(this);
  m_button->setPixmap(_pixmap);
  m_button->setToggleButton( true );

  // The text
  TQLabel *label = new TQLabel(_text, this);
  label->setSizePolicy(TQSizePolicy::Fixed,TQSizePolicy::Fixed);
  setSizePolicy(TQSizePolicy::Expanding,TQSizePolicy::Fixed);
}

KChartButton::~KChartButton()
{
}


// ================================================================


KChartWizardSelectChartTypePage::KChartWizardSelectChartTypePage( TQWidget* parent,
                                                                  KChartPart* chart )
  : TQWidget( parent ),
    m_chart( chart )
{
    m_typeBG = new TQButtonGroup( this );
    m_typeBG->setExclusive( true );
    m_typeBG->hide();
    //  m_typeBG->resize

    m_colPos=0;
    m_rowPos=0;
    m_layout = new TQGridLayout(this, 3, 4, 5);
    m_layout->setRowStretch(0, 0);
    m_layout->setRowStretch(1, 0);
    m_layout->setRowStretch(2, 0);

    addButton( i18n( "Bar" ),            "chart_bar",    KChartParams::Bar );
    addButton( i18n( "Lines" ),          "chart_line",   KChartParams::Line );
    addButton( i18n( "Area" ),           "chart_area",   KChartParams::Area );
#if 0
    addButton( i18n( "Bars & Lines" ),   "chart_barlines", KChartParams::BarLines );
#endif

    addButton( i18n("Hi-Lo-Close"),      "chart_hilo",   KChartParams::HiLo );
    addButton( i18n("Box & Whisker "),   "chart_boxwhisker", KChartParams::BoxWhisker );
    incPos();
    incPos();

    addButton( i18n( "Pie" ),            "chart_pie",    KChartParams::Pie );
    addButton( i18n( "Ring" ),           "chart_ring",   KChartParams::Ring );
    addButton( i18n( "Polar" ),          "chart_polar",  KChartParams::Polar);

    TQPushButton *current = ((TQPushButton*)m_typeBG->find( m_chart->params()->chartType() ));
    if (current != NULL) {
	current->setOn( true );
    }
  
    m_type = m_chart->params()->chartType();
    connect( m_typeBG, TQT_SIGNAL( clicked( int ) ),
	     this, TQT_SLOT( chartTypeSelected( int ) ) );

    ////  parent->resize( 425, 256 );
    //     parent->resize(xstep*5+50, ystep*4 + 100);
}


void KChartWizardSelectChartTypePage::addButton(const TQString &name,
                                                const TQString &icon_name,
                                                int type)
{
    KChartButton *button = new KChartButton( this, name, 
					     BarIcon( icon_name, 
						      TDEIcon::SizeMedium,
						      TDEIcon::DefaultState,
						      KChartFactory::global()) );
    m_layout->addWidget(button, m_rowPos, m_colPos);
    m_typeBG->insert( button->button(), type );

    incPos();
}

void KChartWizardSelectChartTypePage::incPos()
{
    if (m_colPos == 3) {
	m_colPos=0;
	m_rowPos++; //place the next button in the second row
    }
    else
	m_colPos++;
}

void KChartWizardSelectChartTypePage::chartTypeSelected( int type )
{
    m_type = (KChartParams::ChartType) type;
    emit chartChange(type);
}

void KChartWizardSelectChartTypePage::apply()
{
    m_chart->params()->setChartType( m_type );
}

}  //namespace KChart

#include "kchartWizardSelectChartTypePage.moc"