kspread_canvas.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef KSPREAD_CANVAS
00033 #define KSPREAD_CANVAS
00034
00035 #include <qlineedit.h>
00036 #include <qtooltip.h>
00037 #include <qpen.h>
00038
00039 #include <koQueryTrader.h>
00040 #include <koRect.h>
00041
00042 #include "kspread_util.h"
00043
00044 #include <koffice_export.h>
00045
00046 class KSpreadEditWidget;
00047 class KSpreadCanvas;
00048 class KSpreadHBorder;
00049 class KSpreadVBorder;
00050 class KSpreadSheet;
00051 class KSpreadDoc;
00052 class KSpreadPoint;
00053 class KSpreadRange;
00054 class KSpreadView;
00055 class KSpreadSelection;
00056 class KSpreadCellEditor;
00057 class KSpreadCell;
00058 class QWidget;
00059 class QTimer;
00060 class QButton;
00061 class KSpreadLocationEditWidget;
00062 class KSpreadComboboxLocationEditWidget;
00063 class QPainter;
00064 class QLabel;
00065 class QScrollBar;
00066
00067 #define YBORDER_WIDTH 50
00068 #define XBORDER_HEIGHT 20
00069
00070 class CanvasPrivate;
00071
00080 class KSPREAD_EXPORT KSpreadCanvas : public QWidget
00081 {
00082 friend class KSpreadHBorder;
00083 friend class KSpreadVBorder;
00084 friend class KSpreadView;
00085
00086 Q_OBJECT
00087 public:
00092 enum MouseActions { NoAction = 0, Mark = 1, ResizeCell = 2, AutoFill = 3 };
00093 enum EditorType { CellEditor, FormulaEditor, EditWidget };
00094
00095 KSpreadCanvas (KSpreadView *_view);
00096 ~KSpreadCanvas( );
00097
00098 KSpreadView* view();
00099 KSpreadDoc* doc();
00100
00105 void init();
00106
00107 KSpreadEditWidget* editWidget() const;
00108 KSpreadCellEditor* editor() const;
00109
00110
00117 int chooseTextLen() const;
00118
00119 KSpreadSelection* selectionInfo() const;
00120 QRect selection() const;
00121 QPoint marker() const;
00122 int markerColumn() const;
00123 int markerRow() const;
00124
00125 void updateCellRect( const QRect &_rect );
00126 void updateSelection( const QRect& oldSelection, const QPoint& oldMarker );
00127
00128 const QPen& defaultGridPen() const;
00129
00130 double zoom() const;
00131
00135 double xOffset() const;
00139 double yOffset() const;
00140
00144 QRect visibleCells();
00145
00146 KSpreadSheet* activeSheet() const;
00147 KSpreadSheet* findSheet( const QString& _name ) const;
00148
00152 bool gotoLocation( const KSpreadRange & _range );
00156 bool gotoLocation( const KSpreadPoint& _cell );
00157
00174 void gotoLocation( QPoint const & location, KSpreadSheet* sheet = NULL,
00175 bool extendSelection = false);
00176
00180 void gotoLocation( int col, int row, KSpreadSheet* sheet = NULL,
00181 bool extendSelection = false)
00182 {gotoLocation(QPoint(col, row), sheet, extendSelection);}
00183
00184
00188 void paintUpdates();
00189
00190
00196 void scrollToCell(QPoint location);
00201 void createEditor();
00202 bool createEditor( EditorType type, bool addFocus = true );
00211 void deleteEditor( bool saveChanges );
00212
00220 void setLastEditorWithFocus( EditorType type );
00221
00226 void startChoose();
00230 void startChoose( const QRect& selection );
00231 void endChoose();
00232
00233 bool chooseMode() const;
00234
00238 void adjustArea(bool makeUndo=true);
00239
00240 void equalizeRow();
00241 void equalizeColumn();
00242
00243 void updatePosWidget();
00244
00245 void closeEditor();
00246
00247
00248
00249 void setEditWidget( KSpreadEditWidget * ew );
00250
00251 virtual bool focusNextPrevChild( bool );
00252
00253 bool chooseFormulaArea() const { return chooseMode();}
00254
00261 double autoScrollAccelerationX( int offset );
00268 double autoScrollAccelerationY( int offset );
00269
00270 public slots:
00271 void slotScrollVert( int _value );
00272 void slotScrollHorz( int _value );
00273
00274 void slotMaxColumn( int _max_column );
00275 void slotMaxRow( int _max_row );
00276
00277 protected:
00278 virtual void keyPressEvent ( QKeyEvent* _ev );
00279 virtual void paintEvent ( QPaintEvent* _ev );
00280 virtual void mousePressEvent( QMouseEvent* _ev );
00281 virtual void mouseReleaseEvent( QMouseEvent* _ev );
00282 virtual void mouseMoveEvent( QMouseEvent* _ev );
00283 virtual void mouseDoubleClickEvent( QMouseEvent* );
00284 virtual void wheelEvent( QWheelEvent* );
00285 virtual void focusInEvent( QFocusEvent* );
00286 virtual void focusOutEvent( QFocusEvent* );
00287 virtual void resizeEvent( QResizeEvent * _ev );
00288 virtual void dragMoveEvent(QDragMoveEvent * _ev);
00289 virtual void dropEvent(QDropEvent * _ev);
00290 virtual void dragLeaveEvent(QDragLeaveEvent * _ev);
00291
00292 private slots:
00293 void doAutoScroll();
00294
00295 private:
00296 virtual void chooseMousePressEvent( QMouseEvent* _ev );
00297 virtual void chooseMouseReleaseEvent( QMouseEvent* _ev );
00298 virtual void chooseMouseMoveEvent( QMouseEvent* _ev );
00299
00300 virtual bool eventFilter( QObject *o, QEvent *e );
00301
00302 KSpreadHBorder* hBorderWidget() const;
00303 KSpreadVBorder* vBorderWidget() const;
00304 QScrollBar* horzScrollBar() const;
00305 QScrollBar* vertScrollBar() const;
00306
00307 void drawChooseMarker( );
00308 void drawChooseMarker( const QRect& );
00309
00313 void clipoutChildren( QPainter& painter, QWMatrix& matrix );
00314
00318 void paintChildren( QPainter& painter, QWMatrix& matrix );
00319
00323 EditorType lastEditorWithFocus() const;
00324
00329
00330
00331
00332
00333
00334
00335
00343
00344
00345
00346 private:
00347
00348 void startTheDrag();
00349 void paintSelectionChange(QRect area1, QRect area2);
00350
00356 void ExtendRectBorder(QRect& area);
00357
00358
00359 void paintChooseRect(QPainter& painter, const KoRect &viewRect);
00360
00361 void paintNormalMarker(QPainter& painter, const KoRect &viewRect);
00362
00363 void retrieveMarkerInfo( const QRect &marker, const KoRect &viewRect,
00364 double positions[], bool paintSides[] );
00365
00366
00367
00368 bool formatKeyPress( QKeyEvent * _ev );
00369
00371 bool formatCellByKey (KSpreadCell *cell, int key, const QRect &rect);
00372
00373 void processClickSelectionHandle(QMouseEvent *event);
00374 void processLeftClickAnchor();
00375
00376
00383 void extendCurrentSelection(QPoint cell);
00384
00386 QPoint cursorPos ();
00387
00391 QRect moveDirection(KSpread::MoveTo direction, bool extendSelection);
00392
00393 void processEnterKey(QKeyEvent *event);
00394 void processArrowKey(QKeyEvent *event);
00395 void processEscapeKey(QKeyEvent *event);
00396 bool processHomeKey(QKeyEvent *event);
00397 bool processEndKey(QKeyEvent *event);
00398 bool processPriorKey(QKeyEvent *event);
00399 bool processNextKey(QKeyEvent *event);
00400 void processDeleteKey(QKeyEvent *event);
00401 void processF2Key(QKeyEvent *event);
00402 void processF4Key(QKeyEvent *event);
00403 void processOtherKey(QKeyEvent *event);
00404 bool processControlArrowKey(QKeyEvent *event);
00405
00406 void processIMEvent( QIMEvent * event );
00407
00408 void updateChooseRect(const QPoint &newMarker, const QPoint &newAnchor);
00409
00417 void setSelectionChangePaintDirty(KSpreadSheet* sheet,
00418 QRect area1, QRect area2);
00419
00420 private:
00421 CanvasPrivate* d;
00422
00423 };
00424
00427 class KSpreadHBorder : public QWidget
00428 {
00429 Q_OBJECT
00430 public:
00431 KSpreadHBorder( QWidget *_parent, KSpreadCanvas *_canvas, KSpreadView *_view );
00432 ~KSpreadHBorder();
00433
00434 int markerColumn() const { return m_iSelectionAnchor; }
00435 void resizeColumn( double resize, int nb = -1, bool makeUndo = true );
00436 void adjustColumn( int _col = -1, bool makeUndo = true );
00437 void equalizeColumn( double resize );
00438
00439 void updateColumns( int from, int to );
00440
00441 QSize sizeHint() const;
00442
00443 private slots:
00444 void doAutoScroll();
00445
00446 protected:
00447 virtual void paintEvent ( QPaintEvent* _ev );
00448 virtual void mousePressEvent( QMouseEvent* _ev );
00449 virtual void mouseReleaseEvent( QMouseEvent* _ev );
00450 virtual void mouseDoubleClickEvent( QMouseEvent* _ev );
00451 virtual void mouseMoveEvent( QMouseEvent* _ev );
00452 virtual void wheelEvent( QWheelEvent* );
00453 virtual void focusOutEvent( QFocusEvent* ev );
00454 virtual void resizeEvent( QResizeEvent * _ev );
00455 void paintSizeIndicator( int mouseX, bool firstTime );
00456
00457 private:
00458 KSpreadCanvas *m_pCanvas;
00459 KSpreadView *m_pView;
00460 QTimer * m_scrollTimer;
00461
00468 bool m_bSelection;
00469
00475 int m_iSelectionAnchor;
00476
00482 bool m_bResize;
00483
00490 int m_iResizedColumn;
00491
00495 int m_iResizePos;
00496
00500 QLabel *m_lSize;
00501
00505 bool m_bMousePressed;
00506
00507 private:
00508 };
00509
00512 class KSpreadVBorder : public QWidget
00513 {
00514 Q_OBJECT
00515 public:
00516 KSpreadVBorder( QWidget *_parent, KSpreadCanvas *_canvas, KSpreadView *_view );
00517 ~KSpreadVBorder();
00518
00519 int markerRow() const { return m_iSelectionAnchor; }
00520 void resizeRow( double resize, int nb = -1, bool makeUndo = true );
00521 void adjustRow( int _row = -1, bool makeUndo = true );
00522 void equalizeRow( double resize );
00523 void updateRows( int from, int to );
00524
00525 QSize sizeHint() const;
00526
00527 private slots:
00528 void doAutoScroll();
00529
00530 protected:
00531 virtual void paintEvent ( QPaintEvent* _ev );
00532 virtual void mousePressEvent( QMouseEvent* _ev );
00533 virtual void mouseReleaseEvent( QMouseEvent* _ev );
00534 virtual void mouseMoveEvent( QMouseEvent* _ev );
00535 virtual void mouseDoubleClickEvent( QMouseEvent* _ev );
00536 virtual void wheelEvent( QWheelEvent* );
00537 virtual void focusOutEvent( QFocusEvent* ev );
00538 void paintSizeIndicator( int mouseY, bool firstTime );
00539
00540 private:
00541 KSpreadCanvas *m_pCanvas;
00542 KSpreadView *m_pView;
00543 QTimer * m_scrollTimer;
00544
00545 bool m_bSelection;
00546 int m_iSelectionAnchor;
00547 bool m_bResize;
00548 int m_iResizedRow;
00549 int m_iResizePos;
00553 QLabel *m_lSize;
00554
00558 bool m_bMousePressed;
00559 };
00560
00561
00562
00563
00564 class KSpreadToolTip : public QToolTip
00565 {
00566 public:
00567 KSpreadToolTip( KSpreadCanvas* canvas );
00568
00569 protected:
00573 void maybeTip( const QPoint& p );
00574
00575 private:
00576 KSpreadCanvas* m_canvas;
00577 };
00578
00579 #endif // KSPREAD_CANVAS
This file is part of the documentation for kspread Library Version 1.4.2.