kspread

kspread_canvas.h

00001 /* This file is part of the KDE project
00002 
00003    Copyright 2006 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
00004    Copyright 1999-2002,2004 Laurent Montel <montel@kde.org>
00005    Copyright 2002-2005 Ariya Hidayat <ariya@kde.org>
00006    Copyright 1999-2001,2003 David Faure <faure@kde.org>
00007    Copyright 2001-2003 Philipp Mueller <philipp.mueller@gmx.de>
00008    Copyright 2002-2003 Norbert Andres <nandres@web.de>
00009    Copyright 2000-2001 Werner Trobin <trobin@kde.org>
00010    Copyright 2002 Harri Porten <porten@kde.org>
00011    Copyright 2002 John Dailey <dailey@vt.edu>
00012    Copyright 1999-2000 Torben Weis <weis@kde.org>
00013    Copyright 2000 Wilco Greven <greven@kde.org>
00014    Copyright 1999 Boris Wedl <boris.wedl@kfunigraz.ac.at>
00015    Copyright 1999 Reginald Stadlbauer <reggie@kde.org>
00016 
00017    This library is free software; you can redistribute it and/or
00018    modify it under the terms of the GNU Library General Public
00019    License as published by the Free Software Foundation; either
00020    version 2 of the License, or (at your option) any later version.
00021 
00022    This library is distributed in the hope that it will be useful,
00023    but WITHOUT ANY WARRANTY; without even the implied warranty of
00024    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00025    Library General Public License for more details.
00026 
00027    You should have received a copy of the GNU Library General Public License
00028    along with this library; see the file COPYING.LIB.  If not, write to
00029    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00030  * Boston, MA 02110-1301, USA.
00031 */
00032 
00033 #ifndef KSPREAD_CANVAS
00034 #define KSPREAD_CANVAS
00035 
00036 #include <vector>
00037 
00038 #include <qlineedit.h>
00039 #include <qtooltip.h>
00040 #include <qpen.h>
00041 
00042 #include <ksharedptr.h>
00043 
00044 #include <koffice_export.h>
00045 
00046 #include "kspread_util.h"
00047 
00048 #define YBORDER_WIDTH 50
00049 #define XBORDER_HEIGHT 20
00050 
00051 class QWidget;
00052 class QTimer;
00053 class QButton;
00054 class QPainter;
00055 class QLabel;
00056 class QScrollBar;
00057 class KoRect;
00058 class KoPoint;
00059 
00060 namespace KSpread
00061 {
00062 
00063 class Cell;
00064 class EditWidget;
00065 class Canvas;
00066 class HBorder;
00067 class VBorder;
00068 class Sheet;
00069 class Doc;
00070 class Point;
00071 class Range;
00072 class Region;
00073 class View;
00074 class Selection;
00075 class CellEditor;
00076 class LocationEditWidget;
00077 class ComboboxLocationEditWidget;
00078 class EmbeddedObject;
00079 
00080 
00089 class KSPREAD_EXPORT Canvas : public QWidget
00090 {
00091     friend class HBorder;
00092     friend class VBorder;
00093     friend class View;
00094 
00095     Q_OBJECT
00096 public:
00101     enum MouseActions
00102     {
00104       NoAction,
00106       Mark,
00108       ResizeCell,
00110       AutoFill,
00112       ResizeSelection
00113     };
00114     enum EditorType { CellEditor, EditWidget };
00115 
00116     Canvas (View *_view);
00117     ~Canvas( );
00118 
00119     View* view() const;
00120     Doc* doc() const;
00121 
00122     KSpread::EditWidget* editWidget() const;
00123     KSpread::CellEditor* editor() const;
00124 
00128     Selection* selectionInfo() const;
00132     Selection* choice() const;
00133 
00140     QRect selection() const;
00146     QPoint marker() const;
00152     int markerColumn() const;
00158     int markerRow() const;
00159 
00163     const QPen& defaultGridPen() const;
00164 
00169     double zoom() const;
00170 
00174     double xOffset() const;
00178     double yOffset() const;
00182     void  setXOffset( double _xOffset );
00186     void  setYOffset( double _yOffset );
00187 
00191     QRect visibleCells() const;
00192 
00196     Sheet* activeSheet() const;
00201     Sheet* findSheet( const QString& _name ) const;
00202 
00203 
00207     void validateSelection();
00208 
00209 
00213     void paintUpdates();
00214 
00215 
00221     void scrollToCell(QPoint location) const;
00226     void createEditor( bool captureArrowKeys=false );
00227     bool createEditor( EditorType type, bool addFocus = true, bool captureArrowKeys=false );
00237     void deleteEditor(bool saveChanges, bool array = false);
00238 
00246     void setLastEditorWithFocus( EditorType type );
00247 
00253     void startChoose();
00257     void startChoose( const QRect& selection );
00262     void endChoose();
00267     void setChooseMode(bool state);
00271     bool chooseMode() const;
00272 
00273     void equalizeRow();
00274     void equalizeColumn();
00275 
00279     void updatePosWidget();
00284     void closeEditor();
00285 
00286     // Created by the view since it's layout is managed there,
00287     // but is in fact a sibling of the canvas, which needs to know about it.
00288     void setEditWidget( KSpread::EditWidget * ew );
00289 
00290     virtual bool focusNextPrevChild( bool );
00291 
00298     double autoScrollAccelerationX( int offset );
00305     double autoScrollAccelerationY( int offset );
00306 
00307     //TODO: These embedded-object related methods need API documentation!
00308     EmbeddedObject* getObject( const QPoint &pos, Sheet *_sheet );
00309     void selectAllObjects();
00310     void deselectAllObjects();
00311     void selectObject( EmbeddedObject* );
00312     void deselectObject( EmbeddedObject* );
00313     void setMouseSelectedObject(bool b);
00314     bool isObjectSelected();
00315 
00322     void moveObjectsByMouse( KoPoint &pos, bool keepXorYunchanged );
00323 
00324     //---- stuff needed for resizing ----
00326     void resizeObject( ModifyType _modType, const KoPoint & point, bool keepRatio );
00328     void finishResizeObject( const QString &name, bool layout = true );
00329 
00338     void raiseObject( EmbeddedObject *object );
00342     void lowerObject();
00352     void displayObjectList( QPtrList<EmbeddedObject> &list );
00353 
00354     KoRect objectRect( bool all ) const;
00355 
00356     void repaintObject( EmbeddedObject *obj );
00357 
00364     void copyOasisObjects();
00365     //void insertOasisData();
00366 
00367 public slots:
00368     void slotScrollVert( int _value );
00369     void slotScrollHorz( int _value );
00370 
00371     void slotMaxColumn( int _max_column );
00372     void slotMaxRow( int _max_row );
00373 
00374 signals:
00375     void objectSelectedChanged();
00376     void objectSizeChanged();
00377 
00378 protected:
00379     virtual void keyPressEvent ( QKeyEvent* _ev );
00380     virtual void paintEvent ( QPaintEvent* _ev );
00381     virtual void mousePressEvent( QMouseEvent* _ev );
00382     virtual void mouseReleaseEvent( QMouseEvent* _ev );
00383     virtual void mouseMoveEvent( QMouseEvent* _ev );
00384     virtual void mouseDoubleClickEvent( QMouseEvent* );
00385     virtual void wheelEvent( QWheelEvent* );
00386     virtual void focusInEvent( QFocusEvent* );
00387     virtual void focusOutEvent( QFocusEvent* );
00388     virtual void resizeEvent( QResizeEvent * _ev );
00389     virtual void dragMoveEvent(QDragMoveEvent * _ev);
00390     virtual void dropEvent(QDropEvent * _ev);
00391     virtual void dragLeaveEvent(QDragLeaveEvent * _ev);
00392 
00402     bool highlightRangeSizeGripAt(double x, double y);
00403 
00404 private slots:
00405 
00409     void slotAutoScroll(const QPoint &scrollDist);
00410 
00411     void doAutoScroll();
00412     void speakCell(QWidget* w, const QPoint& p, uint flags);
00413 
00414 private:
00415     virtual bool eventFilter( QObject *o, QEvent *e );
00416 
00417     HBorder* hBorderWidget() const;
00418     VBorder* vBorderWidget() const;
00419     QScrollBar* horzScrollBar() const;
00420     QScrollBar* vertScrollBar() const;
00421 
00428     QRect painterWindowGeometry( const QPainter& painter ) const;
00429     
00435     void clipoutChildren( QPainter& painter ) const;
00436 
00443     QRect cellsInArea( const QRect area ) const;
00444     
00448     void paintChildren( QPainter& painter, QWMatrix& matrix );
00449 
00453     EditorType lastEditorWithFocus() const;
00454 
00455 private:
00456   void moveObject( int x, int y, bool key );
00457 
00458   void startTheDrag();
00459 
00460   /* helpers for the paintUpdates function */
00461   void paintNormalMarker(QPainter& painter, const KoRect &viewRect);
00462 
00469   void paintHighlightedRanges(QPainter& painter, const KoRect& viewRect);
00470 
00482   void sheetAreaToVisibleRect( const QRect& sheetArea,
00483                    KoRect& visibleRect ); 
00484 
00493   void sheetAreaToRect( const QRect& sheetArea, KoRect& rect );
00494 
00495 
00510   void retrieveMarkerInfo( const QRect &marker, const KoRect &viewRect,
00511                            double positions[], bool paintSides[] );
00512 
00513 
00514 
00515 
00516   bool formatKeyPress( QKeyEvent * _ev );
00517 
00519   bool formatCellByKey(Cell *cell, int key, const QRect &rect);
00520 
00521   void processClickSelectionHandle(QMouseEvent *event);
00522   void processLeftClickAnchor();
00523 
00524 
00526   QPoint cursorPos();
00527 
00531   QRect moveDirection(KSpread::MoveTo direction, bool extendSelection);
00532 
00533   void processEnterKey(QKeyEvent *event);
00534   void processArrowKey(QKeyEvent *event);
00535   void processEscapeKey(QKeyEvent *event);
00536   bool processHomeKey(QKeyEvent *event);
00537   bool processEndKey(QKeyEvent *event);
00538   bool processPriorKey(QKeyEvent *event);
00539   bool processNextKey(QKeyEvent *event);
00540   void processDeleteKey(QKeyEvent *event);
00541   void processF2Key(QKeyEvent *event);
00542   void processF4Key(QKeyEvent *event);
00543   void processOtherKey(QKeyEvent *event);
00544   bool processControlArrowKey(QKeyEvent *event);
00545 
00546   void processIMEvent( QIMEvent * event );
00547 
00553   void updateEditor();
00554 
00563   void setSelectionChangePaintDirty(Sheet* sheet, const Region& changedRegion);
00564 
00565 private:
00566   class Private;
00567   Private* d;
00568 };
00569 
00570 
00571 
00575 class HBorder : public QWidget
00576 {
00577     Q_OBJECT
00578 public:
00579     HBorder( QWidget *_parent, Canvas *_canvas, View *_view  );
00580     ~HBorder();
00581 
00582     int markerColumn() const { return  m_iSelectionAnchor; }
00583     void equalizeColumn( double resize );
00584 
00585     void updateColumns( int from, int to );
00586 
00587     QSize sizeHint() const;
00588 
00589 private slots:
00590     void doAutoScroll();
00591 
00592 protected:
00593     virtual void paintEvent ( QPaintEvent* _ev );
00594     virtual void mousePressEvent( QMouseEvent* _ev );
00595     virtual void mouseReleaseEvent( QMouseEvent* _ev );
00596     virtual void mouseDoubleClickEvent( QMouseEvent* _ev );
00597     virtual void mouseMoveEvent( QMouseEvent* _ev );
00598     virtual void wheelEvent( QWheelEvent* );
00599     virtual void focusOutEvent( QFocusEvent* ev );
00600     virtual void resizeEvent( QResizeEvent * _ev );
00601     void paintSizeIndicator( int mouseX, bool firstTime );
00602 
00603 private:
00604     Canvas *m_pCanvas;
00605     View *m_pView;
00606     QTimer * m_scrollTimer;
00607 
00614     bool m_bSelection;
00615 
00621     int m_iSelectionAnchor;
00622 
00628     bool m_bResize;
00629 
00636     int m_iResizedColumn;
00637 
00641     int m_iResizePos;
00642 
00646     QLabel *m_lSize;
00647 
00651     bool m_bMousePressed;
00652 
00653 private:
00654 };
00655 
00656 
00657 
00661 class VBorder : public QWidget
00662 {
00663     Q_OBJECT
00664 public:
00665     VBorder( QWidget *_parent, Canvas *_canvas, View *_view );
00666     ~VBorder();
00667 
00668     int markerRow() const { return  m_iSelectionAnchor; }
00669     void equalizeRow( double resize );
00670     void updateRows( int from, int to );
00671 
00672     QSize sizeHint() const;
00673 
00674 private slots:
00675     void doAutoScroll();
00676 
00677 protected:
00678     virtual void paintEvent ( QPaintEvent* _ev );
00679     virtual void mousePressEvent( QMouseEvent* _ev );
00680     virtual void mouseReleaseEvent( QMouseEvent* _ev );
00681     virtual void mouseMoveEvent( QMouseEvent* _ev );
00682     virtual void mouseDoubleClickEvent( QMouseEvent* _ev );
00683     virtual void wheelEvent( QWheelEvent* );
00684     virtual void focusOutEvent( QFocusEvent* ev );
00685     void paintSizeIndicator( int mouseY, bool firstTime );
00686 
00687 private:
00688     Canvas *m_pCanvas;
00689     View *m_pView;
00690     QTimer * m_scrollTimer;
00691 
00692     bool m_bSelection;
00693     int m_iSelectionAnchor;
00694     bool m_bResize;
00695     int m_iResizedRow;
00696     int m_iResizePos;
00700     QLabel *m_lSize;
00701 
00705     bool m_bMousePressed;
00706 };
00707 
00708 
00709 
00713 class ToolTip : public QToolTip
00714 {
00715 public:
00716     ToolTip( Canvas* canvas );
00717 
00718 protected:
00722     void maybeTip( const QPoint& p );
00723 
00724 private:
00725     Canvas* m_canvas;
00726 };
00727 
00728 } // namespace KSpread
00729 
00730 #endif // KSPREAD_CANVAS
KDE Home | KDE Accessibility Home | Description of Access Keys