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