Import doxygen generated api doc
[qanava.git] / src / qanGridItem.cpp
blob39a0b000beed7bbb952e623810e5c6de6e33633d
1 /*
2 Qanava - Graph drawing library for QT
3 Copyright (C) 2006 Benoit AUTHEMAN
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library 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 GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; 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 canGrid.cpp
24 // \author Benoit Autheman (benoit@libqanava.org)
25 // \date 2004 December 05
26 //-----------------------------------------------------------------------------
29 // Qanava headers
30 #include "./qanGridItem.h"
33 // QT headers
34 #include <QPen>
35 #include <QPainter>
36 #include <QGraphicsLineItem>
39 // STD headers
40 //#include <math.h>
43 namespace qan { // ::qan
46 /* Grid Constructor/Destructor *///-------------------------------------------
47 /*!
49 GridItem::GridItem( GraphicsView* graphicsView ) :
50 QGraphicsItem( 0, graphicsView->scene( ) )
52 //connect( graphView->getGraphicsScene( ), SIGNAL( sceneRectChanged(const QRectF&) ),
53 // this, SLOT( sceneRectChanged(const QRectF&) ) );
55 graphicsView->setGrid( this );
58 GridItem::~GridItem( )
62 //-----------------------------------------------------------------------------
65 /* Graphics View Grid Implementation *///--------------------------------------
66 QRectF GridItem::boundingRect( ) const
68 return QRectF( QPointF( 0., 0. ), QSizeF( 1., 1. ) );
71 void GridItem::drawBackground( QPainter& painter, const QRectF& rect )
75 //-----------------------------------------------------------------------------
79 /* Grid Content Management *///-----------------------------------------------
80 void GridItem::addLine( QLineF l, float w, bool dash, bool dot )
82 QGraphicsLineItem* line = new QGraphicsLineItem( l, this, scene( ) );
84 // TODO: dash, dot, w
87 void GridItem::addRectangle( QRectF r, QColor c )
91 void GridItem::addText( const QString& text, QPointF p, bool bold )
95 void GridItem::addHorizontalLine( QLineF l, int w, bool dash, bool dot )
99 void GridItem::addVerticalLine( QLineF l, int w, bool dash, bool dot )
102 //-----------------------------------------------------------------------------
106 /* Regular Grid Management *///-----------------------------------------------
107 GridRegularItem::GridRegularItem( GraphicsView* graphicsView, int spacing ) :
108 GridItem( graphicsView ),
109 _spacing( spacing ),
110 _sizeMax( 0, 0 ),
111 _gradCount( 0, 0 )
115 //-----------------------------------------------------------------------------
119 /* CheckBoard Grid Management *///--------------------------------------------
120 GridCheckBoardItem::GridCheckBoardItem( GraphicsView* graphicsView, QColor white, QColor black, qreal length ) :
121 GridItem( graphicsView ),
122 _white( white ),
123 _black( black )
125 _squaresPattern = QPixmap( length * 2, length * 2 );
126 QPainter painter( &_squaresPattern );
127 painter.fillRect( 0, 0, length, length, white );
128 painter.fillRect( length, 0, length, length, black );
129 painter.fillRect( 0, length, length, length, black );
130 painter.fillRect( length, length, length, length, white );
131 painter.end( );
134 void GridCheckBoardItem::drawBackground( QPainter& painter, const QRectF& rect )
136 GridItem::drawBackground( painter, rect );
138 int left = ( int )rect.left( );
139 int top = ( int )rect.top( );
140 int x = ( ( left / 100 ) * 100 );
141 int y = ( ( top / 100 ) * 100 );
143 if ( left < 0 )
144 x = x - 100;
145 if ( top < 0 )
146 y = y - 100;
148 if ( !_squaresPattern.isNull( ) )
149 painter.drawTiledPixmap( x, y, rect.width( ) + 100, rect.height( ) + 100, _squaresPattern );
151 //-----------------------------------------------------------------------------
154 } // ::qan