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 canCanvas.cpp
24 // \author Benoit Autheman (benoit@faktiss.net)
25 // \date 2004 October 13
26 //-----------------------------------------------------------------------------
30 #include "canCanvas.h"
37 namespace qan
{ // ::qan
38 namespace can
{ // ::qan::can
41 /* Image Management *///-------------------------------------------------------
42 QImage
* ImageManager::getImage( const std::string
& fileName
)
44 NameImageMap::iterator imageIter
= _nameImageMap
.find( fileName
);
45 if ( imageIter
!= _nameImageMap
.end( ) )
46 return ( *imageIter
).second
;
49 QImage
* image
= new QImage( fileName
.c_str( ) );
50 if ( image
!= 0 && image
->isNull( ) )
55 else if ( image
!= 0 && !image
->isNull( ) )
57 _nameImageMap
.insert( std::pair
< const std::string
, QImage
* >( fileName
, image
) );
64 //-----------------------------------------------------------------------------
68 /* Canvas Constructor/Destructor *///------------------------------------------
69 Canvas::Canvas( int w
, int h
, QColor backColor
) :
74 setDoubleBuffering( true );
75 setBackgroundColor( backColor
);
76 setAdvancePeriod( 30 ); // Fix a refresh bug with shadows (item affected by style do not refresh the
77 // canvas state properly
79 // Connect the resized() signal to slot canvasResized()
80 connect( this, SIGNAL(resized()), this, SLOT(canvasResized()) );
82 //-----------------------------------------------------------------------------
86 /* Item Management *///-------------------------------------------------------
87 void Canvas::addItem( Item
& item
)
89 _items
.push_back( &item
);
92 Canvas::Items
& Canvas::getItems( )
97 bool Canvas::isFreed( void* item
)
99 std::set
< void* >::const_iterator itemIter
= _freezed
.find( item
);
100 if ( itemIter
!= _freezed
.end( ) )
105 void Canvas::setFreezed( void* item
)
107 _freezed
.insert( item
);
110 void Canvas::canvasResized( )
112 getGrid( ).resize( width( ), height( ) );
114 //-----------------------------------------------------------------------------