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.
24 // \author Benoit Autheman (benoit@libqanava.org)
25 // \date 2004 December 05
26 //-----------------------------------------------------------------------------
30 #include "./qanGridItem.h"
36 #include <QGraphicsLineItem>
43 namespace qan
{ // ::qan
46 /* Grid Constructor/Destructor *///-------------------------------------------
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( ) );
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
),
115 //-----------------------------------------------------------------------------
119 /* CheckBoard Grid Management *///--------------------------------------------
120 GridCheckBoardItem::GridCheckBoardItem( GraphicsView
* graphicsView
, QColor white
, QColor black
, qreal length
) :
121 GridItem( graphicsView
),
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
);
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 );
148 if ( !_squaresPattern
.isNull( ) )
149 painter
.drawTiledPixmap( x
, y
, rect
.width( ) + 100, rect
.height( ) + 100, _squaresPattern
);
151 //-----------------------------------------------------------------------------