File indexing completed on 2024-05-12 16:37:09
0001 /* This file is part of the KDE project 0002 0003 Copyright (C) 2010 Boudewijn Rempt <boud@valdyas.org> 0004 0005 This library is free software; you can redistribute it and/or 0006 modify it under the terms of the GNU Library General Public 0007 License as published by the Free Software Foundation; either 0008 version 2 of the License, or (at your option) any later version. 0009 0010 This library is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 Library General Public License for more details. 0014 0015 You should have received a copy of the GNU Library General Public License 0016 along with this library; see the file COPYING.LIB. If not, write to 0017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 Boston, MA 02110-1301, USA. 0019 */ 0020 0021 #ifndef KWCANVASITEM_H 0022 #define KWCANVASITEM_H 0023 0024 #include "KWDocument.h" 0025 #include "KWCanvasBase.h" 0026 #include "KWViewMode.h" 0027 #include "words_export.h" 0028 0029 #include <QGraphicsWidget> 0030 0031 class QRect; 0032 class QPainter; 0033 0034 class KWView; 0035 0036 /** 0037 * This class is responsible for the rendering of the frames to 0038 * the screen as well as the interaction with the user via mouse 0039 * and keyboard. There is one per view. 0040 */ 0041 class WORDS_EXPORT KWCanvasItem : public QGraphicsWidget, public KWCanvasBase 0042 { 0043 Q_OBJECT 0044 0045 public: 0046 /** 0047 * Constructor 0048 * Creates a new canvas widget that can display pages and frames. 0049 * @param viewMode the initial KWViewMode this canvas should use 0050 * @param document as this is one view in the MVC design; the document holds all content 0051 */ 0052 KWCanvasItem(const QString &viewMode, KWDocument *document); 0053 ~KWCanvasItem() override; 0054 0055 /// ask the widget to set the size this canvas takes to display all content 0056 void updateSize(); 0057 0058 // KoCanvasBase interface methods. 0059 /// reimplemented method from superclass 0060 bool snapToGrid() const override; 0061 0062 /// reimplemented method from superclass 0063 QWidget *canvasWidget() override { 0064 return 0; 0065 } 0066 0067 /// reimplemented method from superclass 0068 const QWidget *canvasWidget() const override { 0069 return 0; 0070 } 0071 0072 /// reimplemented method from superclass 0073 QGraphicsObject *canvasItem() override { 0074 return this; 0075 } 0076 0077 /// reimplemented method from superclass 0078 const QGraphicsObject *canvasItem() const override { 0079 return this; 0080 } 0081 0082 /// reimplemented method from superclass 0083 void updateInputMethodInfo() override; 0084 0085 /// reimplemented method from superclass 0086 void updateCanvas(const QRectF &rc) override; 0087 0088 void setCursor(const QCursor &cursor) override; 0089 0090 public Q_SLOTS: 0091 /** 0092 * sets the document offset in the scrollArea 0093 * @param offset the offset, in pixels. 0094 */ 0095 void setDocumentOffset(const QPoint &offset); 0096 0097 Q_SIGNALS: 0098 /** 0099 * emitted when the contentsSize changes. 0100 * @see KWViewMode::contentsSize 0101 * @param size the content area size, in pixels. 0102 */ 0103 void documentSize(const QSizeF &size); 0104 0105 /// Emitted when updateCanvas has been called. 0106 void canvasUpdated(); 0107 0108 protected: //QGraphicsWidget 0109 /// reimplemented method from superclass 0110 void keyPressEvent(QKeyEvent *e) override; 0111 0112 /// reimplemented method from superclass 0113 void mouseMoveEvent(QGraphicsSceneMouseEvent *e) override; 0114 0115 /// reimplemented method from superclass 0116 void mousePressEvent(QGraphicsSceneMouseEvent *e) override; 0117 0118 /// reimplemented method from superclass 0119 void mouseReleaseEvent(QGraphicsSceneMouseEvent *e) override; 0120 0121 /// reimplemented method from superclass 0122 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *e) override; 0123 0124 /// reimplemented method from superclass 0125 0126 void keyReleaseEvent(QKeyEvent *e) override; 0127 0128 /// reimplemented method from superclass 0129 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override; 0130 0131 /// reimplemented method from superclass 0132 // virtual void tabletEvent(QTabletEvent *e); 0133 0134 /// reimplemented method from superclass 0135 void wheelEvent(QGraphicsSceneWheelEvent *e) override; 0136 0137 /// reimplemented method from superclass 0138 QVariant inputMethodQuery(Qt::InputMethodQuery query) const override; 0139 0140 /// reimplemented method from superclass 0141 void inputMethodEvent(QInputMethodEvent *event) override; 0142 0143 /// reimplemented method from superclass 0144 void updateCanvasInternal(const QRectF &clip) override { update(clip); } 0145 0146 private Q_SLOTS: 0147 /// Called whenever there was a page added/removed or simply resized. 0148 void pageSetupChanged(); 0149 }; 0150 0151 #endif