1 /* This file is part of the KDE project 2 * Copyright (C) 2006, 2008 Thomas Zander <zander@kde.org> 3 * Copyright (C) 2007-2010 Boudewijn Rempt <boud@valdyas.org> 4 * Copyright (C) 2007-2008 C. Boemann <cbo@boemann.dk> 5 * Copyright (C) 2006-2007 Jan Hambrecht <jaham@gmx.net> 6 * Copyright (C) 2009 Thorsten Zachmann <zachmann@kde.org> 7 * 8 * This library is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU Library General Public 10 * License as published by the Free Software Foundation; either 11 * version 2 of the License, or (at your option) any later version. 12 * 13 * This library is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * Library General Public License for more details. 17 * 18 * You should have received a copy of the GNU Library General Public License 19 * along with this library; see the file COPYING.LIB. If not, write to 20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 21 * Boston, MA 02110-1301, USA. 22 */ 23 24 #ifndef KOCANVASCONTROLLERWIDGET_H 25 #define KOCANVASCONTROLLERWIDGET_H 26 27 #include "kritaflake_export.h" 28 29 #include <QAbstractScrollArea> 30 #include <QPointer> 31 #include "KoCanvasController.h" 32 33 class KoShape; 34 class KoCanvasBase; 35 class KoCanvasSupervisor; 36 /** 37 * KoCanvasController implementation for QWidget based canvases 38 */ 39 class KRITAFLAKE_EXPORT KoCanvasControllerWidget : public QAbstractScrollArea, public KoCanvasController 40 { 41 Q_OBJECT 42 public: 43 44 /** 45 * Constructor. 46 * @param actionCollection the action collection for this widget 47 * @param parent the parent this widget will belong to 48 */ 49 explicit KoCanvasControllerWidget(KActionCollection * actionCollection, KoCanvasSupervisor *observerProvider, QWidget *parent = 0); 50 ~KoCanvasControllerWidget() override; 51 52 /** 53 * Reimplemented from QAbstractScrollArea. 54 */ 55 void scrollContentsBy(int dx, int dy) override; 56 57 QSizeF viewportSize() const override; 58 59 /// Reimplemented from KoCanvasController 60 61 /** 62 * Activate this canvascontroller 63 */ 64 virtual void activate(); 65 66 void setCanvas(KoCanvasBase *canvas) override; 67 68 KoCanvasBase *canvas() const override; 69 70 /** 71 * Change the actual canvas widget used by the current canvas. This allows the canvas widget 72 * to be changed while keeping the current KoCanvasBase canvas and its associated resources as 73 * they are. This might be used, for example, to switch from a QWidget to a QOpenGLWidget canvas. 74 * @param widget the new canvas widget. 75 */ 76 virtual void changeCanvasWidget(QWidget *widget); 77 78 int visibleHeight() const override; 79 int visibleWidth() const override; 80 int canvasOffsetX() const override; 81 int canvasOffsetY() const override; 82 83 void ensureVisible(const QRectF &rect, bool smooth = false) override; 84 85 void ensureVisible(KoShape *shape) override; 86 87 /** 88 * will cause the toolOptionWidgetsChanged to be emitted and all 89 * listeners to be updated to the new widget. 90 * 91 * FIXME: This doesn't belong her and it does an 92 * inherits("KoView") so it too much tied to komain 93 * 94 * @param widgets the map of widgets 95 */ 96 void setToolOptionWidgets(const QList<QPointer<QWidget> > &widgets); 97 98 void zoomIn(const QPoint ¢er) override; 99 100 void zoomOut(const QPoint ¢er) override; 101 102 void zoomBy(const QPoint ¢er, qreal zoom) override; 103 104 void zoomTo(const QRect &rect) override; 105 106 /** 107 * Zoom document keeping point \p widgetPoint unchanged 108 * \param widgetPoint sticky point in widget pixels 109 * \param zoomCoeff the zoom 110 */ 111 virtual void zoomRelativeToPoint(const QPoint &widgetPoint, qreal zoomCoeff); 112 113 void recenterPreferred() override; 114 115 void setPreferredCenter(const QPointF &viewPoint) override; 116 117 /// Returns the currently set preferred center point in view coordinates (pixels) 118 QPointF preferredCenter() const override; 119 120 void pan(const QPoint &distance) override; 121 122 virtual void panUp() override; 123 virtual void panDown() override; 124 virtual void panLeft() override; 125 virtual void panRight() override; 126 127 void setMargin(int margin) override; 128 129 QPoint scrollBarValue() const override; 130 131 /** 132 * Used by KisCanvasController to correct the scrollbars position 133 * after the rotation. 134 */ 135 void setScrollBarValue(const QPoint &value) override; 136 137 void updateDocumentSize(const QSizeF &sz, bool recalculateCenter = true) override; 138 139 /** 140 * Set mouse wheel to zoom behaviour 141 * @param zoom if true wheel will zoom instead of scroll, control modifier will scroll 142 */ 143 void setZoomWithWheel(bool zoom) override; 144 145 void setVastScrolling(qreal factor) override; 146 147 QPointF currentCursorPosition() const override; 148 149 void resetScrollBars() override; 150 151 /** 152 * \internal 153 */ 154 class Private; 155 KoCanvasControllerWidget::Private *priv(); 156 157 private Q_SLOTS: 158 159 /// Called by the horizontal scrollbar when its value changes 160 void updateCanvasOffsetX(); 161 162 /// Called by the vertical scrollbar when its value changes 163 void updateCanvasOffsetY(); 164 165 protected: 166 friend class KisZoomAndPanTest; 167 168 qreal vastScrollingFactor() const; 169 170 /// reimplemented from QWidget 171 void paintEvent(QPaintEvent *event) override; 172 /// reimplemented from QWidget 173 void resizeEvent(QResizeEvent *resizeEvent) override; 174 /// reimplemented from QWidget 175 void dragEnterEvent(QDragEnterEvent *event) override; 176 /// reimplemented from QWidget 177 void dropEvent(QDropEvent *event) override; 178 /// reimplemented from QWidget 179 void dragMoveEvent(QDragMoveEvent *event) override; 180 /// reimplemented from QWidget 181 void dragLeaveEvent(QDragLeaveEvent *event) override; 182 /// reimplemented from QWidget 183 void wheelEvent(QWheelEvent *event) override; 184 /// reimplemented from QWidget 185 bool focusNextPrevChild(bool next) override; 186 /// reimplemented from QAbstractScrollArea 187 bool viewportEvent(QEvent *event) override; 188 189 private: 190 Q_PRIVATE_SLOT(d, void activate()) 191 192 Private * const d; 193 }; 194 195 #endif 196