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