1 /*
2  Copyright (c) 2008-2021, Benoit AUTHEMAN All rights reserved.
3 
4  Redistribution and use in source and binary forms, with or without
5  modification, are permitted provided that the following conditions are met:
6     * Redistributions of source code must retain the above copyright
7       notice, this list of conditions and the following disclaimer.
8     * Redistributions in binary form must reproduce the above copyright
9       notice, this list of conditions and the following disclaimer in the
10       documentation and/or other materials provided with the distribution.
11     * Neither the name of the author or Destrat.io nor the
12       names of its contributors may be used to endorse or promote products
13       derived from this software without specific prior written permission.
14 
15  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18  DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY
19  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26 
27 //-----------------------------------------------------------------------------
28 // This file is a part of the QuickQanava software library.
29 //
30 // \file	qanGrid.cpp
31 // \author	benoit@destrat.io
32 // \date	2017 01 29
33 //-----------------------------------------------------------------------------
34 
35 // Std headers
36 #include <math.h>        // std::round
37 #include <iostream>
38 
39 // Qt headers
40 
41 // QuickQanava headers
42 #include "./qanGrid.h"
43 
44 namespace qan {  // ::qan
45 
46 /* Grid Object Management *///-------------------------------------------------
Grid(QQuickItem * parent)47 Grid::Grid( QQuickItem* parent ) :
48     QQuickItem{parent}
49 {
50     setEnabled(false);  // Prevent event stealing, grids are not interactive
51 }
52 
updateGrid(const QRectF & viewRect,const QQuickItem & container,const QQuickItem & navigable)53 bool    Grid::updateGrid(const QRectF& viewRect,
54                          const QQuickItem& container,
55                          const QQuickItem& navigable ) noexcept
56 {
57     Q_UNUSED(viewRect)
58     Q_UNUSED(container)
59     Q_UNUSED(navigable)
60     return false;
61 }
62 
updateGrid()63 bool    Grid::updateGrid() noexcept { return false; }
64 //-----------------------------------------------------------------------------
65 
66 /* Grid Management *///--------------------------------------------------------
setThickColor(QColor thickColor)67 void    Grid::setThickColor( QColor thickColor ) noexcept
68 {
69     if ( thickColor != _thickColor ) {
70         _thickColor = thickColor;
71         emit thickColorChanged();
72     }
73 }
74 
setGridWidth(qreal gridWidth)75 void    Grid::setGridWidth( qreal gridWidth ) noexcept
76 {
77     if ( gridWidth < 0.001 ) {
78         qWarning() << "qan::Grid::setMinorWidth(): Warning, major width should be superior to 0.0";
79         return;
80     }
81     if ( !qFuzzyCompare(1.0 + gridWidth, 1.0 + _gridWidth) ) {
82         _gridWidth = gridWidth;
83         emit gridWidthChanged();
84     }
85 }
86 
setGridScale(qreal gridScale)87 void    Grid::setGridScale( qreal gridScale ) noexcept
88 {
89     if ( gridScale < 0.001 ) {
90         qWarning() << "qan::Grid::setGridScale(): Warning, grid scale should be superior to 0.0";
91         return;
92     }
93     if ( !qFuzzyCompare(1.0 + gridScale, 1.0 + _gridScale) ) {
94         _gridScale = gridScale;
95         emit gridScaleChanged();
96         updateGrid();
97     }
98 }
99 
setGridMajor(int gridMajor)100 void    Grid::setGridMajor( int gridMajor ) noexcept
101 {
102     if ( gridMajor < 1 ) {
103         qWarning() << "qan::Grid::setGridMajor(): Warning, grid major should be superior or equal to 1";
104         return;
105     }
106     if ( gridMajor != _gridMajor ) {
107         _gridMajor = gridMajor;
108         emit gridMajorChanged();
109         updateGrid();
110     }
111 }
112 //-----------------------------------------------------------------------------
113 
114 } // ::qan
115