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>
39 namespace qan
{ // ::qan
42 /* Grid Constructor/Destructor *///-------------------------------------------
45 GridItem::GridItem( GraphView
* GraphView
) :
46 QGraphicsItem( 0, GraphView
->scene( ) )
48 //connect( graphView->getGraphicsScene( ), SIGNAL( sceneRectChanged(const QRectF&) ),
49 // this, SLOT( sceneRectChanged(const QRectF&) ) );
51 GraphView
->setGrid( this );
54 GridItem::~GridItem( )
58 //-----------------------------------------------------------------------------
61 /* Graphics View Grid Implementation *///--------------------------------------
62 QRectF
GridItem::boundingRect( ) const
64 return QRectF( QPointF( 0., 0. ), QSizeF( 1., 1. ) );
67 void GridItem::drawBackground( QPainter
& painter
, const QRectF
& rect
)
71 //-----------------------------------------------------------------------------
75 /* Grid Content Management *///-----------------------------------------------
76 void GridItem::addLine( QLineF l
, float w
, bool dash
, bool dot
)
78 QGraphicsLineItem
* line
= new QGraphicsLineItem( l
, this, scene( ) );
83 void GridItem::addRectangle( QRectF r
, QColor c
)
87 void GridItem::addText( const QString
& text
, QPointF p
, bool bold
)
91 void GridItem::addHorizontalLine( QLineF l
, int w
, bool dash
, bool dot
)
95 void GridItem::addVerticalLine( QLineF l
, int w
, bool dash
, bool dot
)
98 //-----------------------------------------------------------------------------
102 /* Regular Grid Management *///-----------------------------------------------
103 GridRegularItem::GridRegularItem( GraphView
* GraphView
, int spacing
) :
104 GridItem( GraphView
),
111 //-----------------------------------------------------------------------------
115 /* CheckBoard Grid Management *///--------------------------------------------
116 GridCheckBoardItem::GridCheckBoardItem( GraphView
* GraphView
, QColor white
, QColor black
, qreal length
) :
117 GridItem( GraphView
),
121 _squaresPattern
= QPixmap( length
* 2, length
* 2 );
122 QPainter
painter( &_squaresPattern
);
123 painter
.fillRect( 0, 0, length
, length
, white
);
124 painter
.fillRect( length
, 0, length
, length
, black
);
125 painter
.fillRect( 0, length
, length
, length
, black
);
126 painter
.fillRect( length
, length
, length
, length
, white
);
130 void GridCheckBoardItem::drawBackground( QPainter
& painter
, const QRectF
& rect
)
132 GridItem::drawBackground( painter
, rect
);
134 int left
= ( int )rect
.left( );
135 int top
= ( int )rect
.top( );
136 int x
= ( ( left
/ 100 ) * 100 );
137 int y
= ( ( top
/ 100 ) * 100 );
144 if ( !_squaresPattern
.isNull( ) )
145 painter
.drawTiledPixmap( x
, y
, rect
.width( ) + 100, rect
.height( ) + 100, _squaresPattern
);
147 //-----------------------------------------------------------------------------