24#include "kspread_dlg_paperlayout.h"
25#include <kspread_doc.h>
26#include "kspread_map.h"
27#include "kspread_sheet.h"
28#include "kspread_sheetprint.h"
29#include <kspread_undo.h>
30#include <kspread_util.h>
31#include <kspread_view.h>
34#include <tqcheckbox.h>
36#include <tqlineedit.h>
37#include <tqradiobutton.h>
38#include <tqbuttongroup.h>
39#include <tqcombobox.h>
41#include <tqhgroupbox.h>
43#include <tdeapplication.h>
46#include <tdemessagebox.h>
50PaperLayout::PaperLayout( TQWidget * parent,
const char * name,
51 const KoPageLayout & layout,
52 const KoHeadFoot & headfoot,
53 int tabs, KoUnit::Unit unit,
54 Sheet * sheet,
View * view)
55 : KoPageLayoutDia( parent, name, layout, headfoot, tabs, unit, false ),
60 connect(view->selectionInfo(), TQ_SIGNAL(changed(
const Region&)),
61 this, TQ_SLOT(slotSelectionChanged()));
62 tqApp->installEventFilter(
this );
66void PaperLayout::initTab()
68 SheetPrint* print = m_pSheet->print();
70 TQWidget *tab = addPage(i18n(
"Options" ));
71 TQVBoxLayout *vbox =
new TQVBoxLayout( tab, KDialog::marginHint(), KDialog::spacingHint() );
73 pApplyToAll =
new TQCheckBox ( i18n(
"&Apply to all sheets" ), tab );
74 pApplyToAll->setChecked( print->printGrid() );
75 vbox->addWidget( pApplyToAll );
78 initGeneralOptions( tab, vbox );
81 initRanges( tab, vbox );
84 initScaleOptions( tab, vbox );
86 vbox->addStretch( 1 );
89void PaperLayout::initGeneralOptions( TQWidget * tab, TQVBoxLayout * vbox )
91 SheetPrint* print = m_pSheet->print();
93 TQGroupBox *group =
new TQGroupBox( i18n(
"General Options"), tab );
94 TQGridLayout *l =
new TQGridLayout( group, 2, 3 );
96 pPrintGrid =
new TQCheckBox ( i18n(
"Print &grid"), group );
97 pPrintGrid->setChecked( print->printGrid() );
98 l->addWidget( pPrintGrid, 0, 0 );
100 pPrintCommentIndicator =
new TQCheckBox ( i18n(
"Print &comment indicator"), group );
101 pPrintCommentIndicator->setChecked( print->printCommentIndicator() );
102 l->addWidget( pPrintCommentIndicator, 0, 1 );
104 pPrintFormulaIndicator =
new TQCheckBox ( i18n(
"Print &formula indicator"), group );
105 pPrintFormulaIndicator->setChecked( print->printFormulaIndicator() );
106 l->addWidget( pPrintFormulaIndicator, 0, 2 );
108 pPrintObjects =
new TQCheckBox ( i18n(
"Print &objects"), group );
109 pPrintObjects->setChecked( print->printObjects() );
110 l->addWidget( pPrintObjects, 1, 0 );
112 pPrintCharts =
new TQCheckBox ( i18n(
"Print &charts"), group );
113 pPrintCharts->setChecked( print->printCharts() );
114 l->addWidget( pPrintCharts, 1, 1 );
121 vbox->addWidget( group );
124void PaperLayout::initRanges( TQWidget * tab, TQVBoxLayout * vbox )
126 SheetPrint* print = m_pSheet->print();
128 TQGroupBox *rangeGroup =
new TQGroupBox( i18n(
"Ranges"), tab );
129 rangeGroup->setColumnLayout( 0, TQt::Vertical );
130 rangeGroup->setMargin( KDialog::marginHint() );
131 vbox->addWidget( rangeGroup );
133 TQGridLayout *grid =
new TQGridLayout( rangeGroup->layout(), 3, 2, KDialog::spacingHint() );
135 TQLabel *pPrintRange =
new TQLabel ( i18n(
"Print range:"), rangeGroup );
136 grid->addWidget( pPrintRange, 0, 0 );
138 ePrintRange =
new TQLineEdit( rangeGroup );
139 ePrintRange->setText( util_rangeName( print->printRange() ) );
140 grid->addWidget( ePrintRange, 0, 1 );
142 TQLabel *pRepeatCols =
new TQLabel ( i18n(
"Repeat columns on each page:"), rangeGroup );
143 grid->addWidget( pRepeatCols, 1, 0 );
145 eRepeatCols =
new TQLineEdit( rangeGroup );
146 if ( print->printRepeatColumns().first != 0 )
147 eRepeatCols->setText(
Cell::columnName( print->printRepeatColumns().first ) +
":" +
149 grid->addWidget( eRepeatCols, 1, 1 );
151 TQLabel *pRepeatRows =
new TQLabel ( i18n(
"Repeat rows on each page:"), rangeGroup );
152 grid->addWidget( pRepeatRows, 2, 0 );
154 eRepeatRows =
new TQLineEdit( rangeGroup );
155 if ( print->printRepeatRows().first != 0 )
156 eRepeatRows->setText( TQString().setNum( print->printRepeatRows().first ) +
158 TQString().setNum( print->printRepeatRows().second ) );
159 grid->addWidget( eRepeatRows, 2, 1 );
161 grid->addColSpacing( 0, pPrintRange->width() );
162 grid->addColSpacing( 0, pRepeatRows->width() );
163 grid->addColSpacing( 0, pRepeatCols->width() );
164 grid->addColSpacing( 1, ePrintRange->width() );
165 grid->addColSpacing( 1, eRepeatRows->width() );
166 grid->addColSpacing( 1, eRepeatCols->width() );
168 grid->addRowSpacing( 0, pPrintRange->height() );
169 grid->addRowSpacing( 0, ePrintRange->height() );
170 grid->addRowSpacing( 1, pRepeatRows->height() );
171 grid->addRowSpacing( 1, eRepeatRows->height() );
172 grid->addRowSpacing( 2, pRepeatCols->height() );
173 grid->addRowSpacing( 2, eRepeatCols->height() );
176void PaperLayout::initScaleOptions( TQWidget * tab, TQVBoxLayout * vbox )
178 SheetPrint* print = m_pSheet->print();
180 TQButtonGroup *zoomGroup =
new TQButtonGroup( i18n(
"Scale Printout"), tab );
181 zoomGroup->setColumnLayout( 0, TQt::Vertical );
182 zoomGroup->setMargin( KDialog::marginHint() );
183 vbox->addWidget( zoomGroup );
185 TQGridLayout *grid =
new TQGridLayout( zoomGroup->layout(), 2, 6,
186 KDialog::spacingHint() );
188 m_rScalingZoom =
new TQRadioButton ( i18n(
"Zoom:"), zoomGroup );
189 grid->addWidget( m_rScalingZoom, 0, 0 );
191 m_cZoom =
new TQComboBox(
true, zoomGroup,
"Zoom" );
192 grid->addMultiCellWidget( m_cZoom, 0, 0, 1, 5, TQt::AlignLeft );
195 for(
int i = 5; i < 500; i += 5 )
197 lst.append( TQString( i18n(
"%1%" ) ).arg( i ) );
198 if( tqRound( print->zoom() * 100 ) > i &&
199 tqRound( print->zoom() * 100 ) < i + 5 )
201 lst.append( TQString( i18n(
"%1%" ) ).arg( tqRound( print->zoom() * 100 ) ) );
204 m_cZoom->insertStringList( lst );
206 int number_of_entries = m_cZoom->count();
207 TQString
string = TQString( i18n(
"%1%" ) ).arg( tqRound( print->zoom() * 100 ) );
208 for (
int i = 0; i < number_of_entries ; i++)
210 if (
string == (TQString) m_cZoom->text(i) )
212 m_cZoom->setCurrentItem( i );
217 m_rScalingLimitPages =
new TQRadioButton ( i18n(
"Limit pages:"), zoomGroup );
218 grid->addWidget( m_rScalingLimitPages, 1, 0 );
220 TQLabel *pLimitPagesX =
new TQLabel ( i18n(
"X:"), zoomGroup );
221 grid->addWidget( pLimitPagesX, 1, 1 );
223 m_cLimitPagesX =
new TQComboBox(
true, zoomGroup,
"pagesX" );
224 grid->addWidget( m_cLimitPagesX, 1, 2 );
227 lstX.append( i18n(
"No Limit" ) );
228 for(
int i = 1; i <= 20; i += 1 )
230 lstX.append( TQString(
"%1" ).arg( i ) );
232 if( print->pageLimitX() > 20 )
234 lstX.append( TQString(
"%1" ).arg( print->pageLimitX() ) );
236 m_cLimitPagesX->insertStringList( lstX );
238 if ( print->pageLimitX() <= 20 )
239 m_cLimitPagesX->setCurrentItem( print->pageLimitX() );
241 m_cLimitPagesX->setCurrentItem( 21 );
243 TQLabel *pLimitPagesY =
new TQLabel ( i18n(
"Y:"), zoomGroup );
244 grid->addWidget( pLimitPagesY, 1, 3 );
246 m_cLimitPagesY =
new TQComboBox(
true, zoomGroup,
"pagesY" );
247 grid->addWidget( m_cLimitPagesY, 1, 4 );
250 lstY.append( i18n(
"No Limit" ) );
251 for(
int i = 1; i <= 20; i += 1 )
253 lstY.append( TQString(
"%1" ).arg( i ) );
255 if( print->pageLimitY() > 20 )
257 lstY.append( TQString(
"%1" ).arg( print->pageLimitY() ) );
259 m_cLimitPagesY->insertStringList( lstY );
261 if ( print->pageLimitY() <= 20 )
262 m_cLimitPagesY->setCurrentItem( print->pageLimitY() );
264 m_cLimitPagesY->setCurrentItem( 21 );
266 if ( print->pageLimitY() != 0 || print->pageLimitX() != 0 )
268 m_rScalingLimitPages->setChecked(
true );
272 m_rScalingZoom->setChecked(
true );
275 connect( m_cZoom, TQ_SIGNAL( activated(
int ) ),
this, TQ_SLOT( slotChooseZoom(
int ) ) );
276 connect( m_cLimitPagesX, TQ_SIGNAL( activated(
int ) ),
this, TQ_SLOT( slotChoosePageLimit(
int ) ) );
277 connect( m_cLimitPagesY, TQ_SIGNAL( activated(
int ) ),
this, TQ_SLOT( slotChoosePageLimit(
int ) ) );
280void PaperLayout::slotChooseZoom(
int )
282 m_rScalingZoom->setChecked(
true );
285void PaperLayout::slotChoosePageLimit(
int )
287 m_rScalingLimitPages->setChecked(
true );
290void PaperLayout::slotOk()
292 if ( !m_pSheet->doc()->undoLocked() )
294 UndoAction* undo =
new UndoPaperLayout( m_pSheet->doc(), m_pSheet );
295 m_pSheet->doc()->addCommand( undo );
302 if ( pApplyToAll->isChecked() )
303 map = m_pSheet->doc()->map();
313 SheetPrint *print = sheet->print();
315 KoPageLayout pl = layout();
316 KoHeadFoot hf = headFoot();
317 KoUnit::Unit unit = sheet->doc()->unit();
318 print->setPrintGrid( pPrintGrid->isChecked() );
319 print->setPrintCommentIndicator( pPrintCommentIndicator->isChecked() );
320 print->setPrintFormulaIndicator( pPrintFormulaIndicator->isChecked() );
321 print->setPrintObjects( pPrintObjects->isChecked() );
322 print->setPrintCharts( pPrintCharts->isChecked() );
324 TQString tmpPrintRange = ePrintRange->text();
325 TQString tmpRepeatCols = eRepeatCols->text();
326 TQString tmpRepeatRows = eRepeatRows->text();
327 if ( tmpPrintRange.isEmpty() )
329 print->setPrintRange( TQRect( TQPoint( 1, 1 ), TQPoint( KS_colMax, KS_rowMax ) ) );
334 int first = tmpPrintRange.find(
":");
335 if ( ( first != -1 ) && ( (
int)tmpPrintRange.length() > first ) )
337 Point point1 ( tmpPrintRange.left( first ) );
338 if ( point1.isValid() )
340 Point point2 ( tmpPrintRange.mid( first+1 ) );
341 if ( point2.isValid() )
344 print->setPrintRange ( TQRect( TQPoint( TQMIN( point1.pos().x(), point2.pos().x() ),
345 TQMIN( point1.pos().y(), point2.pos().y() ) ),
346 TQPoint( TQMAX( point1.pos().x(), point2.pos().x() ),
347 TQMAX( point1.pos().y(), point2.pos().y() ) ) ) );
352 if ( error ) KMessageBox::information( 0, i18n(
"Print range wrong, changes are ignored." ) );
355 if ( tmpRepeatCols.isEmpty() )
357 print->setPrintRepeatColumns( qMakePair( 0, 0 ) );
362 int first = tmpRepeatCols.find(
":");
363 if ( ( first != -1 ) && ( (
int)tmpRepeatCols.length() > first ) )
366 if ( col1 > 0 && col1 <= KS_colMax )
369 if ( col2 > 0 && col2 <= KS_colMax )
372 print->setPrintRepeatColumns ( qMakePair( col1, col2 ) );
378 KMessageBox::information( 0, i18n(
"Repeated columns range wrong, changes are ignored.\nMust be in format column:column (eg. B:C)" ) );
381 if ( tmpRepeatRows.isEmpty() )
383 print->setPrintRepeatRows ( qMakePair( 0, 0 ) );
388 int first = tmpRepeatRows.find(
":");
389 if ( ( first != -1 ) && ( (
int)tmpRepeatRows.length() > first ) )
391 int row1 = tmpRepeatRows.left( first ).toInt();
392 if ( row1 > 0 && row1 <= KS_rowMax )
394 int row2 = tmpRepeatRows.mid( first+1 ).toInt();
395 if ( row2 > 0 && row2 <= KS_rowMax )
398 print->setPrintRepeatRows ( qMakePair( row1, row2 ) );
404 KMessageBox::information( 0, i18n(
"Repeated rows range wrong, changes are ignored.\nMust be in format row:row (eg. 2:3)" ) );
407 if ( m_rScalingZoom->isChecked() )
409 kdDebug() <<
"Zoom is selected" << endl;
410 if( TQString(
"%1%" ).arg( tqRound( print->zoom() * 100 ) ) != m_cZoom->currentText() )
412 kdDebug() <<
"New zoom is different than original: " << m_cZoom->currentText() << endl;
413 TQString zoomtext = m_cZoom->currentText();
414 zoomtext.replace(
"%",
"");
415 bool convertok =
false;
416 double zoomvalue = zoomtext.toDouble(&convertok);
419 kdWarning() <<
"Could not convert zoom text to double value!!!" << endl;
421 else if( zoomvalue != 0.0 )
424 print->setPageLimitX(0);
425 print->setPageLimitY(0);
426 kdDebug() <<
"Setting print zoom: " << zoomvalue*0.01 << endl;
427 print->setZoom( 0.01 * zoomvalue );
428 kdDebug() <<
"New print zoom: " << print->zoom() << endl;
431 kdDebug() <<
"Did not set print zoom" << endl;
434 kdDebug() <<
"new zoom is same as original: " << m_cZoom->currentText() << endl;
436 else if (m_rScalingLimitPages->isChecked())
438 kdDebug() <<
"Limit pages is selected" << endl;
439 kdDebug() <<
"Current zoom: " << print->zoom() << endl;
444 print->setPageLimitX( 0 );
445 print->setPageLimitY( 0 );
449 if (print->zoom() < 1.0)
451 kdDebug() <<
"Resetting zoom to 1.0" << endl;
452 print->setZoom(1.0,
false);
453 kdDebug() <<
"Zoom is now: " << print->zoom() << endl;
456 bool convertok =
false;
458 int limitX = m_cLimitPagesX->currentText().toInt(&convertok);
463 int limitY = m_cLimitPagesY->currentText().toInt(&convertok);
467 kdDebug() <<
"Zoom before setting limits: " << print->zoom() << endl;
468 kdDebug() <<
"Chosen Limits: x: " << limitX <<
"; y: " << limitY << endl;
469 print->setPageLimitX( limitX );
470 kdDebug() <<
"Zoom after setting x limit: " << print->zoom() << endl;
471 print->setPageLimitY( limitY );
472 kdDebug() <<
"Zoom after setting y limit: " << print->zoom() << endl;
475 kdWarning() <<
"ERROR: unknown zoom option selected" << endl;
477 sheet->doc()->setModified(
true );
479 if ( pl.format == PG_CUSTOM )
481 print->setPaperWidth( tqRound( POINT_TO_MM( pl.ptWidth ) *1000 ) / 1000 );
482 print->setPaperHeight( tqRound( POINT_TO_MM( pl.ptHeight ) *1000 ) / 1000 );
485 print->setPaperLayout( POINT_TO_MM(pl.ptLeft), POINT_TO_MM(pl.ptTop),
486 POINT_TO_MM(pl.ptRight), POINT_TO_MM(pl.ptBottom),
487 pl.format, pl.orientation );
489 print->setHeadFootLine( print->delocalizeHeadFootLine( hf.headLeft ),
490 print->delocalizeHeadFootLine( hf.headMid ),
491 print->delocalizeHeadFootLine( hf.headRight ),
492 print->delocalizeHeadFootLine( hf.footLeft ),
493 print->delocalizeHeadFootLine( hf.footMid ),
494 print->delocalizeHeadFootLine( hf.footRight ) );
496 sheet->doc()->setUnit( unit );
499 sheet = map->nextSheet();
504 m_pView->slotUpdateView( m_pView->activeSheet() );
508void PaperLayout::closeEvent ( TQCloseEvent * )
513void PaperLayout::slotSelectionChanged()
516 if (!m_pView->selectionInfo()->isValid())
519 TQString area = util_rangeName( m_pView->selectionInfo()->lastRange() );
522 if ( m_focus == ePrintRange )
523 area = util_rangeName( m_pView->selectionInfo()->lastRange() );
524 else if ( m_focus == eRepeatRows )
525 area = util_rangeRowName( m_pView->selectionInfo()->lastRange() );
526 else if ( m_focus == eRepeatCols )
527 area = util_rangeColumnName( m_pView->selectionInfo()->lastRange() );
530 m_focus->setText( area );
534void PaperLayout::slotCancel()
539bool PaperLayout::eventFilter( TQObject* obj, TQEvent* ev )
541 if ( obj == ePrintRange && ev->type() == TQEvent::FocusIn )
542 m_focus = ePrintRange;
543 else if ( obj == eRepeatCols && ev->type() == TQEvent::FocusIn )
544 m_focus = eRepeatCols;
545 else if ( obj == eRepeatRows && ev->type() == TQEvent::FocusIn )
546 m_focus = eRepeatRows;
554#include "kspread_dlg_paperlayout.moc"
TQString columnName() const
Returns the column name of the cell.
void emitBeginOperation(bool waitCursor)
Functions to begin a kspread 'operation'.
Sheet * firstSheet()
Use the nextSheet function to get all the other sheets.
The one for all class for points and ranges.
The View class displays a KSpread document.
KSPREAD_EXPORT int util_decodeColumnLabelText(const TQString &_col)
Call this function to decode the text of a column label to an integer i.e.