File indexing completed on 2024-05-12 16:35:43
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 Copyright (C) 2010 Boudewijn Rempt <boud@kogmbh.com> 0016 0017 This library is free software; you can redistribute it and/or 0018 modify it under the terms of the GNU Library General Public 0019 License as published by the Free Software Foundation; either 0020 version 2 of the License, or (at your option) any later version. 0021 0022 This library is distributed in the hope that it will be useful, 0023 but WITHOUT ANY WARRANTY; without even the implied warranty of 0024 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0025 Library General Public License for more details. 0026 0027 You should have received a copy of the GNU Library General Public License 0028 along with this library; see the file COPYING.LIB. If not, write to 0029 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0030 Boston, MA 02110-1301, USA. 0031 */ 0032 0033 #ifndef CALLIGRA_SHEETS_CANVAS_ITEM 0034 #define CALLIGRA_SHEETS_CANVAS_ITEM 0035 0036 #include <QList> 0037 #include <QGraphicsWidget> 0038 0039 #include <KoCanvasBase.h> 0040 0041 #include "sheets_common_export.h" 0042 0043 #include "Global.h" 0044 #include "CanvasBase.h" 0045 0046 class QEvent; 0047 class QFocusEvent; 0048 class QKeyEvent; 0049 class QPainter; 0050 0051 namespace Calligra 0052 { 0053 namespace Sheets 0054 { 0055 class Cell; 0056 class CanvasItem; 0057 class ColumnHeader; 0058 class Damage; 0059 class Doc; 0060 class Sheet; 0061 class RowHeader; 0062 class Selection; 0063 class View; 0064 0065 0066 /** 0067 * The scrollable area showing the cells. 0068 */ 0069 class CALLIGRA_SHEETS_COMMON_EXPORT CanvasItem : public QGraphicsWidget, public CanvasBase 0070 { 0071 friend class ColumnHeaderItem; 0072 friend class RowHeaderItem; 0073 friend class View; 0074 friend class CellTool; 0075 0076 Q_OBJECT 0077 0078 public: 0079 explicit CanvasItem(Doc* doc, QGraphicsItem *parent = 0); 0080 ~CanvasItem() override; 0081 0082 QWidget* canvasWidget() override { 0083 return 0; 0084 } 0085 const QWidget* canvasWidget() const override { 0086 return 0; 0087 } 0088 0089 /** 0090 * Return the widget that will be added to the scrollArea. 0091 */ 0092 QGraphicsObject *canvasItem() override { return this; } 0093 0094 /** 0095 * Return the widget that will be added to the scrollArea. 0096 */ 0097 const QGraphicsObject *canvasItem() const override{ return this; } 0098 0099 0100 public Q_SLOTS: 0101 void setDocumentOffset(const QPoint& offset) { 0102 CanvasBase::setDocumentOffset(offset); 0103 } 0104 void setDocumentSize(const QSizeF& size) { 0105 CanvasBase::setDocumentSize(size); 0106 } 0107 0108 void refreshSheetViews(); 0109 void setActiveSheet(Sheet* sheet); 0110 0111 void setObscuredRange(const QSize& size); 0112 0113 /** 0114 * \ingroup Damages 0115 * Handles damages that need visual updates. 0116 */ 0117 void handleDamages(const QList<Damage*>& damages); 0118 0119 void updateAccessedCellRange(Sheet* sheet, const QPoint& location); 0120 0121 Q_SIGNALS: 0122 /* virtual */ void documentSizeChanged(const QSize&) override; 0123 void obscuredRangeChanged(const Calligra::Sheets::Sheet* sheet, const QSize&); 0124 0125 public: 0126 void mousePressEvent(QGraphicsSceneMouseEvent* _ev) override; 0127 void mouseReleaseEvent(QGraphicsSceneMouseEvent* _ev) override; 0128 protected: 0129 void keyPressEvent(QKeyEvent* _ev) override { 0130 CanvasBase::keyPressed(_ev); 0131 } 0132 void paint( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0) override; 0133 void mouseMoveEvent(QGraphicsSceneMouseEvent* _ev) override; 0134 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent*) override; 0135 void focusInEvent(QFocusEvent* _ev) override { 0136 CanvasBase::focusIn(_ev); 0137 QGraphicsWidget::focusInEvent(_ev); 0138 } 0139 void dragEnterEvent(QGraphicsSceneDragDropEvent*) override; 0140 void dragMoveEvent(QGraphicsSceneDragDropEvent*) override; 0141 void dragLeaveEvent(QGraphicsSceneDragDropEvent*) override; 0142 void dropEvent(QGraphicsSceneDragDropEvent*) override; 0143 /// reimplemented method from superclass 0144 QVariant inputMethodQuery(Qt::InputMethodQuery query) const override { 0145 return CanvasBase::inputMethodQuery(query); 0146 } 0147 /// reimplemented method from superclass 0148 void inputMethodEvent(QInputMethodEvent *event) override { 0149 CanvasBase::inputMethodEvent(event); 0150 } 0151 /// reimplemented method from superclass 0152 virtual void tabletEvent(QTabletEvent *e) { 0153 CanvasBase::tabletEvent(e); 0154 } 0155 0156 private: 0157 bool eventFilter(QObject *o, QEvent *e) override { 0158 return CanvasBase::eventFilter(o, e); 0159 } 0160 0161 public: 0162 Selection* selection() const override; 0163 Sheet* activeSheet() const override; 0164 KoZoomHandler* zoomHandler() const override; 0165 SheetView* sheetView(const Sheet* sheet) const override; 0166 0167 bool isViewLoading() const override { return false; } 0168 void enableAutoScroll() override {} 0169 void disableAutoScroll() override {} 0170 void setVertScrollBarPos(qreal) override {} 0171 void setHorizScrollBarPos(qreal) override {} 0172 0173 void update() override { QGraphicsWidget::update(); } 0174 void update(const QRectF& rect) override { QGraphicsWidget::update(rect); } 0175 Qt::LayoutDirection layoutDirection() const override { return QGraphicsWidget::layoutDirection(); } 0176 QRectF rect() const override { return QGraphicsWidget::rect(); } 0177 QSizeF size() const override { return QGraphicsWidget::size(); } 0178 QPoint mapToGlobal(const QPointF& point) const override { return QGraphicsWidget::mapToScene(point).toPoint(); /* TODO */ } 0179 void updateMicroFocus() override { /*QGraphicsWidget::updateMicroFocus();*/ } 0180 0181 ColumnHeader* columnHeader() const override; 0182 RowHeader* rowHeader() const override; 0183 void setCursor(const QCursor &cursor) override; 0184 0185 void showContextMenu(const QPoint& globalPos) override { Q_UNUSED(globalPos); } 0186 private: 0187 Q_DISABLE_COPY(CanvasItem) 0188 0189 class Private; 0190 Private * const d; 0191 }; 0192 0193 } // namespace Sheets 0194 } // namespace Calligra 0195 0196 #endif // CALLIGRA_SHEETS_CANVAS_ITEM