Warning, file /office/calligra/libs/flake/KoCanvasControllerWidget.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* This file is part of the KDE project 0002 * Copyright (C) 2006, 2008 Thomas Zander <zander@kde.org> 0003 * Copyright (C) 2007-2010 Boudewijn Rempt <boud@valdyas.org> 0004 * Copyright (C) 2007-2008 C. Boemann <cbo@boemann.dk> 0005 * Copyright (C) 2006-2007 Jan Hambrecht <jaham@gmx.net> 0006 * Copyright (C) 2009 Thorsten Zachmann <zachmann@kde.org> 0007 * 0008 * This library is free software; you can redistribute it and/or 0009 * modify it under the terms of the GNU Library General Public 0010 * License as published by the Free Software Foundation; either 0011 * version 2 of the License, or (at your option) any later version. 0012 * 0013 * This library is distributed in the hope that it will be useful, 0014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0016 * Library General Public License for more details. 0017 * 0018 * You should have received a copy of the GNU Library General Public License 0019 * along with this library; see the file COPYING.LIB. If not, write to 0020 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0021 * Boston, MA 02110-1301, USA. 0022 */ 0023 0024 #ifndef KOCANVASCONTROLLERWIDGET_H 0025 #define KOCANVASCONTROLLERWIDGET_H 0026 0027 #include "flake_export.h" 0028 0029 #include <QAbstractScrollArea> 0030 #include <QPointer> 0031 #include "KoCanvasController.h" 0032 0033 class KoShape; 0034 class KoCanvasBase; 0035 0036 /** 0037 * KoCanvasController implementation for QWidget based canvases 0038 */ 0039 class FLAKE_EXPORT KoCanvasControllerWidget : public QAbstractScrollArea, public KoCanvasController 0040 { 0041 Q_OBJECT 0042 public: 0043 0044 /** 0045 * Constructor. 0046 * @param actionCollection the action collection for this widget 0047 * @param parent the parent this widget will belong to 0048 */ 0049 explicit KoCanvasControllerWidget(KActionCollection * actionCollection, QWidget *parent = 0); 0050 ~KoCanvasControllerWidget() override; 0051 0052 /// Reimplemented from QObject 0053 bool eventFilter(QObject *watched, QEvent *event) override; 0054 0055 /** 0056 * Reimplemented from QAbstractScrollArea. 0057 */ 0058 void scrollContentsBy(int dx, int dy) override; 0059 0060 QSize viewportSize() const override; 0061 0062 /// Reimplemented from KoCanvasController 0063 0064 /** 0065 * Activate this canvascontroller 0066 */ 0067 virtual void activate(); 0068 0069 void setDrawShadow(bool drawShadow) override; 0070 0071 void setCanvas(KoCanvasBase *canvas) override; 0072 0073 KoCanvasBase *canvas() const override; 0074 0075 /** 0076 * Change the actual canvas widget used by the current canvas. This allows the canvas widget 0077 * to be changed while keeping the current KoCanvasBase canvas and its associated resources as 0078 * they are. This might be used, for example, to switch from a QWidget to a QOpenGLWidget canvas. 0079 * @param widget the new canvas widget. 0080 */ 0081 virtual void changeCanvasWidget(QWidget *widget); 0082 0083 int visibleHeight() const override; 0084 int visibleWidth() const override; 0085 int canvasOffsetX() const override; 0086 int canvasOffsetY() const override; 0087 0088 void ensureVisible(const QRectF &rect, bool smooth = false) override; 0089 0090 void ensureVisible(KoShape *shape) override; 0091 0092 /** 0093 * will cause the toolOptionWidgetsChanged to be emitted and all 0094 * listeners to be updated to the new widget. 0095 * 0096 * FIXME: This doesn't belong her and it does an 0097 * inherits("KoView") so it too much tied to komain 0098 * 0099 * @param widgets the map of widgets 0100 */ 0101 void setToolOptionWidgets(const QList<QPointer<QWidget> > &widgets); 0102 0103 void zoomIn(const QPoint ¢er) override; 0104 0105 void zoomOut(const QPoint ¢er) override; 0106 0107 void zoomBy(const QPoint ¢er, qreal zoom) override; 0108 0109 void zoomTo(const QRect &rect) override; 0110 0111 /** 0112 * Zoom document keeping point \p widgetPoint unchanged 0113 * \param widgetPoint sticky point in widget pixels 0114 * \param zoomCoeff the zoom coefficient 0115 */ 0116 virtual void zoomRelativeToPoint(const QPoint &widgetPoint, qreal zoomCoeff); 0117 0118 void recenterPreferred() override; 0119 0120 void setPreferredCenter(const QPointF &viewPoint) override; 0121 0122 /// Returns the currently set preferred center point in view coordinates (pixels) 0123 QPointF preferredCenter() const override; 0124 0125 void pan(const QPoint &distance) override; 0126 0127 void setMargin(int margin) override; 0128 0129 QPoint scrollBarValue() const override; 0130 0131 /** 0132 * Used by KisCanvasController to correct the scrollbars position 0133 * after the rotation. 0134 */ 0135 void setScrollBarValue(const QPoint &value) override; 0136 0137 void updateDocumentSize(const QSize &sz, bool recalculateCenter = true) override; 0138 0139 /** 0140 * Set mouse wheel to zoom behaviour 0141 * @param zoom if true wheel will zoom instead of scroll, control modifier will scroll 0142 */ 0143 void setZoomWithWheel(bool zoom) override; 0144 0145 void setVastScrolling(qreal factor) override; 0146 0147 /** 0148 * \internal 0149 */ 0150 class Private; 0151 KoCanvasControllerWidget::Private *priv(); 0152 0153 Q_SIGNALS: 0154 0155 /** 0156 * Emit the new tool option widgets to be used with this canvas. 0157 */ 0158 void toolOptionWidgetsChanged(const QList<QPointer<QWidget> > &widgets); 0159 0160 private Q_SLOTS: 0161 0162 /// Called by the horizontal scrollbar when its value changes 0163 void updateCanvasOffsetX(); 0164 0165 /// Called by the vertical scrollbar when its value changes 0166 void updateCanvasOffsetY(); 0167 0168 protected: 0169 friend class KisZoomAndPanTest; 0170 0171 /// reimplemented from QWidget 0172 void paintEvent(QPaintEvent *event) override; 0173 /// reimplemented from QWidget 0174 void resizeEvent(QResizeEvent *resizeEvent) override; 0175 /// reimplemented from QWidget 0176 void dragEnterEvent(QDragEnterEvent *event) override; 0177 /// reimplemented from QWidget 0178 void dropEvent(QDropEvent *event) override; 0179 /// reimplemented from QWidget 0180 void dragMoveEvent(QDragMoveEvent *event) override; 0181 /// reimplemented from QWidget 0182 void dragLeaveEvent(QDragLeaveEvent *event) override; 0183 /// reimplemented from QWidget 0184 void wheelEvent(QWheelEvent *event) override; 0185 /// reimplemented from QWidget 0186 void keyPressEvent(QKeyEvent *event) override; 0187 /// reimplemented from QWidget 0188 bool focusNextPrevChild(bool next) override; 0189 0190 private: 0191 Q_PRIVATE_SLOT(d, void activate()) 0192 0193 Private * const d; 0194 }; 0195 0196 #endif