File indexing completed on 2024-05-12 15:56:38
0001 /* This file is part of the KDE project 0002 * SPDX-FileCopyrightText: 2006, 2008 Thomas Zander <zander@kde.org> 0003 * SPDX-FileCopyrightText: 2007-2010 Boudewijn Rempt <boud@valdyas.org> 0004 * SPDX-FileCopyrightText: 2007-2008 C. Boemann <cbo@boemann.dk> 0005 * SPDX-FileCopyrightText: 2006-2007 Jan Hambrecht <jaham@gmx.net> 0006 * SPDX-FileCopyrightText: 2009 Thorsten Zachmann <zachmann@kde.org> 0007 * 0008 * SPDX-License-Identifier: LGPL-2.0-or-later 0009 */ 0010 0011 #ifndef KOCANVASCONTROLLERWIDGET_H 0012 #define KOCANVASCONTROLLERWIDGET_H 0013 0014 #include "kritaflake_export.h" 0015 0016 #include <QAbstractScrollArea> 0017 #include <QPointer> 0018 #include "KoCanvasController.h" 0019 0020 class KoShape; 0021 class KoCanvasBase; 0022 class KoCanvasSupervisor; 0023 /** 0024 * KoCanvasController implementation for QWidget based canvases 0025 */ 0026 class KRITAFLAKE_EXPORT KoCanvasControllerWidget : public QAbstractScrollArea, public KoCanvasController 0027 { 0028 Q_OBJECT 0029 public: 0030 0031 /** 0032 * Constructor. 0033 * @param actionCollection the action collection for this widget 0034 * @param parent the parent this widget will belong to 0035 */ 0036 explicit KoCanvasControllerWidget(KisKActionCollection * actionCollection, KoCanvasSupervisor *observerProvider, QWidget *parent = 0); 0037 ~KoCanvasControllerWidget() override; 0038 0039 /** 0040 * Reimplemented from QAbstractScrollArea. 0041 */ 0042 void scrollContentsBy(int dx, int dy) override; 0043 0044 QSizeF viewportSize() const override; 0045 0046 /// Reimplemented from KoCanvasController 0047 0048 /** 0049 * Activate this canvascontroller 0050 */ 0051 virtual void activate(); 0052 0053 void setCanvas(KoCanvasBase *canvas) override; 0054 0055 KoCanvasBase *canvas() const override; 0056 0057 /** 0058 * Change the actual canvas widget used by the current canvas. This allows the canvas widget 0059 * to be changed while keeping the current KoCanvasBase canvas and its associated resources as 0060 * they are. This might be used, for example, to switch from a QWidget to a QOpenGLWidget canvas. 0061 * @param widget the new canvas widget. 0062 */ 0063 virtual void changeCanvasWidget(QWidget *widget); 0064 0065 int visibleHeight() const override; 0066 int visibleWidth() const override; 0067 int canvasOffsetX() const override; 0068 int canvasOffsetY() const override; 0069 0070 void ensureVisible(const QRectF &rect, bool smooth = false) override; 0071 0072 void ensureVisible(KoShape *shape) override; 0073 0074 /** 0075 * will cause the toolOptionWidgetsChanged to be emitted and all 0076 * listeners to be updated to the new widget. 0077 * 0078 * FIXME: This doesn't belong her and it does an 0079 * inherits("KoView") so it too much tied to komain 0080 * 0081 * @param widgets the map of widgets 0082 */ 0083 void setToolOptionWidgets(const QList<QPointer<QWidget> > &widgets); 0084 0085 void zoomIn(const QPoint ¢er) override; 0086 0087 void zoomOut(const QPoint ¢er) override; 0088 0089 void zoomBy(const QPoint ¢er, qreal zoom) override; 0090 0091 void zoomTo(const QRect &rect) override; 0092 0093 /** 0094 * Zoom document keeping point \p widgetPoint unchanged 0095 * \param widgetPoint sticky point in widget pixels 0096 * \param zoomCoeff the zoom 0097 */ 0098 virtual void zoomRelativeToPoint(const QPoint &widgetPoint, qreal zoomCoeff); 0099 0100 void recenterPreferred() override; 0101 0102 void setPreferredCenter(const QPointF &viewPoint) override; 0103 0104 /// Returns the currently set preferred center point in view coordinates (pixels) 0105 QPointF preferredCenter() const override; 0106 0107 void pan(const QPoint &distance) override; 0108 0109 virtual void panUp() override; 0110 virtual void panDown() override; 0111 virtual void panLeft() override; 0112 virtual void panRight() override; 0113 0114 void setMargin(int margin) override; 0115 0116 QPoint scrollBarValue() const override; 0117 0118 /** 0119 * Used by KisCanvasController to correct the scrollbars position 0120 * after the rotation. 0121 */ 0122 void setScrollBarValue(const QPoint &value) override; 0123 0124 void updateDocumentSize(const QSizeF &sz, bool recalculateCenter = true) override; 0125 0126 /** 0127 * Set mouse wheel to zoom behaviour 0128 * @param zoom if true wheel will zoom instead of scroll, control modifier will scroll 0129 */ 0130 void setZoomWithWheel(bool zoom) override; 0131 0132 void setVastScrolling(qreal factor) override; 0133 0134 QPointF currentCursorPosition() const override; 0135 0136 void resetScrollBars() override; 0137 0138 /** 0139 * \internal 0140 */ 0141 class Private; 0142 KoCanvasControllerWidget::Private *priv(); 0143 0144 private Q_SLOTS: 0145 0146 /// Called by the horizontal scrollbar when its value changes 0147 void updateCanvasOffsetX(); 0148 0149 /// Called by the vertical scrollbar when its value changes 0150 void updateCanvasOffsetY(); 0151 0152 protected: 0153 friend class KisZoomAndPanTest; 0154 0155 qreal vastScrollingFactor() const; 0156 0157 /// reimplemented from QWidget 0158 void paintEvent(QPaintEvent *event) override; 0159 /// reimplemented from QWidget 0160 void resizeEvent(QResizeEvent *resizeEvent) override; 0161 /// reimplemented from QWidget 0162 void dragEnterEvent(QDragEnterEvent *event) override; 0163 /// reimplemented from QWidget 0164 void dropEvent(QDropEvent *event) override; 0165 /// reimplemented from QWidget 0166 void dragMoveEvent(QDragMoveEvent *event) override; 0167 /// reimplemented from QWidget 0168 void dragLeaveEvent(QDragLeaveEvent *event) override; 0169 /// reimplemented from QWidget 0170 void wheelEvent(QWheelEvent *event) override; 0171 /// reimplemented from QWidget 0172 bool focusNextPrevChild(bool next) override; 0173 /// reimplemented from QAbstractScrollArea 0174 bool viewportEvent(QEvent *event) override; 0175 0176 private: 0177 Q_PRIVATE_SLOT(d, void activate()) 0178 0179 Private * const d; 0180 }; 0181 0182 #endif