00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "KoPageLayoutDia.h"
00026 #include "KoPageLayoutColumns.h"
00027 #include "KoPageLayoutSize.h"
00028 #include "KoPageLayoutHeader.h"
00029 #include <KoUnit.h>
00030 #include "KoUnitWidgets.h"
00031
00032 #include <klocale.h>
00033 #include <kiconloader.h>
00034 #include <kmessagebox.h>
00035
00036 #include <QLabel>
00037 #include <QPainter>
00038 #include <QLineEdit>
00039 #include <QButtonGroup>
00040 #include <QRadioButton>
00041 #include <QCheckBox>
00042
00043
00044
00045
00046
00047
00048
00049 KoPagePreview::KoPagePreview( QWidget* parent, const char* , const KoPageLayout& layout )
00050 : QGroupBox( i18n( "Page Preview" ), parent )
00051 {
00052 setPageLayout( layout );
00053 columns = 1;
00054 setMinimumSize( 150, 150 );
00055 }
00056
00057
00058 KoPagePreview::~KoPagePreview()
00059 {
00060 }
00061
00062
00063 void KoPagePreview::setPageLayout( const KoPageLayout &layout )
00064 {
00065 m_layout = layout;
00066 updateZoomedSize();
00067 update();
00068 }
00069
00070 void KoPagePreview::updateZoomedSize()
00071 {
00072
00073 double resolutionX = POINT_TO_INCH( static_cast<double>(KoGlobal::dpiX()) );
00074 double resolutionY = POINT_TO_INCH( static_cast<double>(KoGlobal::dpiY()) );
00075
00076 m_pageWidth = m_layout.ptWidth * resolutionX;
00077 m_pageHeight = m_layout.ptHeight * resolutionY;
00078
00079 QRect cr = contentsRect();
00080
00081 double zh = (cr.height()-30) / m_pageHeight;
00082 double zw = (cr.width()-30) / m_pageWidth;
00083 double z = qMin( zw, zh );
00084
00085 m_pageWidth *= z;
00086 m_pageHeight *= z;
00087
00088 m_textFrameX = m_layout.ptLeft * resolutionX * z;
00089 m_textFrameY = m_layout.ptTop * resolutionY * z;
00090 m_textFrameWidth = m_pageWidth - ( m_layout.ptLeft + m_layout.ptRight ) * resolutionX * z;
00091 m_textFrameHeight = m_pageHeight - ( m_layout.ptTop + m_layout.ptBottom ) * resolutionY * z;
00092 }
00093
00094
00095 void KoPagePreview::setPageColumns( const KoColumns &_columns )
00096 {
00097 columns = _columns.columns;
00098 update();
00099 }
00100
00101
00102
00103 void KoPagePreview::paintEvent( QPaintEvent * event )
00104 {
00105 QGroupBox::paintEvent( event );
00106 QPainter painter( this );
00107
00108 double cw = m_textFrameWidth;
00109 if(columns!=1)
00110 cw/=static_cast<double>(columns);
00111
00112 painter.setBrush( Qt::white );
00113 painter.setPen( QPen( Qt::black ) );
00114
00115 QRect cr = contentsRect();
00116
00117 int x=static_cast<int>( cr.left() + ( cr.width() - m_pageWidth ) * 0.5 );
00118 int y=static_cast<int>( cr.top() + ( cr.height() - m_pageHeight ) * 0.5 );
00119 int w=static_cast<int>(m_pageWidth);
00120 int h=static_cast<int>(m_pageHeight);
00121
00122 painter.drawRect( x, y, w, h );
00123
00124 painter.setBrush( QBrush( Qt::black, Qt::HorPattern ) );
00125 if ( m_textFrameWidth == m_pageWidth || m_textFrameHeight == m_pageHeight )
00126 painter.setPen( Qt::NoPen );
00127 else
00128 painter.setPen( Qt::lightGray );
00129
00130 for ( int i = 0; i < columns; ++i )
00131 painter.drawRect( x + static_cast<int>(m_textFrameX) + static_cast<int>(i * cw),
00132 y + static_cast<int>(m_textFrameY), static_cast<int>(cw),
00133 static_cast<int>(m_textFrameHeight) );
00134 }
00135
00136 void KoPagePreview::resizeEvent ( QResizeEvent * event )
00137 {
00138 updateZoomedSize();
00139 }
00140
00141
00142
00143
00144
00145
00146 KoPageLayoutDia::KoPageLayoutDia( QWidget* parent, const char* name,
00147 const KoPageLayout& layout,
00148 const KoHeadFoot& hf, int tabs,
00149 KoUnit::Unit unit, bool modal )
00150 : KPageDialog( parent )
00151 {
00152 setCaption( i18n("Page Layout") );
00153 setFaceType( KPageDialog::Tabbed );
00154 setButtons( KDialog::Ok | KDialog::Cancel );
00155 setDefaultButton( KDialog::Ok );
00156 setObjectName( name );
00157 setModal( modal );
00158 flags = tabs;
00159 m_layout = layout;
00160 m_unit = unit;
00161 m_pageSizeTab = 0;
00162 m_columnsTab = 0;
00163 m_headerTab = 0;
00164
00165 m_column.columns = 1;
00166
00167 if ( tabs & FORMAT_AND_BORDERS ) setupTab1( true );
00168 if ( tabs & HEADER_AND_FOOTER ) setupTab2( hf );
00169
00170 setFocusPolicy( Qt::StrongFocus );
00171 setFocus();
00172 }
00173
00174
00175 KoPageLayoutDia::KoPageLayoutDia( QWidget* parent, const char* name,
00176 const KoPageLayout& layout,
00177 const KoHeadFoot& hf,
00178 const KoColumns& columns,
00179 const KoKWHeaderFooter& kwhf,
00180 int tabs, KoUnit::Unit unit )
00181 : KPageDialog( parent )
00182 {
00183 setCaption( i18n("Page Layout") );
00184 setFaceType( KPageDialog::Tabbed );
00185 setButtons( KDialog::Ok | KDialog::Cancel );
00186 setDefaultButton( KDialog::Ok );
00187 setObjectName( name );
00188 setModal( true );
00189
00190 flags = tabs;
00191
00192 m_layout = layout;
00193 m_column = columns;
00194 m_unit = unit;
00195 m_pageSizeTab = 0;
00196 m_columnsTab = 0;
00197 m_headerTab = 0;
00198
00199 if ( tabs & FORMAT_AND_BORDERS ) setupTab1( !( tabs & DISABLE_BORDERS ) );
00200 if ( tabs & HEADER_AND_FOOTER ) setupTab2( hf );
00201 if ( tabs & COLUMNS ) setupTab3();
00202 if ( tabs & KW_HEADER_AND_FOOTER ) setupTab4(kwhf);
00203
00204 setFocusPolicy( Qt::StrongFocus );
00205 setFocus();
00206 }
00207
00208
00209 KoPageLayoutDia::~KoPageLayoutDia()
00210 {
00211 }
00212
00213
00214 bool KoPageLayoutDia::pageLayout( KoPageLayout& layout, KoHeadFoot& hf, int tabs, KoUnit::Unit& unit, QWidget* parent )
00215 {
00216 bool res = false;
00217 KoPageLayoutDia *dlg = new KoPageLayoutDia( parent, "PageLayout", layout, hf, tabs, unit );
00218
00219 if ( dlg->exec() == QDialog::Accepted ) {
00220 res = true;
00221 if ( tabs & FORMAT_AND_BORDERS ) layout = dlg->layout();
00222 if ( tabs & HEADER_AND_FOOTER ) hf = dlg->headFoot();
00223 unit = dlg->unit();
00224 }
00225
00226 delete dlg;
00227
00228 return res;
00229 }
00230
00231
00232 bool KoPageLayoutDia::pageLayout( KoPageLayout& layout, KoHeadFoot& hf, KoColumns& columns,
00233 KoKWHeaderFooter &_kwhf, int tabs, KoUnit::Unit& unit, QWidget* parent )
00234 {
00235 bool res = false;
00236 KoPageLayoutDia *dlg = new KoPageLayoutDia( parent, "PageLayout", layout, hf, columns, _kwhf, tabs, unit );
00237
00238 if ( dlg->exec() == QDialog::Accepted ) {
00239 res = true;
00240 if ( tabs & FORMAT_AND_BORDERS ) layout = dlg->layout();
00241 if ( tabs & HEADER_AND_FOOTER ) hf = dlg->headFoot();
00242 if ( tabs & COLUMNS ) columns = dlg->columns();
00243 if ( tabs & KW_HEADER_AND_FOOTER ) _kwhf = dlg->headerFooter();
00244 unit = dlg->unit();
00245 }
00246
00247 delete dlg;
00248
00249 return res;
00250 }
00251
00252
00253 KoPageLayout KoPageLayoutDia::standardLayout()
00254 {
00255 return KoPageLayout::standardLayout();
00256 }
00257
00258
00259 KoHeadFoot KoPageLayoutDia::headFoot() const
00260 {
00261 KoHeadFoot hf;
00262 hf.headLeft = eHeadLeft->text();
00263 hf.headMid = eHeadMid->text();
00264 hf.headRight = eHeadRight->text();
00265 hf.footLeft = eFootLeft->text();
00266 hf.footMid = eFootMid->text();
00267 hf.footRight = eFootRight->text();
00268 return hf;
00269 }
00270
00271
00272 const KoKWHeaderFooter& KoPageLayoutDia::headerFooter()
00273 {
00274 return m_headerTab->headerFooter();
00275 }
00276
00277
00278 void KoPageLayoutDia::setupTab1( bool enableBorders )
00279 {
00280 QWidget* tab1 = new QWidget();
00281 addPage( tab1, i18n( "Page Size && &Margins" ));
00282 QHBoxLayout *lay = new QHBoxLayout(tab1);
00283 m_pageSizeTab = new KoPageLayoutSize(tab1, m_layout, m_unit, m_column, !(flags & DISABLE_UNIT), enableBorders );
00284 lay->addWidget(m_pageSizeTab);
00285 tab1->setLayout( lay );
00286
00287 m_pageSizeTab->show();
00288 connect (m_pageSizeTab, SIGNAL( propertyChange(KoPageLayout&)),
00289 this, SLOT (sizeUpdated( KoPageLayout&)));
00290 }
00291
00292 void KoPageLayoutDia::sizeUpdated(KoPageLayout &layout) {
00293 m_layout.ptWidth = layout.ptWidth;
00294 m_layout.ptHeight = layout.ptHeight;
00295 m_layout.ptLeft = layout.ptLeft;
00296 m_layout.ptRight = layout.ptRight;
00297 m_layout.ptTop = layout.ptTop;
00298 m_layout.ptBottom = layout.ptBottom;
00299 m_layout.format = layout.format;
00300 m_layout.orientation = layout.orientation;
00301 if(m_columnsTab)
00302 m_columnsTab->setLayout(layout);
00303 }
00304
00305
00306 void KoPageLayoutDia::setupTab2( const KoHeadFoot& hf )
00307 {
00308 QWidget *tab2 = new QWidget();
00309 addPage(tab2, i18n( "H&eader && Footer" ));
00310 QGridLayout *grid2 = new QGridLayout( tab2 );
00311 grid2->setSpacing( KDialog::spacingHint() );
00312
00313
00314 QGroupBox *gHead = new QGroupBox( i18n( "Head Line" ), tab2 );
00315 QGridLayout *headGrid = new QGridLayout( gHead );
00316 gHead->setLayout( headGrid );
00317
00318 QLabel *lHeadLeft = new QLabel( i18n( "Left:" ), gHead );
00319 headGrid->addWidget( lHeadLeft, 0, 0 );
00320
00321 eHeadLeft = new QLineEdit( gHead );
00322 headGrid->addWidget( eHeadLeft, 1, 0 );
00323 eHeadLeft->setText( hf.headLeft );
00324
00325 QLabel *lHeadMid = new QLabel( i18n( "Mid:" ), gHead );
00326 headGrid->addWidget( lHeadMid, 0, 1 );
00327
00328 eHeadMid = new QLineEdit( gHead );
00329 headGrid->addWidget( eHeadMid, 1, 1 );
00330 eHeadMid->setText( hf.headMid );
00331
00332 QLabel *lHeadRight = new QLabel( i18n( "Right:" ), gHead );
00333 headGrid->addWidget( lHeadRight, 0, 2 );
00334
00335 eHeadRight = new QLineEdit( gHead );
00336 headGrid->addWidget( eHeadRight, 1, 2 );
00337 eHeadRight->setText( hf.headRight );
00338
00339 grid2->addWidget( gHead, 0, 2, 1, 1 );
00340
00341
00342 QGroupBox *gFoot = new QGroupBox( i18n( "Foot Line" ), tab2 );
00343 QGridLayout *footGrid = new QGridLayout( gFoot );
00344 gFoot->setLayout( footGrid );
00345
00346 QLabel *lFootLeft = new QLabel( i18n( "Left:" ), gFoot );
00347 footGrid->addWidget( lFootLeft, 0, 0 );
00348
00349 eFootLeft = new QLineEdit( gFoot );
00350 footGrid->addWidget( eFootLeft, 1, 0 );
00351 eFootLeft->setText( hf.footLeft );
00352
00353 QLabel *lFootMid = new QLabel( i18n( "Mid:" ), gFoot );
00354 footGrid->addWidget( lFootMid, 0, 1 );
00355
00356 eFootMid = new QLineEdit( gFoot );
00357 footGrid->addWidget( eFootMid, 1, 1 );
00358 eFootMid->setText( hf.footMid );
00359
00360 QLabel *lFootRight = new QLabel( i18n( "Right:" ), gFoot );
00361 footGrid->addWidget( lFootRight, 0, 2 );
00362
00363 eFootRight = new QLineEdit( gFoot );
00364 footGrid->addWidget( eFootRight, 1, 2 );
00365 eFootRight->setText( hf.footRight );
00366
00367 grid2->addWidget( gFoot, 2, 0, 2, 2 );
00368
00369 QLabel *lMacros2 = new QLabel( i18n( "You can insert several tags in the text:" ), tab2 );
00370 grid2->addWidget( lMacros2, 4, 0, 1, 2 );
00371
00372 QLabel *lMacros3 = new QLabel( i18n("<qt><ul><li><sheet> The sheet name</li>"
00373 "<li><page> The current page</li>"
00374 "<li><pages> The total number of pages</li>"
00375 "<li><name> The filename or URL</li>"
00376 "<li><file> The filename with complete path or the URL</li></ul></qt>"), tab2 );
00377 grid2->addWidget( lMacros3, 5, 0, 2, 1, Qt::AlignTop );
00378
00379 QLabel *lMacros4 = new QLabel( i18n("<qt><ul><li><time> The current time</li>"
00380 "<li><date> The current date</li>"
00381 "<li><author> Your full name</li>"
00382 "<li><org> Your organization</li>"
00383 "<li><email> Your email address</li></ul></qt>"), tab2 );
00384 grid2->addWidget( lMacros4, 5, 1, 2, 1, Qt::AlignTop );
00385 }
00386
00387
00388 void KoPageLayoutDia::setupTab3()
00389 {
00390 QWidget *tab3 = new QWidget();
00391 addPage(tab3, i18n( "Col&umns" ));
00392 QHBoxLayout *lay = new QHBoxLayout(tab3);
00393 m_columnsTab = new KoPageLayoutColumns(tab3, m_column, m_unit, m_layout);
00394 m_columnsTab->layout()->setMargin(0);
00395 lay->addWidget(m_columnsTab);
00396 m_columnsTab->show();
00397 connect (m_columnsTab, SIGNAL( propertyChange(KoColumns&)),
00398 this, SLOT (columnsUpdated( KoColumns&)));
00399 }
00400
00401 void KoPageLayoutDia::columnsUpdated(KoColumns &columns) {
00402 m_column.columns = columns.columns;
00403 m_column.ptColumnSpacing = columns.ptColumnSpacing;
00404 if(m_pageSizeTab)
00405 m_pageSizeTab->setColumns(columns);
00406 }
00407
00408
00409 void KoPageLayoutDia::setupTab4(const KoKWHeaderFooter kwhf )
00410 {
00411 QWidget *tab4 = new QWidget();
00412 addPage(tab4, i18n( "H&eader && Footer" ));
00413 QHBoxLayout *lay = new QHBoxLayout(tab4);
00414 m_headerTab = new KoPageLayoutHeader(tab4, m_unit, kwhf);
00415 m_headerTab->layout()->setMargin(0);
00416 lay->addWidget(m_headerTab);
00417 m_headerTab->show();
00418
00419 }
00420
00421
00422
00423
00424
00425 void KoPageLayoutDia::slotOk()
00426 {
00427 if( m_pageSizeTab )
00428 m_pageSizeTab->queryClose();
00429 slotButtonClicked( KDialog::Ok );
00430 }
00431
00432 #include "KoPageLayoutDia.moc"