(empty message)
[qanava.git] / src / can / canCanvas.cpp
blob32bcfa7e76d03b8cb2625b934a79ca69f32e7e47
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 canCanvas.cpp
24 // \author Benoit Autheman (benoit@faktiss.net)
25 // \date 2004 October 13
26 //-----------------------------------------------------------------------------
29 // Qanava headers
30 #include "canCanvas.h"
33 // QT headers
34 #include <qwmatrix.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;
47 else
49 QImage* image = new QImage( fileName.c_str( ) );
50 if ( image != 0 && image->isNull( ) )
52 delete image;
53 return 0;
55 else if ( image != 0 && !image->isNull( ) )
57 _nameImageMap.insert( std::pair< const std::string, QImage* >( fileName, image ) );
58 return image;
62 return 0;
64 //-----------------------------------------------------------------------------
68 /* Canvas Constructor/Destructor *///------------------------------------------
69 Canvas::Canvas( int w, int h, QColor backColor ) :
70 QCanvas( w, h ),
71 _view( 0 ),
72 _grid( *this )
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( )
94 return _items;
97 bool Canvas::isFreed( void* item )
99 std::set< void* >::const_iterator itemIter = _freezed.find( item );
100 if ( itemIter != _freezed.end( ) )
101 return true;
102 return false;
105 void Canvas::setFreezed( void* item )
107 _freezed.insert( item );
110 void Canvas::canvasResized( )
112 getGrid( ).resize( width( ), height( ) );
114 //-----------------------------------------------------------------------------
117 } // ::qan::can
118 } // ::qan