kspread

Canvas.h

Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002    Copyright 2006-2007 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
00003    Copyright 1999-2002,2004 Laurent Montel <montel@kde.org>
00004    Copyright 2002-2005 Ariya Hidayat <ariya@kde.org>
00005    Copyright 1999-2001,2003 David Faure <faure@kde.org>
00006    Copyright 2001-2003 Philipp Mueller <philipp.mueller@gmx.de>
00007    Copyright 2002-2003 Norbert Andres <nandres@web.de>
00008    Copyright 2000-2001 Werner Trobin <trobin@kde.org>
00009    Copyright 2002 Harri Porten <porten@kde.org>
00010    Copyright 2002 John Dailey <dailey@vt.edu>
00011    Copyright 1999-2000 Torben Weis <weis@kde.org>
00012    Copyright 2000 Wilco Greven <greven@kde.org>
00013    Copyright 1999 Boris Wedl <boris.wedl@kfunigraz.ac.at>
00014    Copyright 1999 Reginald Stadlbauer <reggie@kde.org>
00015 
00016    This library is free software; you can redistribute it and/or
00017    modify it under the terms of the GNU Library General Public
00018    License as published by the Free Software Foundation; either
00019    version 2 of the License, or (at your option) any later version.
00020 
00021    This library is distributed in the hope that it will be useful,
00022    but WITHOUT ANY WARRANTY; without even the implied warranty of
00023    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00024    Library General Public License for more details.
00025 
00026    You should have received a copy of the GNU Library General Public License
00027    along with this library; see the file COPYING.LIB.  If not, write to
00028    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00029    Boston, MA 02110-1301, USA.
00030 */
00031 
00032 #ifndef KSPREAD_CANVAS
00033 #define KSPREAD_CANVAS
00034 
00035 #include <QList>
00036 #include <QWidget>
00037 
00038 #include <KoCanvasBase.h>
00039 
00040 #include "kspread_export.h"
00041 
00042 #include "Global.h"
00043 
00044 // Width of row header and height of column headers.  These are not
00045 // part of the styles.
00046 // FIXME: Rename to ROWHEADER_WIDTH and COLHEADER_HEIGHT?
00047 #define YBORDER_WIDTH  35
00048 #define XBORDER_HEIGHT 20
00049 
00050 class QDragLeaveEvent;
00051 class QDragMoveEvent;
00052 class QDropEvent;
00053 class QEvent;
00054 class QFocusEvent;
00055 class QKeyEvent;
00056 class QMouseEvent;
00057 class QPainter;
00058 class QPaintEvent;
00059 class QPen;
00060 class QResizeEvent;
00061 class QScrollBar;
00062 
00063 namespace KSpread
00064 {
00065 class Cell;
00066 class CellEditor;
00067 class Canvas;
00068 class ColumnHeader;
00069 class Doc;
00070 class Sheet;
00071 class RowHeader;
00072 class Selection;
00073 class View;
00074 
00075 
00083 class KSPREAD_EXPORT Canvas : public QWidget, public KoCanvasBase
00084 {
00085     friend class ColumnHeader;
00086     friend class RowHeader;
00087     friend class View;
00088     friend class CellTool;
00089 
00090     Q_OBJECT
00091 
00092 public:
00097     enum MouseActions
00098     {
00099       NoAction,       
00100       Mark,           
00101       ResizeCell,     
00102       AutoFill,       
00103       ResizeSelection 
00104     };
00105 
00106     explicit Canvas( View* view );
00107     ~Canvas();
00108 
00109     View* view() const;
00110     Doc* doc() const;
00111 
00112     // KoCanvasBase interface methods.
00114     virtual void gridSize( qreal* horizontal, qreal* vertical ) const;
00116     virtual bool snapToGrid() const;
00118     virtual void addCommand( QUndoCommand* command );
00120     virtual KoShapeManager* shapeManager() const;
00122     virtual void updateCanvas( const QRectF& rc );
00124     virtual KoToolProxy* toolProxy() const;
00126     virtual const KoViewConverter* viewConverter() const;
00128     virtual QWidget* canvasWidget() { return this; }
00129     virtual const QWidget* canvasWidget() const { return this; }
00131     virtual KoUnit unit() const;
00133     virtual void updateInputMethodInfo();
00134 
00138     KSpread::Selection* selection() const;
00139 
00140     QPointF offset() const;
00141 
00145     double xOffset() const;
00146 
00150     double yOffset() const;
00151 
00155     QRect visibleCells() const;
00156 
00160     Sheet* activeSheet() const;
00161 
00165     void validateSelection();
00166 
00167 
00172     void scrollToCell(const QPoint& location) const;
00173 
00174 public Q_SLOTS:
00175     void setDocumentOffset( const QPoint& offset );
00176     void setDocumentSize( const QSizeF& size );
00177 #if 0
00178     void slotScrollVert( int _value );
00179     void slotScrollHorz( int _value );
00180 
00186     void slotMaxColumn( int maxColumn );
00187 
00193     void slotMaxRow( int maxRow );
00194 #endif
00195 
00196 Q_SIGNALS:
00197     void documentSizeChanged( const QSize& );
00198 
00199 protected:
00200     virtual void keyPressEvent ( QKeyEvent* _ev );
00201     virtual void paintEvent ( QPaintEvent* _ev );
00202     virtual void mousePressEvent( QMouseEvent* _ev );
00203     virtual void mouseReleaseEvent( QMouseEvent* _ev );
00204     virtual void mouseMoveEvent( QMouseEvent* _ev );
00205     virtual void mouseDoubleClickEvent( QMouseEvent* );
00206     virtual void focusInEvent( QFocusEvent* );
00207     virtual void focusOutEvent( QFocusEvent* );
00208     virtual void dragEnterEvent(QDragEnterEvent*);
00209     virtual void dragMoveEvent(QDragMoveEvent*);
00210     virtual void dragLeaveEvent(QDragLeaveEvent*);
00211     virtual void dropEvent(QDropEvent*);
00213     virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
00215     virtual void inputMethodEvent(QInputMethodEvent *event);
00217     virtual void tabletEvent(QTabletEvent *e);
00218 
00228     bool highlightRangeSizeGripAt(double x, double y);
00229 
00230 private slots:
00231 
00235     void slotAutoScroll(const QPoint &scrollDist);
00236 
00237 private:
00238     virtual bool eventFilter( QObject *o, QEvent *e );
00239 
00240     ColumnHeader* columnHeader() const;
00241     RowHeader* rowHeader() const;
00242     QScrollBar* horzScrollBar() const;
00243     QScrollBar* vertScrollBar() const;
00244 
00251     QRect viewToCellCoordinates( const QRectF& area ) const;
00252 
00260     QRectF cellCoordinatesToView( const QRect& cellRange ) const;
00261 
00262 private:
00263   void startTheDrag();
00264 
00269   void showToolTip( const QPoint& point );
00270 
00271 private:
00272     Q_DISABLE_COPY( Canvas )
00273 
00274   class Private;
00275   Private * const d;
00276 };
00277 
00278 } // namespace KSpread
00279 
00280 #endif // KSPREAD_CANVAS