lib Library API Documentation

koPageLayoutDia.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017    Boston, MA 02111-1307, USA.
00018 */
00019 
00020 // Description: Page Layout Dialog (header)
00021 
00022 /******************************************************************/
00023 
00024 #include <koPageLayoutDia.h>
00025 
00026 #include <qcombobox.h>
00027 #include <qlabel.h>
00028 #include <qlayout.h>
00029 #include <qpainter.h>
00030 #include <qlineedit.h>
00031 #include <qbuttongroup.h>
00032 #include <qradiobutton.h>
00033 #include <knumvalidator.h>
00034 #include <qspinbox.h>
00035 
00036 #include <klocale.h>
00037 #include <koUnit.h>
00038 #include <knuminput.h>
00039 #include <qcheckbox.h>
00040 
00041 #include <kiconloader.h>
00042 #include <kmessagebox.h>
00043 
00044 /******************************************************************/
00045 /* class KoPagePreview                                            */
00046 /******************************************************************/
00047 
00048 /*===================== constrcutor ==============================*/
00049 KoPagePreview::KoPagePreview( QWidget* parent, const char *name, const KoPageLayout& _layout )
00050     : QGroupBox( i18n( "Page Preview" ), parent, name )
00051 {
00052     setPageLayout( _layout );
00053     columns = 1;
00054     setMinimumSize( 150, 150 );
00055 }
00056 
00057 /*====================== destructor ==============================*/
00058 KoPagePreview::~KoPagePreview()
00059 {
00060 }
00061 
00062 /*=================== set layout =================================*/
00063 void KoPagePreview::setPageLayout( const KoPageLayout &_layout )
00064 {
00065     pgWidth = POINT_TO_MM(_layout.ptWidth) * 0.5;
00066     pgHeight = POINT_TO_MM(_layout.ptHeight) * 0.5;
00067 
00068     pgX = POINT_TO_MM(_layout.ptLeft) * 0.5;
00069     pgY = POINT_TO_MM(_layout.ptTop) * 0.5;
00070     pgW = pgWidth - ( POINT_TO_MM(_layout.ptLeft) + POINT_TO_MM(_layout.ptRight) ) * 0.5;
00071     pgH = pgHeight - ( POINT_TO_MM(_layout.ptTop) + POINT_TO_MM(_layout.ptBottom) ) * 0.5;
00072 
00073     repaint( true );
00074 }
00075 
00076 /*=================== set layout =================================*/
00077 void KoPagePreview::setPageColumns( const KoColumns &_columns )
00078 {
00079     columns = _columns.columns;
00080     repaint( true );
00081 }
00082 
00083 /*======================== draw contents =========================*/
00084 void KoPagePreview::drawContents( QPainter *painter )
00085 {
00086     double cw = pgW;
00087     if(columns!=1)
00088         cw/=static_cast<double>(columns);
00089 
00090     painter->setBrush( white );
00091     painter->setPen( QPen( black ) );
00092 
00093     int x=static_cast<int>( ( width() - pgWidth ) * 0.5 );
00094     int y=static_cast<int>( ( height() - pgHeight ) * 0.5 );
00095     int w=static_cast<int>(pgWidth);
00096     int h=static_cast<int>(pgHeight);
00097     //painter->drawRect( x + 1, y + 1, w, h);
00098     painter->drawRect( x, y, w, h );
00099 
00100     painter->setBrush( QBrush( black, HorPattern ) );
00101     if ( pgW == pgWidth || pgH == pgHeight )
00102         painter->setPen( NoPen );
00103     else
00104         painter->setPen( lightGray );
00105 
00106     for ( int i = 0; i < columns; ++i )
00107         painter->drawRect( x + static_cast<int>(pgX) + static_cast<int>(i * cw),
00108                            y + static_cast<int>(pgY), static_cast<int>(cw),
00109                            static_cast<int>(pgH) );
00110 }
00111 
00112 /******************************************************************/
00113 /* class KoPageLayoutDia                                          */
00114 /******************************************************************/
00115 
00116 /*==================== constructor ===============================*/
00117 KoPageLayoutDia::KoPageLayoutDia( QWidget* parent, const char* name,
00118                                   const KoPageLayout& _layout,
00119                                   const KoHeadFoot& _hf, int tabs,
00120                                   KoUnit::Unit unit, bool modal )
00121     : KDialogBase( KDialogBase::Tabbed, i18n("Page Layout"), KDialogBase::Ok | KDialogBase::Cancel,
00122                    KDialogBase::Ok, parent, name, modal)
00123 {
00124 
00125     flags = tabs;
00126     pgPreview = 0;
00127     pgPreview2 = 0;
00128 
00129     layout = _layout;
00130     hf = _hf;
00131     m_unit = unit;
00132 
00133     cl.columns = 1;
00134 
00135     enableBorders = true;
00136 
00137     if ( tabs & FORMAT_AND_BORDERS ) setupTab1();
00138     if ( tabs & HEADER_AND_FOOTER ) setupTab2();
00139 
00140     retPressed = false;
00141 
00142     setFocusPolicy( QWidget::StrongFocus );
00143     setFocus();
00144 }
00145 
00146 /*==================== constructor ===============================*/
00147 KoPageLayoutDia::KoPageLayoutDia( QWidget* parent, const char* name,
00148                   const KoPageLayout& _layout,
00149                   const KoHeadFoot& _hf,
00150                   const KoColumns& _cl,
00151                   const KoKWHeaderFooter& _kwhf,
00152                   int tabs, KoUnit::Unit unit )
00153     : KDialogBase( KDialogBase::Tabbed, i18n("Page Layout"), KDialogBase::Ok | KDialogBase::Cancel,
00154                    KDialogBase::Ok, parent, name, true)
00155 {
00156     flags = tabs;
00157     pgPreview = 0;
00158     pgPreview2 = 0;
00159 
00160     layout = _layout;
00161     hf = _hf;
00162     cl = _cl;
00163     kwhf = _kwhf;
00164     m_unit = unit;
00165 
00166     enableBorders = true;
00167 
00168     if ( tabs & DISABLE_BORDERS ) enableBorders = false;
00169     if ( tabs & FORMAT_AND_BORDERS ) setupTab1();
00170     if ( tabs & HEADER_AND_FOOTER ) setupTab2();
00171     if ( tabs & COLUMNS ) setupTab3();
00172     if ( tabs & KW_HEADER_AND_FOOTER ) setupTab4();
00173 
00174     retPressed = false;
00175 
00176     setFocusPolicy( QWidget::StrongFocus );
00177     setFocus();
00178 }
00179 
00180 /*===================== destructor ===============================*/
00181 KoPageLayoutDia::~KoPageLayoutDia()
00182 {
00183 }
00184 
00185 /*======================= show dialog ============================*/
00186 bool KoPageLayoutDia::pageLayout( KoPageLayout& _layout, KoHeadFoot& _hf, int _tabs, KoUnit::Unit& unit )
00187 {
00188     bool res = false;
00189     KoPageLayoutDia *dlg = new KoPageLayoutDia( 0, "PageLayout", _layout, _hf, _tabs, unit );
00190 
00191     if ( dlg->exec() == QDialog::Accepted ) {
00192         res = true;
00193         if ( _tabs & FORMAT_AND_BORDERS ) _layout = dlg->getLayout();
00194         if ( _tabs & HEADER_AND_FOOTER ) _hf = dlg->getHeadFoot();
00195         unit = dlg->unit();
00196     }
00197 
00198     delete dlg;
00199 
00200     return res;
00201 }
00202 
00203 /*======================= show dialog ============================*/
00204 bool KoPageLayoutDia::pageLayout( KoPageLayout& _layout, KoHeadFoot& _hf, KoColumns& _cl,
00205                                   KoKWHeaderFooter &_kwhf, int _tabs, KoUnit::Unit& unit )
00206 {
00207     bool res = false;
00208     KoPageLayoutDia *dlg = new KoPageLayoutDia( 0, "PageLayout", _layout, _hf, _cl, _kwhf, _tabs, unit );
00209 
00210     if ( dlg->exec() == QDialog::Accepted ) {
00211         res = true;
00212         if ( _tabs & FORMAT_AND_BORDERS ) _layout = dlg->getLayout();
00213         if ( _tabs & HEADER_AND_FOOTER ) _hf = dlg->getHeadFoot();
00214         if ( _tabs & COLUMNS ) _cl = dlg->getColumns();
00215         if ( _tabs & KW_HEADER_AND_FOOTER ) _kwhf = dlg->getKWHeaderFooter();
00216         unit = dlg->unit();
00217     }
00218 
00219     delete dlg;
00220 
00221     return res;
00222 }
00223 
00224 /*===================== get a standard page layout ===============*/
00225 KoPageLayout KoPageLayoutDia::standardLayout()
00226 {
00227     KoPageLayout        _layout;
00228     _layout.format = PG_DIN_A4;
00229     _layout.orientation = PG_PORTRAIT;
00230     _layout.ptWidth = MM_TO_POINT( PG_A4_WIDTH );
00231     _layout.ptHeight = MM_TO_POINT( PG_A4_HEIGHT );
00232     _layout.ptLeft = MM_TO_POINT( 20.0 );
00233     _layout.ptRight = MM_TO_POINT( 20.0 );
00234     _layout.ptTop = MM_TO_POINT( 20.0 );
00235     _layout.ptBottom = MM_TO_POINT( 20.0 );
00236 
00237     return  _layout;
00238 }
00239 
00240 /*====================== get header - footer =====================*/
00241 KoHeadFoot KoPageLayoutDia::getHeadFoot()
00242 {
00243     hf.headLeft = eHeadLeft->text();
00244     hf.headMid = eHeadMid->text();
00245     hf.headRight = eHeadRight->text();
00246     hf.footLeft = eFootLeft->text();
00247     hf.footMid = eFootMid->text();
00248     hf.footRight = eFootRight->text();
00249 
00250     return hf;
00251 }
00252 
00253 /*================================================================*/
00254 KoColumns KoPageLayoutDia::getColumns()
00255 {
00256     cl.columns = nColumns->value();
00257     cl.ptColumnSpacing = KoUnit::ptFromUnit( nCSpacing->value(), m_unit  );
00258     return cl;
00259 }
00260 
00261 /*================================================================*/
00262 KoKWHeaderFooter KoPageLayoutDia::getKWHeaderFooter()
00263 {
00264     if ( rhFirst->isChecked() && rhEvenOdd->isChecked() )
00265         kwhf.header = HF_FIRST_EO_DIFF;
00266     else if ( rhFirst->isChecked() )
00267         kwhf.header = HF_FIRST_DIFF;
00268     else if ( rhEvenOdd->isChecked() )
00269         kwhf.header = HF_EO_DIFF;
00270     else
00271         kwhf.header = HF_SAME;
00272 
00273     kwhf.ptHeaderBodySpacing = KoUnit::ptFromUnit( nHSpacing->value(), m_unit );
00274     kwhf.ptFooterBodySpacing = KoUnit::ptFromUnit( nFSpacing->value(), m_unit );
00275     kwhf.ptFootNoteBodySpacing = KoUnit::ptFromUnit( nFNSpacing->value(), m_unit);
00276     if ( rfFirst->isChecked() && rfEvenOdd->isChecked() )
00277         kwhf.footer = HF_FIRST_EO_DIFF;
00278     else if ( rfFirst->isChecked() )
00279         kwhf.footer = HF_FIRST_DIFF;
00280     else if ( rfEvenOdd->isChecked() )
00281         kwhf.footer = HF_EO_DIFF;
00282     else
00283         kwhf.footer = HF_SAME;
00284 
00285     return kwhf;
00286 }
00287 
00288 /*================ setup page size & margins tab ==================*/
00289 void KoPageLayoutDia::setupTab1()
00290 {
00291     QWidget *tab1 = addPage(i18n( "Page Size && &Margins" ));
00292 
00293     QGridLayout *grid1 = new QGridLayout( tab1, 5, 2, KDialog::marginHint(), KDialog::spacingHint() );
00294 
00295     QLabel *lpgUnit;
00296     if ( !( flags & DISABLE_UNIT ) ) {
00297         // ------------- unit _______________
00298         QWidget* unitFrame = new QWidget( tab1 );
00299         grid1->addWidget( unitFrame, 0, 0, Qt::AlignLeft );
00300         QBoxLayout* unitLayout = new QHBoxLayout( unitFrame, KDialog::marginHint(), KDialog::spacingHint() );
00301 
00302         // label unit
00303         lpgUnit = new QLabel( i18n( "Unit:" ), unitFrame );
00304         unitLayout->addWidget( lpgUnit, 0, Qt::AlignRight | Qt::AlignVCenter );
00305 
00306         // combo unit
00307         cpgUnit = new QComboBox( false, unitFrame, "cpgUnit" );
00308         cpgUnit->insertStringList( KoUnit::listOfUnitName() );
00309         unitLayout->addWidget( cpgUnit, 0, Qt::AlignLeft | Qt::AlignVCenter );
00310         connect( cpgUnit, SIGNAL( activated( int ) ), this, SLOT( unitChanged( int ) ) );
00311     } else {
00312         QString str=KoUnit::unitDescription(m_unit);
00313 
00314         lpgUnit = new QLabel( i18n("All values are given in %1.").arg(str), tab1 );
00315         grid1->addWidget( lpgUnit, 0, 0, Qt::AlignLeft );
00316     }
00317 
00318     // -------------- page size -----------------
00319     QGroupBox *formatFrame = new QGroupBox( i18n( "Page Size" ), tab1 );
00320     grid1->addWidget( formatFrame, 1, 0 );
00321     QGridLayout *formatGrid = new QGridLayout( formatFrame, 3, 2,
00322        2*KDialog::marginHint(), KDialog::spacingHint() );
00323     formatGrid->setColStretch( 1, 1 );
00324 
00325     // label page size
00326     QLabel *lpgFormat = new QLabel( i18n( "&Size:" ), formatFrame );
00327     formatGrid->addWidget( lpgFormat, 0, 0, Qt::AlignRight | Qt::AlignVCenter );
00328 
00329     // combo size
00330     cpgFormat = new QComboBox( false, formatFrame, "cpgFormat" );
00331     cpgFormat->insertStringList( KoPageFormat::allFormats() );
00332     lpgFormat->setBuddy( cpgFormat );
00333     formatGrid->addWidget( cpgFormat, 0, 1, Qt::AlignLeft | Qt::AlignVCenter );
00334     connect( cpgFormat, SIGNAL( activated( int ) ), this, SLOT( formatChanged( int ) ) );
00335 
00336     // label width
00337     QLabel *lpgWidth = new QLabel( i18n( "&Width:" ), formatFrame );
00338     formatGrid->addWidget( lpgWidth, 1, 0, Qt::AlignRight | Qt::AlignVCenter );
00339 
00340     // linedit width
00341     epgWidth = new KDoubleNumInput( formatFrame, "Width" );
00342     lpgWidth->setBuddy( epgWidth );
00343     formatGrid->addWidget( epgWidth, 1, 1, Qt::AlignLeft | Qt::AlignVCenter );
00344     if ( layout.format != PG_CUSTOM )
00345         epgWidth->setEnabled( false );
00346     connect( epgWidth, SIGNAL( valueChanged(double) ), this, SLOT( widthChanged() ) );
00347 
00348     // label height
00349     QLabel *lpgHeight = new QLabel( i18n( "&Height:" ), formatFrame );
00350     formatGrid->addWidget( lpgHeight, 2, 0, Qt::AlignRight | Qt::AlignVCenter );
00351 
00352     // linedit height
00353     epgHeight = new KDoubleNumInput( formatFrame, "Height" );
00354     lpgHeight->setBuddy( epgHeight );
00355     formatGrid->addWidget( epgHeight, 2, 1, Qt::AlignLeft | Qt::AlignVCenter );
00356     if ( layout.format != PG_CUSTOM )
00357         epgHeight->setEnabled( false );
00358     connect( epgHeight, SIGNAL( valueChanged(double ) ), this, SLOT( heightChanged() ) );
00359 
00360     // --------------- orientation ---------------
00361     QButtonGroup *orientFrame = new QButtonGroup( i18n( "Orientation" ), tab1 );
00362     grid1->addWidget( orientFrame, 2, 0 );
00363     QLayout *orientLayout = new QGridLayout( orientFrame, 2, 2,
00364        2*KDialog::marginHint(), KDialog::spacingHint() );
00365     orientLayout->setAutoAdd( true );
00366 
00367     QLabel* lbPortrait = new QLabel( orientFrame );
00368     lbPortrait->setPixmap( QPixmap( UserIcon( "koPortrait" ) ) );
00369     lbPortrait->setMaximumWidth( lbPortrait->pixmap()->width() );
00370     rbPortrait = new QRadioButton( i18n("&Portrait"), orientFrame );
00371 
00372     QLabel* lbLandscape = new QLabel( orientFrame );
00373     lbLandscape->setPixmap( QPixmap( UserIcon( "koLandscape" ) ) );
00374     lbLandscape->setMaximumWidth( lbLandscape->pixmap()->width() );
00375     rbLandscape = new QRadioButton( i18n("La&ndscape"), orientFrame );
00376 
00377 
00378     connect( rbPortrait, SIGNAL( clicked() ), this, SLOT( orientationChanged() ) );
00379     connect( rbLandscape, SIGNAL( clicked() ), this, SLOT( orientationChanged() ) );
00380 
00381     // --------------- page margins ---------------
00382     QButtonGroup *marginsFrame = new QButtonGroup( i18n( "Margins" ), tab1 );
00383     grid1->addWidget( marginsFrame, 3, 0 );
00384     QGridLayout *marginsLayout = new QGridLayout( marginsFrame, 4, 2,
00385        2*KDialog::marginHint(), KDialog::spacingHint() );
00386     marginsLayout->setColStretch( 1, 1 );
00387 
00388     // left margin
00389     QLabel* lbLeft = new QLabel( i18n( "&Left:" ), marginsFrame );
00390     marginsLayout->addWidget( lbLeft,
00391        0, 0, Qt::AlignRight | Qt::AlignVCenter );
00392     ebrLeft = new KDoubleNumInput( marginsFrame, "Left" );
00393     lbLeft->setBuddy( ebrLeft );
00394     marginsLayout->addWidget( ebrLeft, 0, 1 );
00395     connect( ebrLeft, SIGNAL( valueChanged( double ) ), this, SLOT( leftChanged() ) );
00396     if ( !enableBorders ) ebrLeft->setEnabled( false );
00397 
00398     // right margin
00399     QLabel* lbRight = new QLabel( i18n( "&Right:" ), marginsFrame );
00400     marginsLayout->addWidget( lbRight,
00401        1, 0, Qt::AlignRight | Qt::AlignVCenter );
00402     ebrRight = new KDoubleNumInput( marginsFrame, "Right" );
00403     lbRight->setBuddy( ebrRight );
00404     marginsLayout->addWidget( ebrRight, 1, 1 );
00405     connect( ebrRight, SIGNAL( valueChanged( double ) ), this, SLOT( rightChanged() ) );
00406     if ( !enableBorders ) ebrRight->setEnabled( false );
00407 
00408     // top margin
00409     QLabel* lbTop = new QLabel( i18n( "&Top:" ), marginsFrame );
00410     marginsLayout->addWidget( lbTop,
00411        2, 0, Qt::AlignRight | Qt::AlignVCenter );
00412     ebrTop = new KDoubleNumInput( marginsFrame, "Top" );
00413     lbTop->setBuddy( ebrTop );
00414     marginsLayout->addWidget( ebrTop, 2, 1 );
00415     connect( ebrTop, SIGNAL( valueChanged( double ) ), this, SLOT( topChanged() ) );
00416     if ( !enableBorders ) ebrTop->setEnabled( false );
00417 
00418     // bottom margin
00419     QLabel* lbBottom = new QLabel ( i18n( "&Bottom:" ), marginsFrame );
00420     marginsLayout->addWidget( lbBottom,
00421        3, 0, Qt::AlignRight | Qt::AlignVCenter );
00422     ebrBottom = new KDoubleNumInput( marginsFrame, "Bottom" );
00423     lbBottom->setBuddy( ebrBottom );
00424     marginsLayout->addWidget( ebrBottom, 3, 1 );
00425     connect( ebrBottom, SIGNAL( valueChanged( double ) ), this, SLOT( bottomChanged() ) );
00426     if ( !enableBorders ) ebrBottom->setEnabled( false );
00427 
00428     // ------------- preview -----------
00429     pgPreview = new KoPagePreview( tab1, "Preview", layout );
00430     grid1->addMultiCellWidget( pgPreview, 1, 3, 1, 1 );
00431 
00432     // ------------- spacers -----------
00433     QWidget* spacer1 = new QWidget( tab1 );
00434     QWidget* spacer2 = new QWidget( tab1 );
00435     spacer1->setSizePolicy( QSizePolicy( QSizePolicy::Expanding,
00436        QSizePolicy::Expanding ) );
00437     spacer2->setSizePolicy( QSizePolicy( QSizePolicy::Expanding,
00438        QSizePolicy::Expanding ) );
00439     grid1->addWidget( spacer1, 4, 0 );
00440     grid1->addWidget( spacer2, 4, 1 );
00441 
00442     setValuesTab1();
00443     updatePreview( layout );
00444 }
00445 
00446 /*================= setup values for tab one =====================*/
00447 void KoPageLayoutDia::setValuesTab1()
00448 {
00449     // unit
00450     if ( !( flags & DISABLE_UNIT ) )
00451         cpgUnit->setCurrentItem( m_unit );
00452 
00453     // page format
00454     cpgFormat->setCurrentItem( layout.format );
00455 
00456     // orientation
00457     if( layout.orientation == PG_PORTRAIT )
00458        rbPortrait->setChecked( true );
00459     else
00460        rbLandscape->setChecked( true );
00461 
00462     setValuesTab1Helper();
00463 
00464     pgPreview->setPageLayout( layout );
00465 }
00466 
00467 void KoPageLayoutDia::setValuesTab1Helper()
00468 {
00469     epgWidth->setValue( KoUnit::ptToUnit( layout.ptWidth, m_unit ) );
00470     epgWidth->setSuffix( KoUnit::unitName( m_unit ) );
00471 
00472     epgHeight->setValue( KoUnit::ptToUnit( layout.ptHeight, m_unit ) );
00473     epgHeight->setSuffix( KoUnit::unitName( m_unit ) );
00474 
00475     ebrLeft->setValue( KoUnit::ptToUnit( layout.ptLeft, m_unit ) );
00476     ebrLeft->setSuffix( KoUnit::unitName( m_unit ) );
00477     ebrLeft->setRange( 0, KoUnit::ptToUnit( layout.ptWidth, m_unit)  );
00478 
00479     ebrRight->setValue( KoUnit::ptToUnit( layout.ptRight, m_unit ) );
00480     ebrRight->setSuffix( KoUnit::unitName( m_unit ) );
00481     ebrRight->setRange( 0, KoUnit::ptToUnit( layout.ptWidth, m_unit)  );
00482 
00483     ebrTop->setValue( KoUnit::ptToUnit( layout.ptTop, m_unit ) );
00484     ebrTop->setSuffix( KoUnit::unitName( m_unit ) );
00485     ebrTop->setRange( 0, KoUnit::ptToUnit( layout.ptHeight, m_unit)  );
00486 
00487     ebrBottom->setValue( KoUnit::ptToUnit( layout.ptBottom, m_unit ) );
00488     ebrBottom->setSuffix( KoUnit::unitName( m_unit ) );
00489     ebrBottom->setRange( 0, KoUnit::ptToUnit( layout.ptHeight, m_unit)  );
00490 }
00491 
00492 /*================ setup header and footer tab ===================*/
00493 void KoPageLayoutDia::setupTab2()
00494 {
00495     QWidget *tab2 = addPage(i18n( "H&eader && Footer" ));
00496     QGridLayout *grid2 = new QGridLayout( tab2, 7, 2, KDialog::marginHint(), KDialog::spacingHint() );
00497 
00498     // ------------- header ---------------
00499     QGroupBox *gHead = new QGroupBox( 0, Qt::Vertical, i18n( "Head Line" ), tab2 );
00500     gHead->layout()->setSpacing(KDialog::spacingHint());
00501     gHead->layout()->setMargin(KDialog::marginHint());
00502     QGridLayout *headGrid = new QGridLayout( gHead->layout(), 2, 3 );
00503 
00504     QLabel *lHeadLeft = new QLabel( i18n( "Left:" ), gHead );
00505     headGrid->addWidget( lHeadLeft, 0, 0 );
00506 
00507     eHeadLeft = new QLineEdit( gHead );
00508     headGrid->addWidget( eHeadLeft, 1, 0 );
00509     eHeadLeft->setText( hf.headLeft );
00510 
00511     QLabel *lHeadMid = new QLabel( i18n( "Mid:" ), gHead );
00512     headGrid->addWidget( lHeadMid, 0, 1 );
00513 
00514     eHeadMid = new QLineEdit( gHead );
00515     headGrid->addWidget( eHeadMid, 1, 1 );
00516     eHeadMid->setText( hf.headMid );
00517 
00518     QLabel *lHeadRight = new QLabel( i18n( "Right:" ), gHead );
00519     headGrid->addWidget( lHeadRight, 0, 2 );
00520 
00521     eHeadRight = new QLineEdit( gHead );
00522     headGrid->addWidget( eHeadRight, 1, 2 );
00523     eHeadRight->setText( hf.headRight );
00524 
00525     grid2->addMultiCellWidget( gHead, 0, 1, 0, 1 );
00526 
00527     // ------------- footer ---------------
00528     QGroupBox *gFoot = new QGroupBox( 0, Qt::Vertical, i18n( "Foot Line" ), tab2 );
00529     gFoot->layout()->setSpacing(KDialog::spacingHint());
00530     gFoot->layout()->setMargin(KDialog::marginHint());
00531     QGridLayout *footGrid = new QGridLayout( gFoot->layout(), 2, 3 );
00532 
00533     QLabel *lFootLeft = new QLabel( i18n( "Left:" ), gFoot );
00534     footGrid->addWidget( lFootLeft, 0, 0 );
00535 
00536     eFootLeft = new QLineEdit( gFoot );
00537     footGrid->addWidget( eFootLeft, 1, 0 );
00538     eFootLeft->setText( hf.footLeft );
00539 
00540     QLabel *lFootMid = new QLabel( i18n( "Mid:" ), gFoot );
00541     footGrid->addWidget( lFootMid, 0, 1 );
00542 
00543     eFootMid = new QLineEdit( gFoot );
00544     footGrid->addWidget( eFootMid, 1, 1 );
00545     eFootMid->setText( hf.footMid );
00546 
00547     QLabel *lFootRight = new QLabel( i18n( "Right:" ), gFoot );
00548     footGrid->addWidget( lFootRight, 0, 2 );
00549 
00550     eFootRight = new QLineEdit( gFoot );
00551     footGrid->addWidget( eFootRight, 1, 2 );
00552     eFootRight->setText( hf.footRight );
00553 
00554     grid2->addMultiCellWidget( gFoot, 2, 3, 0, 1 );
00555 
00556     QLabel *lMacros2 = new QLabel( i18n( "You can insert several tags in the text:" ), tab2 );
00557     grid2->addMultiCellWidget( lMacros2, 4, 4, 0, 1 );
00558 
00559     QLabel *lMacros3 = new QLabel( i18n("<qt><ul><li>&lt;sheet&gt; The sheet name</li>"
00560                            "<li>&lt;page&gt; The current page</li>"
00561                            "<li>&lt;pages&gt; The total number of pages</li>"
00562                            "<li>&lt;name&gt; The filename or URL</li>"
00563                            "<li>&lt;file&gt; The filename with complete path or the URL</li></ul></qt>"), tab2 );
00564     grid2->addMultiCellWidget( lMacros3, 5, 6, 0, 0, Qt::AlignTop );
00565 
00566     QLabel *lMacros4 = new QLabel( i18n("<qt><ul><li>&lt;time&gt; The current time</li>"
00567                            "<li>&lt;date&gt; The current date</li>"
00568                            "<li>&lt;author&gt; Your full name</li>"
00569                            "<li>&lt;org&gt; Your organization</li>"
00570                            "<li>&lt;email&gt; Your email address</li></ul></qt>"), tab2 );
00571     grid2->addMultiCellWidget( lMacros4, 5, 6, 1, 1, Qt::AlignTop );
00572 }
00573 
00574 /*================================================================*/
00575 void KoPageLayoutDia::setupTab3()
00576 {
00577     QWidget *tab3 = addPage(i18n( "Col&umns" ));
00578 
00579     QGridLayout *grid3 = new QGridLayout( tab3, 5, 2, KDialog::marginHint(), KDialog::spacingHint() );
00580 
00581     QLabel *lColumns = new QLabel( i18n( "Co&lumns:" ), tab3 );
00582     grid3->addWidget( lColumns, 0, 0 );
00583 
00584     nColumns = new QSpinBox( 1, 16, 1, tab3 );
00585     lColumns->setBuddy( nColumns );
00586     grid3->addWidget( nColumns, 1, 0 );
00587     nColumns->setValue( cl.columns );
00588     connect( nColumns, SIGNAL( valueChanged( int ) ), this, SLOT( nColChanged( int ) ) );
00589 
00590     QString str = KoUnit::unitName( m_unit );
00591 
00592     QLabel *lCSpacing = new QLabel( i18n("Column &spacing (%1):").arg(str), tab3 );
00593     grid3->addWidget( lCSpacing, 2, 0 );
00594 
00595     nCSpacing = new KDoubleNumInput( tab3, "" );
00596     lCSpacing->setBuddy( nCSpacing );
00597     grid3->addWidget( nCSpacing, 3, 0 );
00598 
00599     nCSpacing->setValue( KoUnit::ptToUnit( cl.ptColumnSpacing, m_unit ) );
00600     connect( nCSpacing, SIGNAL( valueChanged(double) ),
00601              this, SLOT( nSpaceChanged( double ) ) );
00602 
00603     // ------------- preview -----------
00604     pgPreview2 = new KoPagePreview( tab3, "Preview", layout );
00605     grid3->addMultiCellWidget( pgPreview2, 0, 4, 1, 1 );
00606 
00607     // --------------- main grid ------------------
00608     grid3->addColSpacing( 0, lColumns->width() );
00609     grid3->addColSpacing( 0, nColumns->width() );
00610     grid3->addColSpacing( 0, lCSpacing->width() );
00611     grid3->addColSpacing( 0, nCSpacing->width() );
00612     grid3->addColSpacing( 1, pgPreview2->width() );
00613     grid3->setColStretch( 1, 1 );
00614 
00615     grid3->addRowSpacing( 0, lColumns->height() );
00616     grid3->addRowSpacing( 1, nColumns->height() );
00617     grid3->addRowSpacing( 2, lCSpacing->height() );
00618     grid3->addRowSpacing( 3, nCSpacing->height() );
00619     grid3->setRowStretch( 4, 1 );
00620 
00621     if ( pgPreview ) pgPreview->setPageColumns( cl );
00622     pgPreview2->setPageColumns( cl );
00623 }
00624 
00625 /*================================================================*/
00626 void KoPageLayoutDia::setupTab4()
00627 {
00628     QString str = KoUnit::unitName(m_unit);
00629 
00630     QWidget *tab4 = addPage(i18n( "H&eader && Footer" ));
00631     QGridLayout *grid4 = new QGridLayout( tab4, 4, 1, KDialog::marginHint(), KDialog::spacingHint() );
00632 
00633     QButtonGroup *gHeader = new QButtonGroup( 0, Qt::Vertical, i18n( "&Header" ), tab4 );
00634     gHeader->layout()->setSpacing(KDialog::spacingHint());
00635     gHeader->layout()->setMargin(KDialog::marginHint());
00636     QGridLayout *headerGrid = new QGridLayout( gHeader->layout(), 4, 2 );
00637 
00638     rhFirst = new QCheckBox( i18n( "Different header for the first page" ), gHeader );
00639     gHeader->insert( rhFirst );
00640     headerGrid->addMultiCellWidget( rhFirst, 1, 1, 0, 1 );
00641     if ( kwhf.header == HF_FIRST_DIFF || kwhf.header == HF_FIRST_EO_DIFF )
00642         rhFirst->setChecked( true );
00643 
00644     rhEvenOdd = new QCheckBox( i18n( "Different header for even and odd pages" ), gHeader );
00645     gHeader->insert( rhEvenOdd );
00646     headerGrid->addMultiCellWidget( rhEvenOdd, 2, 2, 0, 1 );
00647     if ( kwhf.header == HF_EO_DIFF || kwhf.header == HF_FIRST_EO_DIFF )
00648         rhEvenOdd->setChecked( true );
00649 
00650     QLabel *lHSpacing = new QLabel( i18n("Spacing between header and body (%1):").arg(str), gHeader );
00651     lHSpacing->setAlignment( AlignRight | AlignVCenter );
00652     headerGrid->addWidget( lHSpacing, 4, 0 );
00653 
00654     nHSpacing = new KDoubleNumInput( gHeader, "" );
00655     headerGrid->addWidget( nHSpacing, 4, 1 );
00656 
00657     nHSpacing->setValue( KoUnit::ptToUnit( kwhf.ptHeaderBodySpacing, m_unit ) );
00658 
00659     headerGrid->addRowSpacing( 0, KDialog::spacingHint() );
00660 
00661     grid4->addWidget( gHeader, 0, 0 );
00662 
00663     QButtonGroup *gFooter = new QButtonGroup( 0, Qt::Vertical, i18n( "&Footer" ), tab4 );
00664     gFooter->layout()->setSpacing(KDialog::spacingHint());
00665     gFooter->layout()->setMargin(KDialog::marginHint());
00666     QGridLayout *footerGrid = new QGridLayout( gFooter->layout(), 4, 2 );
00667 
00668     rfFirst = new QCheckBox( i18n( "Different footer for the first page" ), gFooter );
00669     gFooter->insert( rfFirst );
00670     footerGrid->addMultiCellWidget( rfFirst, 1, 1, 0, 1 );
00671     if ( kwhf.footer == HF_FIRST_DIFF || kwhf.footer == HF_FIRST_EO_DIFF )
00672         rfFirst->setChecked( true );
00673 
00674     rfEvenOdd = new QCheckBox( i18n( "Different footer for even and odd pages" ), gFooter );
00675     gFooter->insert( rfEvenOdd );
00676     footerGrid->addMultiCellWidget( rfEvenOdd, 2, 2, 0, 1 );
00677     if ( kwhf.footer == HF_EO_DIFF || kwhf.footer == HF_FIRST_EO_DIFF )
00678         rfEvenOdd->setChecked( true );
00679 
00680     QLabel *lFSpacing = new QLabel( i18n("Spacing between footer and body (%1):").arg(str), gFooter );
00681     lFSpacing->setAlignment( AlignRight | AlignVCenter );
00682     footerGrid->addWidget( lFSpacing, 4, 0 );
00683 
00684     nFSpacing = new KDoubleNumInput( gFooter, "" );
00685     footerGrid->addWidget( nFSpacing, 4, 1 );
00686 
00687     nFSpacing->setValue(KoUnit::ptToUnit( kwhf.ptFooterBodySpacing, m_unit ) );
00688 
00689     footerGrid->addRowSpacing( 0, KDialog::spacingHint() );
00690 
00691     grid4->addWidget( gFooter, 2, 0 );
00692 
00693     QButtonGroup *gFootNote = new QButtonGroup( 0, Qt::Vertical, i18n( "Foot&note/Endnote" ), tab4 ); // why doesn't the accel work??? - Clarence
00694     gFootNote->layout()->setSpacing(KDialog::spacingHint());
00695     gFootNote->layout()->setMargin(KDialog::marginHint());
00696     QGridLayout *footNoteGrid = new QGridLayout( gFootNote->layout(), 2, 2 );
00697 
00698     QLabel *lFNSpacing = new QLabel( i18n("Spacing between footnote and body (%1):").arg(str), gFootNote );
00699     lFNSpacing->setAlignment( AlignRight | AlignVCenter );
00700     footNoteGrid->addWidget( lFNSpacing, 1, 0 );
00701 
00702     nFNSpacing = new KDoubleNumInput( gFootNote, "" );
00703     footNoteGrid->addWidget( nFNSpacing, 1, 1 );
00704 
00705     nFNSpacing->setValue(KoUnit::ptToUnit( kwhf.ptFootNoteBodySpacing, m_unit ) );
00706 
00707     footNoteGrid->addRowSpacing( 0, KDialog::spacingHint() );
00708 
00709     grid4->addWidget( gFootNote, 3, 0 );
00710 
00711     grid4->setRowStretch( 1, 1 ); // between the groupboxes
00712     grid4->setRowStretch( 2, 1 ); // between the groupboxes
00713     grid4->setRowStretch( 4, 10 ); // bottom
00714 }
00715 
00716 /*====================== update the preview ======================*/
00717 void KoPageLayoutDia::updatePreview( const KoPageLayout& )
00718 {
00719     if ( pgPreview ) pgPreview->setPageLayout( layout );
00720     if ( pgPreview ) pgPreview->setPageColumns( cl );
00721     if ( pgPreview2 ) pgPreview2->setPageLayout( layout );
00722     if ( pgPreview2 ) pgPreview2->setPageColumns( cl );
00723 }
00724 
00725 /*===================== unit changed =============================*/
00726 void KoPageLayoutDia::unitChanged( int _unit )
00727 {
00728     m_unit = static_cast<KoUnit::Unit>( _unit );
00729     setValuesTab1Helper();
00730     updatePreview( layout );
00731 }
00732 
00733 /*===================== format changed =============================*/
00734 void KoPageLayoutDia::formatChanged( int _format )
00735 {
00736     if ( ( KoFormat )_format != layout.format ) {
00737         bool enable = true;
00738 
00739         layout.format = ( KoFormat )_format;
00740         if ( ( KoFormat )_format != PG_CUSTOM ) enable = false;
00741         epgWidth->setEnabled( enable );
00742         epgHeight->setEnabled( enable );
00743 
00744         double w = layout.ptWidth;
00745         double h = layout.ptHeight;
00746         if ( layout.format != PG_CUSTOM )
00747         {
00748             w = MM_TO_POINT( KoPageFormat::width( layout.format, layout.orientation ) );
00749             h = MM_TO_POINT( KoPageFormat::height( layout.format, layout.orientation ) );
00750         }
00751 
00752         layout.ptWidth = w;
00753         layout.ptHeight = h;
00754 
00755         epgWidth->setValue( KoUnit::ptToUnit( layout.ptWidth, m_unit ) );
00756         epgHeight->setValue( KoUnit::ptToUnit( layout.ptHeight, m_unit ) );
00757 
00758         updatePreview( layout );
00759     }
00760 }
00761 
00762 /*===================== format changed =============================*/
00763 
00764 void KoPageLayoutDia::orientationChanged()
00765 {
00766     KoOrientation oldOrientation = layout.orientation;
00767     layout.orientation = ( rbPortrait->isChecked() ) ?  PG_PORTRAIT : PG_LANDSCAPE;
00768 
00769     // without this check, width & height would be swapped around (below)
00770     // even though the orientation has not changed
00771     if (layout.orientation == oldOrientation) return;
00772 
00773     layout.ptWidth = KoUnit::ptFromUnit( epgWidth->value(), m_unit );
00774     layout.ptHeight = KoUnit::ptFromUnit( epgHeight->value(), m_unit );
00775     layout.ptLeft = KoUnit::ptFromUnit( ebrLeft->value(), m_unit );
00776     layout.ptRight = KoUnit::ptFromUnit( ebrRight->value(), m_unit );
00777     layout.ptTop = KoUnit::ptFromUnit( ebrTop->value(), m_unit );
00778     layout.ptBottom = KoUnit::ptFromUnit( ebrBottom->value(), m_unit );
00779 
00780     // swap dimension and adjust margins
00781     qSwap( layout.ptWidth, layout.ptHeight );
00782     double tmp = layout.ptTop;
00783     layout.ptTop = layout.ptRight;
00784     layout.ptRight = layout.ptBottom;
00785     layout.ptBottom = layout.ptLeft;
00786     layout.ptLeft = tmp;
00787 
00788     setValuesTab1();
00789     updatePreview( layout );
00790 }
00791 
00792 void KoPageLayoutDia::changed(KDoubleNumInput *line, double &pt) {
00793 
00794     if ( line->value() == 0 && retPressed )
00795         line->setValue( 0.0 );
00796     if ( line->value()<0)
00797         line->setValue( 0.0 );
00798     pt = KoUnit::ptFromUnit( line->value(), m_unit );
00799     retPressed = false;
00800 }
00801 
00802 /*===================== width changed =============================*/
00803 void KoPageLayoutDia::widthChanged()
00804 {
00805     changed(epgWidth, layout.ptWidth);
00806     updatePreview( layout );
00807 }
00808 
00809 /*===================== height changed ============================*/
00810 void KoPageLayoutDia::heightChanged()
00811 {
00812     changed(epgHeight, layout.ptHeight);
00813     updatePreview( layout );
00814 }
00815 
00816 /*===================== left border changed =======================*/
00817 void KoPageLayoutDia::leftChanged()
00818 {
00819     changed(ebrLeft, layout.ptLeft);
00820     updatePreview( layout );
00821 }
00822 
00823 /*===================== right border changed =======================*/
00824 void KoPageLayoutDia::rightChanged()
00825 {
00826     changed(ebrRight, layout.ptRight);
00827     updatePreview( layout );
00828 }
00829 
00830 /*===================== top border changed =========================*/
00831 void KoPageLayoutDia::topChanged()
00832 {
00833     changed(ebrTop, layout.ptTop);
00834     updatePreview( layout );
00835 }
00836 
00837 /*===================== bottom border changed ======================*/
00838 void KoPageLayoutDia::bottomChanged()
00839 {
00840     changed(ebrBottom, layout.ptBottom);
00841     updatePreview( layout );
00842 }
00843 
00844 /*==================================================================*/
00845 void KoPageLayoutDia::nColChanged( int _val )
00846 {
00847     cl.columns = _val;
00848     updatePreview( layout );
00849 }
00850 
00851 /*==================================================================*/
00852 void KoPageLayoutDia::nSpaceChanged( double _val )
00853 {
00854     cl.ptColumnSpacing = KoUnit::ptFromUnit( _val, m_unit );
00855     updatePreview( layout );
00856 }
00857 
00858 /* Validation when closing. Error messages are never liked, but
00859   better let the users enter all values in any order, and have one
00860   final validation, than preventing them from entering values. */
00861 void KoPageLayoutDia::slotOk()
00862 {
00863     if ( layout.ptLeft + layout.ptRight > layout.ptWidth )
00864     {
00865         KMessageBox::error( this,
00866             i18n("The page width is smaller than the left and right margins."),
00867                             i18n("Page Layout Problem") );
00868         return;
00869     }
00870     if ( layout.ptTop + layout.ptBottom > layout.ptHeight )
00871     {
00872         KMessageBox::error( this,
00873             i18n("The page height is smaller than the top and bottom margins."),
00874                             i18n("Page Layout Problem") );
00875         return;
00876     }
00877     KDialogBase::slotOk(); // accept
00878 }
00879 
00880 #include <koPageLayoutDia.moc>
KDE Logo
This file is part of the documentation for lib Library Version 1.3.5.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sun Mar 20 14:25:25 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003