File indexing completed on 2024-05-19 04:36:39
0001 /* This file is part of the TikZKit project. 0002 * 0003 * Copyright (C) 2013-2014 Dominik Haumann <dhaumann@kde.org> 0004 * 0005 * This library is free software; you can redistribute it and/or modify 0006 * it under the terms of the GNU Library General Public License as published 0007 * by the Free Software Foundation, either version 2 of the License, or 0008 * (at your option) any later version. 0009 * 0010 * This library is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 * GNU Library General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU Library General Public License 0016 * along with this library; see the file COPYING.LIB. If not, see 0017 * <http://www.gnu.org/licenses/>. 0018 */ 0019 0020 #ifndef TIKZ_UI_RENDERER_H 0021 #define TIKZ_UI_RENDERER_H 0022 0023 #include <QGraphicsView> 0024 0025 #include "tikzui_export.h" 0026 0027 #include <tikz/core/Value.h> 0028 #include <tikz/core/Pos.h> 0029 0030 namespace tikz { 0031 namespace ui { 0032 0033 class DocumentPrivate; 0034 class Ruler; 0035 class Grid; 0036 class ZoomController; 0037 0038 class Renderer : public QGraphicsView 0039 { 0040 Q_OBJECT 0041 0042 public: 0043 /** 0044 * Constructor. 0045 */ 0046 Renderer(DocumentPrivate * document = nullptr, QWidget * parent = nullptr); 0047 0048 /** 0049 * Destructor. 0050 */ 0051 virtual ~Renderer(); 0052 0053 /** 0054 * Returns the associated tikz Document. 0055 */ 0056 DocumentPrivate * document() const; 0057 0058 /** 0059 * Snap @p value to the grid. 0060 */ 0061 tikz::Value snapValue(const tikz::Value & value) const; 0062 0063 /** 0064 * Snap x/y components of @p pos to the grid. 0065 */ 0066 tikz::Pos snapPos(const tikz::Pos & pos) const; 0067 0068 /** 0069 * Snap @p angle in degrees to a 15° raster. 0070 */ 0071 qreal snapAngle(qreal angle) const; 0072 0073 /** 0074 * Returns the ZoomController object that handles the zoom operations. 0075 */ 0076 ZoomController * zoomController() const; 0077 0078 public Q_SLOTS: 0079 /** 0080 * Sets the zoom factor. 1.0 maps to 100%. 0081 */ 0082 void setZoom(qreal zoomFactor); 0083 0084 Q_SIGNALS: 0085 /** 0086 * This signal is emitted whenever the mouse moved on the view. 0087 */ 0088 void mousePositionChanged(const tikz::Pos & pos); 0089 0090 protected: 0091 void mousePressEvent(QMouseEvent* event) override; 0092 void mouseMoveEvent(QMouseEvent* event) override; 0093 void mouseReleaseEvent(QMouseEvent* event) override; 0094 void wheelEvent(QWheelEvent* event) override; 0095 bool viewportEvent(QEvent * event) override; 0096 0097 void drawBackground(QPainter * painter, const QRectF & rect) override; 0098 void drawForeground(QPainter * painter, const QRectF & rect) override; 0099 0100 private: 0101 DocumentPrivate * m_doc = nullptr; 0102 tikz::ui::Grid * m_grid = nullptr; 0103 tikz::ui::Ruler * m_hRuler = nullptr; 0104 tikz::ui::Ruler * m_vRuler = nullptr; 0105 tikz::ui::ZoomController * m_zoomController = nullptr; 0106 QPointF m_lastMousePos; 0107 bool m_handTool = false; 0108 }; 0109 0110 } 0111 } 0112 0113 #endif // TIKZ_UI_RENDERER_H 0114 0115 // kate: indent-width 4; replace-tabs on;