00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "kspread_dlg_paperlayout.h"
00024 #include <kspread_doc.h>
00025 #include "kspread_map.h"
00026 #include "kspread_sheet.h"
00027 #include "kspread_sheetprint.h"
00028 #include <kspread_undo.h>
00029 #include <kspread_util.h>
00030 #include <kspread_view.h>
00031
00032 #include <qcheckbox.h>
00033 #include <qlabel.h>
00034 #include <qlineedit.h>
00035 #include <qradiobutton.h>
00036 #include <qbuttongroup.h>
00037 #include <qcombobox.h>
00038 #include <qlayout.h>
00039 #include <qhgroupbox.h>
00040
00041 #include <kapplication.h>
00042 #include <kdebug.h>
00043 #include <klocale.h>
00044 #include <kmessagebox.h>
00045
00046 KSpreadPaperLayout::KSpreadPaperLayout( QWidget * parent, const char * name,
00047 const KoPageLayout & layout,
00048 const KoHeadFoot & headfoot,
00049 int tabs, KoUnit::Unit unit,
00050 KSpreadSheet * sheet, KSpreadView * view)
00051 : KoPageLayoutDia( parent, name, layout, headfoot, tabs, unit, false ),
00052 m_pSheet( sheet ),
00053 m_pView( view )
00054 {
00055 initTab();
00056 connect( view, SIGNAL( sig_selectionChanged( KSpreadSheet *, const QRect & ) ),
00057 this, SLOT( slotSelectionChanged( KSpreadSheet *, const QRect & ) ) );
00058 qApp->installEventFilter( this );
00059 m_focus= 0L;
00060 }
00061
00062 void KSpreadPaperLayout::initTab()
00063 {
00064 KSpreadSheetPrint* print = m_pSheet->print();
00065
00066 QWidget *tab = addPage(i18n( "Options" ));
00067 QVBoxLayout *vbox = new QVBoxLayout( tab, KDialog::marginHint(), KDialog::spacingHint() );
00068
00069 pApplyToAll = new QCheckBox ( i18n( "&Apply to all sheets" ), tab );
00070 pApplyToAll->setChecked( print->printGrid() );
00071 vbox->addWidget( pApplyToAll );
00072
00073
00074 initGeneralOptions( tab, vbox );
00075
00076
00077 initRanges( tab, vbox );
00078
00079
00080 initScaleOptions( tab, vbox );
00081
00082 vbox->addStretch( 1 );
00083 }
00084
00085 void KSpreadPaperLayout::initGeneralOptions( QWidget * tab, QVBoxLayout * vbox )
00086 {
00087 KSpreadSheetPrint* print = m_pSheet->print();
00088
00089 QHGroupBox *group = new QHGroupBox( i18n("General Options"), tab );
00090 vbox->addWidget( group );
00091
00092 pPrintGrid = new QCheckBox ( i18n("Print &grid"), group );
00093 pPrintGrid->setChecked( print->printGrid() );
00094
00095 pPrintCommentIndicator = new QCheckBox ( i18n("Print &comment indicator"), group );
00096 pPrintCommentIndicator->setChecked( print->printCommentIndicator() );
00097
00098 pPrintFormulaIndicator = new QCheckBox ( i18n("Print &formula indicator"), group );
00099 pPrintFormulaIndicator->setChecked( print->printFormulaIndicator() );
00100 }
00101
00102 void KSpreadPaperLayout::initRanges( QWidget * tab, QVBoxLayout * vbox )
00103 {
00104 KSpreadSheetPrint* print = m_pSheet->print();
00105
00106 QGroupBox *rangeGroup = new QGroupBox( i18n("Ranges"), tab );
00107 rangeGroup->setColumnLayout( 0, Qt::Vertical );
00108 rangeGroup->setMargin( KDialog::marginHint() );
00109 vbox->addWidget( rangeGroup );
00110
00111 QGridLayout *grid = new QGridLayout( rangeGroup->layout(), 3, 2, KDialog::spacingHint() );
00112
00113 QLabel *pPrintRange = new QLabel ( i18n("Print range:"), rangeGroup );
00114 grid->addWidget( pPrintRange, 0, 0 );
00115
00116 ePrintRange = new QLineEdit( rangeGroup );
00117 ePrintRange->setText( util_rangeName( print->printRange() ) );
00118 grid->addWidget( ePrintRange, 0, 1 );
00119
00120 QLabel *pRepeatCols = new QLabel ( i18n("Repeat columns on each page:"), rangeGroup );
00121 grid->addWidget( pRepeatCols, 1, 0 );
00122
00123 eRepeatCols = new QLineEdit( rangeGroup );
00124 if ( print->printRepeatColumns().first != 0 )
00125 eRepeatCols->setText( KSpreadCell::columnName( print->printRepeatColumns().first ) + ":" +
00126 KSpreadCell::columnName( print->printRepeatColumns().second ) );
00127 grid->addWidget( eRepeatCols, 1, 1 );
00128
00129 QLabel *pRepeatRows = new QLabel ( i18n("Repeat rows on each page:"), rangeGroup );
00130 grid->addWidget( pRepeatRows, 2, 0 );
00131
00132 eRepeatRows = new QLineEdit( rangeGroup );
00133 if ( print->printRepeatRows().first != 0 )
00134 eRepeatRows->setText( QString().setNum( print->printRepeatRows().first ) +
00135 ":" +
00136 QString().setNum( print->printRepeatRows().second ) );
00137 grid->addWidget( eRepeatRows, 2, 1 );
00138
00139 grid->addColSpacing( 0, pPrintRange->width() );
00140 grid->addColSpacing( 0, pRepeatRows->width() );
00141 grid->addColSpacing( 0, pRepeatCols->width() );
00142 grid->addColSpacing( 1, ePrintRange->width() );
00143 grid->addColSpacing( 1, eRepeatRows->width() );
00144 grid->addColSpacing( 1, eRepeatCols->width() );
00145
00146 grid->addRowSpacing( 0, pPrintRange->height() );
00147 grid->addRowSpacing( 0, ePrintRange->height() );
00148 grid->addRowSpacing( 1, pRepeatRows->height() );
00149 grid->addRowSpacing( 1, eRepeatRows->height() );
00150 grid->addRowSpacing( 2, pRepeatCols->height() );
00151 grid->addRowSpacing( 2, eRepeatCols->height() );
00152 }
00153
00154 void KSpreadPaperLayout::initScaleOptions( QWidget * tab, QVBoxLayout * vbox )
00155 {
00156 KSpreadSheetPrint* print = m_pSheet->print();
00157
00158 QButtonGroup *zoomGroup = new QButtonGroup( i18n("Scale Printout"), tab );
00159 zoomGroup->setColumnLayout( 0, Qt::Vertical );
00160 zoomGroup->setMargin( KDialog::marginHint() );
00161 vbox->addWidget( zoomGroup );
00162
00163 QGridLayout *grid = new QGridLayout( zoomGroup->layout(), 2, 6,
00164 KDialog::spacingHint() );
00165
00166 m_rScalingZoom = new QRadioButton ( i18n("Zoom:"), zoomGroup );
00167 grid->addWidget( m_rScalingZoom, 0, 0 );
00168
00169 m_cZoom = new QComboBox( true, zoomGroup, "Zoom" );
00170 grid->addMultiCellWidget( m_cZoom, 0, 0, 1, 5, Qt::AlignLeft );
00171
00172 QStringList lst;
00173 for( int i = 5; i < 500; i += 5 )
00174 {
00175 lst.append( QString( i18n( "%1%" ) ).arg( i ) );
00176 if( qRound( print->zoom() * 100 ) > i &&
00177 qRound( print->zoom() * 100 ) < i + 5 )
00178 {
00179 lst.append( QString( i18n( "%1%" ) ).arg( qRound( print->zoom() * 100 ) ) );
00180 }
00181 }
00182 m_cZoom->insertStringList( lst );
00183
00184 int number_of_entries = m_cZoom->count();
00185 QString string = QString( i18n( "%1%" ) ).arg( qRound( print->zoom() * 100 ) );
00186 for (int i = 0; i < number_of_entries ; i++)
00187 {
00188 if ( string == (QString) m_cZoom->text(i) )
00189 {
00190 m_cZoom->setCurrentItem( i );
00191 break;
00192 }
00193 }
00194
00195 m_rScalingLimitPages = new QRadioButton ( i18n("Limit pages:"), zoomGroup );
00196 grid->addWidget( m_rScalingLimitPages, 1, 0 );
00197
00198 QLabel *pLimitPagesX = new QLabel ( i18n("X:"), zoomGroup );
00199 grid->addWidget( pLimitPagesX, 1, 1 );
00200
00201 m_cLimitPagesX = new QComboBox( true, zoomGroup, "pagesX" );
00202 grid->addWidget( m_cLimitPagesX, 1, 2 );
00203
00204 QStringList lstX;
00205 lstX.append( i18n( "No Limit" ) );
00206 for( int i = 1; i <= 20; i += 1 )
00207 {
00208 lstX.append( QString( "%1" ).arg( i ) );
00209 if( print->pageLimitX() > 20 )
00210 {
00211 lstX.append( QString( "%1" ).arg( print->pageLimitX() ) );
00212 }
00213 }
00214 m_cLimitPagesX->insertStringList( lstX );
00215
00216 if ( print->pageLimitX() <= 20 )
00217 m_cLimitPagesX->setCurrentItem( print->pageLimitX() );
00218 else
00219 m_cLimitPagesX->setCurrentItem( 21 );
00220
00221 QLabel *pLimitPagesY = new QLabel ( i18n("Y:"), zoomGroup );
00222 grid->addWidget( pLimitPagesY, 1, 3 );
00223
00224 m_cLimitPagesY = new QComboBox( true, zoomGroup, "pagesY" );
00225 grid->addWidget( m_cLimitPagesY, 1, 4 );
00226
00227 QStringList lstY;
00228 lstY.append( i18n( "No Limit" ) );
00229 for( int i = 1; i <= 20; i += 1 )
00230 {
00231 lstY.append( QString( "%1" ).arg( i ) );
00232 if( print->pageLimitY() > 20 )
00233 {
00234 lstY.append( QString( "%1" ).arg( print->pageLimitY() ) );
00235 }
00236 }
00237 m_cLimitPagesY->insertStringList( lstY );
00238
00239 if ( print->pageLimitY() <= 20 )
00240 m_cLimitPagesY->setCurrentItem( print->pageLimitY() );
00241 else
00242 m_cLimitPagesY->setCurrentItem( 21 );
00243
00244 if ( print->pageLimitY() != 0 || print->pageLimitX() != 0 )
00245 {
00246 m_rScalingLimitPages->setChecked( true );
00247 }
00248 else
00249 {
00250 m_rScalingZoom->setChecked( true );
00251 }
00252
00253 connect( m_cZoom, SIGNAL( activated( int ) ), this, SLOT( slotChooseZoom( int ) ) );
00254 connect( m_cLimitPagesX, SIGNAL( activated( int ) ), this, SLOT( slotChoosePageLimit( int ) ) );
00255 connect( m_cLimitPagesY, SIGNAL( activated( int ) ), this, SLOT( slotChoosePageLimit( int ) ) );
00256 }
00257
00258 void KSpreadPaperLayout::slotChooseZoom( int )
00259 {
00260 m_rScalingZoom->setChecked( true );
00261 }
00262
00263 void KSpreadPaperLayout::slotChoosePageLimit( int )
00264 {
00265 m_rScalingLimitPages->setChecked( true );
00266 }
00267
00268 void KSpreadPaperLayout::slotOk()
00269 {
00270 if ( !m_pSheet->doc()->undoLocked() )
00271 {
00272 KSpreadUndoAction* undo = new KSpreadUndoPaperLayout( m_pSheet->doc(), m_pSheet );
00273 m_pSheet->doc()->addCommand( undo );
00274 }
00275
00276
00277 leftChanged();
00278 rightChanged();
00279 topChanged();
00280 bottomChanged();
00281
00282 KSpreadMap * map = 0;
00283 KSpreadSheet * sheet = 0;
00284
00285 if ( pApplyToAll->isChecked() )
00286 map = m_pSheet->doc()->map();
00287
00288 if ( map )
00289 sheet = map->firstSheet();
00290 else
00291 sheet = m_pSheet;
00292
00293 m_pView->doc()->emitBeginOperation( false );
00294 while ( sheet )
00295 {
00296 KSpreadSheetPrint *print = sheet->print();
00297
00298 KoPageLayout pl = layout();
00299 KoHeadFoot hf = headFoot();
00300 KoUnit::Unit unit = sheet->doc()->getUnit();
00301 print->setPrintGrid( pPrintGrid->isChecked() );
00302 print->setPrintCommentIndicator( pPrintCommentIndicator->isChecked() );
00303 print->setPrintFormulaIndicator( pPrintFormulaIndicator->isChecked() );
00304 QString tmpPrintRange = ePrintRange->text();
00305 QString tmpRepeatCols = eRepeatCols->text();
00306 QString tmpRepeatRows = eRepeatRows->text();
00307 if ( tmpPrintRange.isEmpty() )
00308 {
00309 print->setPrintRange( QRect( QPoint( 1, 1 ), QPoint( KS_colMax, KS_rowMax ) ) );
00310 }
00311 else
00312 {
00313 bool error = true;
00314 int first = tmpPrintRange.find(":");
00315 if ( ( first != -1 ) && ( (int)tmpPrintRange.length() > first ) )
00316 {
00317 KSpreadPoint point1 ( tmpPrintRange.left( first ) );
00318 if ( point1.isValid() )
00319 {
00320 KSpreadPoint point2 ( tmpPrintRange.mid( first+1 ) );
00321 if ( point2.isValid() )
00322 {
00323 error = false;
00324 print->setPrintRange ( QRect( QPoint( QMIN( point1.pos.x(), point2.pos.x() ),
00325 QMIN( point1.pos.y(), point2.pos.y() ) ),
00326 QPoint( QMAX( point1.pos.x(), point2.pos.x() ),
00327 QMAX( point1.pos.y(), point2.pos.y() ) ) ) );
00328 }
00329 }
00330 }
00331
00332 if ( error ) KMessageBox::information( 0, i18n( "Print range wrong, changes are ignored." ) );
00333 }
00334
00335 if ( tmpRepeatCols.isEmpty() )
00336 {
00337 print->setPrintRepeatColumns( qMakePair( 0, 0 ) );
00338 }
00339 else
00340 {
00341 bool error = true;
00342 int first = tmpRepeatCols.find(":");
00343 if ( ( first != -1 ) && ( (int)tmpRepeatCols.length() > first ) )
00344 {
00345 int col1 = util_decodeColumnLabelText( tmpRepeatCols.left( first ) );
00346 if ( col1 > 0 && col1 <= KS_colMax )
00347 {
00348 int col2 = util_decodeColumnLabelText( tmpRepeatCols.mid( first+1 ) );
00349 if ( col2 > 0 && col2 <= KS_colMax )
00350 {
00351 error = false;
00352 print->setPrintRepeatColumns ( qMakePair( col1, col2 ) );
00353 }
00354 }
00355 }
00356
00357 if ( error )
00358 KMessageBox::information( 0, i18n( "Repeated columns range wrong, changes are ignored.\nMust be in format column:column (eg. B:C)" ) );
00359 }
00360
00361 if ( tmpRepeatRows.isEmpty() )
00362 {
00363 print->setPrintRepeatRows ( qMakePair( 0, 0 ) );
00364 }
00365 else
00366 {
00367 bool error = true;
00368 int first = tmpRepeatRows.find(":");
00369 if ( ( first != -1 ) && ( (int)tmpRepeatRows.length() > first ) )
00370 {
00371 int row1 = tmpRepeatRows.left( first ).toInt();
00372 if ( row1 > 0 && row1 <= KS_rowMax )
00373 {
00374 int row2 = tmpRepeatRows.mid( first+1 ).toInt();
00375 if ( row2 > 0 && row2 <= KS_rowMax )
00376 {
00377 error = false;
00378 print->setPrintRepeatRows ( qMakePair( row1, row2 ) );
00379 }
00380 }
00381 }
00382
00383 if ( error )
00384 KMessageBox::information( 0, i18n( "Repeated rows range wrong, changes are ignored.\nMust be in format row:row (eg. 2:3)" ) );
00385 }
00386
00387 if ( m_rScalingZoom->isChecked() )
00388 {
00389 if( QString( "%1%" ).arg( qRound( print->zoom() * 100 ) ) != m_cZoom->currentText() )
00390 {
00391 if( m_cZoom->currentText().toDouble() != 0.0 )
00392 print->setZoom( 0.01 * m_cZoom->currentText().toDouble() );
00393 }
00394 }
00395 else
00396 {
00397 if( print->pageLimitX() != m_cLimitPagesX->currentText().toInt() )
00398 print->setPageLimitX( m_cLimitPagesX->currentText().toInt() );
00399
00400 if( print->pageLimitY() != m_cLimitPagesY->currentText().toInt() )
00401 print->setPageLimitY( m_cLimitPagesY->currentText().toInt() );
00402 }
00403
00404 sheet->doc()->setModified( true );
00405
00406 if ( pl.format == PG_CUSTOM )
00407 {
00408 print->setPaperWidth( qRound( POINT_TO_MM( pl.ptWidth ) *1000 ) / 1000 );
00409 print->setPaperHeight( qRound( POINT_TO_MM( pl.ptHeight ) *1000 ) / 1000 );
00410 }
00411
00412 print->setPaperLayout( POINT_TO_MM(pl.ptLeft), POINT_TO_MM(pl.ptTop),
00413 POINT_TO_MM(pl.ptRight), POINT_TO_MM(pl.ptBottom),
00414 pl.format, pl.orientation );
00415
00416 print->setHeadFootLine( print->delocalizeHeadFootLine( hf.headLeft ),
00417 print->delocalizeHeadFootLine( hf.headMid ),
00418 print->delocalizeHeadFootLine( hf.headRight ),
00419 print->delocalizeHeadFootLine( hf.footLeft ),
00420 print->delocalizeHeadFootLine( hf.footMid ),
00421 print->delocalizeHeadFootLine( hf.footRight ) );
00422
00423 sheet->doc()->setUnit( unit );
00424
00425 if ( map )
00426 sheet = map->nextSheet();
00427 else
00428 sheet = 0;
00429 }
00430
00431 m_pView->slotUpdateView( m_pView->activeSheet() );
00432 accept();
00433 }
00434
00435 void KSpreadPaperLayout::closeEvent ( QCloseEvent * )
00436 {
00437 delete this;
00438 }
00439
00440 void KSpreadPaperLayout::slotSelectionChanged( KSpreadSheet* , const QRect& _selection )
00441 {
00442 if ( _selection.left() == 0 || _selection.top() == 0 ||
00443 _selection.right() == 0 || _selection.bottom() == 0 )
00444 return;
00445
00446 QString area = util_rangeName( _selection );
00447 if ( m_focus )
00448 {
00449 if ( m_focus == ePrintRange )
00450 area = util_rangeName( _selection );
00451 else if ( m_focus == eRepeatRows )
00452 area = util_rangeRowName( _selection );
00453 else if ( m_focus == eRepeatCols )
00454 area = util_rangeColumnName( _selection );
00455 else
00456 return;
00457 m_focus->setText( area );
00458 }
00459 }
00460
00461 void KSpreadPaperLayout::slotCancel()
00462 {
00463 reject();
00464 }
00465
00466 bool KSpreadPaperLayout::eventFilter( QObject* obj, QEvent* ev )
00467 {
00468 if ( obj == ePrintRange && ev->type() == QEvent::FocusIn )
00469 m_focus = ePrintRange;
00470 else if ( obj == eRepeatCols && ev->type() == QEvent::FocusIn )
00471 m_focus = eRepeatCols;
00472 else if ( obj == eRepeatRows && ev->type() == QEvent::FocusIn )
00473 m_focus = eRepeatRows;
00474 else
00475 return false;
00476
00477 return false;
00478 }
00479
00480
00481 #include "kspread_dlg_paperlayout.moc"