File indexing completed on 2024-05-19 04:36:38
0001 /* This file is part of the TikZKit project. 0002 * 0003 * Copyright (C) 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_GRID_H 0021 #define TIKZ_UI_GRID_H 0022 0023 #include <QObject> 0024 #include <QVarLengthArray> 0025 #include <QRectF> 0026 #include <QLineF> 0027 0028 #include <tikz/core/Value.h> 0029 #include <tikz/core/Pos.h> 0030 0031 class QPainter; 0032 0033 namespace tikz { 0034 namespace ui { 0035 0036 class GridPrivate; 0037 0038 /** 0039 * A Grid for a QGraphicsView. 0040 * 0041 * The grid is painted in the background and consists of major and minor lines. 0042 * Major lines are drawn at each full unit (e.g. 0cm, 1cm, 2cm, etc.). 0043 * Minor lines are drawn between the major lines as an additional help. 0044 * The amout of the minor lines varies depending on the zoom of the QGraphicsView. 0045 */ 0046 class Grid : public QObject 0047 { 0048 Q_OBJECT 0049 Q_PROPERTY(Unit unit READ unit WRITE setUnit) 0050 Q_PROPERTY(qreal zoom READ zoom WRITE setZoom) 0051 0052 public: 0053 /** 0054 * Constructor with required @p view. 0055 */ 0056 explicit Grid(QObject * parent = nullptr); 0057 0058 /** 0059 * Destructor. 0060 */ 0061 ~Grid(); 0062 0063 /** 0064 * Draw the grid using the painter @p p. 0065 */ 0066 void draw(QPainter * p, const QRectF & rect); 0067 0068 /** 0069 * Returns this Grid's unit. 0070 */ 0071 tikz::Unit unit() const noexcept; 0072 0073 /** 0074 * Returns this Grid's zoom factor. 0075 */ 0076 qreal zoom() const noexcept; 0077 0078 public Q_SLOTS: 0079 /** 0080 * Set the unit of this Grid to @p unit. 0081 */ 0082 void setUnit(tikz::Unit unit) noexcept; 0083 0084 /** 0085 * Set this Grid's zoom factor to @p zoomFactor. 0086 */ 0087 void setZoom(qreal zoomFactor) noexcept; 0088 0089 public: 0090 /** 0091 * Snap @p value to the grid. 0092 */ 0093 tikz::Value snapValue(const tikz::Value & value) const; 0094 0095 /** 0096 * Snap x/y components of @p pos to the grid. 0097 */ 0098 tikz::Pos snapPos(const tikz::Pos & pos) const; 0099 0100 private: 0101 GridPrivate * const d; 0102 }; 0103 0104 } 0105 } 0106 0107 #endif // TIKZ_UI_GRID_H 0108 0109 // kate: indent-width 4; replace-tabs on;