kchart

kchartPageLayout.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2002  Montel Laurent <lmontel@mandrakesoft.com>
00003    This library is free software; you can redistribute it and/or
00004    modify it under the terms of the GNU Library General Public
00005    License as published by the Free Software Foundation; either
00006    version 2 of the License, or (at your option) any later version.
00007 
00008    This library is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011    Library General Public License for more details.
00012 
00013    You should have received a copy of the GNU Library General Public License
00014    along with this library; see the file COPYING.LIB.  If not, write to
00015    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016  * Boston, MA 02110-1301, USA.
00017 */
00018 
00019 
00020 #include "kchartPageLayout.h"
00021 #include "kchartPageLayout.moc"
00022 #include "kchart_params.h"
00023 #include <knumvalidator.h>
00024 #include <qlineedit.h>
00025 #include <qlayout.h>
00026 #include <klocale.h>
00027 #include <qlabel.h>
00028 #include <qgroupbox.h>
00029 
00030 namespace KChart
00031 {
00032 
00033 KChartPageLayout::KChartPageLayout( KChartParams* _params, QWidget* parent, const char* name )
00034     : KDialogBase( parent, name, TRUE,i18n("Page Layout"),KDialogBase::Ok | KDialogBase::Cancel | KDialogBase::User1 | KDialogBase::Apply , KDialogBase::Ok,true )
00035 {
00036     params=_params;
00037 #if 0
00038     QWidget *page = new QWidget( this );
00039 #else
00040     QGroupBox* page = new QGroupBox( 2, Qt::Horizontal, i18n("Margins"),
00041                      this );
00042 #endif
00043     setMainWidget(page);
00044 
00045     // FIXME: The following code is strange, since it is written to
00046     // use a grid layout with a standard QWidget.  However, with the
00047     // QGroupBox, it looks better, and since it actually works, there
00048     // is no immediate need for rewriting.  In the sake of clarity, it
00049     // should be done though, and we should use the layout
00050     // capabilities of the groupbox instead..
00051 
00052     setButtonText( KDialogBase::User1, i18n("&Reset") );
00053 
00054     QGridLayout *grid = new QGridLayout(page, 4, 2, KDialog::marginHint(), KDialog::spacingHint());
00055 
00056     QLabel *lab=new QLabel(i18n("Left:"),page);
00057     grid->addWidget(lab,0,0);
00058 
00059     leftBorder=new QLineEdit(page);
00060     leftBorder->setValidator( new KIntValidator( 0,9999,leftBorder ) );
00061     grid->addWidget(leftBorder,1,0);
00062 
00063     lab=new QLabel(i18n("Right:"),page);
00064     grid->addWidget(lab,0,1);
00065 
00066     rightBorder=new QLineEdit(page);
00067     rightBorder->setValidator( new KIntValidator( 0,9999,rightBorder ) );
00068     grid->addWidget(rightBorder,1,1);
00069 
00070     lab=new QLabel(i18n("Top:"),page);
00071     grid->addWidget(lab,2,0);
00072 
00073     topBorder=new QLineEdit(page);
00074     topBorder->setValidator( new KIntValidator( 0,9999,topBorder ) );
00075     grid->addWidget(topBorder,3,0);
00076 
00077     lab=new QLabel(i18n("Bottom:"),page);
00078     grid->addWidget(lab,2,1);
00079 
00080     bottomBorder=new QLineEdit(page);
00081     bottomBorder->setValidator( new KIntValidator( 0,9999,bottomBorder ) );
00082     grid->addWidget(bottomBorder,3,1);
00083 
00084     init();
00085     connect( this, SIGNAL( okClicked() ),    this, SLOT( slotOk() ) );
00086     connect( this, SIGNAL( applyClicked() ), this, SLOT( slotApply() ) );
00087     connect( this, SIGNAL( user1Clicked() ), this ,SLOT( slotReset() ));
00088 
00089 }
00090 
00091 void KChartPageLayout::init()
00092 {
00093     oldGlobalLeadingRight  = params->globalLeadingRight();
00094     oldGlobalLeadingLeft   = params->globalLeadingLeft();
00095     oldGlobalLeadingTop    = params->globalLeadingTop();
00096     oldGlobalLeadingBottom = params->globalLeadingBottom();
00097     slotReset();
00098 }
00099 
00100 void KChartPageLayout::slotOk()
00101 {
00102     slotApply();
00103     accept();
00104 }
00105 
00106 void KChartPageLayout::slotApply()
00107 {
00108     params->setGlobalLeading( leftBorder->text().toInt(),topBorder->text().toInt() , rightBorder->text().toInt(), bottomBorder->text().toInt() );
00109     emit dataChanged();
00110 }
00111 
00112 void KChartPageLayout::slotReset()
00113 {
00114     rightBorder->setText(QString::number(oldGlobalLeadingRight));
00115     leftBorder->setText(QString::number(oldGlobalLeadingLeft));
00116     topBorder->setText(QString::number(oldGlobalLeadingTop));
00117     bottomBorder->setText(QString::number(oldGlobalLeadingBottom));
00118 }
00119 
00120 }  //KChart namespace
KDE Home | KDE Accessibility Home | Description of Access Keys