File indexing completed on 2024-05-12 15:56:39

0001 /* This file is part of the KDE project
0002  * SPDX-FileCopyrightText: 2006-2007 Thomas Zander <zander@kde.org>
0003  * SPDX-FileCopyrightText: 2007-2010 Boudewijn Rempt <boud@valdyas.org>
0004  *
0005  * SPDX-License-Identifier: LGPL-2.0-or-later
0006  */
0007 
0008 #ifndef KOCANVASCONTROLLERWIDGETVIEWPORT_P_H
0009 #define KOCANVASCONTROLLERWIDGETVIEWPORT_P_H
0010 
0011 #include <QWidget>
0012 #include <QSize>
0013 #include <QPoint>
0014 
0015 class KoCanvasControllerWidget;
0016 class KoShape;
0017 
0018 class Viewport : public QWidget
0019 {
0020     Q_OBJECT
0021 
0022 public:
0023 
0024     explicit Viewport(KoCanvasControllerWidget *parent);
0025     ~Viewport() override {}
0026 
0027     void setCanvas(QWidget *canvas);
0028     QWidget *canvas() const {
0029         return m_canvas;
0030     }
0031     void setDocumentSize(const QSizeF &size);
0032 
0033 public Q_SLOTS:
0034     void documentOffsetMoved(const QPoint &);
0035 
0036 Q_SIGNALS:
0037     void sizeChanged();
0038 
0039 public:
0040 
0041     void handleDragEnterEvent(QDragEnterEvent *event);
0042     void handleDropEvent(QDropEvent *event);
0043     void handleDragMoveEvent(QDragMoveEvent *event);
0044     void handleDragLeaveEvent(QDragLeaveEvent *event);
0045     void handlePaintEvent(QPainter &gc, QPaintEvent *event);
0046     void setMargin(int margin) { m_margin = margin; resetLayout(); }
0047 
0048 private:
0049 
0050     QPointF correctPosition(const QPoint &point) const;
0051     void repaint(KoShape *shape);
0052 
0053     /**
0054        Decides whether the containing canvas widget should be as
0055        big as the viewport (i.e., no margins are visible) or whether
0056        there are margins to be left blank, and then places the canvas
0057        widget accordingly.
0058     */
0059     void resetLayout();
0060 
0061 private:
0062 
0063     KoCanvasControllerWidget *m_parent;
0064     KoShape *m_draggedShape;
0065 
0066     QWidget *m_canvas;
0067     QSizeF m_documentSize; // Size in pixels of the document
0068     QPoint m_documentOffset; // Place where the canvas widget should
0069     int m_margin; // The viewport margin around the document
0070 };
0071 
0072 #endif