(empty message)
[qanava.git] / src / la / laGrid.cpp
blob5fd13c8d5a4582ce7a648c72849dd152875a4c6d
1 /*
2 Qanava - Graph drawing library for QT
3 Copyright (C) 2005 Benoit AUTHEMAN
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 //-----------------------------------------------------------------------------
21 // This file is a part of the Qanava software.
23 // \file laGrid.cpp
24 // \author Benoit Autheman (benoit@faktiss.net)
25 // \date 2004 December 05
26 //-----------------------------------------------------------------------------
29 // Qanava headers
30 #include "laGrid.h"
33 namespace qan { // ::qan
34 namespace la { // ::qan::la
37 /* Grid Constructor and Destructor *///----------------------------------------
38 Grid::Grid( GridLayout* layout ) :
39 _layout( 0 )
41 setLayout( layout );
44 Grid::~Grid( )
46 if ( _layout )
47 delete _layout;
49 //-----------------------------------------------------------------------------
53 /* Layout and Size Management *///--------------------------------------------
54 void Grid::resize( int width, int height )
56 if ( _layout != 0 )
57 _layout->resize( width, height );
60 void Grid::setLayout( GridLayout* layout )
62 if ( _layout != 0 )
63 delete _layout;
64 _layout = layout;
66 //-----------------------------------------------------------------------------
70 //-----------------------------------------------------------------------------
71 /*!
72 \param width Width of the grid to build (often the grid's canvas width).
73 \param height Height of the grid to build (often the grid's canvas height).
75 void GridLayoutRegular::build( int width, int height )
77 _lastX = 0;
78 _lastY = 0;
79 _gridCountX = 0;
80 _gridCountY = 0;
81 updateGrid( width, height );
84 /*!
85 \param width Width of the grid to build (often the grid's canvas width).
86 \param height Height of the grid to build (often the grid's canvas height).
88 void GridLayoutRegular::resize( int width, int height )
90 if ( _lastX < width && _lastY < height )
91 updateGrid( width, height );
94 void GridLayoutRegular::updateGrid( int width, int height )
96 int incX = _spacing;
97 int incY = _spacing;
99 int smallGradCount = 5;
101 if ( _lastX + incX < width ) // Take care of update (do not duplicate lines)
103 _lastX += ( _lastX == 0 ? 0 : incX ); // For each update, start a new line, for an initial build, start on the border
104 for ( int x = _lastX; x < width; _gridCountX++, x += incX )
106 int lineWeight = 1;
107 bool dash = false;
108 bool dot = true;
109 if ( _gridCountX % smallGradCount == 0 )
111 lineWeight = 1;
112 dash = true;
113 dot = false;
115 if ( x > 0 )
117 getGrid( ).addVerticalLine( x, 0, x, height, lineWeight, dash, dot );
118 _lastX = x;
123 if ( _lastY + incY < height ) // Take care of update (do not duplicate lines)
125 _lastY += ( _lastY == 0 ? 0 : incY ); // For each update, start a new line, for an initial build, start on the border
126 for ( int y = _lastY; y < height; _gridCountY++, y += incY )
128 int lineWeight = 1;
129 bool dash = false;
130 bool dot = true;
131 if ( _gridCountY % smallGradCount == 0 )
133 lineWeight = 1;
134 dash = true;
135 dot = false;
137 if ( y > 0 )
139 getGrid( ).addHorizontalLine( 0, y, width, y, lineWeight, dash, dot );
140 _lastY = y;
145 //-----------------------------------------------------------------------------
148 } // ::qan::la
149 } // ::qan