kspread

kspread_canvas.h
1/* This file is part of the KDE project
2
3 Copyright 2006 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
4 Copyright 1999-2002,2004 Laurent Montel <montel@kde.org>
5 Copyright 2002-2005 Ariya Hidayat <ariya@kde.org>
6 Copyright 1999-2001,2003 David Faure <faure@kde.org>
7 Copyright 2001-2003 Philipp Mueller <philipp.mueller@gmx.de>
8 Copyright 2002-2003 Norbert Andres <nandres@web.de>
9 Copyright 2000-2001 Werner Trobin <trobin@kde.org>
10 Copyright 2002 Harri Porten <porten@kde.org>
11 Copyright 2002 John Dailey <dailey@vt.edu>
12 Copyright 1999-2000 Torben Weis <weis@kde.org>
13 Copyright 2000 Wilco Greven <greven@kde.org>
14 Copyright 1999 Boris Wedl <boris.wedl@kfunigraz.ac.at>
15 Copyright 1999 Reginald Stadlbauer <reggie@kde.org>
16
17 This library is free software; you can redistribute it and/or
18 modify it under the terms of the GNU Library General Public
19 License as published by the Free Software Foundation; either
20 version 2 of the License, or (at your option) any later version.
21
22 This library is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 Library General Public License for more details.
26
27 You should have received a copy of the GNU Library General Public License
28 along with this library; see the file COPYING.LIB. If not, write to
29 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
30 * Boston, MA 02110-1301, USA.
31*/
32
33#ifndef KSPREAD_CANVAS
34#define KSPREAD_CANVAS
35
36#include <vector>
37
38#include <tqlineedit.h>
39#include <tqtooltip.h>
40#include <tqpen.h>
41
42#include <ksharedptr.h>
43
44#include <koffice_export.h>
45
46#include "kspread_util.h"
47
48#define YBORDER_WIDTH 50
49#define XBORDER_HEIGHT 20
50
51class TQWidget;
52class TQTimer;
53class TQButton;
54class TQPainter;
55class TQLabel;
56class TQScrollBar;
57class KoRect;
58class KoPoint;
59
60namespace KSpread
61{
62
63class Cell;
64class EditWidget;
65class Canvas;
66class HBorder;
67class VBorder;
68class Sheet;
69class Doc;
70class Point;
71class Range;
72class Region;
73class View;
74class Selection;
75class CellEditor;
76class LocationEditWidget;
77class ComboboxLocationEditWidget;
78class EmbeddedObject;
79
80
89class KSPREAD_EXPORT Canvas : public TQWidget
90{
91 friend class HBorder;
92 friend class VBorder;
93 friend class View;
94
95 TQ_OBJECT
96
97public:
103 {
113 ResizeSelection
114 };
115 enum EditorType { CellEditor, EditWidget };
116
117 Canvas (View *_view);
118 ~Canvas( );
119
120 View* view() const;
121 Doc* doc() const;
122
123 KSpread::EditWidget* editWidget() const;
124 KSpread::CellEditor* editor() const;
125
129 Selection* selectionInfo() const;
133 Selection* choice() const;
134
141 TQRect selection() const;
147 TQPoint marker() const;
153 int markerColumn() const;
159 int markerRow() const;
160
164 const TQPen& defaultGridPen() const;
165
170 double zoom() const;
171
175 double xOffset() const;
179 double yOffset() const;
183 void setXOffset( double _xOffset );
187 void setYOffset( double _yOffset );
188
192 TQRect visibleCells() const;
193
197 Sheet* activeSheet() const;
202 Sheet* findSheet( const TQString& _name ) const;
203
204
208 void validateSelection();
209
210
214 void paintUpdates();
215
216
222 void scrollToCell(TQPoint location) const;
227 void createEditor( bool captureArrowKeys=false );
228 bool createEditor( EditorType type, bool addFocus = true, bool captureArrowKeys=false );
238 void deleteEditor(bool saveChanges, bool array = false);
239
247 void setLastEditorWithFocus( EditorType type );
248
254 void startChoose();
258 void startChoose( const TQRect& selection );
263 void endChoose();
268 void setChooseMode(bool state);
272 bool chooseMode() const;
273
274 void equalizeRow();
275 void equalizeColumn();
276
280 void updatePosWidget();
285 void closeEditor();
286
287 // Created by the view since it's layout is managed there,
288 // but is in fact a sibling of the canvas, which needs to know about it.
289 void setEditWidget( KSpread::EditWidget * ew );
290
291 virtual bool focusNextPrevChild( bool );
292
299 double autoScrollAccelerationX( int offset );
306 double autoScrollAccelerationY( int offset );
307
308 //TODO: These embedded-object related methods need API documentation!
309 EmbeddedObject* getObject( const TQPoint &pos, Sheet *_sheet );
310 void selectAllObjects();
311 void deselectAllObjects();
312 void selectObject( EmbeddedObject* );
313 void deselectObject( EmbeddedObject* );
314 void setMouseSelectedObject(bool b);
315 bool isObjectSelected();
316
323 void moveObjectsByMouse( KoPoint &pos, bool keepXorYunchanged );
324
325 //---- stuff needed for resizing ----
327 void resizeObject( ModifyType _modType, const KoPoint & point, bool keepRatio );
329 void finishResizeObject( const TQString &name, bool layout = true );
330
339 void raiseObject( EmbeddedObject *object );
343 void lowerObject();
353 void displayObjectList( TQPtrList<EmbeddedObject> &list );
354
355 KoRect objectRect( bool all ) const;
356
357 void repaintObject( EmbeddedObject *obj );
358
365 void copyOasisObjects();
366 //void insertOasisData();
367
368public slots:
369 void slotScrollVert( int _value );
370 void slotScrollHorz( int _value );
371
372 void slotMaxColumn( int _max_column );
373 void slotMaxRow( int _max_row );
374
375signals:
376 void objectSelectedChanged();
377 void objectSizeChanged();
378
379protected:
380 virtual void keyPressEvent ( TQKeyEvent* _ev );
381 virtual void paintEvent ( TQPaintEvent* _ev );
382 virtual void mousePressEvent( TQMouseEvent* _ev );
383 virtual void mouseReleaseEvent( TQMouseEvent* _ev );
384 virtual void mouseMoveEvent( TQMouseEvent* _ev );
385 virtual void mouseDoubleClickEvent( TQMouseEvent* );
386 virtual void wheelEvent( TQWheelEvent* );
387 virtual void focusInEvent( TQFocusEvent* );
388 virtual void focusOutEvent( TQFocusEvent* );
389 virtual void resizeEvent( TQResizeEvent * _ev );
390 virtual void dragMoveEvent(TQDragMoveEvent * _ev);
391 virtual void dropEvent(TQDropEvent * _ev);
392 virtual void dragLeaveEvent(TQDragLeaveEvent * _ev);
393
403 bool highlightRangeSizeGripAt(double x, double y);
404
405private slots:
406
410 void slotAutoScroll(const TQPoint &scrollDist);
411
412 void doAutoScroll();
413 void speakCell(TQWidget* w, const TQPoint& p, uint flags);
414
415private:
416 virtual bool eventFilter( TQObject *o, TQEvent *e );
417
418 HBorder* hBorderWidget() const;
419 VBorder* vBorderWidget() const;
420 TQScrollBar* horzScrollBar() const;
421 TQScrollBar* vertScrollBar() const;
422
429 TQRect painterWindowGeometry( const TQPainter& painter ) const;
430
436 void clipoutChildren( TQPainter& painter ) const;
437
444 TQRect cellsInArea( const TQRect area ) const;
445
449 void paintChildren( TQPainter& painter, TQWMatrix& matrix );
450
454 EditorType lastEditorWithFocus() const;
455
456private:
457 void moveObject( int x, int y, bool key );
458
459 void startTheDrag();
460
461 /* helpers for the paintUpdates function */
462 void paintNormalMarker(TQPainter& painter, const KoRect &viewRect);
463
470 void paintHighlightedRanges(TQPainter& painter, const KoRect& viewRect);
471
483 void sheetAreaToVisibleRect( const TQRect& sheetArea,
484 KoRect& visibleRect );
485
494 void sheetAreaToRect( const TQRect& sheetArea, KoRect& rect );
495
496
511 void retrieveMarkerInfo( const TQRect &marker, const KoRect &viewRect,
512 double positions[], bool paintSides[] );
513
514
515
516
517 bool formatKeyPress( TQKeyEvent * _ev );
518
520 bool formatCellByKey(Cell *cell, int key, const TQRect &rect);
521
522 void processClickSelectionHandle(TQMouseEvent *event);
523 void processLeftClickAnchor();
524
525
527 TQPoint cursorPos();
528
532 TQRect moveDirection(KSpread::MoveTo direction, bool extendSelection);
533
534 void processEnterKey(TQKeyEvent *event);
535 void processArrowKey(TQKeyEvent *event);
536 void processEscapeKey(TQKeyEvent *event);
537 bool processHomeKey(TQKeyEvent *event);
538 bool processEndKey(TQKeyEvent *event);
539 bool processPriorKey(TQKeyEvent *event);
540 bool processNextKey(TQKeyEvent *event);
541 void processDeleteKey(TQKeyEvent *event);
542 void processF2Key(TQKeyEvent *event);
543 void processF4Key(TQKeyEvent *event);
544 void processOtherKey(TQKeyEvent *event);
545 bool processControlArrowKey(TQKeyEvent *event);
546
547 void processIMEvent( TQIMEvent * event );
548
554 void updateEditor();
555
564 void setSelectionChangePaintDirty(Sheet* sheet, const Region& changedRegion);
565
566private:
567 class Private;
568 Private* d;
569};
570
571
572
576class HBorder : public TQWidget
577{
578 TQ_OBJECT
579
580public:
581 HBorder( TQWidget *_parent, Canvas *_canvas, View *_view );
582 ~HBorder();
583
584 int markerColumn() const { return m_iSelectionAnchor; }
585 void equalizeColumn( double resize );
586
587 void updateColumns( int from, int to );
588
589 TQSize sizeHint() const;
590
591private slots:
592 void doAutoScroll();
593
594protected:
595 virtual void paintEvent ( TQPaintEvent* _ev );
596 virtual void mousePressEvent( TQMouseEvent* _ev );
597 virtual void mouseReleaseEvent( TQMouseEvent* _ev );
598 virtual void mouseDoubleClickEvent( TQMouseEvent* _ev );
599 virtual void mouseMoveEvent( TQMouseEvent* _ev );
600 virtual void wheelEvent( TQWheelEvent* );
601 virtual void focusOutEvent( TQFocusEvent* ev );
602 virtual void resizeEvent( TQResizeEvent * _ev );
603 void paintSizeIndicator( int mouseX, bool firstTime );
604
605private:
606 Canvas *m_pCanvas;
607 View *m_pView;
608 TQTimer * m_scrollTimer;
609
616 bool m_bSelection;
617
623 int m_iSelectionAnchor;
624
630 bool m_bResize;
631
638 int m_iResizedColumn;
639
643 int m_iResizePos;
644
648 TQLabel *m_lSize;
649
653 bool m_bMousePressed;
654
655private:
656};
657
658
659
663class VBorder : public TQWidget
664{
665 TQ_OBJECT
666
667public:
668 VBorder( TQWidget *_parent, Canvas *_canvas, View *_view );
669 ~VBorder();
670
671 int markerRow() const { return m_iSelectionAnchor; }
672 void equalizeRow( double resize );
673 void updateRows( int from, int to );
674
675 TQSize sizeHint() const;
676
677private slots:
678 void doAutoScroll();
679
680protected:
681 virtual void paintEvent ( TQPaintEvent* _ev );
682 virtual void mousePressEvent( TQMouseEvent* _ev );
683 virtual void mouseReleaseEvent( TQMouseEvent* _ev );
684 virtual void mouseMoveEvent( TQMouseEvent* _ev );
685 virtual void mouseDoubleClickEvent( TQMouseEvent* _ev );
686 virtual void wheelEvent( TQWheelEvent* );
687 virtual void focusOutEvent( TQFocusEvent* ev );
688 void paintSizeIndicator( int mouseY, bool firstTime );
689
690private:
691 Canvas *m_pCanvas;
692 View *m_pView;
693 TQTimer * m_scrollTimer;
694
695 bool m_bSelection;
696 int m_iSelectionAnchor;
697 bool m_bResize;
698 int m_iResizedRow;
699 int m_iResizePos;
703 TQLabel *m_lSize;
704
708 bool m_bMousePressed;
709};
710
711
712
716class ToolTip : public TQToolTip
717{
718public:
719 ToolTip( Canvas* canvas );
720
721protected:
725 void maybeTip( const TQPoint& p );
726
727private:
728 Canvas* m_canvas;
729};
730
731} // namespace KSpread
732
733#endif // KSPREAD_CANVAS
The canvas builds a part of the GUI of KSpread.
MouseActions
The current action associated with the mouse.
@ ResizeCell
Merging cell.
@ NoAction
No mouse action (default)
@ AutoFill
Autofilling.
@ Mark
Marking action.
class CellEditor
The widget that appears above the sheet and allows to edit the cells content.
Tooltip, which displays the comment and cell content, when it's too short.
void maybeTip(const TQPoint &p)
The View class displays a KSpread document.
The KSpread namespace.
Definition commands.h:39