kchart

kchartPageLayout.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2002 Montel Laurent <lmontel@mandrakesoft.com>
3 This library is free software; you can redistribute it and/or
4 modify it under the terms of the GNU Library General Public
5 License as published by the Free Software Foundation; either
6 version 2 of the License, or (at your option) any later version.
7
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 * Boston, MA 02110-1301, USA.
17*/
18
19
20#include "kchartPageLayout.h"
21#include "kchartPageLayout.moc"
22#include "kchart_params.h"
23#include <knumvalidator.h>
24#include <tqlineedit.h>
25#include <tqlayout.h>
26#include <tdelocale.h>
27#include <tqlabel.h>
28#include <tqgroupbox.h>
29
30namespace KChart
31{
32
33KChartPageLayout::KChartPageLayout( KChartParams* _params, TQWidget* parent, const char* name )
34 : KDialogBase( parent, name, true,i18n("Page Layout"),KDialogBase::Ok | KDialogBase::Cancel | KDialogBase::User1 | KDialogBase::Apply , KDialogBase::Ok,true )
35{
36 params=_params;
37#if 0
38 TQWidget *page = new TQWidget( this );
39#else
40 TQGroupBox* page = new TQGroupBox( 2, TQt::Horizontal, i18n("Margins"),
41 this );
42#endif
43 setMainWidget(page);
44
45 // FIXME: The following code is strange, since it is written to
46 // use a grid layout with a standard TQWidget. However, with the
47 // TQGroupBox, it looks better, and since it actually works, there
48 // is no immediate need for rewriting. In the sake of clarity, it
49 // should be done though, and we should use the layout
50 // capabilities of the groupbox instead..
51
52 setButtonText( KDialogBase::User1, i18n("&Reset") );
53
54 TQGridLayout *grid = new TQGridLayout(page, 4, 2, KDialog::marginHint(), KDialog::spacingHint());
55
56 TQLabel *lab=new TQLabel(i18n("Left:"),page);
57 grid->addWidget(lab,0,0);
58
59 leftBorder=new TQLineEdit(page);
60 leftBorder->setValidator( new KIntValidator( 0,9999,leftBorder ) );
61 grid->addWidget(leftBorder,1,0);
62
63 lab=new TQLabel(i18n("Right:"),page);
64 grid->addWidget(lab,0,1);
65
66 rightBorder=new TQLineEdit(page);
67 rightBorder->setValidator( new KIntValidator( 0,9999,rightBorder ) );
68 grid->addWidget(rightBorder,1,1);
69
70 lab=new TQLabel(i18n("Top:"),page);
71 grid->addWidget(lab,2,0);
72
73 topBorder=new TQLineEdit(page);
74 topBorder->setValidator( new KIntValidator( 0,9999,topBorder ) );
75 grid->addWidget(topBorder,3,0);
76
77 lab=new TQLabel(i18n("Bottom:"),page);
78 grid->addWidget(lab,2,1);
79
80 bottomBorder=new TQLineEdit(page);
81 bottomBorder->setValidator( new KIntValidator( 0,9999,bottomBorder ) );
82 grid->addWidget(bottomBorder,3,1);
83
84 init();
85 connect( this, TQ_SIGNAL( okClicked() ), this, TQ_SLOT( slotOk() ) );
86 connect( this, TQ_SIGNAL( applyClicked() ), this, TQ_SLOT( slotApply() ) );
87 connect( this, TQ_SIGNAL( user1Clicked() ), this ,TQ_SLOT( slotReset() ));
88
89}
90
91void KChartPageLayout::init()
92{
93 oldGlobalLeadingRight = params->globalLeadingRight();
94 oldGlobalLeadingLeft = params->globalLeadingLeft();
95 oldGlobalLeadingTop = params->globalLeadingTop();
96 oldGlobalLeadingBottom = params->globalLeadingBottom();
97 slotReset();
98}
99
100void KChartPageLayout::slotOk()
101{
102 slotApply();
103 accept();
104}
105
106void KChartPageLayout::slotApply()
107{
108 params->setGlobalLeading( leftBorder->text().toInt(),topBorder->text().toInt() , rightBorder->text().toInt(), bottomBorder->text().toInt() );
109 emit dataChanged();
110}
111
112void KChartPageLayout::slotReset()
113{
114 rightBorder->setText(TQString::number(oldGlobalLeadingRight));
115 leftBorder->setText(TQString::number(oldGlobalLeadingLeft));
116 topBorder->setText(TQString::number(oldGlobalLeadingTop));
117 bottomBorder->setText(TQString::number(oldGlobalLeadingBottom));
118}
119
120} //KChart namespace