26#include <tdemessagebox.h>
27#include <kstaticdeleter.h>
29#include "kspread_canvas.h"
30#include "kspread_cell.h"
31#include "kspread_doc.h"
32#include "kspread_map.h"
33#include "kspread_sheet.h"
34#include "kspread_style.h"
35#include "kspread_style_manager.h"
36#include "kspread_undo.h"
37#include "kspread_view.h"
39#include "manipulator.h"
87Manipulator::Manipulator()
99Manipulator::~Manipulator()
103void Manipulator::execute()
107 kdWarning() <<
"Manipulator::execute(): No explicit m_sheet is set. "
108 <<
"Manipulating all sheets of the region." << endl;
111 bool successfully =
true;
112 successfully = preProcessing();
115 kdWarning() <<
"Manipulator::execute(): preprocessing was not successful!" << endl;
119 m_sheet->doc()->setModified(
true);
120 m_sheet->doc()->undoLock ();
121 m_sheet->doc()->emitBeginOperation();
124 Region::Iterator endOfList(
cells().end());
125 for (Region::Iterator it =
cells().begin(); it != endOfList; ++it)
127 successfully = successfully && process(*it);
132 kdWarning() <<
"Manipulator::execute(): processing was not successful!" << endl;
136 successfully = postProcessing();
139 kdWarning() <<
"Manipulator::execute(): postprocessing was not successful!" << endl;
142 m_sheet->setRegionPaintDirty( *
this );
143 m_sheet->doc()->emitEndOperation();
144 m_sheet->doc()->undoUnlock ();
147 if (m_firstrun && m_register)
150 m_sheet->doc()->addCommand (
this);
152 m_sheet->doc()->setModified (
true);
157void Manipulator::unexecute()
159 m_reverse = !m_reverse;
161 m_reverse = !m_reverse;
164bool Manipulator::process(Element* element)
166 Sheet* sheet = m_sheet;
167 if (m_sheet && sheet != m_sheet)
172 TQRect range = element->rect().normalize();
173 if (m_format && element->isColumn())
175 for (
int col = range.left(); col <= range.right(); ++col)
177 kdDebug() <<
"Processing column " << col <<
"." << endl;
178 ColumnFormat*
format = sheet->nonDefaultColumnFormat(col);
183 else if (m_format && element->isRow())
185 for (
int row = range.top(); row <= range.bottom(); ++row)
187 kdDebug() <<
"Processing row " << row <<
"." << endl;
188 RowFormat*
format = sheet->nonDefaultRowFormat(row);
195 kdDebug() <<
"Processing cell(s) at " << range <<
"." << endl;
196 for (
int col = range.left(); col <= range.right(); ++col)
198 sheet->enableScrollBarUpdates(
false);
199 for (
int row = range.top(); row <= range.bottom(); ++row)
201 Cell* cell = sheet->cellAt(col, row);
210 if (cell == sheet->defaultCell() && m_creation)
212 Style* style = sheet->doc()->styleManager()->defaultStyle();
213 cell =
new Cell(sheet, style, col, row);
214 sheet->insertCell(cell);
223 sheet->enableScrollBarUpdates(
true);
224 sheet->checkRangeVBorder(range.bottom());
226 sheet->checkRangeHBorder(range.right());
237FormatManipulator::FormatManipulator()
241 m_topBorderPen = TQPen(TQColor(), 0, TQt::NoPen);
242 m_bottomBorderPen = TQPen(TQColor(), 0, TQt::NoPen);
243 m_leftBorderPen = TQPen(TQColor(), 0, TQt::NoPen);
244 m_rightBorderPen = TQPen(TQColor(), 0, TQt::NoPen);
245 m_horizontalPen = TQPen(TQColor(), 0, TQt::NoPen);
246 m_verticalPen = TQPen(TQColor(), 0, TQt::NoPen);
247 m_fallDiagonalPen = TQPen(TQColor(), 0, TQt::NoPen);
248 m_goUpDiagonalPen = TQPen(TQColor(), 0, TQt::NoPen);
251FormatManipulator::~FormatManipulator()
253 TQValueList<layoutCell>::Iterator it2;
254 for ( it2 = m_lstFormats.begin(); it2 != m_lstFormats.end(); ++it2 )
258 m_lstFormats.clear();
260 for ( it2 = m_lstRedoFormats.begin(); it2 != m_lstRedoFormats.end(); ++it2 )
264 m_lstRedoFormats.clear();
266 TQValueList<layoutColumn>::Iterator it3;
267 for ( it3 = m_lstColFormats.begin(); it3 != m_lstColFormats.end(); ++it3 )
271 m_lstColFormats.clear();
273 for ( it3 = m_lstRedoColFormats.begin(); it3 != m_lstRedoColFormats.end(); ++it3 )
277 m_lstRedoColFormats.clear();
279 TQValueList<layoutRow>::Iterator it4;
280 for ( it4 = m_lstRowFormats.begin(); it4 != m_lstRowFormats.end(); ++it4 )
284 m_lstRowFormats.clear();
286 for ( it4 = m_lstRedoRowFormats.begin(); it4 != m_lstRedoRowFormats.end(); ++it4 )
290 m_lstRedoRowFormats.clear();
293bool FormatManipulator::preProcessing ()
296 copyFormat (m_lstRedoFormats, m_lstRedoColFormats, m_lstRedoRowFormats);
298 copyFormat (m_lstFormats, m_lstColFormats, m_lstRowFormats);
302bool FormatManipulator::process (Element *element)
305 TQRect range = element->rect().normalize();
309 int top = range.top();
310 int left = range.left();
311 int bottom = range.bottom();
312 int right = range.right();
316 if ( element->isColumn() )
318 for ( RowFormat * row = m_sheet->firstRow(); row; row = row->next() )
320 if ( !row->isDefault() )
322 for (
int col = left; col <= right; ++col )
324 cell = m_sheet->nonDefaultCell( col, row->row() );
331 if ( element->isRow() )
333 for (
int row = top; row <= bottom; ++row )
335 cell = m_sheet->getFirstCellRow( row );
339 cell = m_sheet->getNextCellRight( cell->
column(), row );
341 RowFormat * rowFormat = m_sheet->nonDefaultRowFormat(row);
342 doWork(rowFormat, row==top, row==bottom,
false,
false);
346 else if ( element->isColumn() )
348 for (
int col = left; col <= right; ++col )
350 cell = m_sheet->getFirstCellColumn( col );
354 cell = m_sheet->getNextCellDown( col, cell->
row() );
356 ColumnFormat * colFormat = m_sheet->nonDefaultColumnFormat( col );
357 doWork(colFormat,
false,
false, col==left, col==right);
360 for ( RowFormat * rowFormat = m_sheet->firstRow(); rowFormat; rowFormat = rowFormat->next() )
362 if ( !rowFormat->isDefault() && testCondition( rowFormat ) )
364 for (
int col = left; col <= right; ++col )
366 cell = m_sheet->nonDefaultCell(col, rowFormat->row() );
367 doWork(cell->
format(),
false,
false, col==left, col==right );
375 for (
int col = left; col <= right; ++col )
377 for (
int row = top; row <= bottom; ++row )
379 cell = m_sheet->nonDefaultCell(col,row);
382 cell->setDisplayDirtyFlag();
383 doWork(cell->
format(), row==top, row==bottom, col==left, col==right);
384 cell->clearDisplayDirtyFlag();
392 if( element->isColumn() )
394 TQValueList<layoutColumn>::Iterator it2;
395 for ( it2 = m_lstColFormats.begin(); it2 != m_lstColFormats.end(); ++it2 )
397 ColumnFormat * col = m_sheet->nonDefaultColumnFormat( (*it2).col );
398 col->copy( *(*it2).l );
401 else if( element->isRow() )
403 TQValueList<layoutRow>::Iterator it2;
404 for ( it2 = m_lstRowFormats.begin(); it2 != m_lstRowFormats.end(); ++it2 )
406 RowFormat * row = m_sheet->nonDefaultRowFormat( (*it2).row );
407 row->copy( *(*it2).l );
411 TQValueList<layoutCell>::Iterator it2;
412 for ( it2 = m_lstFormats.begin(); it2 != m_lstFormats.end(); ++it2 )
414 Cell *cell = m_sheet->nonDefaultCell( (*it2).col,(*it2).row );
415 cell->
format()->copy( *(*it2).l );
417 cell->setDisplayDirtyFlag();
418 m_sheet->updateCell( cell, (*it2).col, (*it2).row );
424void FormatManipulator::copyFormat(TQValueList<layoutCell> & list,
425 TQValueList<layoutColumn> & listCol,
426 TQValueList<layoutRow> & listRow)
428 TQValueList<layoutCell>::Iterator end = list.end();
429 for (TQValueList<layoutCell>::Iterator it2 = list.begin(); it2 != end; ++it2)
436 Region::ConstIterator endOfList(
cells().constEnd());
437 for (Region::ConstIterator it =
cells().constBegin(); it != endOfList; ++it)
439 TQRect range = (*it)->rect().normalize();
440 int bottom = range.bottom();
441 int right = range.right();
443 if ( (*it)->isColumn() )
455 for (
int col = range.left(); col <= right; ++col )
457 layoutColumn tmplayout;
459 tmplayout.l =
new ColumnFormat( m_sheet, col );
460 tmplayout.l->copy( *(m_sheet->columnFormat( col )) );
461 listCol.append(tmplayout);
463 cell = m_sheet->getFirstCellColumn( col );
468 cell = m_sheet->getNextCellDown( col, cell->
row() );
472 layoutCell tmplayout;
474 tmplayout.row = cell->
row();
475 tmplayout.l =
new Format( m_sheet, 0 );
476 tmplayout.l->copy( *(m_sheet->cellAt( tmplayout.col, tmplayout.row )->format()) );
477 list.append(tmplayout);
479 cell = m_sheet->getNextCellDown( col, cell->
row() );
500 else if ((*it)->isRow())
502 for (
int row = range.top(); row <= bottom; ++row )
506 tmplayout.l =
new RowFormat( m_sheet, row );
507 tmplayout.l->copy( *(m_sheet->rowFormat( row )) );
508 listRow.append(tmplayout);
510 cell = m_sheet->getFirstCellRow( row );
515 cell = m_sheet->getNextCellRight( cell->
column(), row );
518 layoutCell tmplayout;
519 tmplayout.col = cell->
column();
521 tmplayout.l =
new Format( m_sheet, 0 );
522 tmplayout.l->copy( *(m_sheet->cellAt( cell->
column(), row )->format()) );
523 list.append(tmplayout);
525 cell = m_sheet->getNextCellRight( cell->
column(), row );
548 for (
int row = range.top(); row <= bottom; ++row )
549 for (
int col = range.left(); col <= right; ++col )
551 Cell * cell = m_sheet->nonDefaultCell( col, row );
554 layoutCell tmplayout;
557 tmplayout.l =
new Format( m_sheet, 0 );
558 tmplayout.l->copy( *(m_sheet->cellAt( col, row )->format()) );
559 list.append(tmplayout);
566bool FormatManipulator::testCondition(RowFormat* row)
568 for (TQ_UINT32 property = Format::PAlign;
569 property <= Format::PHideFormula;
572 if (m_properties & property)
574 return ( row->hasProperty((Format::Properties) property) );
580void FormatManipulator::doWork(Format* format,
581 bool isTop,
bool isBottom,
582 bool isLeft,
bool isRight)
586 if (m_properties & Format::PFont)
588 if ( !m_font.isEmpty() )
589 format->setTextFontFamily( m_font );
591 format->setTextFontSize( m_size );
593 format->setTextFontItalic( (
bool)m_italic );
595 format->setTextFontBold( (
bool)m_bold );
596 if ( m_underline >= 0 )
597 format->setTextFontUnderline( (
bool)m_underline );
599 format->setTextFontStrike( (
bool)m_strike );
602 if (m_properties & Format::PAngle)
604 format->setAngle( m_angle );
607 if (m_properties & Format::PTextPen)
609 format->setTextColor( m_textColor );
612 if (m_properties & Format::PBackgroundColor)
614 format->setBgColor( m_backgroundColor );
617 if (m_properties & Format::PLeftBorder)
621 if (m_leftBorderPen.color().isValid())
623 format->setLeftBorderPen(m_leftBorderPen);
628 if (m_verticalPen.color().isValid())
630 format->setLeftBorderPen(m_verticalPen);
634 if (m_properties & Format::PRightBorder)
638 if (m_rightBorderPen.color().isValid())
640 format->setRightBorderPen(m_rightBorderPen);
645 if (m_verticalPen.color().isValid())
647 format->setRightBorderPen(m_verticalPen);
651 if (m_properties & Format::PTopBorder)
655 if (m_topBorderPen.color().isValid())
657 format->setTopBorderPen(m_topBorderPen);
662 if (m_horizontalPen.color().isValid())
664 format->setTopBorderPen(m_horizontalPen);
668 if (m_properties & Format::PBottomBorder)
672 if (m_bottomBorderPen.color().isValid())
674 format->setBottomBorderPen(m_bottomBorderPen);
679 if (m_horizontalPen.color().isValid())
681 format->setBottomBorderPen(m_horizontalPen);
685 if (m_properties & Format::PFallDiagonal)
687 format->setFallDiagonalPen(m_fallDiagonalPen);
689 if (m_properties & Format::PGoUpDiagonal)
691 format->setGoUpDiagonalPen(m_goUpDiagonalPen);
694 if (m_properties & Format::PAlign)
696 format->setAlign( m_horAlign );
699 if (m_properties & Format::PAlignY)
701 format->setAlignY( m_verAlign );
703 if (m_properties & Format::PPrefix)
705 format->setPrefix(m_prefix);
707 if (m_properties & Format::PPostfix)
709 format->setPostfix(m_postfix);
711 if (m_properties & Format::PBackgroundBrush)
713 format->setBackGroundBrush(m_backgroundBrush);
715 if (m_properties & Format::PFloatFormat)
717 format->setFloatFormat(m_floatFormat);
719 if (m_properties & Format::PFloatColor)
721 format->setFloatColor(m_floatColor);
723 if (m_properties & Format::PMultiRow)
725 format->setMultiRow(m_multiRow);
727 if (m_properties & Format::PVerticalText)
729 format->setVerticalText(m_verticalText);
731 if (m_properties & Format::PPrecision)
733 format->setPrecision(m_precision);
735 if (m_properties & Format::PFormatType)
737 format->setFormatType(m_formatType);
738 if (m_formatType == Money_format)
740 format->setCurrency(m_currencyType, m_currencySymbol);
743 if (m_properties & Format::PComment)
745 format->setComment(m_comment);
747 if (m_properties & Format::PIndent)
749 format->setIndent(m_indent);
751 if (m_properties & Format::PDontPrintText)
753 format->setDontPrintText(m_dontPrintText);
755 if (m_properties & Format::PCustomFormat)
759 if (m_properties & Format::PNotProtected)
761 format->setNotProtected(m_notProtected);
763 if (m_properties & Format::PHideAll)
765 format->setHideAll(m_hideAll);
767 if (m_properties & Format::PHideFormula)
769 format->setHideFormula(m_hideFormula);
773void FormatManipulator::prepareCell(
Cell* cell)
775 for (TQ_UINT32 property = Format::PAlign;
776 property <= Format::PHideFormula;
779 if (m_properties & property)
781 cell->
format()->clearProperty((Format::Properties) property);
782 cell->
format()->clearNoFallBackProperties((Format::Properties) property);
793MergeManipulator::MergeManipulator()
796 m_mergeHorizontal(false),
797 m_mergeVertical(false),
802MergeManipulator::~MergeManipulator()
807bool MergeManipulator::process(Element* element)
809 if (element->type() != Element::Range || element->isRow() || element->isColumn())
816 if( m_sheet->isProtected() || m_sheet->workbook()->isProtected() )
821 TQRect range = element->rect().normalize();
822 int left = range.left();
823 int right = range.right();
824 int top = range.top();
825 int bottom = range.bottom();
826 int height = range.height();
827 int width = range.width();
829 bool doMerge = m_reverse ? (!m_merge) : m_merge;
833 if (m_mergeHorizontal)
835 for (
int row = top; row <= bottom; ++row)
838 for (
int col = left; col <= right; ++col)
840 Cell *cell = m_sheet->cellAt( col, row );
847 Cell *cell = m_sheet->nonDefaultCell( left, row );
850 cell->
mergeCells( left, row, width - 1, rows );
854 else if (m_mergeVertical)
856 for (
int col = left; col <= right; ++col)
859 for (
int row = top; row <= bottom; ++row)
861 Cell *cell = m_sheet->cellAt( col, row );
868 Cell *cell = m_sheet->nonDefaultCell( col, top );
871 cell->
mergeCells( col, top, cols, height - 1);
877 Cell *cell = m_sheet->nonDefaultCell( left, top );
878 cell->
mergeCells( left, top, width - 1, height - 1);
883 for (
int col = left; col <= right; ++col)
885 for (
int row = top; row <= bottom; ++row)
887 Cell *cell = m_sheet->cellAt( col, row );
900TQString MergeManipulator::name()
const
904 if (m_mergeHorizontal)
906 return i18n(
"Merge Cells Horizontally");
908 else if (m_mergeVertical)
910 return i18n(
"Merge Cells Vertically");
914 return i18n(
"Merge Cells");
917 return i18n(
"Dissociate Cells");
920bool MergeManipulator::preProcessing()
924 KMessageBox::information( 0, i18n(
"Merging of columns or rows is not supported." ) );
932 ConstIterator endOfList = constEnd();
933 for (ConstIterator it = constBegin(); it != endOfList; ++it)
935 Element* element = *it;
936 TQRect range = element->rect().normalize();
937 int right = range.right();
938 int bottom = range.bottom();
939 for (
int row = range.top(); row <= bottom; ++row)
941 for (
int col = range.left(); col <= right; ++col)
943 Cell *cell = m_sheet->cellAt(col, row);
947 mergedCells.
add(rect);
958 if (!m_mergeHorizontal && !m_mergeVertical)
960 m_unmerger->setReverse(
true);
962 m_unmerger->setSheet(m_sheet);
963 m_unmerger->setRegisterUndo(
false);
964 m_unmerger->
add(mergedCells);
987 if (!m_mergeHorizontal && !m_mergeVertical)
989 m_unmerger->execute();
996bool MergeManipulator::postProcessing()
1003 if (m_mergeHorizontal || m_mergeVertical)
1005 m_unmerger->execute();
1009 m_unmerger->unexecute();
1016 if (m_sheet->getAutoCalc())
1023 m_sheet->refreshMergedCell();
1034DilationManipulator::DilationManipulator()
1039DilationManipulator::~DilationManipulator()
1043void DilationManipulator::execute()
1046 ConstIterator end(
cells().constEnd());
1047 for (ConstIterator it =
cells().constBegin(); it != end; ++it)
1049 Element* element = *it;
1050 TQRect area = element->rect().normalize();
1056 int left = area.left();
1057 int right = area.right();
1058 int top = area.top();
1059 int bottom = area.bottom();
1062 if (element->type() == Region::Element::Point)
1064 Cell* cell = m_sheet->cellAt(left, top);
1074 if ( right < KS_colMax )
1079 col = m_sheet->columnFormat( right );
1080 }
while ( col->isHide() && right != KS_colMax );
1087 col = m_sheet->columnFormat( left );
1088 }
while ( col->isHide() && left != 1);
1091 if ( bottom < KS_rowMax )
1096 rl = m_sheet->rowFormat( bottom );
1097 }
while ( rl->isHide() && bottom != KS_rowMax );
1105 rl = m_sheet->rowFormat( top );
1106 }
while ( rl->isHide() && top != 1);
1110 area.setRight(right);
1112 area.setBottom(bottom);
1114 extendedRegion.
add(area, element->sheet());
1117 add(extendedRegion);
1120void DilationManipulator::unexecute()
1122 kdError() <<
"DilationManipulator::unexecute(): "
1123 <<
"An undo of dilating a region is not possible." << endl;
1132ResizeColumnManipulator::ResizeColumnManipulator()
1136ResizeColumnManipulator::~ResizeColumnManipulator()
1140bool ResizeColumnManipulator::process(Element* element)
1142 TQRect range = element->rect().normalize();
1143 for (
int col = range.right(); col >= range.left(); --col)
1145 ColumnFormat *
format = m_sheet->nonDefaultColumnFormat( col );
1146 format->setDblWidth( TQMAX( 2.0, m_reverse ? m_oldSize : m_newSize ) );
1157ResizeRowManipulator::ResizeRowManipulator()
1161ResizeRowManipulator::~ResizeRowManipulator()
1165bool ResizeRowManipulator::process(Element* element)
1167 TQRect range = element->rect().normalize();
1168 for (
int row = range.bottom(); row >= range.top(); --row)
1170 RowFormat* rl = m_sheet->nonDefaultRowFormat( row );
1171 rl->setDblHeight( TQMAX( 2.0, m_reverse ? m_oldSize : m_newSize ) );
1182AdjustColumnRowManipulator::AdjustColumnRowManipulator()
1184 m_adjustColumn(false),
1189AdjustColumnRowManipulator::~AdjustColumnRowManipulator()
1193bool AdjustColumnRowManipulator::process(Element* element)
1195 Sheet* sheet = m_sheet;
1196 if (m_sheet && sheet != m_sheet)
1201 TQMap<int,double> heights;
1202 TQMap<int,double> widths;
1205 heights = m_oldHeights;
1206 widths = m_oldWidths;
1210 heights = m_newHeights;
1211 widths = m_newWidths;
1214 TQRect range = element->rect().normalize();
1217 if (element->isRow())
1219 for (
int row = range.top(); row <= range.bottom(); ++row)
1221 Cell* cell = sheet->getFirstCellRow( row );
1224 int col = cell->
column();
1227 if (widths.contains(col) && widths[col] != -1.0)
1229 ColumnFormat*
format = sheet->nonDefaultColumnFormat(col);
1230 if ( kAbs(
format->dblWidth() - widths[col] ) > DBL_EPSILON )
1232 format->setDblWidth( TQMAX( 2.0, widths[col] ) );
1236 cell = sheet->getNextCellRight(col, row);
1242 for (
int col = range.left(); col <= range.right(); ++col)
1244 if (widths.contains(col) && widths[col] != -1.0)
1246 ColumnFormat*
format = sheet->nonDefaultColumnFormat(col);
1247 if ( kAbs(
format->dblWidth() - widths[col] ) > DBL_EPSILON )
1249 format->setDblWidth( TQMAX( 2.0, widths[col] ) );
1257 if (element->isColumn())
1259 for (
int col = range.left(); col <= range.right(); ++col)
1261 Cell* cell = sheet->getFirstCellColumn( col );
1264 int row = cell->
row();
1267 if (heights.contains(row) && heights[row] != -1.0)
1269 RowFormat*
format = sheet->nonDefaultRowFormat(row);
1270 if ( kAbs(
format->dblHeight() - heights[row] ) > DBL_EPSILON )
1272 format->setDblHeight( TQMAX( 2.0, heights[row] ) );
1276 cell = sheet->getNextCellDown( col, row );
1282 for (
int row = range.top(); row <= range.bottom(); ++row)
1284 if (heights.contains(row) && heights[row] != -1.0)
1286 RowFormat*
format = sheet->nonDefaultRowFormat(row);
1287 if ( kAbs(
format->dblHeight() - heights[row] ) > DBL_EPSILON )
1289 format->setDblHeight( TQMAX( 2.0, heights[row] ) );
1298bool AdjustColumnRowManipulator::preProcessing()
1305 if (!m_newHeights.isEmpty() || !m_newWidths.isEmpty())
1311 ConstIterator endOfList(
cells().end());
1312 for (ConstIterator it =
cells().begin(); it != endOfList; ++it)
1314 Element* element = *it;
1315 TQRect range = element->rect().normalize();
1316 if (element->isColumn())
1318 for (
int col = range.left(); col <= range.right(); ++col)
1320 Cell* cell = m_sheet->getFirstCellColumn( col );
1323 int row = cell->
row();
1326 if (!m_newWidths.contains(col))
1328 m_newWidths[col] = -1.0;
1329 ColumnFormat*
format = m_sheet->columnFormat(col);
1330 m_oldWidths[col] =
format->dblWidth();
1334 m_newWidths[col] = TQMAX(adjustColumnHelper(cell, col, row),
1340 if (!m_newHeights.contains(row))
1342 m_newHeights[row] = -1.0;
1343 RowFormat*
format = m_sheet->rowFormat(row);
1344 m_oldHeights[row] =
format->dblHeight();
1348 m_newHeights[row] = TQMAX(adjustRowHelper(cell, col, row),
1352 cell = m_sheet->getNextCellDown( col, row );
1356 else if (element->isRow())
1358 for (
int row = range.top(); row <= range.bottom(); ++row)
1360 Cell* cell = m_sheet->getFirstCellRow( row );
1363 int col = cell->
column();
1366 if (!m_newWidths.contains(col))
1368 m_newWidths[col] = -1.0;
1369 ColumnFormat*
format = m_sheet->columnFormat(col);
1370 m_oldWidths[col] =
format->dblWidth();
1374 m_newWidths[col] = TQMAX(adjustColumnHelper(cell, col, row),
1380 if (!m_newHeights.contains(row))
1382 m_newHeights[row] = -1.0;
1383 RowFormat*
format = m_sheet->rowFormat(row);
1384 m_oldHeights[row] =
format->dblHeight();
1388 m_newHeights[row] = TQMAX(adjustRowHelper(cell, col, row),
1392 cell = m_sheet->getNextCellRight(col, row);
1399 for (
int col = range.left(); col <= range.right(); ++col)
1401 for (
int row = range.top(); row <= range.bottom(); ++row )
1403 cell = m_sheet->cellAt( col, row );
1406 if (!m_newWidths.contains(col))
1408 m_newWidths[col] = -1.0;
1409 ColumnFormat*
format = m_sheet->columnFormat(col);
1410 m_oldWidths[col] =
format->dblWidth();
1414 m_newWidths[col] = TQMAX(adjustColumnHelper(cell, col, row),
1420 if (!m_newHeights.contains(row))
1422 m_newHeights[row] = -1.0;
1423 RowFormat*
format = m_sheet->rowFormat(row);
1424 m_oldHeights[row] =
format->dblHeight();
1428 m_newHeights[row] = TQMAX(adjustRowHelper(cell, col, row),
1440double AdjustColumnRowManipulator::adjustColumnHelper(
Cell* cell,
int col,
int row )
1442 double long_max = 0.0;
1446 double indent = 0.0;
1447 Format::Align alignment = cell->
format()->align(cell->
column(), cell->
row());
1448 if (alignment == Format::Undefined)
1452 alignment = Format::Right;
1456 alignment = Format::Left;
1460 if (alignment == Format::Left)
1471 if ( long_max == 0.0 )
1477 return long_max + 4;
1481double AdjustColumnRowManipulator::adjustRowHelper(
Cell* cell,
int col,
int row)
1483 double long_max = 0.0;
1488 + cell->
format()->topBorderWidth(col, row)
1489 + cell->
format()->bottomBorderWidth(col, row);
1494 if ( long_max == 0.0 )
1500 return long_max + 1;
1504TQString AdjustColumnRowManipulator::name()
const
1506 if (m_adjustColumn && m_adjustRow)
1508 return i18n(
"Adjust Columns/Rows");
1510 else if (m_adjustColumn)
1512 return i18n(
"Adjust Columns");
1516 return i18n(
"Adjust Rows");
1526HideShowManipulator::HideShowManipulator()
1527 : m_manipulateColumns(false),
1528 m_manipulateRows(false)
1532HideShowManipulator::~HideShowManipulator()
1536bool HideShowManipulator::process(Element* element)
1538 TQRect range = element->rect().normalize();
1539 if (m_manipulateColumns)
1541 for (
int col = range.left(); col <= range.right(); ++col)
1543 ColumnFormat*
format = m_sheet->nonDefaultColumnFormat(col);
1544 format->setHide(!m_reverse);
1547 if (m_manipulateRows)
1549 for (
int row = range.top(); row <= range.bottom(); ++row)
1551 RowFormat*
format = m_sheet->nonDefaultRowFormat(row);
1552 format->setHide(!m_reverse);
1558bool HideShowManipulator::preProcessing()
1561 ConstIterator endOfList =
cells().constEnd();
1562 for (ConstIterator it =
cells().constBegin(); it != endOfList; ++it)
1566 TQRect range = (*it)->rect().normalize();
1567 if (m_manipulateColumns)
1569 if (range.left() > 1)
1572 for (col = 1; col < range.left(); ++col)
1574 ColumnFormat*
format = m_sheet->columnFormat(col);
1580 if (col == range.left())
1582 region.
add(TQRect(1, 1, range.left()-1, KS_rowMax));
1585 for (
int col = range.left(); col <= range.right(); ++col)
1587 ColumnFormat*
format = m_sheet->columnFormat(col);
1590 region.
add(TQRect(col, 1, 1, KS_rowMax));
1594 if (m_manipulateRows)
1596 if (range.top() > 1)
1599 for (row = 1; row < range.top(); ++row)
1601 RowFormat*
format = m_sheet->rowFormat(row);
1607 if (row == range.top())
1609 region.
add(TQRect(1, 1, KS_colMax, range.top()-1));
1612 for (
int row = range.top(); row <= range.bottom(); ++row)
1614 RowFormat*
format = m_sheet->rowFormat(row);
1617 region.
add(TQRect(1, row, KS_colMax, 1));
1623 if (((*it)->isRow() && m_manipulateColumns) ||
1624 ((*it)->isColumn() && m_manipulateRows))
1640bool HideShowManipulator::postProcessing()
1642 if (m_manipulateColumns)
1644 m_sheet->emitHideColumn();
1646 if (m_manipulateRows)
1648 m_sheet->emitHideRow();
1654TQString HideShowManipulator::name()
const
1665 if (m_manipulateColumns)
1669 if (m_manipulateColumns && m_manipulateRows)
1673 if (m_manipulateRows)
1688static KStaticDeleter<ManipulatorManager> staticManipulatorManagerDeleter;
1699ManipulatorManager::ManipulatorManager()
1703ManipulatorManager::~ManipulatorManager()
1707Manipulator* ManipulatorManager::create(
const TQString& type)
1709 if (type ==
"bgcolor")
1711 kdDebug() <<
"Background color manipulator created." << endl;
1714 else if (type ==
"textcolor")
1716 kdDebug() <<
"Text color manipulator created." << endl;
1721 kdError() <<
"Unknown manipulator!" << endl;
For every cell in the spread sheet there is a Cell object.
void setLayoutDirtyFlag(bool format=false)
Causes the format to be recalculated when the cell is drawn next time.
int row() const
Returns the cell's row.
const Value value() const
Returns the value that this cell holds.
bool doesMergeCells() const
int column() const
Returns the cell's column.
double textHeight() const
return height of the text
bool isEmpty() const
Returns true if this cell has no content, i.e no text and no formula.
void calculateTextParameters(TQPainter &painter, int _col, int _row)
Calculates the text parameters stored in cell Applies font to use to painter.
Format * format() const
Returns the format object of this cell.
void mergeCells(int _col, int _row, int _x, int _y)
Merge a number of cells, i.e.
bool isPartOfMerged() const
If this cell is part of a merged cell, then the marker may never reside on this cell.
bool isDate() const
returns true, if cell format is of date type or content is a date
bool isTime() const
returns true, if cell format is of time type or content is a time
double textWidth() const
return width of the text
bool format()
Is this a formatting manipulator ? If so, execute will call process(Format*) for each complete row/co...
The one for all class for points and ranges.
Element * add(const TQPoint &point, Sheet *sheet=0)
Adds the point point to this region.
virtual void clear()
Deletes all elements of the region.
TQValueList< Element * > & cells() const
bool isColumnOrRowSelected() const
The Style class represents a cell style.
bool isNumber() const
Returns true if the type of this value is either integer or floating-point.