48#include <tqapplication.h>
50#include <tqclipboard.h>
51#include <tqdrawutil.h>
54#include <tqscrollbar.h>
57#include <tqwidgetlist.h>
61#include <tdemessagebox.h>
62#include <tdemultipledrag.h>
65#include <ksharedptr.h>
68#include <KoOasisStore.h>
71#include <KoStoreDrag.h>
72#include <KoXmlWriter.h>
73#include <KoDocumentChild.h>
77#include "kspread_doc.h"
78#include "kspread_editors.h"
79#include "kspread_global.h"
80#include "kspread_locale.h"
81#include "kspread_map.h"
82#include "kspread_sheet.h"
83#include "kspread_undo.h"
84#include "kspread_util.h"
85#include "kspread_view.h"
88#include "kspread_canvas.h"
92#define NONCONTIGUOUSSELECTION
106 TQTimer* scrollTimer;
120 TQPen defaultGridPen;
123 Canvas::EditorType focusEditorType;
125 TQLabel *validationInfo;
144 TQRect autoFillSource;
151 bool rubberBandStarted;
152 TQPoint rubberBandStart;
153 TQPoint rubberBandEnd;
158 bool mouseSelectedObject;
164 TQPoint m_savedMousePos;
173 KoPoint m_origMousePos;
177 KoPoint m_moveStartPoint;
180 KoRect m_rectBeforeResize;
182 KoPoint m_moveStartPosMouse;
191 int prevSpokenPointerRow;
192 int prevSpokenPointerCol;
193 int prevSpokenFocusRow;
194 int prevSpokenFocusCol;
207Canvas::Canvas (
View *_view)
208 : TQWidget( _view,
"", WStaticContents| WResizeNoErase | WRepaintNoErase )
213 d->chooseCell =
false;
214 d->validationInfo = 0L;
216 TQWidget::setFocusPolicy( TQWidget::StrongFocus );
218 d->dragStart = TQPoint( -1, -1 );
222 d->defaultGridPen.setColor( lightGray );
223 d->defaultGridPen.setWidth( 1 );
224 d->defaultGridPen.setStyle( TQt::SolidLine );
230 d->mouseAction = NoAction;
231 d->rubberBandStarted =
false;
238 setBackgroundMode( PaletteBase );
240 setMouseTracking(
true );
241 d->mousePressed =
false;
242 d->mouseSelectedObject =
false;
243 d->drawContour =
false;
244 d->modType = MT_NONE;
246 d->m_resizeObject = 0L;
248 d->m_isMoving =
false;
249 d->m_objectDisplayAbove = 0;
250 d->m_isResizing =
false;
252 d->prevSpokenPointerRow = -1;
253 d->prevSpokenPointerCol = -1;
254 d->prevSpokenFocusRow = -1;
255 d->prevSpokenFocusCol = -1;
256 d->prevSpokenRow = -1;
257 d->prevSpokenCol = -1;
259 d->scrollTimer =
new TQTimer(
this );
260 connect (d->scrollTimer, TQ_SIGNAL( timeout() ),
this, TQ_SLOT( doAutoScroll() ) );
264 connect( d->view, TQ_SIGNAL( autoScroll(
const TQPoint & )),
this, TQ_SLOT( slotAutoScroll(
const TQPoint &)));
268 connect (kospeaker, TQ_SIGNAL(customSpeakWidget(TQWidget*,
const TQPoint&, uint)),
269 this, TQ_SLOT(speakCell(TQWidget*,
const TQPoint&, uint)));
273 installEventFilter(
this );
275 setAcceptDrops(
true );
276 setInputMethodEnabled(
true );
278 setWFlags(TQt::WNoAutoErase);
283 delete d->scrollTimer;
284 delete d->validationInfo;
293Doc* Canvas::doc()
const
295 return d->view->doc();
305 return d->editWidget;
310 return d->cellEditor;
325 d->xOffset = _xOffset;
330 d->yOffset = _yOffset;
335 return d->defaultGridPen;
340 d->focusEditorType = type;
343Canvas::EditorType Canvas::lastEditorWithFocus()
const
345 return d->focusEditorType;
349bool Canvas::eventFilter( TQObject *o, TQEvent *e )
358 case TQEvent::KeyPress:
360 TQKeyEvent * keyev =
static_cast<TQKeyEvent*
>(e);
361 if ((keyev->key()==Key_Tab) || (keyev->key()==Key_Backtab))
363 keyPressEvent ( keyev );
368 case TQEvent::IMStart:
369 case TQEvent::IMCompose:
372 TQIMEvent * imev =
static_cast<TQIMEvent *
>(e);
373 processIMEvent( imev );
382bool Canvas::focusNextPrevChild(
bool )
389 return d->view->selectionInfo();
394 return d->view->choice();
399 return d->view->selectionInfo()->selection();
404 return d->view->selectionInfo()->marker();
409 return d->view->selectionInfo()->marker().x();
414 return d->view->selectionInfo()->marker().y();
419 return d->view->zoom();
424 d->chooseCell = state;
429 return d->chooseCell;
441 d->chooseCell =
true;
450 choice()->initialize(rect);
453 d->chooseCell =
true;
467 if ( !d->chooseCell )
470 d->chooseCell =
false;
472 Sheet *sheet =
choice()->sheet();
475 d->view->setActiveSheet(sheet);
479HBorder* Canvas::hBorderWidget()
const
481 return d->view->hBorderWidget();
484VBorder* Canvas::vBorderWidget()
const
486 return d->view->vBorderWidget();
489TQScrollBar* Canvas::horzScrollBar()
const
491 return d->view->horzScrollBar();
494TQScrollBar* Canvas::vertScrollBar()
const
496 return d->view->vertScrollBar();
501 return d->view->doc()->map()->findSheet( _name );
506 return d->view->activeSheet();
521 Cell * cell = sheet->cellAt( col,row );
522 if ( cell && cell->getValidity(0) && cell->getValidity()->displayValidationInformation)
524 TQString title = cell->getValidity(0)->titleInfo;
525 TQString message = cell->getValidity(0)->messageInfo;
526 if ( title.isEmpty() && message.isEmpty() )
529 if ( !d->validationInfo )
530 d->validationInfo =
new TQLabel(
this );
531 kdDebug()<<
" display info validation\n";
540 int moveX = cell->
column();
541 int moveY = cell->
row();
546 xpos = sheet->dblColumnPos( moveX );
547 ypos = sheet->dblRowPos( moveY );
550 d->validationInfo->setAlignment( TQt::AlignVCenter );
552 painter.begin(
this );
556 if ( !title.isEmpty() )
558 len = painter.fontMetrics().width( title );
559 hei = painter.fontMetrics().height();
560 resultText = title +
"\n";
562 if ( !message.isEmpty() )
569 i = message.find(
"\n", pos );
571 t = message.mid( pos, message.length() - pos );
574 t = message.mid( pos, i - pos );
577 hei += painter.fontMetrics().height();
578 len = TQMAX( len, painter.fontMetrics().width( t ) );
581 resultText += message;
584 d->validationInfo->setText( resultText );
586 KoRect unzoomedMarker( xpos -
xOffset()+u,
590 TQRect
marker( d->view->doc()->zoomRect( unzoomedMarker ) );
592 d->validationInfo->setGeometry(
marker );
593 d->validationInfo->show();
597 delete d->validationInfo;
598 d->validationInfo = 0L;
603 delete d->validationInfo;
604 d->validationInfo = 0L;
615 if (d->view->isLoading())
626 Cell* cell = sheet->cellAt(location.x(), location.y(),
true);
629 double unzoomedWidth = d->view->doc()->unzoomItX( width() );
630 double unzoomedHeight = d->view->doc()->unzoomItY( height() );
638 if ( sheet->layoutDirection()==Sheet::LeftToRight )
639 xpos = sheet->dblColumnPos( location.x() ) -
xOffset();
641 xpos = unzoomedWidth - sheet->dblColumnPos( location.x() ) +
xOffset();
642 double ypos = sheet->dblRowPos( location.y() ) -
yOffset();
647 double maxY = unzoomedHeight - 40.0;
651 if ( sheet->layoutDirection()==Sheet::RightToLeft ) {
654 double minX = unzoomedWidth - 100.0;
661 horzScrollBar()->setValue( horzScrollBar()->maxValue() -
662 d->view->doc()->zoomItX(
xOffset() - xpos + minX ) );
665 else if ( xpos < maxX )
667 double horzScrollBarValue =
xOffset() - xpos + maxX;
668 double horzScrollBarValueMax = sheet->sizeMaxX() - unzoomedWidth;
671 if ( horzScrollBarValue > horzScrollBarValueMax )
672 horzScrollBarValue = horzScrollBarValueMax;
674 horzScrollBar()->setValue( horzScrollBar()->maxValue() -
675 d->view->doc()->zoomItX( horzScrollBarValue ) );
682 double maxX = unzoomedWidth - 100.0;
688 horzScrollBar()->setValue( d->view->doc()->zoomItX(
xOffset() + xpos - minX ) );
691 else if ( xpos > maxX )
693 double horzScrollBarValue =
xOffset() + xpos - maxX;
694 double horzScrollBarValueMax = sheet->sizeMaxX() - unzoomedWidth;
697 if ( horzScrollBarValue > horzScrollBarValueMax )
698 horzScrollBarValue = horzScrollBarValueMax;
700 horzScrollBar()->setValue( d->view->doc()->zoomItX( horzScrollBarValue ) );
707 vertScrollBar()->setValue( d->view->doc()->zoomItY(
yOffset() + ypos - minY ) );
710 else if ( ypos > maxY )
712 double vertScrollBarValue =
yOffset() + ypos - maxY;
713 double vertScrollBarValueMax = sheet->sizeMaxY() - unzoomedHeight;
716 if ( vertScrollBarValue > vertScrollBarValueMax )
717 vertScrollBarValue = vertScrollBarValueMax;
719 vertScrollBar()->setValue( d->view->doc()->zoomItY( vertScrollBarValue ) );
723void Canvas::slotScrollHorz(
int _value )
730 kdDebug(36001) <<
"slotScrollHorz: value = " << _value << endl;
733 if ( sheet->layoutDirection()==Sheet::RightToLeft )
734 _value = horzScrollBar()->maxValue() - _value;
736 double unzoomedValue = d->view->doc()->unzoomItX( _value );
737 double dwidth = d->view->doc()->unzoomItX( width() );
739 d->view->doc()->emitBeginOperation(
false);
741 if ( unzoomedValue < 0.0 ) {
743 <<
"Canvas::slotScrollHorz: value out of range (unzoomedValue: "
744 << unzoomedValue <<
")" << endl;
748 double xpos = sheet->dblColumnPos( TQMIN( KS_colMax, d->view->activeSheet()->maxColumn()+10 ) ) - d->xOffset;
749 if ( unzoomedValue > ( xpos + d->xOffset ) )
750 unzoomedValue = xpos + d->xOffset;
752 sheet->enableScrollBarUpdates(
false );
755 int dx = d->view->doc()->zoomItX( d->xOffset - unzoomedValue );
763 area.setRight( area.left() );
764 area.setLeft( sheet->leftColumn( unzoomedValue, tmp ) );
768 area.setLeft( area.right() );
769 area.setRight( sheet->rightColumn( dwidth + unzoomedValue ) );
772 sheet->setRegionPaintDirty(area);
775 kdDebug(36001) <<
"slotScrollHorz(): XOffset before setting: "
776 << d->xOffset << endl;
777 d->xOffset = unzoomedValue;
778 kdDebug(36001) <<
"slotScrollHorz(): XOffset after setting: "
779 << d->xOffset << endl;
781 if ( sheet->layoutDirection()==Sheet::RightToLeft )
786 hBorderWidget()->scroll( dx, 0 );
788 sheet->enableScrollBarUpdates(
true );
790 d->view->doc()->emitEndOperation( sheet->visibleRect(
this ) );
793void Canvas::slotScrollVert(
int _value )
798 d->view->doc()->emitBeginOperation(
false);
799 double unzoomedValue = d->view->doc()->unzoomItY( _value );
801 if ( unzoomedValue < 0 )
804 kdDebug (36001) <<
"Canvas::slotScrollVert: value out of range (unzoomedValue: " <<
805 unzoomedValue <<
")" << endl;
808 double ypos =
activeSheet()->dblRowPos( TQMIN( KS_rowMax, d->view->activeSheet()->maxRow()+10 ) );
809 if ( unzoomedValue > ypos )
810 unzoomedValue = ypos;
815 int dy = d->view->doc()->zoomItY( d->yOffset - unzoomedValue );
823 area.setBottom(area.top());
824 area.setTop(
activeSheet()->topRow(unzoomedValue, tmp));
828 area.setTop(area.bottom());
829 area.setBottom(
activeSheet()->bottomRow(d->view->doc()->unzoomItY(height()) +
836 d->yOffset = unzoomedValue;
838 vBorderWidget()->scroll( 0, dy );
842 d->view->doc()->emitEndOperation(
activeSheet()->visibleRect(
this ) );
845void Canvas::slotMaxColumn(
int _max_column )
847 int oldValue = horzScrollBar()->maxValue() - horzScrollBar()->value();
848 double xpos =
activeSheet()->dblColumnPos( TQMIN( KS_colMax, _max_column + 10 ) ) -
xOffset();
849 double unzoomWidth = d->view->doc()->unzoomItX( width() );
853 if ( xpos > sizeMaxX -
xOffset() - unzoomWidth )
854 xpos = sizeMaxX -
xOffset() - unzoomWidth;
856 horzScrollBar()->setRange( 0, d->view->doc()->zoomItX( xpos +
xOffset() ) );
858 if (
activeSheet()->layoutDirection()==Sheet::RightToLeft )
859 horzScrollBar()->setValue( horzScrollBar()->maxValue() - oldValue );
862void Canvas::slotMaxRow(
int _max_row )
864 double ypos =
activeSheet()->dblRowPos( TQMIN( KS_rowMax, _max_row + 10 ) ) -
yOffset();
865 double unzoomHeight = d->view->doc()->unzoomItY( height() );
869 if ( ypos > sizeMaxY -
yOffset() - unzoomHeight )
870 ypos = sizeMaxY -
yOffset() - unzoomHeight;
872 vertScrollBar()->setRange( 0, d->view->doc()->zoomItY( ypos +
yOffset() ) );
875void Canvas::mouseMoveEvent( TQMouseEvent * _ev )
878 if ( (!d->view->koDocument()->isReadWrite()) && (d->mouseAction!=
Mark))
881 if ( d->mousePressed && d->modType != MT_NONE )
883 KoPoint docPoint ( doc()->unzoomPoint( _ev->pos() ) );
886 if ( d->modType == MT_MOVE )
888 if ( !d->m_isMoving )
890 d->m_moveStartPoint = objectRect(
false ).topLeft();
891 d->m_isMoving =
true;
893 moveObjectsByMouse( docPoint, _ev->state() & AltButton || _ev->state() & ControlButton );
895 else if ( d->m_resizeObject )
897 if ( !d->m_isResizing )
898 d->m_isResizing =
true;
900 bool keepRatio = d->m_resizeObject->isKeepRatio();
901 if ( _ev->state() & AltButton )
905 docPoint = KoPoint( doc()->unzoomPoint( _ev->pos() ) );
984 if ( d->dragStart.x() != -1 )
986 TQPoint p ( (
int) _ev->pos().x() + (
int)
xOffset(),
987 (
int) _ev->pos().y() + (
int)
yOffset() );
989 if ( ( d->dragStart - p ).manhattanLength() > 4 )
993 d->dragStart.setX( -1 );
1007 if ( d->mouseSelectedObject )
1010 TQPoint p ( (
int) _ev->x(),
1012 if ( ( obj = getObject( p,
activeSheet() ) ) && obj->isSelected() )
1014 KoRect
const bound = obj->geometry();
1015 TQRect zoomedBound = doc()->zoomRect( KoRect(bound.left(), bound.top(),
1018 zoomedBound.moveBy( (
int)(-
xOffset() * doc()->zoomedResolutionX() ), (
int)(-
yOffset() * doc()->zoomedResolutionY() ));
1019 setCursor( obj->getCursor( p, d->modType, zoomedBound ) );
1024 double dwidth = d->view->doc()->unzoomItX( width() );
1026 if ( sheet->layoutDirection()==Sheet::RightToLeft )
1028 ev_PosX = dwidth - d->view->doc()->unzoomItX( _ev->pos().x() ) +
xOffset();
1032 ev_PosX = d->view->doc()->unzoomItX( _ev->pos().x() ) +
xOffset();
1034 double ev_PosY = d->view->doc()->unzoomItY( _ev->pos().y() ) +
yOffset();
1039 int col = sheet->leftColumn( ev_PosX, xpos );
1040 int row = sheet->topRow( ev_PosY, ypos );
1043 if ( col > KS_colMax || row > KS_rowMax )
1045 kdDebug(36001) <<
"Canvas::mouseMoveEvent: col or row is out of range: "
1046 <<
"col: " << col <<
" row: " << row << endl;
1054 choice()->update(TQPoint(col,row));
1062 if ( sheet->layoutDirection()==Sheet::RightToLeft )
1063 setCursor( sizeBDiagCursor );
1065 setCursor( sizeFDiagCursor );
1074 double lx = sheet->dblColumnPos( rct.left() );
1075 double rx = sheet->dblColumnPos( rct.right() + 1 );
1076 double ty = sheet->dblRowPos( rct.top() );
1077 double by = sheet->dblRowPos( rct.bottom() + 1 );
1079 r1.setLeft( (
int) (lx - 1) );
1080 r1.setTop( (
int) (ty - 1) );
1081 r1.setRight( (
int) (rx + 1) );
1082 r1.setBottom( (
int) (by + 1) );
1084 r2.setLeft( (
int) (lx + 1) );
1085 r2.setTop( (
int) (ty + 1) );
1086 r2.setRight( (
int) (rx - 1) );
1087 r2.setBottom( (
int) (by - 1) );
1091 Cell *cell = sheet->visibleCellAt( col, row );
1093 if ( sheet->layoutDirection()==Sheet::RightToLeft )
1095 anchor = cell->testAnchor( d->view->doc()->zoomItX( cell->
dblWidth() - ev_PosX + xpos ),
1096 d->view->doc()->zoomItY( ev_PosY - ypos ) );
1100 anchor = cell->testAnchor( d->view->doc()->zoomItX( ev_PosX - xpos ),
1101 d->view->doc()->zoomItY( ev_PosY - ypos ) );
1103 if ( !anchor.isEmpty() && anchor != d->anchor )
1105 setCursor( KCursor::handCursor() );
1112 TQRect selectionHandle = d->view->selectionInfo()->selectionHandleArea();
1113 if ( selectionHandle.contains( TQPoint( d->view->doc()->zoomItX( ev_PosX ),
1114 d->view->doc()->zoomItY( ev_PosY ) ) ) )
1118 col = sheet->leftColumn( ev_PosX - d->view->doc()->unzoomItX( 2 ), xpos );
1119 row = sheet->topRow( ev_PosY - d->view->doc()->unzoomItY( 2 ), ypos );
1121 if ( !sheet->isProtected() )
1123 if ( sheet->layoutDirection()==Sheet::RightToLeft )
1124 setCursor( sizeBDiagCursor );
1126 setCursor( sizeFDiagCursor );
1129 else if ( !d->anchor.isEmpty() )
1131 if ( !sheet->isProtected() )
1132 setCursor( KCursor::handCursor() );
1134 else if ( r1.contains( TQPoint( (
int) ev_PosX, (
int) ev_PosY ) )
1135 && !r2.contains( TQPoint( (
int) ev_PosX, (
int) ev_PosY ) ) )
1137 setCursor( KCursor::handCursor() );
1139 else if ( d->chooseCell )
1142 setCursor( KCursor::crossCursor() );
1147 setCursor( arrowCursor );
1158void Canvas::mouseReleaseEvent( TQMouseEvent* )
1160 if ( d->scrollTimer->isActive() )
1161 d->scrollTimer->stop();
1163 d->mousePressed =
false;
1164 d->view->disableAutoScroll();
1166 if ( d->modType != MT_NONE )
1168 switch ( d->modType )
1172 KoPoint move( objectRect(
false ).topLeft() - d->m_moveStartPosMouse );
1173 if ( move != KoPoint( 0, 0 ) )
1175 KCommand *cmd=
activeSheet()->moveObject( view(), move.x(), move.y() );
1182 d->m_isMoving =
false;
1185 case MT_RESIZE_UP:
case MT_RESIZE_LF:
case MT_RESIZE_RT:
case MT_RESIZE_LU:
case MT_RESIZE_LD:
case MT_RESIZE_RU:
case MT_RESIZE_RD:
1205 if ( d->mouseAction ==
ResizeCell && !sheet->isProtected() )
1208 d->view->updateEditWidget();
1210 else if ( d->mouseAction ==
AutoFill && !sheet->isProtected() )
1213 sheet->autofill( d->autoFillSource, dest );
1215 d->view->updateEditWidget();
1218 else if ( d->mouseAction ==
Mark && !d->chooseCell )
1220 d->view->updateEditWidget();
1224 d->dragging =
false;
1225 d->dragStart.setX( -1 );
1228void Canvas::processClickSelectionHandle( TQMouseEvent *event )
1231 if ( event->button() == TQt::LeftButton )
1238 else if ( event->button() == TQt::MidButton &&
selectionInfo()->isSingular())
1246void Canvas::processLeftClickAnchor()
1248 bool isRefLink = localReferenceAnchor( d->anchor );
1249 bool isLocalLink = (d->anchor.find(
"file:") == 0);
1252 TQString type=KMimeType::findByURL(d->anchor, 0, isLocalLink)->name();
1254 if ( KRun::isExecutableFile( d->anchor , type ) )
1261 TQString question = i18n(
"This link points to the program or script '%1'.\n"
1262 "Malicious programs can harm your computer. Are you sure that you want to run this program?").arg(d->anchor);
1265 int choice = KMessageBox::warningYesNo(
this, question, i18n(
"Open Link?"));
1266 if (
choice != KMessageBox::Yes )
1273 new KRun(d->anchor);
1286 Region::ConstIterator end =
choice()->constEnd();
1287 for (Region::ConstIterator it =
choice()->constBegin(); it != end; ++it)
1291 sheetAreaToRect((*it)->rect().normalize(), visibleRect);
1293 TQPoint bottomRight((
int) visibleRect.right(), (
int) visibleRect.bottom());
1294 TQRect handle( ( (
int) bottomRight.x() - 6 ),
1295 ( (
int) bottomRight.y() - 6 ),
1299 if (handle.contains(TQPoint((
int) x,(
int) y)))
1308void Canvas::mousePressEvent( TQMouseEvent * _ev )
1310 if ( _ev->button() == TQt::LeftButton )
1312 d->mousePressed =
true;
1313 d->view->enableAutoScroll();
1316 if (
activeSheet() && _ev->button() == TQt::LeftButton)
1318 d->m_moveStartPosMouse = objectRect(
false ).topLeft();
1324 if ( _ev->state() & ControlButton && obj->isSelected() )
1325 deselectObject( obj );
1326 else if ( _ev->state() & ControlButton )
1328 if ( d->modType == MT_NONE)
1331 selectObject( obj );
1333 d->m_moveStartPosMouse = objectRect(
false ).topLeft();
1337 if ( d->modType != MT_MOVE || !obj->isSelected() )
1338 deselectAllObjects();
1340 selectObject( obj );
1343 d->m_moveStartPosMouse = objectRect(
false ).topLeft();
1347 if ( d->modType != MT_MOVE && d->modType != MT_NONE && !obj->isProtect() )
1349 deselectAllObjects();
1350 selectObject( obj );
1353 d->m_resizeObject = obj;
1355 d->m_ratio =
static_cast<double>( obj->geometry().width() ) /
1356 static_cast<double>( obj->geometry().height() );
1357 d->m_rectBeforeResize = obj->geometry();
1360 KoPoint docPoint ( doc()->unzoomPoint( _ev->pos() ) );
1362 d->m_origMousePos = docPoint;
1363 d->m_moveStartPosMouse = objectRect(
false ).topLeft();
1368 d->modType = MT_NONE;
1369 if ( !( _ev->state() & ShiftButton ) && !( _ev->state() & ControlButton ) )
1370 deselectAllObjects();
1382 double dwidth = d->view->doc()->unzoomItX( width() );
1384 if ( sheet->layoutDirection()==Sheet::RightToLeft )
1386 ev_PosX = dwidth - d->view->doc()->unzoomItX( _ev->pos().x() ) +
xOffset();
1390 ev_PosX = d->view->doc()->unzoomItX( _ev->pos().x() ) +
xOffset();
1392 double ev_PosY = d->view->doc()->unzoomItY( _ev->pos().y() ) +
yOffset();
1397 int col = sheet->leftColumn( ev_PosX, xpos );
1398 int row = sheet->topRow( ev_PosY, ypos );
1400 if ( col > KS_colMax || row > KS_rowMax )
1402 kdDebug(36001) <<
"Canvas::mousePressEvent: col or row is out of range: "
1403 <<
"col: " << col <<
" row: " << row << endl;
1408 if ( col > KS_colMax || row > KS_rowMax )
1410 kdDebug(36001) <<
"Canvas::mousePressEvent: col or row is out of range: "
1411 <<
"col: " << col <<
" row: " << row << endl;
1417 choice()->setActiveElement(TQPoint(col,row));
1423 if ( d->cellEditor && !d->chooseCell )
1428 d->scrollTimer->start( 50 );
1431 if (
selectionInfo()->selectionHandleArea().contains( TQPoint( d->view->doc()->zoomItX( ev_PosX ),
1432 d->view->doc()->zoomItY( ev_PosY ) ) ) )
1434 processClickSelectionHandle( _ev );
1447 double lx = sheet->dblColumnPos( rct.left() );
1448 double rx = sheet->dblColumnPos( rct.right() + 1 );
1449 double ty = sheet->dblRowPos( rct.top() );
1450 double by = sheet->dblRowPos( rct.bottom() + 1 );
1452 r1.setLeft( (
int) (lx - 1) );
1453 r1.setTop( (
int) (ty - 1) );
1454 r1.setRight( (
int) (rx + 1) );
1455 r1.setBottom( (
int) (by + 1) );
1457 r2.setLeft( (
int) (lx + 1) );
1458 r2.setTop( (
int) (ty + 1) );
1459 r2.setRight( (
int) (rx - 1) );
1460 r2.setBottom( (
int) (by - 1) );
1463 d->dragStart.setX( -1 );
1465 if ( r1.contains( TQPoint( (
int) ev_PosX, (
int) ev_PosY ) )
1466 && !r2.contains( TQPoint( (
int) ev_PosX, (
int) ev_PosY ) ) )
1468 d->dragStart.setX( (
int) ev_PosX );
1469 d->dragStart.setY( (
int) ev_PosY );
1478 if ((_ev->state() & ShiftButton) &&
1479 d->view->koDocument()->isReadWrite() &&
1488 Cell *cell = sheet->cellAt( col, row );
1496 switch (_ev->button())
1498 case TQt::LeftButton:
1499 if (!d->anchor.isEmpty())
1502 processLeftClickAnchor();
1504#ifdef NONCONTIGUOUSSELECTION
1505 else if ( _ev->state() & ControlButton )
1511 d->mouseAction =
Mark;
1519 d->mouseAction =
Mark;
1530 d->mouseAction =
Mark;
1535 case TQt::MidButton:
1537 if ( d->view->koDocument()->isReadWrite() && !sheet->isProtected() )
1545 case TQt::RightButton:
1557 if ( !d->chooseCell )
1559 d->view->updateEditWidgetOnPress();
1564 if ( _ev->button() == TQt::RightButton )
1567 TQPoint p = mapToGlobal( _ev->pos() );
1568 d->view->openPopupMenu( p );
1572void Canvas::startTheDrag()
1580 setCursor( KCursor::handCursor() );
1582 TQDomDocument doc = sheet->saveCellRegion(*
selectionInfo());
1586 buffer.open( IO_WriteOnly );
1587 TQTextStream str( &buffer );
1588 str.setEncoding( TQTextStream::UnicodeUTF8 );
1593 d->setKSpread( buffer.buffer() );
1596 setCursor( KCursor::arrowCursor() );
1599void Canvas::mouseDoubleClickEvent( TQMouseEvent* _ev)
1603 if ( ( obj = getObject( _ev->pos(),
activeSheet() ) ) )
1605 switch ( obj->getType() )
1607 case OBJECT_KOFFICE_PART:
case OBJECT_CHART:
1615 view()->extraProperties();
1622 if ( d->view->koDocument()->isReadWrite() &&
activeSheet() )
1626void Canvas::wheelEvent( TQWheelEvent* _ev )
1628 if ( _ev->orientation() == TQt::Vertical )
1630 if ( vertScrollBar() )
1631 TQApplication::sendEvent( vertScrollBar(), _ev );
1633 else if ( horzScrollBar() )
1635 TQApplication::sendEvent( horzScrollBar(), _ev );
1639void Canvas::paintEvent( TQPaintEvent* _ev )
1641 if ( d->view->doc()->isLoading() )
1650 double dwidth = d->view->doc()->unzoomItX( width() );
1651 KoRect rect = d->view->doc()->unzoomRect( _ev->rect() & TQWidget::rect() );
1652 if ( sheet->layoutDirection()==Sheet::RightToLeft )
1657 KoPoint tl = rect.topLeft();
1658 KoPoint br = rect.bottomRight();
1665 if ( sheet->layoutDirection()==Sheet::RightToLeft )
1667 right_col = sheet->leftColumn( dwidth - tl.x(), tmp );
1668 left_col = sheet->rightColumn( dwidth - br.x() + 1.0 );
1672 left_col = sheet->leftColumn( tl.x(), tmp );
1673 right_col = sheet->rightColumn( br.x() + 1.0 );
1675 int top_row = sheet->topRow( tl.y(), tmp );
1676 int bottom_row = sheet->bottomRow( br.y() + 1.0 );
1678 TQRect vr( TQPoint(left_col, top_row),
1679 TQPoint(right_col, bottom_row) );
1680 d->view->doc()->emitBeginOperation(
false );
1681 sheet->setRegionPaintDirty( vr );
1682 d->view->doc()->emitEndOperation( vr );
1685void Canvas::focusInEvent( TQFocusEvent* )
1687 if ( !d->cellEditor )
1697 d->editWidget->setFocus();
1703 d->cellEditor->setFocus();
1706void Canvas::focusOutEvent( TQFocusEvent* )
1708 if ( d->scrollTimer->isActive() )
1709 d->scrollTimer->stop();
1710 d->mousePressed =
false;
1711 d->view->disableAutoScroll();
1714void Canvas::dragMoveEvent( TQDragMoveEvent * _ev )
1723 _ev->accept( TextDrag::canDecode( _ev ) );
1725 double dwidth = d->view->doc()->unzoomItX( width() );
1726 double xpos = sheet->dblColumnPos(
selectionInfo()->lastRange().left() );
1727 double ypos = sheet->dblRowPos(
selectionInfo()->lastRange().top() );
1728 double width = sheet->columnFormat(
selectionInfo()->lastRange().left() )->dblWidth(
this );
1729 double height = sheet->rowFormat(
selectionInfo()->lastRange().top() )->dblHeight(
this );
1731 TQRect r1 ((
int) xpos - 1, (
int) ypos - 1, (
int) width + 3, (
int) height + 3);
1734 if (sheet->layoutDirection()==Sheet::RightToLeft)
1735 ev_PosX = dwidth - d->view->doc()->unzoomItX( _ev->pos().x() ) +
xOffset();
1737 ev_PosX = d->view->doc()->unzoomItX( _ev->pos().x() ) +
xOffset();
1739 double ev_PosY = d->view->doc()->unzoomItY( _ev->pos().y() ) +
yOffset();
1741 if ( r1.contains( TQPoint ((
int) ev_PosX, (
int) ev_PosY) ) )
1745void Canvas::dragLeaveEvent( TQDragLeaveEvent * )
1747 if ( d->scrollTimer->isActive() )
1748 d->scrollTimer->stop();
1751void Canvas::dropEvent( TQDropEvent * _ev )
1753 d->dragging =
false;
1754 if ( d->scrollTimer->isActive() )
1755 d->scrollTimer->stop();
1757 if ( !sheet || sheet->isProtected() )
1763 double dwidth = d->view->doc()->unzoomItX( width() );
1764 double xpos = sheet->dblColumnPos(
selectionInfo()->lastRange().left() );
1765 double ypos = sheet->dblRowPos(
selectionInfo()->lastRange().top() );
1766 double width = sheet->columnFormat(
selectionInfo()->lastRange().left() )->dblWidth(
this );
1767 double height = sheet->rowFormat(
selectionInfo()->lastRange().top() )->dblHeight(
this );
1769 TQRect r1 ((
int) xpos - 1, (
int) ypos - 1, (
int) width + 3, (
int) height + 3);
1772 if (sheet->layoutDirection()==Sheet::RightToLeft)
1773 ev_PosX = dwidth - d->view->doc()->unzoomItX( _ev->pos().x() ) +
xOffset();
1775 ev_PosX = d->view->doc()->unzoomItX( _ev->pos().x() ) +
xOffset();
1777 double ev_PosY = d->view->doc()->unzoomItY( _ev->pos().y() ) +
yOffset();
1779 if ( r1.contains( TQPoint ((
int) ev_PosX, (
int) ev_PosY) ) )
1788 int col = sheet->leftColumn( ev_PosX, tmp );
1789 int row = sheet->topRow( ev_PosY, tmp );
1791 if ( !TextDrag::canDecode( _ev ) )
1799 bool makeUndo =
true;
1801 if ( _ev->provides( TextDrag::selectionMimeType() ) )
1803 if ( TextDrag::target() == _ev->source() )
1805 if ( !d->view->doc()->undoLocked() )
1812 d->view->doc()->addCommand( undo );
1819 b = _ev->encodedData( TextDrag::selectionMimeType() );
1820 sheet->paste( b, TQRect( col, row, 1, 1 ), makeUndo );
1822 if ( _ev->source() ==
this )
1823 _ev->acceptAction();
1829 if ( !TQTextDrag::decode( _ev, text ) )
1837 sheet->pasteTextPlain( text, TQRect( col, row, 1, 1 ) );
1839 if ( _ev->source() ==
this )
1840 _ev->acceptAction();
1846void Canvas::resizeEvent( TQResizeEvent* _ev )
1852 double ev_Width = d->view->doc()->unzoomItX( _ev->size().width() );
1853 double ev_Height = d->view->doc()->unzoomItY( _ev->size().height() );
1858 if (
activeSheet() &&
activeSheet()->layoutDirection()==Sheet::RightToLeft && !TQApplication::reverseLayout() )
1860 int dx = _ev->size().width() - _ev->oldSize().width();
1863 else if (
activeSheet() &&
activeSheet()->layoutDirection()==Sheet::LeftToRight && TQApplication::reverseLayout() )
1865 int dx = _ev->size().width() - _ev->oldSize().width();
1870 if ( _ev->size().width() > _ev->oldSize().width() )
1872 int oldValue = horzScrollBar()->maxValue() - horzScrollBar()->value();
1874 if ( (
xOffset() + ev_Width ) >
1875 d->view->doc()->zoomItX(
activeSheet()->sizeMaxX() ) )
1877 horzScrollBar()->setRange( 0, d->view->doc()->zoomItX(
activeSheet()->sizeMaxX() - ev_Width ) );
1878 if (
activeSheet()->layoutDirection()==Sheet::RightToLeft )
1879 horzScrollBar()->setValue( horzScrollBar()->maxValue() - oldValue );
1883 else if ( _ev->size().width() < _ev->oldSize().width() )
1885 int oldValue = horzScrollBar()->maxValue() - horzScrollBar()->value();
1887 if ( horzScrollBar()->maxValue() ==
1888 int( d->view->doc()->zoomItX(
activeSheet()->sizeMaxX() ) - ev_Width ) )
1890 horzScrollBar()->setRange( 0, d->view->doc()->zoomItX(
activeSheet()->sizeMaxX() - ev_Width ) );
1891 if (
activeSheet()->layoutDirection()==Sheet::RightToLeft )
1892 horzScrollBar()->setValue( horzScrollBar()->maxValue() - oldValue );
1897 if ( _ev->size().height() > _ev->oldSize().height() )
1899 if ( (
yOffset() + ev_Height ) >
1900 d->view->doc()->zoomItY(
activeSheet()->sizeMaxY() ) )
1902 vertScrollBar()->setRange( 0, d->view->doc()->zoomItY(
activeSheet()->sizeMaxY() - ev_Height ) );
1906 else if ( _ev->size().height() < _ev->oldSize().height() )
1908 if ( vertScrollBar()->maxValue() ==
1909 int( d->view->doc()->zoomItY(
activeSheet()->sizeMaxY() ) - ev_Height ) )
1911 vertScrollBar()->setRange( 0, d->view->doc()->zoomItY(
activeSheet()->sizeMaxY() - ev_Height ) );
1916TQPoint Canvas::cursorPos()
1919 if (d->chooseCell && !
choice()->isEmpty())
1920 cursor =
choice()->cursor();
1927TQRect Canvas::moveDirection( KSpread::MoveTo direction,
bool extendSelection )
1929 kdDebug(36001) <<
"Canvas::moveDirection" << endl;
1931 TQPoint destination;
1932 TQPoint cursor = cursorPos();
1934 TQPoint cellCorner = cursor;
1943 cellCorner = TQPoint(cell->
column(), cell->
row());
1948 RowFormat *rl = NULL;
1949 ColumnFormat *cl = NULL;
1957 case KSpread::Bottom:
1958 offset = cell->
mergedYCells() - (cursor.y() - cellCorner.y()) + 1;
1959 rl =
activeSheet()->rowFormat( cursor.y() + offset );
1960 while ( ((cursor.y() + offset) <= KS_rowMax) && rl->isHide())
1963 rl =
activeSheet()->rowFormat( cursor.y() + offset );
1966 destination = TQPoint(cursor.x(), TQMIN(cursor.y() + offset, KS_rowMax));
1969 offset = (cellCorner.y() - cursor.y()) - 1;
1970 rl =
activeSheet()->rowFormat( cursor.y() + offset );
1971 while ( ((cursor.y() + offset) >= 1) && rl->isHide())
1974 rl =
activeSheet()->rowFormat( cursor.y() + offset );
1976 destination = TQPoint(cursor.x(), TQMAX(cursor.y() + offset, 1));
1979 offset = (cellCorner.x() - cursor.x()) - 1;
1980 cl =
activeSheet()->columnFormat( cursor.x() + offset );
1981 while ( ((cursor.x() + offset) >= 1) && cl->isHide())
1984 cl =
activeSheet()->columnFormat( cursor.x() + offset );
1986 destination = TQPoint(TQMAX(cursor.x() + offset, 1), cursor.y());
1988 case KSpread::Right:
1989 offset = cell->
mergedXCells() - (cursor.x() - cellCorner.x()) + 1;
1990 cl =
activeSheet()->columnFormat( cursor.x() + offset );
1991 while ( ((cursor.x() + offset) <= KS_colMax) && cl->isHide())
1994 cl =
activeSheet()->columnFormat( cursor.x() + offset );
1996 destination = TQPoint(TQMIN(cursor.x() + offset, KS_colMax), cursor.y());
1998 case KSpread::BottomFirst:
1999 offset = cell->
mergedYCells() - (cursor.y() - cellCorner.y()) + 1;
2000 rl =
activeSheet()->rowFormat( cursor.y() + offset );
2001 while ( ((cursor.y() + offset) <= KS_rowMax) && rl->isHide())
2004 rl =
activeSheet()->rowFormat( cursor.y() + offset );
2007 destination = TQPoint( 1, TQMIN( cursor.y() + offset, KS_rowMax ) );
2011 if (extendSelection)
2019 d->view->updateEditWidget();
2021 return TQRect( cursor, destination );
2024void Canvas::processEnterKey(TQKeyEvent* event)
2027 bool array = (
event->state() & TQt::AltButton) &&
2028 (event->state() & TQt::ControlButton);
2039 KSpread::MoveTo direction = d->view->doc()->getMoveToValue();
2042 if (event->state() & TQt::ShiftButton)
2046 case KSpread::Bottom:
2047 direction = KSpread::Top;
2050 direction = KSpread::Bottom;
2053 direction = KSpread::Right;
2055 case KSpread::Right:
2056 direction = KSpread::Left;
2058 case KSpread::BottomFirst:
2059 direction = KSpread::BottomFirst;
2067 TQRect r( moveDirection( direction,
false ) );
2068 d->view->doc()->emitEndOperation( r );
2071void Canvas::processArrowKey( TQKeyEvent *event)
2083 KSpread::MoveTo direction = KSpread::Bottom;
2084 bool makingSelection =
event->state() & ShiftButton;
2086 switch (event->key())
2089 direction = KSpread::Bottom;
2092 direction = KSpread::Top;
2095 if (
activeSheet()->layoutDirection()==Sheet::RightToLeft)
2096 direction = KSpread::Right;
2098 direction = KSpread::Left;
2101 if (
activeSheet()->layoutDirection()==Sheet::RightToLeft)
2102 direction = KSpread::Left;
2104 direction = KSpread::Right;
2107 direction = KSpread::Right;
2111 direction = KSpread::Left;
2112 makingSelection =
false;
2119 TQRect r( moveDirection( direction, makingSelection ) );
2120 d->view->doc()->emitEndOperation( r );
2123void Canvas::processEscapeKey(TQKeyEvent * event)
2125 if ( d->cellEditor )
2128 if ( view()->isInsertingObject() )
2131 setCursor( arrowCursor );
2136 TQPoint cursor = cursorPos();
2138 d->view->doc()->emitEndOperation( TQRect( cursor, cursor ) );
2140 if ( d->mousePressed )
2153 TQRect oldBoundingRect = doc()->zoomRect( d->m_resizeObject->geometry());
2154 d->m_resizeObject->setGeometry( d->m_rectBeforeResize );
2155 oldBoundingRect.moveBy( (
int)( -
xOffset()*doc()->zoomedResolutionX() ) ,
2156 (
int)( -
yOffset() * doc()->zoomedResolutionY()) );
2158 activeSheet()->setRegionPaintDirty( oldBoundingRect );
2159 repaint( oldBoundingRect );
2160 repaintObject( d->m_resizeObject );
2162 d->m_resizeObject = 0;
2163 d->m_isResizing =
false;
2164 view()->disableAutoScroll();
2165 d->mousePressed =
false;
2166 d->modType = MT_NONE;
2171 if ( d->m_isMoving )
2173 KoPoint move( d->m_moveStartPoint - objectRect(
false ).topLeft() );
2175 view()->disableAutoScroll();
2176 d->mousePressed =
false;
2177 d->modType = MT_NONE;
2178 d->m_isMoving =
false;
2189bool Canvas::processHomeKey(TQKeyEvent* event)
2191 bool makingSelection =
event->state() & ShiftButton;
2194 if ( d->cellEditor )
2197 TQApplication::sendEvent( d->editWidget, event );
2202 TQPoint destination;
2213 if (event->state() & ControlButton)
2216 destination = TQPoint( 1, 1 );
2222 Cell * cell = sheet->getFirstCellRow(
marker.y());
2225 cell = sheet->getNextCellRight(cell->
column(), cell->
row());
2228 int col = ( cell ? cell->
column() : 1 );
2231 destination = TQPoint(col,
marker.y());
2236 d->view->doc()->emitEndOperation( TQRect( destination, destination ) );
2240 if (makingSelection)
2252bool Canvas::processEndKey( TQKeyEvent *event )
2254 bool makingSelection =
event->state() & ShiftButton;
2261 if ( d->cellEditor )
2263 TQApplication::sendEvent( d->editWidget, event );
2264 d->view->doc()->emitEndOperation( TQRect(
marker,
marker ) );
2271 cell = sheet->getLastCellRow(
marker.y());
2274 cell = sheet->getNextCellLeft(cell->
column(), cell->
row());
2277 col = (cell == NULL) ? KS_colMax : cell->column();
2279 TQPoint destination( col,
marker.y() );
2280 if ( destination ==
marker )
2282 d->view->doc()->emitEndOperation( TQRect( destination, destination ) );
2286 if (makingSelection)
2298bool Canvas::processPriorKey(TQKeyEvent *event)
2300 bool makingSelection =
event->state() & ShiftButton;
2308 TQPoint destination(
marker.x(), TQMAX(1,
marker.y() - 10));
2309 if ( destination ==
marker )
2311 d->view->doc()->emitEndOperation( TQRect( destination, destination ) );
2315 if (makingSelection)
2326bool Canvas::processNextKey(TQKeyEvent *event)
2328 bool makingSelection =
event->state() & ShiftButton;
2336 TQPoint destination(
marker.x(), TQMAX(1,
marker.y() + 10));
2338 if (
marker == destination )
2340 d->view->doc()->emitEndOperation( TQRect( destination, destination ) );
2344 if (makingSelection)
2355void Canvas::processDeleteKey(TQKeyEvent* )
2357 if ( isObjectSelected() )
2359 d->view->doc()->emitEndOperation(
activeSheet()->visibleRect(
this ) );
2360 d->view->deleteSelectedObjects();
2365 d->editWidget->setText(
"" );
2367 TQPoint cursor = cursorPos();
2369 d->view->doc()->emitEndOperation( TQRect( cursor, cursor ) );
2373void Canvas::processF2Key(TQKeyEvent* )
2375 d->editWidget->setFocus();
2376 if ( d->cellEditor )
2377 d->editWidget->setCursorPosition( d->cellEditor->cursorPosition() - 1 );
2378 d->editWidget->cursorForward(
false );
2381 TQPoint cursor = cursorPos();
2383 d->view->doc()->emitEndOperation( TQRect( cursor, cursor ) );
2387void Canvas::processF4Key(TQKeyEvent* event)
2391 if ( d->cellEditor )
2393 d->cellEditor->handleKeyPressEvent( event );
2395 d->editWidget->setCursorPosition( d->cellEditor->cursorPosition() );
2397 TQPoint cursor = cursorPos();
2399 d->view->doc()->emitEndOperation( TQRect( cursor, cursor ) );
2403void Canvas::processOtherKey(TQKeyEvent *event)
2406 if ( event->text().isEmpty() || !d->view->koDocument()->isReadWrite()
2413 if ( !d->cellEditor && !d->chooseCell )
2417 d->cellEditor->handleKeyPressEvent( event );
2419 else if ( d->cellEditor )
2420 d->cellEditor->handleKeyPressEvent( event );
2423 TQPoint cursor = cursorPos();
2425 d->view->doc()->emitEndOperation( TQRect( cursor, cursor ) );
2430bool Canvas::processControlArrowKey( TQKeyEvent *event )
2432 bool makingSelection =
event->state() & ShiftButton;
2437 TQPoint destination;
2438 bool searchThroughEmpty =
true;
2446 switch ( event->key() )
2452 if ( (cell != NULL) && (!cell->
isEmpty()) && (
marker.y() != 1))
2456 cell = sheet->cellAt(cell->
column(), row);
2457 while ((cell != NULL) && (row > 0) && (!cell->
isEmpty()) )
2459 if (!(sheet->rowFormat(cell->
row())->isHide()))
2462 searchThroughEmpty =
false;
2466 cell = sheet->cellAt(cell->
column(), row);
2470 if (searchThroughEmpty)
2474 while ((cell != NULL) &&
2475 (cell->
isEmpty() || (sheet->rowFormat(cell->
row())->isHide())))
2477 cell = sheet->getNextCellUp(cell->
column(), cell->
row());
2486 while ( sheet->rowFormat(row)->isHide() )
2491 destination.setX(
marker.x());
2492 destination.setY(row);
2499 if ( (cell != NULL) && (!cell->
isEmpty()) && (
marker.y() != KS_rowMax))
2503 cell = sheet->cellAt(cell->
column(), row);
2504 while ((cell != NULL) && (row < KS_rowMax) && (!cell->
isEmpty()) )
2506 if (!(sheet->rowFormat(cell->
row())->isHide()))
2509 searchThroughEmpty =
false;
2512 cell = sheet->cellAt(cell->
column(), row);
2516 if (searchThroughEmpty)
2520 while ((cell != NULL) &&
2521 (cell->
isEmpty() || (sheet->rowFormat(cell->
row())->isHide())))
2523 cell = sheet->getNextCellDown(cell->
column(), cell->
row());
2532 while ( sheet->rowFormat(row)->isHide() )
2537 destination.setX(
marker.x());
2538 destination.setY(row);
2544 if ( sheet->layoutDirection()==Sheet::RightToLeft )
2547 if ( (cell != NULL) && (!cell->
isEmpty()) && (
marker.x() != KS_colMax))
2551 cell = sheet->cellAt(col, cell->
row());
2552 while ((cell != NULL) && (col < KS_colMax) && (!cell->
isEmpty()) )
2554 if (!(sheet->columnFormat(cell->
column())->isHide()))
2557 searchThroughEmpty =
false;
2560 cell = sheet->cellAt(col, cell->
row());
2564 if (searchThroughEmpty)
2566 cell = sheet->getNextCellRight(
marker.x(),
marker.y());
2568 while ((cell != NULL) &&
2569 (cell->
isEmpty() || (sheet->columnFormat(cell->
column())->isHide())))
2571 cell = sheet->getNextCellRight(cell->
column(), cell->
row());
2580 while ( sheet->columnFormat(col)->isHide() )
2585 destination.setX(col);
2586 destination.setY(
marker.y());
2591 if ( (cell != NULL) && (!cell->
isEmpty()) && (
marker.x() != 1))
2595 cell = sheet->cellAt(col, cell->
row());
2596 while ((cell != NULL) && (col > 0) && (!cell->
isEmpty()) )
2598 if (!(sheet->columnFormat(cell->
column())->isHide()))
2601 searchThroughEmpty =
false;
2605 cell = sheet->cellAt(col, cell->
row());
2609 if (searchThroughEmpty)
2613 while ((cell != NULL) &&
2614 (cell->
isEmpty() || (sheet->columnFormat(cell->
column())->isHide())))
2616 cell = sheet->getNextCellLeft(cell->
column(), cell->
row());
2625 while ( sheet->columnFormat(col)->isHide() )
2630 destination.setX(col);
2631 destination.setY(
marker.y());
2638 if ( sheet->layoutDirection()==Sheet::RightToLeft )
2641 if ( (cell != NULL) && (!cell->
isEmpty()) && (
marker.x() != 1))
2645 cell = sheet->cellAt(col, cell->
row());
2646 while ((cell != NULL) && (col > 0) && (!cell->
isEmpty()) )
2648 if (!(sheet->columnFormat(cell->
column())->isHide()))
2651 searchThroughEmpty =
false;
2655 cell = sheet->cellAt(col, cell->
row());
2659 if (searchThroughEmpty)
2663 while ((cell != NULL) &&
2664 (cell->
isEmpty() || (sheet->columnFormat(cell->
column())->isHide())))
2666 cell = sheet->getNextCellLeft(cell->
column(), cell->
row());
2675 while ( sheet->columnFormat(col)->isHide() )
2680 destination.setX(col);
2681 destination.setY(
marker.y());
2686 if ( (cell != NULL) && (!cell->
isEmpty()) && (
marker.x() != KS_colMax))
2690 cell = sheet->cellAt(col, cell->
row());
2691 while ((cell != NULL) && (col < KS_colMax) && (!cell->
isEmpty()) )
2693 if (!(sheet->columnFormat(cell->
column())->isHide()))
2696 searchThroughEmpty =
false;
2699 cell = sheet->cellAt(col, cell->
row());
2703 if (searchThroughEmpty)
2705 cell = sheet->getNextCellRight(
marker.x(),
marker.y());
2707 while ((cell != NULL) &&
2708 (cell->
isEmpty() || (sheet->columnFormat(cell->
column())->isHide())))
2710 cell = sheet->getNextCellRight(cell->
column(), cell->
row());
2719 while ( sheet->columnFormat(col)->isHide() )
2724 destination.setX(col);
2725 destination.setY(
marker.y());
2731 if (
marker == destination )
2733 d->view->doc()->emitEndOperation( TQRect( destination, destination ) );
2737 if (makingSelection)
2749void Canvas::keyPressEvent ( TQKeyEvent * _ev )
2753 if ( !sheet || formatKeyPress( _ev ))
2757 if ( _ev->state() & ( TQt::AltButton | TQt::ControlButton ) &&
2758 (_ev->key() != Key_Down) &&
2759 (_ev->key() != Key_Up) &&
2760 (_ev->key() != Key_Right) &&
2761 (_ev->key() != Key_Left) &&
2762 (_ev->key() != Key_Home) &&
2763 (_ev->key() != Key_Enter) &&
2764 (_ev->key() != Key_Return) &&
2765 (_ev->key() != TDEGlobalSettings::contextMenuKey()))
2767 TQWidget::keyPressEvent( _ev );
2775 d->view->doc()->emitBeginOperation(
false);
2776 if ( _ev->key() == TDEGlobalSettings::contextMenuKey() ) {
2779 KoPoint kop(sheet->columnPos(col,
this), sheet->rowPos(row,
this));
2780 TQPoint p = d->view->doc()->zoomPoint(kop);
2782 d->view->openPopupMenu( p );
2784 switch( _ev->key() )
2788 processEnterKey( _ev );
2797 if (_ev->state() & ControlButton)
2799 if ( !processControlArrowKey( _ev ) )
2804 processArrowKey( _ev );
2810 processEscapeKey( _ev );
2815 if ( !processHomeKey( _ev ) )
2820 if ( !processEndKey( _ev ) )
2825 if ( !processPriorKey( _ev ) )
2830 if ( !processNextKey( _ev ) )
2835 processDeleteKey( _ev );
2840 processF2Key( _ev );
2845 processF4Key( _ev );
2850 processOtherKey( _ev );
2857 d->view->doc()->emitEndOperation( sheet->visibleRect(
this ) );
2861void Canvas::processIMEvent( TQIMEvent * event )
2863 d->view->doc()->emitBeginOperation(
false );
2864 if ( !d->cellEditor && !d->chooseCell )
2868 d->cellEditor->handleIMEvent( event );
2873 if ( d->chooseCell )
2875 cursor =
choice()->cursor();
2877 if (cursor.x() == 0 || cursor.y() == 0)
2878 cursor =
choice()->cursor();
2883 d->view->doc()->emitEndOperation( TQRect( cursor, cursor ) );
2886bool Canvas::formatKeyPress( TQKeyEvent * _ev )
2888 if (!(_ev->state() & ControlButton ))
2891 int key = _ev->key();
2892 if ( key != Key_Exclam && key != Key_At && key != Key_Ampersand
2893 && key != Key_Dollar && key != Key_Percent && key != Key_AsciiCircum
2894 && key != Key_NumberSign )
2900 d->view->doc()->emitBeginOperation(
false);
2902 if ( !d->view->doc()->undoLocked() )
2905 UndoCellFormat * undo =
new UndoCellFormat( d->view->doc(), sheet, *
selectionInfo(), dummy );
2906 d->view->doc()->addCommand( undo );
2910 for (Region::ConstIterator it =
selectionInfo()->constBegin(); it != end; ++it)
2912 TQRect rect = (*it)->rect().normalize();
2914 int right = rect.right();
2915 int bottom = rect.bottom();
2917 if ( util_isRowSelected(rect) )
2919 for (
int r = rect.top(); r <= bottom; ++r )
2921 cell = sheet->getFirstCellRow( r );
2926 cell = sheet->getNextCellRight( cell->
column(), r );
2930 formatCellByKey (cell, _ev->key(), rect);
2932 cell = sheet->getNextCellRight( cell->
column(), r );
2934 RowFormat * rw = sheet->nonDefaultRowFormat( r );
2936 switch ( _ev->key() )
2939 rw->setFormatType (Number_format);
2940 rw->setPrecision( 2 );
2944 rw->setFormatType (Money_format);
2945 rw->setPrecision( d->view->doc()->locale()->fracDigits() );
2949 rw->setFormatType (Percentage_format);
2953 rw->setFormatType( SecondeTime_format );
2956 case Key_NumberSign:
2957 rw->setFormatType( ShortDate_format );
2960 case Key_AsciiCircum:
2961 rw->setFormatType( Scientific_format );
2965 if ( r == rect.top() )
2967 pen = TQPen( d->view->borderColor(), 1, SolidLine);
2968 rw->setTopBorderPen( pen );
2970 if ( r == rect.bottom() )
2972 pen = TQPen( d->view->borderColor(), 1, SolidLine);
2973 rw->setBottomBorderPen( pen );
2978 d->view->doc()->emitEndOperation( rect );
2981 sheet->emit_updateRow( rw, r );
2984 d->view->doc()->emitEndOperation( rect );
2988 if ( util_isColumnSelected(rect) )
2990 for (
int c = rect.left(); c <= right; ++c )
2992 cell = sheet->getFirstCellColumn( c );
2997 cell = sheet->getNextCellDown( c, cell->
row() );
3001 formatCellByKey (cell, _ev->key(), rect);
3003 cell = sheet->getNextCellDown( c, cell->
row() );
3006 ColumnFormat * cw = sheet->nonDefaultColumnFormat( c );
3008 switch ( _ev->key() )
3011 cw->setFormatType( Number_format );
3012 cw->setPrecision( 2 );
3016 cw->setFormatType( Money_format );
3017 cw->setPrecision( d->view->doc()->locale()->fracDigits() );
3021 cw->setFormatType( Percentage_format );
3025 cw->setFormatType( SecondeTime_format );
3028 case Key_NumberSign:
3029 cw->setFormatType( ShortDate_format );
3032 case Key_AsciiCircum:
3033 cw->setFormatType( Scientific_format );
3037 if ( c == rect.left() )
3039 pen = TQPen( d->view->borderColor(), 1, SolidLine);
3040 cw->setLeftBorderPen( pen );
3042 if ( c == rect.right() )
3044 pen = TQPen( d->view->borderColor(), 1, SolidLine);
3045 cw->setRightBorderPen( pen );
3050 d->view->doc()->emitEndOperation( rect );
3053 sheet->emit_updateColumn( cw, c );
3055 d->view->doc()->emitEndOperation( rect );
3059 for (
int row = rect.top(); row <= bottom; ++row )
3061 for (
int col = rect.left(); col <= right; ++ col )
3063 cell = sheet->nonDefaultCell( col, row );
3068 formatCellByKey (cell, _ev->key(), rect);
3079bool Canvas::formatCellByKey (
Cell *cell,
int key,
const TQRect &rect)
3086 cell->
format()->setFormatType (Number_format);
3087 cell->
format()->setPrecision( 2 );
3102 case Key_NumberSign:
3106 case Key_AsciiCircum:
3107 cell->
format()->setFormatType (Scientific_format);
3112 if ( cell->
row() == rect.top() )
3114 pen = TQPen( d->view->borderColor(), 1, SolidLine);
3117 if ( cell->
row() == rect.bottom() )
3119 pen = TQPen( d->view->borderColor(), 1, SolidLine);
3122 if ( cell->
column() == rect.left() )
3124 pen = TQPen( d->view->borderColor(), 1, SolidLine);
3127 if ( cell->
column() == rect.right() )
3129 pen = TQPen( d->view->borderColor(), 1, SolidLine);
3139void Canvas::slotAutoScroll(
const TQPoint &scrollDistance)
3141 TQPoint d = scrollDistance;
3142 horzScrollBar()->setValue( horzScrollBar()->value() + d.x() );
3143 vertScrollBar()->setValue( vertScrollBar()->value() + d.y() );
3146void Canvas::doAutoScroll()
3148 if ( !d->mousePressed )
3150 d->scrollTimer->stop();
3153 bool select =
false;
3154 TQPoint pos = mapFromGlobal( TQCursor::pos() );
3159 vertScrollBar()->setValue ((
int) (vertScrollBar()->value() -
3163 else if ( pos.y() > height() )
3165 vertScrollBar()->setValue ((
int) (vertScrollBar()->value() +
3172 horzScrollBar()->setValue ((
int) (horzScrollBar()->value() -
3176 else if ( pos.x() > width() )
3178 horzScrollBar()->setValue ((
int) (horzScrollBar()->value() +
3185 TQMouseEvent *
event =
new TQMouseEvent(TQEvent::MouseMove, pos, 0, 0);
3186 mouseMoveEvent( event );
3191 d->scrollTimer->start( 50 );
3194void Canvas::speakCell(TQWidget* w,
const TQPoint& p, uint flags)
3197 if (w !=
this)
return;
3202 if (p == TQPoint()) {
3205 if (row == d->prevSpokenFocusRow && col == d->prevSpokenFocusCol)
return;
3206 d->prevSpokenFocusRow = row;
3207 d->prevSpokenFocusCol = col;
3209 TQPoint wp = w->mapFromGlobal(p);
3212 if ( sheet->layoutDirection()==Sheet::RightToLeft )
3214 double dwidth = d->view->doc()->unzoomItX( width() );
3215 posX = dwidth - d->view->doc()->unzoomItX( wp.x() );
3218 posX = d->view->doc()->unzoomItX( wp.x() );
3220 double posY = d->view->doc()->unzoomItY( wp.y() );
3221 col = sheet->leftColumn( (posX +
xOffset()), tmp );
3222 row = sheet->topRow( (posY +
yOffset()), tmp );
3223 if (row == d->prevSpokenPointerRow && col == d->prevSpokenPointerCol)
return;
3224 d->prevSpokenPointerRow = row;
3225 d->prevSpokenPointerCol = col;
3227 if (row == d->prevSpokenRow && col == d->prevSpokenCol)
return;
3228 d->prevSpokenRow = row;
3229 d->prevSpokenCol = col;
3231 if (row >=0 && col >= 0) {
3232 Cell* cell = sheet->cellAt( col, row );
3234 TQString text = cell->strOutText();
3235 if (!text.isEmpty()) {
3236 text.prepend(i18n(
"Spreadsheet cell",
"Cell ") + cell->
name() +
" ");
3238 TQString f = cell->
text();
3241 for (uint i = 0; i < f.length(); i++) f2 += f[i] +
" ";
3242 f2.replace(
"(", i18n(
"character (",
"left paren"));
3243 f2.replace(
")", i18n(
"character )",
"right paren"));
3244 f2.replace(
":", i18n(
"character :",
"colon"));
3245 f2.replace(
";", i18n(
"character ;",
"semicolon"));
3246 f2.replace(
"=", i18n(
"character =",
"equals"));
3247 f2.replace(
".", i18n(
"character .",
"point"));
3248 f2.replace(
",", i18n(
"character ,",
"comma"));
3249 f2.replace(
" . . ", i18n(
"characters ..",
" dot dot "));
3250 text.append(i18n(
"Spreadsheet formula",
" Formula ") + f2);
3253 kospeaker->sayWidget(text);
3260 switch(
static_cast<int>( offset / 20 ) )
3263 case 1:
return 20.0;
3264 case 2:
return d->view->doc()->unzoomItX( width() );
3265 case 3:
return d->view->doc()->unzoomItX( width() );
3266 default:
return d->view->doc()->unzoomItX( (
int) (width() * 5.0) );
3272 switch(
static_cast<int>( offset / 20 ) )
3275 case 1:
return 20.0;
3276 case 2:
return d->view->doc()->unzoomItY( height() );
3277 case 3:
return d->view->doc()->unzoomItY( height() );
3278 default:
return d->view->doc()->unzoomItY( (
int) (height() * 5.0) );
3285 TQPoint
const p ( (
int) pos.x() ,
3288 TQPtrListIterator<EmbeddedObject> itObject( doc()->embeddedObjects() );
3289 for( ; itObject.current(); ++itObject )
3291 if ( itObject.current()->sheet() == _sheet )
3293 KoRect
const bound = ( itObject.current() )->geometry();
3294 TQRect zoomedBound = doc()->zoomRect( KoRect(bound.left(), bound.top(),
3297 zoomedBound.moveBy( (
int)( -
xOffset() * doc()->zoomedResolutionX() ), (
int)( -
yOffset() * doc()->zoomedResolutionY() ) );
3298 if ( zoomedBound.contains( p ) )
3299 return itObject.current();
3307 if ( obj->sheet() !=
activeSheet() || obj->isSelected() )
3309 obj->setSelected(
true );
3310 repaintObject( obj );
3312 d->mouseSelectedObject =
true;
3313 emit objectSelectedChanged();
3319 if ( obj->sheet() !=
activeSheet() || !obj->isSelected() )
3321 obj->setSelected(
false );
3322 repaintObject( obj );
3324 d->mouseSelectedObject =
false;
3325 emit objectSelectedChanged();
3328void Canvas::selectAllObjects()
3330 TQPtrListIterator<EmbeddedObject> it( doc()->embeddedObjects() );
3331 for ( ; it.current() ; ++it )
3334 it.current()->setSelected(
true );
3337 d->mouseSelectedObject =
true;
3341void Canvas::deselectAllObjects()
3348 TQPtrListIterator<EmbeddedObject> it( doc()->embeddedObjects() );
3349 for ( ; it.current() ; ++it )
3350 deselectObject( it.current() );
3352 d->mouseSelectedObject =
false;
3358void Canvas::setMouseSelectedObject(
bool b)
3360 d->mouseSelectedObject = b;
3361 emit objectSelectedChanged();
3364bool Canvas::isObjectSelected()
3366 return d->mouseSelectedObject;
3372 KoRect rect( objectRect(
false ) );
3373 KoPoint move( 0, 0 );
3374 double diffx = pos.x() - d->m_origMousePos.x();
3375 double diffy = pos.y() - d->m_origMousePos.y();
3377 move = KoPoint( diffx, diffy );
3378 d->m_origMousePos = pos;
3381 KoRect movedRect( rect );
3382 movedRect.moveBy( diffx, diffy );
3385 KoPoint diffDueToBorders(0,0);
3387 if ( rect.left() + move.x() < 0 )
3388 diffDueToBorders.setX( -rect.left() - move.x() );
3394 if ( rect.top() + move.y() < 0 )
3395 diffDueToBorders.setY( -rect.top() - move.y() );
3400 move += diffDueToBorders;
3403 if ( keepXorYunchanged )
3405 KoPoint diff( d->m_moveStartPosMouse - movedRect.topLeft() );
3406 if ( fabs( diff.x() ) > fabs( diff.y() ) )
3409 movedRect.moveTopLeft( KoPoint( movedRect.x(), d->m_moveStartPosMouse.y() ) );
3410 move.setY( movedRect.y() - rect.y() );
3415 movedRect.moveTopLeft( KoPoint( d->m_moveStartPosMouse.x(), movedRect.y() ) );
3416 move.setX( movedRect.x() - rect.x() );
3420 if ( move != KoPoint( 0, 0 ) )
3432 KoRect objRect = obj->geometry();
3434 TQRect oldBoundingRect( doc()->zoomRect( objRect ) );
3439 bool bottom =
false;
3440 if ( _modType == MT_RESIZE_UP || _modType == MT_RESIZE_LU || _modType == MT_RESIZE_RU )
3445 if ( _modType == MT_RESIZE_DN || _modType == MT_RESIZE_LD || _modType == MT_RESIZE_RD )
3450 if ( _modType == MT_RESIZE_LF || _modType == MT_RESIZE_LU || _modType == MT_RESIZE_LD )
3455 if ( _modType == MT_RESIZE_RT || _modType == MT_RESIZE_RU || _modType == MT_RESIZE_RD )
3461 double newLeft = objRect.left();
3462 double newRight = objRect.right();
3463 double newTop = objRect.top();
3464 double newBottom = objRect.bottom();
3467 if ( point.y() < objRect.bottom() - MIN_SIZE )
3473 newTop = objRect.bottom() - MIN_SIZE;
3478 if ( point.y() > objRect.top() + MIN_SIZE )
3480 newBottom = point.y();
3484 newBottom = objRect.top() + MIN_SIZE;
3489 if ( point.x() < objRect.right() - MIN_SIZE )
3491 newLeft = point.x();
3495 newLeft = objRect.right() - MIN_SIZE;
3500 if ( point.x() > objRect.left() + MIN_SIZE )
3502 newRight = point.x();
3506 newRight = objRect.left() + MIN_SIZE;
3510 double width = newRight - newLeft;
3511 double height = newBottom - newTop;
3513 if ( keepRatio && d->m_ratio != 0 )
3515 if ( ( top || bottom ) && ( right || left ) )
3517 if ( height * height * d->m_ratio > width * width / d->m_ratio )
3519 width = height * d->m_ratio;
3523 height = width / d->m_ratio;
3526 else if ( top || bottom )
3528 width = height * d->m_ratio;
3532 height = width / d->m_ratio;
3537 newTop = objRect.bottom() - height;
3541 newBottom = objRect.top() + height;
3545 newLeft = objRect.right() - width;
3549 newRight = objRect.right() + width;
3553 if ( newLeft != objRect.left() || newRight != objRect.right() || newTop != objRect.top() || newBottom != objRect.bottom() )
3556 obj->resizeBy( width - objRect.width(), height - objRect.height() );
3558 if ( objRect.left() != newLeft || objRect.top() != newTop )
3560 obj->moveBy( KoPoint( newLeft - objRect.left(), newTop - objRect.top() ) );
3578 repaint( oldBoundingRect );
3579 repaintObject( obj );
3580 emit objectSizeChanged();
3587 if ( d->m_resizeObject )
3589 KoPoint move = KoPoint( d->m_resizeObject->geometry().x() - d->m_rectBeforeResize.x(),
3590 d->m_resizeObject->geometry().y() - d->m_rectBeforeResize.y() );
3591 KoSize size = KoSize( d->m_resizeObject->geometry().width() - d->m_rectBeforeResize.width(),
3592 d->m_resizeObject->geometry().height() - d->m_rectBeforeResize.height() );
3594 if ( ( d->m_resizeObject->geometry() ) != d->m_rectBeforeResize )
3596 ChangeObjectGeometryCommand *resizeCmd =
new ChangeObjectGeometryCommand( d->m_resizeObject, move, size );
3598 doc()->addCommand( resizeCmd );
3605 d->m_isResizing =
false;
3606 repaintObject( d->m_resizeObject );
3607 d->m_resizeObject = NULL;
3613 if ( doc()->embeddedObjects().count() <= 1 )
3616 if ( d->m_objectDisplayAbove == 0 )
3620 d->m_objectDisplayAbove = object;
3627 d->m_objectDisplayAbove = 0;
3632 list = doc()->embeddedObjects();
3633 list.setAutoDelete(
false );
3635 if ( d->m_objectDisplayAbove )
3639 int pos = doc()->embeddedObjects().findRef( d->m_objectDisplayAbove );
3640 if ( pos != -1 && d->m_objectDisplayAbove->isSelected() )
3643 list.append( d->m_objectDisplayAbove );
3654KoRect Canvas::objectRect(
bool all )
const
3661 if ( !d->cellEditor )
3668 d->editWidget->setEditMode(
false );
3670 TQString t = d->cellEditor->text();
3674 delete d->cellEditor;
3682 int openParenthese = t.contains(
'(' );
3683 int closeParenthese = t.contains(
')' );
3684 int diff = TQABS( openParenthese - closeParenthese );
3685 if ( openParenthese > closeParenthese )
3687 for (
int i=0; i < diff;i++)
3693 d->view->setText (t, array);
3697 d->view->updateEditWidget();
3714 d->cellEditor->setText( cell->
text() );
3724 if ( !d->cellEditor )
3728 if ( sheet->isProtected() && !cell->
format()->notProtected(
marker().x(),
marker().y() ) )
3733 d->editWidget->setEditMode(
true );
3748 w = cell->extraWidth();
3749 h = cell->extraHeight();
3755 Sheet::LayoutDirection sheetDir = sheet->layoutDirection();
3756 bool rtlText = cell->strOutText().isRightToLeft();
3760 if ( w > 0 && ( ( sheetDir == Sheet::RightToLeft && !rtlText ) ||
3761 ( sheetDir == Sheet::LeftToRight && rtlText ) ) )
3765 if ( sheetDir == Sheet::RightToLeft )
3767 double dwidth = d->view->doc()->unzoomItX( width() );
3768 double w2 = TQMAX( w, min_w );
3769 xpos = dwidth - w2 - xpos;
3773 TQPalette p = d->cellEditor->palette();
3774 TQColorGroup g( p.active() );
3777 if ( !color.isValid() )
3778 color = TQApplication::palette().active().text();
3779 g.setColor( TQColorGroup::Text, color);
3782 if ( !color.isValid() )
3784 g.setColor( TQColorGroup::Background, color );
3786 d->cellEditor->setPalette( TQPalette( g, p.disabled(), g ) );
3788 tmpFont.setPointSizeFloat( 0.01 * d->view->doc()->zoom() * tmpFont.pointSizeFloat() );
3789 d->cellEditor->setFont( tmpFont );
3791 KoRect rect( xpos, ypos, w, h );
3794 TQRect zoomedRect=d->view->doc()->zoomRect( rect );
3800 d->cellEditor->setGeometry( zoomedRect );
3801 d->cellEditor->setMinimumSize( TQSize( d->view->doc()->zoomItX( min_w ), d->view->doc()->zoomItY( min_h ) ) );
3802 d->cellEditor->show();
3811 d->cellEditor->setFocus();
3823 TQRect canvasRelativeGeometry = doc()->zoomRect( obj->geometry() );
3824 canvasRelativeGeometry.moveBy( (
int)( -
xOffset()*doc()->zoomedResolutionX() ) ,
3825 (
int)( -
yOffset() * doc()->zoomedResolutionY()) );
3827 update( canvasRelativeGeometry );
3850 TQCString mimeType =
"application/vnd.oasis.opendocument.spreadsheet";
3851 KoStore* store = KoStore::createStore( &buffer, KoStore::Write, mimeType );
3853 Q_ASSERT( !store->bad() );
3854 KoOasisStore oasisStore( store );
3856 KoXmlWriter* manifestWriter = oasisStore.manifestWriter( mimeType );
3860 if ( !doc()->saveOasisHelper( store, manifestWriter, Doc::SaveSelected, &plainText, &picture )
3861 || !oasisStore.closeManifestWriter() )
3868 KMultipleDrag* multiDrag =
new KMultipleDrag();
3869 if ( !plainText.isEmpty() )
3870 multiDrag->addDragObject(
new TQTextDrag( plainText, 0 ) );
3871 if ( !picture.isNull() )
3872 multiDrag->addDragObject( picture.dragObject( 0 ) );
3873 KoStoreDrag* storeDrag =
new KoStoreDrag( mimeType, 0 );
3874 kdDebug() << k_funcinfo <<
"setting zip data: " << buffer.buffer().size() <<
" bytes." << endl;
3875 storeDrag->setEncodedData( buffer.buffer() );
3876 multiDrag->addDragObject( storeDrag );
3879 TQPtrListIterator<EmbeddedObject> itObject( doc()->embeddedObjects() );
3881 if ( itObject.current() )
3883 KoRect kr = objectRect(
false);
3884 TQRect r( kr.toTQRect() );
3885 TQPixmap pixmap( r.width(), r.height() );
3886 pixmap.fill(
"white" );
3887 TQPainter p(&pixmap);
3888 for( ; itObject.current(); ++itObject )
3890 if ( itObject.current()->isSelected() )
3891 p.drawPixmap( itObject.current()->geometry().toTQRect().left() - r.left(), itObject.current()->geometry().toTQRect().top() - r.top(), itObject.current()->toPixmap( 1.0 , 1.0 ) );
3894 if (!pixmap.isNull())
3896 TQImageDrag *imagedrag =
new TQImageDrag( pixmap.convertToImage() );
3897 multiDrag->addDragObject( imagedrag );
3901 TQDragObject *dragObject = multiDrag;
3902 TQApplication::clipboard()->setData( dragObject, TQClipboard::Clipboard );
3907 if ( d->chooseCell )
3910 if ( d->cellEditor )
3916void Canvas::updateEditor()
3927 if (
choice()->sheet() != sheet)
3929 d->cellEditor->hide();
3933 d->cellEditor->show();
3935 d->cellEditor->updateChoice();
3939void Canvas::setSelectionChangePaintDirty(Sheet* sheet,
const Region& region)
3941 sheet->setRegionPaintDirty(region);
3953 buffer =
"L" + TQString::number(
markerRow() ) +
3968 buffer+=TQString::number((KS_colMax-
selectionInfo()->lastRange().left()+1))+
"C";
3978 TQString::number(
selectionInfo()->lastRange().top()) +
":" +
3986 if (buffer != d->posWidget->lineEdit()->text())
3987 d->posWidget->lineEdit()->setText(buffer);
3990void Canvas::equalizeRow()
3993 RowFormat *rl = d->view->activeSheet()->rowFormat(s.top());
3994 int size=rl->height(
this);
3995 if ( s.top() == s.bottom() )
3997 for(
int i=s.top()+1;i<=s.bottom();i++)
4002 size=TQMAX(d->view->activeSheet()->rowFormat(i)->height(
this),size);
4004 d->view->vBorderWidget()->equalizeRow(size);
4007void Canvas::equalizeColumn()
4010 ColumnFormat *cl = d->view->activeSheet()->columnFormat(s.left());
4011 int size=cl->width(
this);
4012 if ( s.left() == s.right() )
4015 for(
int i=s.left()+1;i<=s.right();i++)
4017 size=TQMAX(d->view->activeSheet()->columnFormat(i)->width(
this),size);
4019 d->view->hBorderWidget()->equalizeColumn(size);
4022TQRect Canvas::cellsInArea(
const TQRect area )
const
4024 KoRect unzoomedRect = d->view->doc()->unzoomRect( area );
4029 int left_col =
activeSheet()->leftColumn( unzoomedRect.left(), tmp );
4030 int right_col =
activeSheet()->rightColumn( unzoomedRect.right() );
4031 int top_row =
activeSheet()->topRow( unzoomedRect.top(), tmp );
4032 int bottom_row =
activeSheet()->bottomRow( unzoomedRect.bottom() );
4034 return TQRect( left_col, top_row,
4035 right_col - left_col + 1, bottom_row - top_row + 1 );
4040 return cellsInArea( TQRect(0,0,width(),height()) );
4056 TQPainter painter(
this);
4059 TQRegion rgnComplete( painter.clipRegion() );
4063 matrix = d->view->matrix();
4067 matrix = painter.worldMatrix();
4071 paintChildren( painter, matrix );
4074 clipoutChildren( painter );
4076 KoRect unzoomedRect = d->view->doc()->unzoomRect( TQRect( 0, 0, width(), height() ) );
4084 double topPos =
activeSheet()->dblRowPos(range.top());
4085 double leftPos =
activeSheet()->dblColumnPos(range.left());
4092 int right = range.right();
4093 int bottom = range.bottom();
4098 <<
"================================================================"
4100 kdDebug(36001) <<
"painting dirty cells " << endl;
4103 TQValueList<TQPoint> mergedCellsPainted;
4104 for ( x = range.left(); x <= right; ++x )
4106 for ( y = range.top(); y <= bottom; ++y )
4108 if ( sheet->cellIsPaintDirty( TQPoint( x, y ) ) )
4110 cell = sheet->cellAt( x, y );
4116 if (cell->layoutDirtyFlag()) cell->
makeLayout( painter, x, y );
4124 int paintBorder=Cell::Border_None;
4135 if ( x >= KS_colMax )
4137 paintBorder |= Cell::Border_Right;
4141 paintBorder |= Cell::Border_Right;
4143 sheet->cellAt( x + 1, y )->effLeftBorderValue( x + 1, y ) )
4144 rightPen = sheet->cellAt( x + 1, y )->effLeftBorderPen( x + 1, y );
4149 if ( y >= KS_rowMax )
4151 paintBorder |= Cell::Border_Bottom;
4155 paintBorder |= Cell::Border_Bottom;
4157 sheet->cellAt( x, y + 1 )->effTopBorderValue( x, y + 1 ) )
4158 bottomPen = sheet->cellAt( x, y + 1 )->effTopBorderPen( x, y + 1 );
4164 paintBorder |= Cell::Border_Left;
4168 paintBorder |= Cell::Border_Left;
4170 sheet->cellAt( x - 1, y )->effRightBorderValue( x - 1, y ) )
4171 leftPen = sheet->cellAt( x - 1, y )->effRightBorderPen( x - 1, y );
4177 paintBorder |= Cell::Border_Top;
4181 paintBorder |= Cell::Border_Top;
4183 sheet->cellAt( x, y - 1 )->effBottomBorderValue( x, y - 1 ) )
4184 topPen = sheet->cellAt( x, y - 1 )->effBottomBorderPen( x, y - 1 );
4187 cell->
paintCell( unzoomedRect, painter, d->view, dblCorner,
4188 TQPoint( x, y), paintBorder,
4189 rightPen,bottomPen,leftPen,topPen,
4190 mergedCellsPainted);
4192 dblCorner.setY( dblCorner.y() + sheet->rowFormat( y )->dblHeight( ) );
4194 dblCorner.setY( topPos -
yOffset() );
4195 dblCorner.setX( dblCorner.x() + sheet->columnFormat( x )->dblWidth( ) );
4202 paintHighlightedRanges(painter, unzoomedRect);
4203 paintNormalMarker(painter, unzoomedRect);
4212void Canvas::clipoutChildren( TQPainter& painter )
const
4214 TQRegion rgn = painter.clipRegion();
4215 if ( rgn.isEmpty() )
4216 rgn = TQRegion( TQRect( 0, 0, width(), height() ) );
4218 const double horizontalOffset = -
xOffset() * doc()->zoomedResolutionX();
4219 const double verticalOffset = -
yOffset() * doc()->zoomedResolutionY();
4221 TQPtrListIterator<EmbeddedObject> itObject( doc()->embeddedObjects() );
4222 for( ; itObject.current(); ++itObject )
4224 if ( ( itObject.current() )->sheet() ==
activeSheet() )
4226 TQRect childGeometry = doc()->zoomRect( itObject.current()->geometry());
4230 childGeometry.moveBy( (
int)horizontalOffset , (
int)verticalOffset );
4232 if (painter.window().intersects(childGeometry))
4233 rgn -= childGeometry;
4239 painter.setClipRegion( rgn );
4242TQRect Canvas::painterWindowGeometry(
const TQPainter& painter )
const
4244 TQRect zoomedWindowGeometry = painter.window();
4246 zoomedWindowGeometry.moveBy( (
int)(
xOffset() * doc()->zoomedResolutionX() ) , (
int)(
yOffset() * doc()->zoomedResolutionY() ) );
4248 return zoomedWindowGeometry;
4251void Canvas::paintChildren( TQPainter& painter, TQWMatrix& )
4253 TQPtrListIterator<EmbeddedObject> itObject( doc()->embeddedObjects() );
4255 if ( !itObject.current() )
4259 painter.translate( -
xOffset() * doc()->zoomedResolutionX() , -
yOffset() * doc()->zoomedResolutionY() );
4261 const TQRect zoomedWindowGeometry = painterWindowGeometry( painter );
4264 for( ; itObject.current(); ++itObject )
4266 TQRect
const zoomedObjectGeometry = doc()->zoomRect( itObject.current()->geometry() );
4267 if ( ( itObject.current() )->sheet() ==
activeSheet() &&
4268 zoomedWindowGeometry.intersects( zoomedObjectGeometry ) )
4273 TQRect canvasRelativeGeometry = zoomedObjectGeometry;
4274 canvasRelativeGeometry.moveBy( (
int)( -
xOffset()*doc()->zoomedResolutionX() ) ,
4275 (
int)( -
yOffset() * doc()->zoomedResolutionY()) );
4277 const TQRect cellsUnderObject=cellsInArea( canvasRelativeGeometry );
4280 for (
int x=cellsUnderObject.left();x<=cellsUnderObject.right();x++)
4282 for (
int y=cellsUnderObject.top();y<=cellsUnderObject.bottom();y++)
4283 if ( sheet->cellIsPaintDirty( TQPoint(x,y) ) )
4293 itObject.current()->draw( &painter );
4299void Canvas::paintHighlightedRanges(TQPainter& painter,
const KoRect& )
4301 TQValueList<TQColor> colors =
choice()->colors();
4304 Region::ConstIterator end(
choice()->constEnd());
4305 for (Region::ConstIterator it =
choice()->constBegin(); it != end; ++it)
4314 TQRect region = (*it)->rect().normalize();
4318 KoRect unzoomedRect;
4320 sheetAreaToVisibleRect(region,unzoomedRect);
4324 TQPen highlightPen( colors[(index) % colors.size()] );
4325 painter.setPen(highlightPen);
4331 zoomedRect.setCoords ( d->view->doc()->zoomItX(unzoomedRect.left()),
4332 d->view->doc()->zoomItY(unzoomedRect.top()),
4333 d->view->doc()->zoomItX(unzoomedRect.right()),
4334 d->view->doc()->zoomItY(unzoomedRect.bottom()) );
4339 zoomedRect.setLeft(zoomedRect.left()+1);
4340 zoomedRect.setTop(zoomedRect.top()+1);
4341 zoomedRect.setRight(zoomedRect.right()-1);
4342 zoomedRect.setBottom(zoomedRect.bottom()-1);
4344 painter.setBrush(nullBrush);
4345 painter.drawRect(zoomedRect);
4351 TQBrush sizeGripBrush( colors[(index) % colors.size()] );
4352 TQPen sizeGripPen(TQt::white);
4354 painter.setPen(sizeGripPen);
4355 painter.setBrush(sizeGripBrush);
4357 painter.drawRect(zoomedRect.right()-3,zoomedRect.bottom()-3,6,6);
4362void Canvas::paintNormalMarker(TQPainter& painter,
const KoRect &viewRect)
4373 for (Region::ConstIterator it(
selectionInfo()->constBegin()); it != end; ++it)
4375 TQRect range = (*it)->rect().normalize();
4377 double positions[4];
4381 TQPen pen( TQt::black, 2 );
4382 painter.setPen( pen );
4384 retrieveMarkerInfo(
selectionInfo()->extendToMergedAreas(range), viewRect, positions, paintSides );
4386 double left = positions[0];
4387 double top = positions[1];
4388 double right = positions[2];
4389 double bottom = positions[3];
4391 bool paintLeft = paintSides[0];
4392 bool paintTop = paintSides[1];
4393 bool paintRight = paintSides[2];
4394 bool paintBottom = paintSides[3];
4406 painter.drawLine( d->view->doc()->zoomItX( left ) - l, d->view->doc()->zoomItY( top ),
4407 d->view->doc()->zoomItX( right ) + l, d->view->doc()->zoomItY( top ) );
4409 if (
activeSheet()->layoutDirection()==Sheet::RightToLeft )
4413 painter.drawLine( d->view->doc()->zoomItX( right ), d->view->doc()->zoomItY( top ),
4414 d->view->doc()->zoomItX( right ), d->view->doc()->zoomItY( bottom ) );
4416 if ( paintLeft && paintBottom && current )
4419 painter.drawLine( d->view->doc()->zoomItX( left ), d->view->doc()->zoomItY( top ),
4420 d->view->doc()->zoomItX( left ), d->view->doc()->zoomItY( bottom ) - 3 );
4421 painter.drawLine( d->view->doc()->zoomItX( left ) + 4, d->view->doc()->zoomItY( bottom ),
4422 d->view->doc()->zoomItX( right ) + l + 1, d->view->doc()->zoomItY( bottom ) );
4423 painter.fillRect( d->view->doc()->zoomItX( left ) - 2, d->view->doc()->zoomItY( bottom ) -2, 5, 5,
4424 painter.pen().color() );
4430 painter.drawLine( d->view->doc()->zoomItX( left ), d->view->doc()->zoomItY( top ),
4431 d->view->doc()->zoomItX( left ), d->view->doc()->zoomItY( bottom ) );
4435 painter.drawLine( d->view->doc()->zoomItX( left ) - l, d->view->doc()->zoomItY( bottom ),
4436 d->view->doc()->zoomItX( right ) + l + 1, d->view->doc()->zoomItY( bottom ));
4444 painter.drawLine( d->view->doc()->zoomItX( left ), d->view->doc()->zoomItY( top ),
4445 d->view->doc()->zoomItX( left ), d->view->doc()->zoomItY( bottom ) );
4447 if ( paintRight && paintBottom && current )
4450 painter.drawLine( d->view->doc()->zoomItX( right ), d->view->doc()->zoomItY( top ),
4451 d->view->doc()->zoomItX( right ), d->view->doc()->zoomItY( bottom ) - 3 );
4452 painter.drawLine( d->view->doc()->zoomItX( left ) - l, d->view->doc()->zoomItY( bottom ),
4453 d->view->doc()->zoomItX( right ) - 3, d->view->doc()->zoomItY( bottom ) );
4454 painter.fillRect( d->view->doc()->zoomItX( right ) - 2, d->view->doc()->zoomItY( bottom ) - 2, 5, 5,
4455 painter.pen().color() );
4461 painter.drawLine( d->view->doc()->zoomItX( right ), d->view->doc()->zoomItY( top ),
4462 d->view->doc()->zoomItX( right ), d->view->doc()->zoomItY( bottom ) );
4466 painter.drawLine( d->view->doc()->zoomItX( left ) - l, d->view->doc()->zoomItY( bottom ),
4467 d->view->doc()->zoomItX( right ) + l + 1, d->view->doc()->zoomItY( bottom ) );
4474void Canvas::sheetAreaToRect(
const TQRect& sheetArea, KoRect& rect)
4478 if ( sheet->layoutDirection()==Sheet::RightToLeft )
4480 rect.setLeft(sheet->dblColumnPos( sheetArea.right()+1 ) );
4481 rect.setRight(sheet->dblColumnPos( sheetArea.left() ));
4485 rect.setLeft(sheet->dblColumnPos( sheetArea.left() ));
4486 rect.setRight(sheet->dblColumnPos( sheetArea.right()+1 ));
4489 rect.setTop(sheet->dblRowPos(sheetArea.top()));
4490 rect.setBottom(sheet->dblRowPos(sheetArea.bottom()+1));
4494void Canvas::sheetAreaToVisibleRect(
const TQRect& sheetArea,
4495 KoRect& visibleRect )
4502 double dwidth=d->view->doc()->unzoomItX(width());
4506 if ( sheet->layoutDirection()==Sheet::RightToLeft )
4508 xpos = dwidth - sheet->dblColumnPos( sheetArea.right() ) +
xOffset();
4509 x = dwidth - sheet->dblColumnPos( sheetArea.left() ) +
xOffset();
4513 xpos = sheet->dblColumnPos( sheetArea.left() ) -
xOffset();
4514 x = sheet->dblColumnPos( sheetArea.right() ) -
xOffset();
4517 double ypos = sheet->dblRowPos(sheetArea.top())-
yOffset();
4519 const ColumnFormat *columnFormat = sheet->columnFormat( sheetArea.right() );
4520 double tw = columnFormat->dblWidth( );
4521 double w = x - xpos + tw;
4523 double y = sheet->dblRowPos( sheetArea.bottom() ) -
yOffset();
4524 const RowFormat* rowFormat = sheet->rowFormat( sheetArea.bottom() );
4525 double th = rowFormat->dblHeight( );
4526 double h = ( y - ypos ) + th;
4529 if ( sheet->layoutDirection()==Sheet::RightToLeft )
4531 visibleRect.setLeft(xpos - tw );
4532 visibleRect.setRight(xpos - tw + w );
4536 visibleRect.setLeft(xpos );
4537 visibleRect.setRight(xpos + w );
4539 visibleRect.setTop(ypos);
4540 visibleRect.setBottom(ypos + h);
4543void Canvas::retrieveMarkerInfo(
const TQRect &marker,
4544 const KoRect &viewRect,
4554 sheetAreaToVisibleRect(
marker,visibleRect);
4601 double left = visibleRect.left();
4602 double top = visibleRect.top();
4603 double right = visibleRect.right();
4604 double bottom = visibleRect.bottom();
4607 paintSides[0] = (viewRect.left() <= left) && (left <= viewRect.right()) &&
4608 (bottom >= viewRect.top()) && (top <= viewRect.bottom());
4609 paintSides[1] = (viewRect.top() <= top) && (top <= viewRect.bottom())
4610 && (right >= viewRect.left()) && (left <= viewRect.right());
4611 if ( sheet->layoutDirection()==Sheet::RightToLeft )
4612 paintSides[2] = (viewRect.left() <= right ) &&
4613 (right - 1 <= viewRect.right()) &&
4614 (bottom >= viewRect.top()) && (top <= viewRect.bottom());
4616 paintSides[2] = (viewRect.left() <= right ) &&
4617 (right <= viewRect.right()) &&
4618 (bottom >= viewRect.top()) && (top <= viewRect.bottom());
4619 paintSides[3] = (viewRect.top() <= bottom) && (bottom <= viewRect.bottom())
4620 && (right >= viewRect.left()) && (left <= viewRect.right());
4622 positions[0] = TQMAX( left, viewRect.left() );
4623 positions[1] = TQMAX( top, viewRect.top() );
4624 positions[2] = TQMIN( right, viewRect.right() );
4625 positions[3] = TQMIN( bottom, viewRect.bottom() );
4635VBorder::VBorder( TQWidget *_parent,
Canvas *_canvas,
View *_view)
4636 : TQWidget( _parent,
"", WStaticContents | WResizeNoErase | WRepaintNoErase )
4639 m_pCanvas = _canvas;
4642 setBackgroundMode( PaletteButton );
4643 setMouseTracking(
true );
4645 m_bSelection =
false;
4646 m_iSelectionAnchor=1;
4647 m_bMousePressed =
false;
4649 m_scrollTimer =
new TQTimer(
this );
4650 connect (m_scrollTimer, TQ_SIGNAL( timeout() ),
this, TQ_SLOT( doAutoScroll() ) );
4656 delete m_scrollTimer;
4659TQSize VBorder::sizeHint()
const
4661 return TQSize( 40, 10 );
4665void VBorder::mousePressEvent( TQMouseEvent * _ev )
4667 if ( !m_pView->koDocument()->isReadWrite() )
4670 if ( _ev->button() == TQt::LeftButton )
4671 m_bMousePressed =
true;
4677 double ev_PosY = m_pCanvas->d->view->doc()->unzoomItY( _ev->pos().y() ) + m_pCanvas->
yOffset();
4678 double dHeight = m_pCanvas->d->view->doc()->unzoomItY( height() );
4680 m_bSelection =
false;
4683 if ( m_pCanvas->editor() )
4688 m_scrollTimer->start( 50 );
4692 int row = sheet->topRow( m_pCanvas->
yOffset(), y );
4695 while ( y < ( dHeight + m_pCanvas->
yOffset() ) && ( !m_bResize ) )
4697 double h = sheet->rowFormat( row )->dblHeight();
4699 if ( row > KS_rowMax )
4701 if ( ( ev_PosY >= y + h - 2 ) &&
4702 ( ev_PosY <= y + h + 1 ) &&
4703 !( sheet->rowFormat( row )->isHide() && row == 1 ) )
4711 int tmpRow = sheet->topRow( ev_PosY - 1, tmp2 );
4712 if ( sheet->rowFormat( tmpRow )->isHide() && tmpRow == 1 )
4720 m_iResizedRow = sheet->topRow( ev_PosY - 1, tmp );
4721 if ( !sheet->isProtected() )
4722 paintSizeIndicator( _ev->pos().y(),
true );
4726 m_bSelection =
true;
4729 int hit_row = sheet->topRow( ev_PosY, tmp );
4730 if ( hit_row > KS_rowMax )
4733 m_iSelectionAnchor = hit_row;
4735 if ( !m_pView->selectionInfo()->contains( TQPoint(1, hit_row) ) ||
4736 !( _ev->button() == TQt::RightButton ) ||
4737 !m_pView->selectionInfo()->isRowSelected() )
4739 TQPoint newMarker( 1, hit_row );
4740 TQPoint newAnchor( KS_colMax, hit_row );
4741#ifdef NONCONTIGUOUSSELECTION
4742 if (_ev->state() == ControlButton)
4744 m_pView->selectionInfo()->extend(TQRect(newAnchor, newMarker));
4748 if (_ev->state() == ShiftButton)
4750 m_pView->selectionInfo()->update(newMarker);
4754 m_pView->selectionInfo()->initialize(TQRect(newAnchor, newMarker));
4758 if ( _ev->button() == TQt::RightButton )
4760 TQPoint p = mapToGlobal( _ev->pos() );
4761 m_pView->popupRowMenu( p );
4762 m_bSelection =
false;
4768void VBorder::mouseReleaseEvent( TQMouseEvent * _ev )
4770 if ( m_scrollTimer->isActive() )
4771 m_scrollTimer->stop();
4773 m_bMousePressed =
false;
4775 if ( !m_pView->koDocument()->isReadWrite() )
4782 double ev_PosY = m_pCanvas->d->view->doc()->unzoomItY( _ev->pos().y() ) + m_pCanvas->
yOffset();
4788 painter.begin( m_pCanvas );
4789 painter.setRasterOp( NotROP );
4790 painter.drawLine( 0, m_iResizePos, m_pCanvas->width(), m_iResizePos );
4793 int start = m_iResizedRow;
4794 int end = m_iResizedRow;
4796 rect.setCoords( 1, m_iResizedRow, KS_colMax, m_iResizedRow );
4797 if ( m_pView->selectionInfo()->isRowSelected() )
4799 if ( m_pView->selectionInfo()->contains( TQPoint( 1, m_iResizedRow ) ) )
4801 start = m_pView->selectionInfo()->lastRange().top();
4802 end = m_pView->selectionInfo()->lastRange().bottom();
4803 rect = m_pView->selectionInfo()->lastRange();
4807 double height = 0.0;
4808 double y = sheet->dblRowPos( m_iResizedRow );
4809 if ( ev_PosY - y <= 0.0 )
4812 height = ev_PosY - y;
4814 if ( !sheet->isProtected() )
4816 if ( !m_pCanvas->d->view->doc()->undoLocked() )
4819 if ( height != 0.0 )
4822 UndoResizeColRow *undo =
new UndoResizeColRow( m_pCanvas->d->view->doc(), m_pCanvas->
activeSheet(), rect );
4823 m_pCanvas->d->view->doc()->addCommand( undo );
4827 for(
int i = start; i <= end; i++ )
4829 RowFormat *rl = sheet->nonDefaultRowFormat( i );
4830 if ( height != 0.0 )
4832 if ( !rl->isHide() )
4833 rl->setDblHeight( height );
4837 sheet->hideRow(*m_pView->selectionInfo());
4845 else if ( m_bSelection )
4847 TQRect rect = m_pView->selectionInfo()->lastRange();
4851 bool m_frozen =
false;
4854 kdDebug(36001) <<
"selected: T " << rect.top() <<
" B " << rect.bottom() << endl;
4858 TQValueList<int>hiddenRows;
4860 for ( i = rect.top(); i <= rect.bottom(); ++i )
4862 row = m_pView->activeSheet()->rowFormat( i );
4863 if ( row->isHide() )
4865 hiddenRows.append(i);
4869 if ( hiddenRows.count() > 0 )
4870 m_pView->activeSheet()->showRow(*m_pView->selectionInfo());
4874 m_bSelection =
false;
4878void VBorder::equalizeRow(
double resize )
4883 TQRect selection( m_pView->selectionInfo()->selection() );
4884 if ( !m_pCanvas->d->view->doc()->undoLocked() )
4886 UndoResizeColRow *undo =
new UndoResizeColRow( m_pCanvas->d->view->doc(), m_pCanvas->
activeSheet(), selection );
4887 m_pCanvas->d->view->doc()->addCommand( undo );
4890 for (
int i = selection.top(); i <= selection.bottom(); i++ )
4892 rl = sheet->nonDefaultRowFormat( i );
4893 resize = TQMAX( 2.0, resize);
4894 rl->setDblHeight( resize );
4898void VBorder::mouseDoubleClickEvent(TQMouseEvent*)
4904 if ( !m_pView->koDocument()->isReadWrite() || sheet->isProtected() )
4911void VBorder::mouseMoveEvent( TQMouseEvent * _ev )
4913 if ( !m_pView->koDocument()->isReadWrite() )
4921 double ev_PosY = m_pCanvas->d->view->doc()->unzoomItY( _ev->pos().y() ) + m_pCanvas->
yOffset();
4922 double dHeight = m_pCanvas->d->view->doc()->unzoomItY( height() );
4927 if ( !sheet->isProtected() )
4928 paintSizeIndicator( _ev->pos().y(),
false );
4931 else if ( m_bSelection )
4934 int row = sheet->topRow( ev_PosY, y );
4935 if ( row > KS_rowMax )
4938 TQPoint newAnchor = m_pView->selectionInfo()->anchor();
4939 TQPoint newMarker = m_pView->selectionInfo()->marker();
4940 newMarker.setY( row );
4941 newAnchor.setY( m_iSelectionAnchor );
4942 m_pView->selectionInfo()->update(newMarker);
4944 if ( _ev->pos().y() < 0 )
4945 m_pCanvas->vertScrollBar()->setValue( m_pCanvas->d->view->doc()->zoomItY( ev_PosY ) );
4946 else if ( _ev->pos().y() > m_pCanvas->height() )
4948 if ( row < KS_rowMax )
4950 RowFormat *rl = sheet->rowFormat( row + 1 );
4951 y = sheet->dblRowPos( row + 1 );
4952 m_pCanvas->vertScrollBar()->setValue ((
int) (m_pCanvas->d->view->doc()->zoomItY
4953 (ev_PosY + rl->dblHeight()) - dHeight));
4962 const double unzoomedPixel = m_pCanvas->d->view->doc()->unzoomItY( 1 );
4964 int tmpRow = sheet->topRow( m_pCanvas->
yOffset(), y );
4966 while ( y < m_pCanvas->d->view->doc()->unzoomItY( height() ) + m_pCanvas->
yOffset() )
4968 double h = sheet->rowFormat( tmpRow )->dblHeight();
4971 if ( ev_PosY >= y + h - 2 * unzoomedPixel &&
4972 ev_PosY <= y + h + unzoomedPixel &&
4973 !( sheet->rowFormat( tmpRow )->isHide() && tmpRow == 1 ) )
4975 setCursor( splitVCursor );
4981 setCursor( arrowCursor );
4985void VBorder::doAutoScroll()
4987 if ( !m_bMousePressed )
4989 m_scrollTimer->stop();
4993 TQPoint pos( mapFromGlobal( TQCursor::pos() ) );
4995 if ( pos.y() < 0 || pos.y() > height() )
4997 TQMouseEvent *
event =
new TQMouseEvent( TQEvent::MouseMove, pos, 0, 0 );
4998 mouseMoveEvent( event );
5003 m_scrollTimer->start( 50 );
5006void VBorder::wheelEvent( TQWheelEvent* _ev )
5008 if ( m_pCanvas->vertScrollBar() )
5009 TQApplication::sendEvent( m_pCanvas->vertScrollBar(), _ev );
5013void VBorder::paintSizeIndicator(
int mouseY,
bool firstTime )
5020 painter.begin( m_pCanvas );
5021 painter.setRasterOp( NotROP );
5024 painter.drawLine( 0, m_iResizePos, m_pCanvas->width(), m_iResizePos );
5026 m_iResizePos = mouseY;
5029 int y = m_pCanvas->d->view->doc()->zoomItY( sheet->dblRowPos( m_iResizedRow ) - m_pCanvas->
yOffset() );
5030 if ( m_iResizePos < y + 2 )
5033 painter.drawLine( 0, m_iResizePos, m_pCanvas->width(), m_iResizePos );
5038 if ( m_iResizePos != y )
5039 tmpSize = i18n(
"Height: %1 %2").arg( KoUnit::toUserValue( m_pCanvas->doc()->unzoomItY( m_iResizePos - y ),
5040 m_pView->doc()->unit() ) )
5041 .arg( m_pView->doc()->
unitName() );
5043 tmpSize = i18n(
"Hide Row" );
5045 painter.begin(
this );
5046 int len = painter.fontMetrics().width( tmpSize );
5047 int hei = painter.fontMetrics().height();
5052 m_lSize =
new TQLabel( m_pCanvas );
5054 if ( sheet->layoutDirection()==Sheet::RightToLeft )
5055 m_lSize->setGeometry( m_pCanvas->width() - len - 5,
5056 y + 3, len + 2, hei + 2 );
5058 m_lSize->setGeometry( 3, y + 3, len + 2,hei + 2 );
5060 m_lSize->setAlignment( TQt::AlignVCenter );
5061 m_lSize->setText( tmpSize );
5062 m_lSize->setPalette( TQToolTip::palette() );
5067 if ( sheet->layoutDirection()==Sheet::RightToLeft )
5068 m_lSize->setGeometry( m_pCanvas->width() - len - 5,
5069 y + 3, len + 2, hei + 2 );
5071 m_lSize->setGeometry( 3, y + 3, len + 2,hei + 2 );
5073 m_lSize->setText( tmpSize );
5077void VBorder::updateRows(
int from,
int to )
5083 int y0 = sheet->rowPos( from, m_pCanvas );
5084 int y1 = sheet->rowPos( to+1, m_pCanvas );
5085 update( 0, y0, width(), y1-y0 );
5088void VBorder::paintEvent( TQPaintEvent* _ev )
5094 TQPainter painter(
this );
5096 TQPen pen( TQt::black, 1 );
5097 painter.setPen( pen );
5107 painter.setClipRect( _ev->rect() );
5111 int y = sheet->topRow( (m_pCanvas->d->view->doc()->unzoomItY( _ev->rect().y() ) + m_pCanvas->
yOffset()), yPos );
5113 yPos = yPos - m_pCanvas->
yOffset();
5114 int width = m_pCanvas->d->view->doc()->zoomItX( YBORDER_WIDTH );
5116 TQFont normalFont = painter.font();
5117 if ( m_pCanvas->d->view->doc()->zoom() < 100 )
5119 normalFont.setPointSizeFloat( 0.01 * m_pCanvas->d->view->doc()->zoom() *
5120 normalFont.pointSizeFloat() );
5122 TQFont boldFont = normalFont;
5123 boldFont.setBold(
true );
5126 while ( yPos <= m_pCanvas->d->view->doc()->unzoomItY( _ev->rect().bottom() ) )
5128 bool selected = (m_pView->selectionInfo()->isRowSelected(y));
5129 bool highlighted = (!selected && m_pView->selectionInfo()->isRowAffected(y));
5131 const RowFormat *row_lay = sheet->rowFormat( y );
5132 int zoomedYPos = m_pCanvas->d->view->doc()->zoomItY( yPos );
5133 int height = m_pCanvas->d->view->doc()->zoomItY( yPos + row_lay->dblHeight() ) - zoomedYPos;
5137 TQBrush fillSelected( highlightColor );
5138 qDrawPlainRect ( &painter, 0, zoomedYPos, width, height+1, highlightColor.dark(150),
5141 else if ( highlighted )
5143 TQBrush fillHighlighted( highlightColor );
5144 qDrawPlainRect ( &painter, 0, zoomedYPos, width, height+1, highlightColor.dark(150),
5145 1, &fillHighlighted );
5149 TQColor c = colorGroup().background();
5151 qDrawPlainRect ( &painter, 0, zoomedYPos, width, height+1, c.dark(150),
5155 TQString rowText = TQString::number( y );
5158 painter.setFont( normalFont );
5159 painter.setPen( colorGroup().text() );
5162 painter.setPen( colorGroup().highlightedText() );
5163 else if ( highlighted )
5164 painter.setFont( boldFont );
5166 int len = painter.fontMetrics().width( rowText );
5167 if (!row_lay->isHide())
5168 painter.drawText( ( width-len )/2, zoomedYPos +
5169 ( height + painter.fontMetrics().ascent() -
5170 painter.fontMetrics().descent() ) / 2, rowText );
5172 yPos += row_lay->dblHeight();
5178void VBorder::focusOutEvent( TQFocusEvent* )
5180 if ( m_scrollTimer->isActive() )
5181 m_scrollTimer->stop();
5182 m_bMousePressed =
false;
5192HBorder::HBorder( TQWidget *_parent,
Canvas *_canvas,
View *_view )
5193 : TQWidget( _parent,
"", WStaticContents| WResizeNoErase | WRepaintNoErase )
5196 m_pCanvas = _canvas;
5198 setBackgroundMode( PaletteButton );
5199 setMouseTracking(
true );
5201 m_bSelection =
false;
5202 m_iSelectionAnchor=1;
5203 m_bMousePressed =
false;
5205 m_scrollTimer =
new TQTimer(
this );
5206 connect( m_scrollTimer, TQ_SIGNAL( timeout() ),
this, TQ_SLOT( doAutoScroll() ) );
5212 delete m_scrollTimer;
5215TQSize HBorder::sizeHint()
const
5217 return TQSize( 40, 10 );
5220void HBorder::mousePressEvent( TQMouseEvent * _ev )
5222 if (!m_pView->koDocument()->isReadWrite())
5225 if ( _ev->button() == TQt::LeftButton )
5226 m_bMousePressed =
true;
5233 if ( m_pCanvas->editor() )
5238 m_scrollTimer->start( 50 );
5241 double dWidth = m_pCanvas->d->view->doc()->unzoomItX( width() );
5242 if ( sheet->layoutDirection()==Sheet::RightToLeft )
5243 ev_PosX = dWidth - m_pCanvas->d->view->doc()->unzoomItX( _ev->pos().x() ) + m_pCanvas->
xOffset();
5245 ev_PosX = m_pCanvas->d->view->doc()->unzoomItX( _ev->pos().x() ) + m_pCanvas->
xOffset();
5247 m_bSelection =
false;
5252 const double unzoomedPixel = m_pCanvas->d->view->doc()->unzoomItX( 1 );
5253 if ( sheet->layoutDirection()==Sheet::RightToLeft )
5255 int tmpCol = sheet->leftColumn( m_pCanvas->
xOffset(), x );
5257 kdDebug() <<
"evPos: " << ev_PosX <<
", x: " << x <<
", COL: " << tmpCol << endl;
5258 while ( ev_PosX > x && ( !m_bResize ) )
5260 double w = sheet->columnFormat( tmpCol )->dblWidth();
5262 kdDebug() <<
"evPos: " << ev_PosX <<
", x: " << x <<
", w: " << w <<
", COL: " << tmpCol << endl;
5265 if ( tmpCol > KS_colMax )
5270 if ( ev_PosX >= x + w - unzoomedPixel &&
5271 ev_PosX <= x + w + unzoomedPixel &&
5272 !( sheet->columnFormat( tmpCol )->isHide() && tmpCol == 1 ) )
5282 tmpCol = sheet->leftColumn( dWidth - ev_PosX + 1, tmp2 );
5283 if ( sheet->columnFormat( tmpCol )->isHide() && tmpCol == 0 )
5285 kdDebug() <<
"No resize: " << tmpCol <<
", " << sheet->columnFormat( tmpCol )->isHide() << endl;
5289 kdDebug() <<
"Resize: " << m_bResize << endl;
5293 int col = sheet->leftColumn( m_pCanvas->
xOffset(), x );
5296 while ( x < ( dWidth + m_pCanvas->
xOffset() ) && ( !m_bResize ) )
5298 double w = sheet->columnFormat( col )->dblWidth();
5300 if ( col > KS_colMax )
5302 if ( ( ev_PosX >= x + w - unzoomedPixel ) &&
5303 ( ev_PosX <= x + w + unzoomedPixel ) &&
5304 !( sheet->columnFormat( col )->isHide() && col == 1 ) )
5312 int tmpCol = sheet->leftColumn( ev_PosX - 1, tmp2 );
5313 if ( sheet->columnFormat( tmpCol )->isHide() && tmpCol == 1 )
5322 if ( sheet->layoutDirection()==Sheet::RightToLeft )
5324 m_iResizedColumn = sheet->leftColumn( ev_PosX - 1, tmp );
5327 if ( !sheet->isProtected() )
5328 paintSizeIndicator( _ev->pos().x(),
true );
5332 m_iResizedColumn = sheet->leftColumn( ev_PosX - 1, tmp );
5334 if ( !sheet->isProtected() )
5335 paintSizeIndicator( _ev->pos().x(),
true );
5342 m_bSelection =
true;
5345 int hit_col = sheet->leftColumn( ev_PosX, tmp );
5346 if ( hit_col > KS_colMax )
5349 m_iSelectionAnchor = hit_col;
5351 if ( !m_pView->selectionInfo()->contains( TQPoint( hit_col, 1 ) ) ||
5352 !( _ev->button() == TQt::RightButton ) ||
5353 !m_pView->selectionInfo()->isColumnSelected() )
5355 TQPoint newMarker( hit_col, 1 );
5356 TQPoint newAnchor( hit_col, KS_rowMax );
5357#ifdef NONCONTIGUOUSSELECTION
5358 if (_ev->state() == ControlButton)
5360 m_pView->selectionInfo()->extend(TQRect(newAnchor, newMarker));
5364 if (_ev->state() == ShiftButton)
5366 m_pView->selectionInfo()->update(newMarker);
5370 m_pView->selectionInfo()->initialize(TQRect(newAnchor, newMarker));
5374 if ( _ev->button() == TQt::RightButton )
5376 TQPoint p = mapToGlobal( _ev->pos() );
5377 m_pView->popupColumnMenu( p );
5378 m_bSelection =
false;
5384void HBorder::mouseReleaseEvent( TQMouseEvent * _ev )
5386 if ( m_scrollTimer->isActive() )
5387 m_scrollTimer->stop();
5389 m_bMousePressed =
false;
5391 if ( !m_pView->koDocument()->isReadWrite() )
5400 double dWidth = m_pCanvas->d->view->doc()->unzoomItX( width() );
5405 painter.begin( m_pCanvas );
5406 painter.setRasterOp( NotROP );
5407 painter.drawLine( m_iResizePos, 0, m_iResizePos, m_pCanvas->height() );
5410 int start = m_iResizedColumn;
5411 int end = m_iResizedColumn;
5413 rect.setCoords( m_iResizedColumn, 1, m_iResizedColumn, KS_rowMax );
5414 if ( m_pView->selectionInfo()->isColumnSelected() )
5416 if ( m_pView->selectionInfo()->contains( TQPoint( m_iResizedColumn, 1 ) ) )
5418 start = m_pView->selectionInfo()->lastRange().left();
5419 end = m_pView->selectionInfo()->lastRange().right();
5420 rect = m_pView->selectionInfo()->lastRange();
5427 if ( sheet->layoutDirection()==Sheet::RightToLeft )
5428 ev_PosX = dWidth - m_pCanvas->d->view->doc()->unzoomItX( _ev->pos().x() ) + m_pCanvas->
xOffset();
5430 ev_PosX = m_pCanvas->d->view->doc()->unzoomItX( _ev->pos().x() ) + m_pCanvas->
xOffset();
5432 x = sheet->dblColumnPos( m_iResizedColumn );
5434 if ( ev_PosX - x <= 0.0 )
5437 width = ev_PosX - x;
5439 if ( !sheet->isProtected() )
5441 if ( !m_pCanvas->d->view->doc()->undoLocked() )
5447 UndoResizeColRow *undo =
new UndoResizeColRow( m_pCanvas->d->view->doc(), m_pCanvas->
activeSheet(), rect );
5448 m_pCanvas->d->view->doc()->addCommand( undo );
5452 for(
int i = start; i <= end; i++ )
5454 ColumnFormat *cl = sheet->nonDefaultColumnFormat( i );
5457 if ( !cl->isHide() )
5458 cl->setDblWidth( width );
5462 sheet->hideColumn(*m_pView->selectionInfo());
5470 else if ( m_bSelection )
5472 TQRect rect = m_pView->selectionInfo()->lastRange();
5476 bool m_frozen =
false;
5479 kdDebug(36001) <<
"selected: L " << rect.left() <<
" R " << rect.right() << endl;
5483 TQValueList<int>hiddenCols;
5485 for ( i = rect.left(); i <= rect.right(); ++i )
5487 col = m_pView->activeSheet()->columnFormat( i );
5488 if ( col->isHide() )
5490 hiddenCols.append(i);
5494 if ( hiddenCols.count() > 0 )
5495 m_pView->activeSheet()->showColumn(*m_pView->selectionInfo());
5499 m_bSelection =
false;
5503void HBorder::equalizeColumn(
double resize )
5508 TQRect selection( m_pView->selectionInfo()->selection() );
5509 if ( !m_pCanvas->d->view->doc()->undoLocked() )
5511 UndoResizeColRow *undo =
new UndoResizeColRow( m_pCanvas->d->view->doc(), m_pCanvas->
activeSheet(), selection );
5512 m_pCanvas->d->view->doc()->addCommand( undo );
5515 for (
int i = selection.left(); i <= selection.right(); i++ )
5517 cl = sheet->nonDefaultColumnFormat( i );
5518 resize = TQMAX( 2.0, resize );
5519 cl->setDblWidth( resize );
5524void HBorder::mouseDoubleClickEvent(TQMouseEvent*)
5530 if ( !m_pView->koDocument()->isReadWrite() || sheet->isProtected() )
5536void HBorder::mouseMoveEvent( TQMouseEvent * _ev )
5538 if ( !m_pView->koDocument()->isReadWrite() )
5546 double dWidth = m_pCanvas->d->view->doc()->unzoomItX( width() );
5548 if ( sheet->layoutDirection()==Sheet::RightToLeft )
5549 ev_PosX = dWidth - m_pCanvas->d->view->doc()->unzoomItX( _ev->pos().x() ) + m_pCanvas->
xOffset();
5551 ev_PosX = m_pCanvas->d->view->doc()->unzoomItX( _ev->pos().x() ) + m_pCanvas->
xOffset();
5556 if ( !sheet->isProtected() )
5557 paintSizeIndicator( _ev->pos().x(),
false );
5560 else if ( m_bSelection )
5563 int col = sheet->leftColumn( ev_PosX, x );
5565 if ( col > KS_colMax )
5568 TQPoint newMarker = m_pView->selectionInfo()->marker();
5569 TQPoint newAnchor = m_pView->selectionInfo()->anchor();
5570 newMarker.setX( col );
5571 newAnchor.setX( m_iSelectionAnchor );
5572 m_pView->selectionInfo()->update(newMarker);
5574 if ( sheet->layoutDirection()==Sheet::RightToLeft )
5576 if ( _ev->pos().x() < width() - m_pCanvas->width() )
5578 ColumnFormat *cl = sheet->columnFormat( col + 1 );
5579 x = sheet->dblColumnPos( col + 1 );
5580 m_pCanvas->horzScrollBar()->setValue ( m_pCanvas->horzScrollBar()->maxValue() - (
int)
5581 (m_pCanvas->d->view->doc()->zoomItX (ev_PosX + cl->dblWidth()) - m_pCanvas->d->view->doc()->unzoomItX( m_pCanvas->width() )));
5583 else if ( _ev->pos().x() > width() )
5584 m_pCanvas->horzScrollBar()->setValue( m_pCanvas->horzScrollBar()->maxValue() - m_pCanvas->d->view->doc()->zoomItX( ev_PosX - dWidth + m_pCanvas->d->view->doc()->unzoomItX( m_pCanvas->width() ) ) );
5588 if ( _ev->pos().x() < 0 )
5589 m_pCanvas->horzScrollBar()->setValue( m_pCanvas->d->view->doc()->zoomItX( ev_PosX ) );
5590 else if ( _ev->pos().x() > m_pCanvas->width() )
5592 if ( col < KS_colMax )
5594 ColumnFormat *cl = sheet->columnFormat( col + 1 );
5595 x = sheet->dblColumnPos( col + 1 );
5596 m_pCanvas->horzScrollBar()->setValue ((
int)
5597 (m_pCanvas->d->view->doc()->zoomItX (ev_PosX + cl->dblWidth()) - dWidth));
5607 const double unzoomedPixel = m_pCanvas->d->view->doc()->unzoomItX( 1 );
5610 if ( sheet->layoutDirection()==Sheet::RightToLeft )
5612 int tmpCol = sheet->leftColumn( m_pCanvas->
xOffset(), x );
5614 while ( ev_PosX > x )
5616 double w = sheet->columnFormat( tmpCol )->dblWidth();
5621 if ( ev_PosX >= x + w - unzoomedPixel &&
5622 ev_PosX <= x + w + unzoomedPixel &&
5623 !( sheet->columnFormat( tmpCol )->isHide() && tmpCol == 0 ) )
5625 setCursor( splitHCursor );
5630 setCursor( arrowCursor );
5634 int tmpCol = sheet->leftColumn( m_pCanvas->
xOffset(), x );
5636 while ( x < m_pCanvas->d->view->doc()->unzoomItY( width() ) + m_pCanvas->
xOffset() )
5638 double w = sheet->columnFormat( tmpCol )->dblWidth();
5641 if ( ev_PosX >= x + w - unzoomedPixel &&
5642 ev_PosX <= x + w + unzoomedPixel &&
5643 !( sheet->columnFormat( tmpCol )->isHide() && tmpCol == 1 ) )
5645 setCursor( splitHCursor );
5651 setCursor( arrowCursor );
5656void HBorder::doAutoScroll()
5658 if ( !m_bMousePressed )
5660 m_scrollTimer->stop();
5664 TQPoint pos( mapFromGlobal( TQCursor::pos() ) );
5666 if ( pos.x() < 0 || pos.x() > width() )
5668 TQMouseEvent *
event =
new TQMouseEvent( TQEvent::MouseMove, pos, 0, 0 );
5669 mouseMoveEvent( event );
5674 m_scrollTimer->start( 50 );
5677void HBorder::wheelEvent( TQWheelEvent* _ev )
5679 if ( m_pCanvas->horzScrollBar() )
5680 TQApplication::sendEvent( m_pCanvas->horzScrollBar(), _ev );
5683void HBorder::resizeEvent( TQResizeEvent* _ev )
5688 if ( m_pCanvas->
activeSheet() && m_pCanvas->
activeSheet()->layoutDirection()==Sheet::RightToLeft && !TQApplication::reverseLayout() )
5690 int dx = _ev->size().width() - _ev->oldSize().width();
5693 else if ( m_pCanvas->
activeSheet() && m_pCanvas->
activeSheet()->layoutDirection()==Sheet::LeftToRight && TQApplication::reverseLayout() )
5695 int dx = _ev->size().width() - _ev->oldSize().width();
5700void HBorder::paintSizeIndicator(
int mouseX,
bool firstTime )
5707 painter.begin( m_pCanvas );
5708 painter.setRasterOp( NotROP );
5711 painter.drawLine( m_iResizePos, 0, m_iResizePos, m_pCanvas->height() );
5713 if ( sheet->layoutDirection()==Sheet::RightToLeft )
5714 m_iResizePos = mouseX + m_pCanvas->width() - width();
5716 m_iResizePos = mouseX;
5719 int x = m_pCanvas->d->view->doc()->zoomItX( sheet->dblColumnPos( m_iResizedColumn ) - m_pCanvas->
xOffset() );
5721 if ( sheet->layoutDirection()==Sheet::RightToLeft )
5723 x = m_pCanvas->width() - x;
5725 if ( m_iResizePos > x - 2 )
5730 if ( m_iResizePos < x + 2 )
5734 painter.drawLine( m_iResizePos, 0, m_iResizePos, m_pCanvas->height() );
5739 if ( m_iResizePos != x )
5740 tmpSize = i18n(
"Width: %1 %2")
5741 .arg( TDEGlobal::locale()->formatNumber( KoUnit::toUserValue( m_pCanvas->doc()->unzoomItX( (sheet->layoutDirection()==Sheet::RightToLeft) ? x - m_iResizePos : m_iResizePos - x ),
5742 m_pView->doc()->unit() )))
5743 .arg( m_pView->doc()->unitName() );
5745 tmpSize = i18n(
"Hide Column" );
5747 painter.begin(
this );
5748 int len = painter.fontMetrics().width( tmpSize );
5749 int hei = painter.fontMetrics().height();
5754 m_lSize =
new TQLabel( m_pCanvas );
5756 if ( sheet->layoutDirection()==Sheet::RightToLeft )
5757 m_lSize->setGeometry( x - len - 5, 3, len + 2, hei + 2 );
5759 m_lSize->setGeometry( x + 3, 3, len + 2, hei + 2 );
5761 m_lSize->setAlignment( TQt::AlignVCenter );
5762 m_lSize->setText( tmpSize );
5763 m_lSize->setPalette( TQToolTip::palette() );
5768 if ( sheet->layoutDirection()==Sheet::RightToLeft )
5769 m_lSize->setGeometry( x - len - 5, 3, len + 2, hei + 2 );
5771 m_lSize->setGeometry( x + 3, 3, len + 2, hei + 2 );
5773 m_lSize->setText( tmpSize );
5777void HBorder::updateColumns(
int from,
int to )
5783 int x0 = sheet->columnPos( from, m_pCanvas );
5784 int x1 = sheet->columnPos( to+1, m_pCanvas );
5785 update( x0, 0, x1-x0, height() );
5788void HBorder::paintEvent( TQPaintEvent* _ev )
5795 TQPainter painter(
this );
5796 TQPen pen( TQt::black, 1 );
5797 painter.setPen( pen );
5798 painter.setBackgroundColor( white );
5800 painter.setClipRect( _ev->rect() );
5812 if ( sheet->layoutDirection()==Sheet::RightToLeft )
5815 x = sheet->leftColumn(
int( m_pCanvas->d->view->doc()->unzoomItX( width() ) - m_pCanvas->d->view->doc()->unzoomItX( _ev->rect().x() ) + m_pCanvas->
xOffset() ), xPos );
5817 xPos = m_pCanvas->d->view->doc()->unzoomItX( width() ) - xPos + m_pCanvas->
xOffset();
5822 x = sheet->leftColumn(
int( m_pCanvas->d->view->doc()->unzoomItX( _ev->rect().x() ) + m_pCanvas->
xOffset() ), xPos );
5824 xPos = xPos - m_pCanvas->
xOffset();
5827 int height = m_pCanvas->d->view->doc()->zoomItY( TQFont(painter.font()).pointSizeFloat() + 5 );
5829 TQFont normalFont = painter.font();
5830 if ( m_pCanvas->d->view->doc()->zoom() < 100 )
5832 normalFont.setPointSizeFloat( 0.01 * m_pCanvas->d->view->doc()->zoom() *
5833 normalFont.pointSizeFloat() );
5835 TQFont boldFont = normalFont;
5836 boldFont.setBold(
true );
5838 if ( sheet->layoutDirection()==Sheet::RightToLeft )
5840 if ( x > KS_colMax )
5843 xPos -= sheet->columnFormat( x )->dblWidth();
5846 while ( xPos <= m_pCanvas->d->view->doc()->unzoomItX( _ev->rect().right() ) )
5848 bool selected = (m_pView->selectionInfo()->isColumnSelected(x));
5849 bool highlighted = (!selected && m_pView->selectionInfo()->isColumnAffected(x));
5851 const ColumnFormat * col_lay = sheet->columnFormat( x );
5852 int zoomedXPos = m_pCanvas->d->view->doc()->zoomItX( xPos );
5853 int width = m_pCanvas->d->view->doc()->zoomItX( xPos + col_lay->dblWidth() ) - zoomedXPos;
5857 TQBrush fillSelected( highlightColor );
5858 qDrawPlainRect ( &painter, zoomedXPos, 0, width+1, height, highlightColor.dark(150),
5861 else if ( highlighted )
5863 TQBrush fillHighlighted( highlightColor );
5864 qDrawPlainRect ( &painter, zoomedXPos, 0, width+1, height, highlightColor.dark(150),
5865 1, &fillHighlighted );
5869 TQColor c = colorGroup().background();
5871 qDrawPlainRect ( &painter, zoomedXPos, 0, width+1, height, c.dark(150),
5876 painter.setFont( normalFont );
5877 painter.setPen( colorGroup().text() );
5880 painter.setPen( colorGroup().highlightedText() );
5881 else if ( highlighted )
5882 painter.setFont( boldFont );
5883 if ( !m_pView->activeSheet()->getShowColumnNumber() )
5886 int len = painter.fontMetrics().width( colText );
5887 if ( !col_lay->isHide() )
5888 painter.drawText( zoomedXPos + ( width - len ) / 2,
5889 ( height + painter.fontMetrics().ascent() -
5890 painter.fontMetrics().descent() ) / 2, colText );
5895 int len = painter.fontMetrics().width( tmp.setNum(x) );
5896 if (!col_lay->isHide())
5897 painter.drawText( zoomedXPos + ( width - len ) / 2,
5898 ( height + painter.fontMetrics().ascent() -
5899 painter.fontMetrics().descent() ) / 2,
5902 xPos += col_lay->dblWidth();
5909 while ( xPos <= m_pCanvas->d->view->doc()->unzoomItX( _ev->rect().right() ) )
5911 bool selected = (m_pView->selectionInfo()->isColumnSelected(x));
5912 bool highlighted = (!selected && m_pView->selectionInfo()->isColumnAffected(x));
5914 const ColumnFormat *col_lay = sheet->columnFormat( x );
5915 int zoomedXPos = m_pCanvas->d->view->doc()->zoomItX( xPos );
5916 int width = m_pCanvas->d->view->doc()->zoomItX( xPos + col_lay->dblWidth() ) - zoomedXPos;
5920 TQBrush fillSelected( highlightColor );
5921 qDrawPlainRect ( &painter, zoomedXPos, 0, width+1, height, highlightColor.dark(),
5924 else if ( highlighted )
5926 TQBrush fillHighlighted( highlightColor );
5927 qDrawPlainRect ( &painter, zoomedXPos, 0, width+1, height, highlightColor.dark(),
5928 1, &fillHighlighted );
5932 TQColor c = colorGroup().background();
5934 qDrawPlainRect ( &painter, zoomedXPos, 0, width+1, height, c.dark(150),
5939 painter.setFont( normalFont );
5940 painter.setPen( colorGroup().text() );
5943 painter.setPen( colorGroup().highlightedText() );
5944 else if ( highlighted )
5945 painter.setFont( boldFont );
5946 if ( !m_pView->activeSheet()->getShowColumnNumber() )
5949 int len = painter.fontMetrics().width( colText );
5950 if (!col_lay->isHide())
5951 painter.drawText( zoomedXPos + ( width - len ) / 2,
5952 ( height + painter.fontMetrics().ascent() -
5953 painter.fontMetrics().descent() ) / 2, colText );
5958 int len = painter.fontMetrics().width( tmp.setNum(x) );
5959 if (!col_lay->isHide())
5960 painter.drawText( zoomedXPos + ( width - len ) / 2,
5961 ( height + painter.fontMetrics().ascent() -
5962 painter.fontMetrics().descent() ) / 2,
5965 xPos += col_lay->dblWidth();
5972void HBorder::focusOutEvent( TQFocusEvent* )
5974 if ( m_scrollTimer->isActive() )
5975 m_scrollTimer->stop();
5976 m_bMousePressed =
false;
5985ToolTip::ToolTip(
Canvas* canvas )
5986 : TQToolTip( canvas ), m_canvas( canvas )
5992TQLabel *tip_findLabel()
5994 TQWidgetList *list = TQApplication::allWidgets();
5995 TQWidgetListIt it( *list );
5997 while ( (w=it.current()) != 0 )
5999 if(w->isA(
"TQTipLabel"))
6000 return static_cast<TQLabel*
>(w);
6015 double dwidth = m_canvas->doc()->unzoomItX( m_canvas->width() );
6017 if ( sheet->layoutDirection()==Sheet::RightToLeft )
6018 col = sheet->leftColumn( (dwidth - m_canvas->doc()->unzoomItX( p.x() ) +
6021 col = sheet->leftColumn( (m_canvas->doc()->unzoomItX( p.x() ) +
6025 int row = sheet->topRow( (m_canvas->doc()->unzoomItY( p.y() ) +
6028 const Cell* cell = sheet->visibleCellAt( col, row );
6034 if( cell->strOutText().isEmpty() )
6042 TQString comment = cell->
format()->comment( col, row );
6045 if ( cell->testFlag( Cell::Flag_CellTooShortX ) ||
6046 cell->testFlag( Cell::Flag_CellTooShortY ) )
6048 tipText = cell->strOutText();
6052 if ( tipText.isEmpty() )
6054 tipText = cell->
link();
6058 if ( tipText.isEmpty() && comment.isEmpty() )
6062 const unsigned maxLen = 256;
6063 if ( tipText.length() > maxLen )
6064 tipText = tipText.left(maxLen).append(
"...");
6074 const int moveX = cell->
column();
6075 const int moveY = cell->
row();
6080 xpos = sheet->dblColumnPos( moveX );
6081 ypos = sheet->dblRowPos( moveY );
6086 bool insideMarker =
false;
6088 if ( sheet->layoutDirection()==Sheet::RightToLeft )
6090 KoRect unzoomedMarker( dwidth - u - xpos + m_canvas->
xOffset(),
6095 marker = m_canvas->doc()->zoomRect( unzoomedMarker );
6096 insideMarker = marker.contains( p );
6100 KoRect unzoomedMarker( xpos - m_canvas->
xOffset(),
6105 marker = m_canvas->doc()->zoomRect( unzoomedMarker );
6106 insideMarker = marker.contains( p );
6110 if ( !insideMarker )
6115 TQLabel* tipLabel = tip_findLabel();
6120 tipLabel->setTextFormat( TQt::PlainText );
6122 TQFontMetrics fm = tipLabel ? tipLabel->fontMetrics() : m_canvas->fontMetrics();
6123 const TQRect r( 0, 0, 200, -1 );
6125 if ( tipText.length() > 16 )
6127 KWordWrap* wrap = KWordWrap::formatText( fm, r, 0, tipText );
6128 tipText = wrap->wrappedString();
6132 if ( comment.length() > 16 )
6134 KWordWrap* wrap = KWordWrap::formatText( fm, r, 0, comment );
6135 comment = wrap->wrappedString();
6140 if ( tipText.isEmpty() )
6144 else if ( !comment.isEmpty() )
6147 if ( !comment.isEmpty() )
6148 comment =
"\n\n" + i18n(
"Comment:") +
"\n" + comment;
6154 tip( marker, tipText );
6160 tipLabel = tip_findLabel();
6162 tipLabel->setTextFormat( TQt::PlainText );
6167#include "kspread_canvas.moc"
The canvas builds a part of the GUI of KSpread.
int markerRow() const
convenience function.
TQPoint marker() const
convenience function.
TQRect visibleCells() const
bool highlightRangeSizeGripAt(double x, double y)
Checks to see if there is a size grip for a highlight range at a given position.
void moveObjectsByMouse(KoPoint &pos, bool keepXorYunchanged)
Move object by mouse.
void closeEditor()
Close the cell editor and saves changes.
double autoScrollAccelerationY(int offset)
Depending on the offset in "zoomed" screen pixels for the vertical direction, the function returns th...
void scrollToCell(TQPoint location) const
Makes sure a cell is visible onscreen by scrolling up/down and left/right.
void validateSelection()
Validates the selected cell.
void deleteEditor(bool saveChanges, bool array=false)
Deletes the current cell editor.
void lowerObject()
Don't display an object above the others.
void displayObjectList(TQPtrList< EmbeddedObject > &list)
Get the list of objects in the order they should be displayed.
const TQPen & defaultGridPen() const
void finishResizeObject(const TQString &name, bool layout=true)
create KPrResizeCmd
void setXOffset(double _xOffset)
Sets the width of the columns before the current screen.
void setChooseMode(bool state)
Switches the choose mode on and off.
void resizeObject(ModifyType _modType, const KoPoint &point, bool keepRatio)
resize the m_resizeObject
int markerColumn() const
convenience function.
void paintUpdates()
Paint all visible cells that have a paint dirty flag set.
void raiseObject(EmbeddedObject *object)
Display object above the other objects in editiong mode.
void endChoose()
Switches to selection mode.
MouseActions
The current action associated with the mouse.
@ ResizeCell
Merging cell.
@ NoAction
No mouse action (default)
@ ResizeSelection
Resizing the selection.
void startChoose()
Switches to choose mode and sets the initial selection to the position returned by marker().
void createEditor(bool captureArrowKeys=false)
Chooses the correct EditorType by looking at the current cells value.
Selection * choice() const
void setYOffset(double _yOffset)
Sets the height of the rows before the current screen.
double zoom() const
convenience function
Selection * selectionInfo() const
Sheet * findSheet(const TQString &_name) const
convenience function
void copyOasisObjects()
This is intended to copy the selected objects to the clipboard so that they can be pasted into other ...
void updatePosWidget()
Updates the position widget.
void setLastEditorWithFocus(EditorType type)
Called from EditWidget and CellEditor if they loose the focus because the user started a "choose sele...
Sheet * activeSheet() const
double autoScrollAccelerationX(int offset)
Depending on the offset in "zoomed" screen pixels for the horizontal direction, the function returns ...
For every cell in the spread sheet there is a Cell object.
double dblHeight(int _row=-1, const Canvas *_canvas=0L) const
const TQPen & effBottomBorderPen(int col, int row) const
TQString link() const
Returns the link associated with cell.
bool calc(bool delay=true)
Starts calculating.
TQString text() const
Return the text the user entered.
TQString name() const
Returns the name of the cell.
int row() const
Returns the cell's row.
void setRightBorderPen(const TQPen &p)
void convertToDate()
converts content to date format
TQValueList< Cell * > obscuringCells() const
int column() const
Returns the cell's column.
bool calcDirtyFlag()
Checks the calcDirtyFlag.
void paintCell(const KoRect &rect, TQPainter &painter, View *view, const KoPoint &coordinate, const TQPoint &cellRef, int paintBorder, TQPen &rightPen, TQPen &bottomPen, TQPen &leftPen, TQPen &topPen, TQValueList< TQPoint > &mergedCellsPainted, bool drawCursor=true)
Paints the cell.
bool isEmpty() const
Returns true if this cell has no content, i.e no text and no formula.
uint effRightBorderValue(int col, int row) const
const TQPen & effTopBorderPen(int col, int row) const
void setTopBorderPen(const TQPen &p)
const TQPen & effRightBorderPen(int col, int row) const
void convertToPercent()
converts content to percentageformat
bool isFormula() const
Returns true if this cell holds a formula.
uint effLeftBorderValue(int col, int row) const
uint effTopBorderValue(int col, int row) const
void convertToMoney()
converts content to money format
const TQPen & effLeftBorderPen(int col, int row) const
Format * format() const
Returns the format object of this cell.
void setBottomBorderPen(const TQPen &p)
void convertToTime()
converts content to time format
void makeLayout(TQPainter &_painter, int _col, int _row)
Calculates the layout of the cell, i,e, determines what should be shown for this cell,...
double dblWidth(int _col=-1, const Canvas *_canvas=0L) const
uint effBottomBorderValue(int col, int row) const
void convertToDouble()
converts content to double format
TQString columnName() const
Returns the column name of the cell.
bool isDefault() const
Returns true if this is a default cell (with row and column equal to zero).
const TQColor & bgColor(int col, int row) const
bool isPartOfMerged() const
If this cell is part of a merged cell, then the marker may never reside on this cell.
void setLeftBorderPen(const TQPen &p)
This class holds the data that makes up a spreadsheet.
void addCommand(KCommand *command)
Adds a command to the command history.
TQString unitName() const
Returns the name of the unit used to display margins.
Holds an embedded koffice object.
Contains basic information for every object.
The one for all class for points and ranges.
This is a class for handling clipboard data.
The View class displays a KSpread document.
ComboboxLocationEditWidget * posWidget() const
Returns the location widget.
static TQColor highlightColor()
Returns the default color for highlighting cells and column / row headers.
void resetInsertHandle()
Resets the internal handle pointer, called from InsertHandler destructor.
void updateEditWidget()
Fills the EditWidget with the current cells content.