Frapper  1.0a
PainterGraphicsScene.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of FRAPPER
4 research.animationsinstitut.de
5 sourceforge.net/projects/frapper
6 
7 Copyright (c) 2008-2012 Filmakademie Baden-Wuerttemberg, Institute of Animation
8 
9 This program is free software; you can redistribute it and/or modify it under
10 the terms of the GNU Lesser General Public License as published by the Free Software
11 Foundation; version 2.1 of the License.
12 
13 This program is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16 
17 You should have received a copy of the GNU Lesser General Public License along with
18 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
20 http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
21 -----------------------------------------------------------------------------
22 */
23 
32 
33 #ifndef PAINTERGRAPHICSSCENE_H
34 #define PAINTERGRAPHICSSCENE_H
35 
36 #include "FrapperPrerequisites.h"
37 
38 #include <QtGui/QGraphicsScene>
39 #include <QtGui/QGraphicsItem>
40 
41 namespace PainterPanel {
42 using namespace Frapper;
43 
44  class PainterGraphicsScene: public QGraphicsScene
45  {
46  public: // constructors and destructors
47 
52  PainterGraphicsScene () : QGraphicsScene(),
53  m_background(NULL)
54  {};
55 
64  {};
65 
69  void setBackground( QImage image )
70  {
71  if( m_background )
72  delete m_background;
73 
74  // set new background item
75  // add background image as pixmap item
76  m_background = new QGraphicsPixmapItem( QPixmap::fromImage(image));
77  m_background->setZValue(-1000.0f);
78  m_background->setFlag( QGraphicsItem::ItemIsSelectable, false );
79 
80  this->addItem(m_background);
81  }
82 
86  QGraphicsItem* getBackground() const { return m_background; }
87 
92  void renderToImage( QImage &image )
93  {
94  QPainter painter( &image );
95  if( m_background )
96  this->render( &painter, image.rect(), m_background->boundingRect());
97  else
98  this->render( &painter, image.rect());
99  }
100 
104  void clear()
105  {
106  Q_FOREACH( QGraphicsItem *item, this->items() ) {
107  if( item != m_background)
108  delete item;
109  }
110  }
111 
112  private: // data
113 
115  QGraphicsItem* m_background;
116 
117  }; //PainterGraphicsBaseItem
118 
119 } // end namespace Frapper
120 
121 #endif // PAINTERGRAPHICSSCENE_H