File indexing completed on 2024-05-19 16:08:30
0001 /* This file is part of the KDE project 0002 Copyright 2006-2007 Stefan Nikolaus <stefan.nikolaus@kdemail.net> 0003 Copyright 1999-2002,2004 Laurent Montel <montel@kde.org> 0004 Copyright 2002-2005 Ariya Hidayat <ariya@kde.org> 0005 Copyright 1999-2001,2003 David Faure <faure@kde.org> 0006 Copyright 2001-2003 Philipp Mueller <philipp.mueller@gmx.de> 0007 Copyright 2002-2003 Norbert Andres <nandres@web.de> 0008 Copyright 2000-2001 Werner Trobin <trobin@kde.org> 0009 Copyright 2002 Harri Porten <porten@kde.org> 0010 Copyright 2002 John Dailey <dailey@vt.edu> 0011 Copyright 1999-2000 Torben Weis <weis@kde.org> 0012 Copyright 2000 Wilco Greven <greven@kde.org> 0013 Copyright 1999 Boris Wedl <boris.wedl@kfunigraz.ac.at> 0014 Copyright 1999 Reginald Stadlbauer <reggie@kde.org> 0015 0016 This library is free software; you can redistribute it and/or 0017 modify it under the terms of the GNU Library General Public 0018 License as published by the Free Software Foundation; either 0019 version 2 of the License, or (at your option) any later version. 0020 0021 This library is distributed in the hope that it will be useful, 0022 but WITHOUT ANY WARRANTY; without even the implied warranty of 0023 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0024 Library General Public License for more details. 0025 0026 You should have received a copy of the GNU Library General Public License 0027 along with this library; see the file COPYING.LIB. If not, write to 0028 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0029 Boston, MA 02110-1301, USA. 0030 */ 0031 0032 #ifndef CALLIGRA_SHEETS_CANVASBASE 0033 #define CALLIGRA_SHEETS_CANVASBASE 0034 0035 #include <QList> 0036 #include <QSizeF> 0037 #include <KoCanvasBase.h> 0038 0039 #include "sheets_common_export.h" 0040 #include "../Global.h" 0041 0042 class QFocusEvent; 0043 class QKeyEvent; 0044 class QInputMethodEvent; 0045 class QTabletEvent; 0046 class QMimeData; 0047 class QPainter; 0048 class KoPointerEvent; 0049 class KoZoomHandler; 0050 0051 namespace Calligra 0052 { 0053 namespace Sheets 0054 { 0055 class Canvas; 0056 class ColumnHeader; 0057 class Doc; 0058 class Sheet; 0059 class RowHeader; 0060 class Selection; 0061 class SheetView; 0062 0063 /** 0064 * The scrollable area showing the cells. 0065 */ 0066 class CALLIGRA_SHEETS_COMMON_EXPORT CanvasBase : public KoCanvasBase 0067 { 0068 friend class ColumnHeader; 0069 friend class RowHeader; 0070 friend class View; 0071 friend class CellTool; 0072 friend class Canvas; 0073 public: 0074 explicit CanvasBase(Doc* doc); 0075 ~CanvasBase() override; 0076 0077 Doc* doc() const; 0078 0079 // KoCanvasBase interface methods. 0080 /// reimplemented method from KoCanvasBase 0081 void gridSize(qreal* horizontal, qreal* vertical) const override; 0082 /// reimplemented method from KoCanvasBase 0083 bool snapToGrid() const override; 0084 /// reimplemented method from KoCanvasBase 0085 void addCommand(KUndo2Command* command) override; 0086 /// reimplemented method from KoCanvasBase 0087 KoShapeManager* shapeManager() const override; 0088 /// reimplemented method from KoCanvasBase 0089 void updateCanvas(const QRectF& rc) override; 0090 /// reimplemented method from KoCanvasBase 0091 KoToolProxy* toolProxy() const override; 0092 0093 /// reimplemented method from KoCanvasBase 0094 KoUnit unit() const override; 0095 /// reimplemented method from KoCanvasBase 0096 void updateInputMethodInfo() override; 0097 0098 /** 0099 * @return the usual selection of cells 0100 */ 0101 virtual Calligra::Sheets::Selection* selection() const = 0; 0102 0103 QPointF offset() const; 0104 0105 /** 0106 * @return the width of the columns before the current screen 0107 */ 0108 double xOffset() const; 0109 0110 /** 0111 * @return the height of the rows before the current screen 0112 */ 0113 double yOffset() const; 0114 0115 /** 0116 * @return a rect indicating which cell range is currently visible onscreen 0117 */ 0118 QRect visibleCells() const; 0119 0120 /** 0121 * @return a pointer to the active sheet 0122 */ 0123 virtual Sheet* activeSheet() const = 0; 0124 0125 /** 0126 * Validates the selected cell. 0127 */ 0128 void validateSelection(); 0129 0130 public: 0131 void setDocumentOffset(const QPoint& offset); 0132 void setDocumentSize(const QSizeF& size); 0133 0134 protected: 0135 void keyPressed(QKeyEvent* _ev); 0136 void paint(QPainter* painter, const QRectF& painterRect); // maybe add a QRegion overload 0137 void mousePressed(KoPointerEvent* _ev); 0138 void mouseReleased(KoPointerEvent* _ev); 0139 void mouseMoved(KoPointerEvent* _ev); 0140 void mouseDoubleClicked(KoPointerEvent* _ev); 0141 void focusIn(QFocusEvent*); 0142 0143 bool dragEnter(const QMimeData* mimeData); 0144 bool dragMove(const QMimeData* mimeData, const QPointF& eventPos, const QObject *source); 0145 void dragLeave(); 0146 bool drop(const QMimeData* mimeData, const QPointF& eventPos, const QObject *source); 0147 0148 QVariant inputMethodQuery(Qt::InputMethodQuery query) const; 0149 void inputMethodEvent(QInputMethodEvent *event); 0150 void tabletEvent(QTabletEvent *e); 0151 0152 bool eventFilter(QObject *o, QEvent *e); 0153 virtual ColumnHeader* columnHeader() const { return 0; }; 0154 virtual RowHeader* rowHeader() const { return 0; }; 0155 0156 public: 0157 virtual void update() = 0; 0158 virtual void update(const QRectF& rect) = 0; 0159 virtual void documentSizeChanged(const QSize&) = 0; 0160 virtual Qt::LayoutDirection layoutDirection() const = 0; 0161 virtual QRectF rect() const = 0; 0162 virtual QSizeF size() const = 0; 0163 qreal width() const { return size().width(); } 0164 qreal height() const { return size().height(); } 0165 virtual QPoint mapToGlobal(const QPointF& point) const = 0; 0166 virtual void updateMicroFocus() = 0; 0167 0168 virtual KoZoomHandler* zoomHandler() const = 0; 0169 KoViewConverter* viewConverter() const override; 0170 virtual bool isViewLoading() const = 0; // not sure if is needed 0171 virtual SheetView* sheetView(const Sheet* sheet) const = 0; 0172 virtual void enableAutoScroll() = 0; 0173 virtual void disableAutoScroll() = 0; 0174 0175 virtual void showContextMenu(const QPoint& globalPos) = 0; 0176 protected: 0177 /** 0178 * Returns the range of cells which appear in the specified area of the Canvas widget 0179 * For example, viewToCellCoordinates( QRect(0,0,width(),height()) ) returns a range containing all visible cells 0180 * 0181 * @param area The area (in pixels) on the Canvas widget 0182 */ 0183 QRect viewToCellCoordinates(const QRectF& area) const; 0184 0185 /** 0186 * Calculates the region in view coordinates occupied by a range of cells on 0187 * the currently active sheet. Respects the scrolling offset and the layout 0188 * direction 0189 * 0190 * \param cellRange The range of cells on the current sheet. 0191 */ 0192 QRectF cellCoordinatesToView(const QRect& cellRange) const; 0193 0194 // negative values mean max - pos 0195 virtual void setVertScrollBarPos(qreal pos) = 0; 0196 virtual void setHorizScrollBarPos(qreal pos) = 0; 0197 private: 0198 /** 0199 * Determines the cell at @p point and shows its tooltip. 0200 * @param point the position for which a tooltip is requested 0201 */ 0202 void showToolTip(const QPoint& point); 0203 0204 private: 0205 Q_DISABLE_COPY(CanvasBase) 0206 0207 class Private; 0208 Private * const d; 0209 }; 0210 0211 } // namespace Sheets 0212 } // namespace Calligra 0213 0214 #endif // CALLIGRA_SHEETS_CANVAS