00001 /****************************************************************************************************** 00002 * (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released * 00003 * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file * 00004 * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. * 00005 ******************************************************************************************************/ 00006 00007 #include "BackgroundStateAbstractBase.h" 00008 #include "DataKey.h" 00009 #include "EngaugeAssert.h" 00010 #include "GraphicsItemType.h" 00011 #include "GraphicsScene.h" 00012 #include "Logger.h" 00013 #include "ZValues.h" 00014 00015 BackgroundStateAbstractBase::BackgroundStateAbstractBase(BackgroundStateContext &context, 00016 GraphicsScene &scene) : 00017 m_context (context), 00018 m_scene (scene), 00019 m_imageItem (0) 00020 { 00021 // Create an image but do not show it until the appropriate state is reached 00022 QPixmap dummy; 00023 m_imageItem = m_scene.addPixmap (dummy); 00024 m_imageItem->setVisible (false); 00025 m_imageItem->setZValue (Z_VALUE_BACKGROUND); 00026 m_imageItem->setData (DATA_KEY_IDENTIFIER, "view"); 00027 m_imageItem->setData (DATA_KEY_GRAPHICS_ITEM_TYPE, GRAPHICS_ITEM_TYPE_IMAGE); 00028 } 00029 00030 BackgroundStateAbstractBase::~BackgroundStateAbstractBase() 00031 { 00032 } 00033 00034 BackgroundStateContext &BackgroundStateAbstractBase::context() 00035 { 00036 return m_context; 00037 } 00038 00039 const BackgroundStateContext &BackgroundStateAbstractBase::context() const 00040 { 00041 return m_context; 00042 } 00043 00044 QImage BackgroundStateAbstractBase::image () const 00045 { 00046 return m_image; 00047 } 00048 00049 QGraphicsPixmapItem &BackgroundStateAbstractBase::imageItem () const 00050 { 00051 return *m_imageItem; 00052 } 00053 00054 GraphicsScene &BackgroundStateAbstractBase::scene() 00055 { 00056 return m_scene; 00057 } 00058 00059 const GraphicsScene &BackgroundStateAbstractBase::scene() const 00060 { 00061 return m_scene; 00062 } 00063 00064 void BackgroundStateAbstractBase::setImageVisible (bool visible) 00065 { 00066 m_imageItem->setVisible (visible); 00067 } 00068 00069 void BackgroundStateAbstractBase::setProcessedPixmap (const QPixmap &pixmap) 00070 { 00071 LOG4CPP_INFO_S ((*mainCat)) << "BackgroundStateAbstractBase::setProcessedPixmap" 00072 << " map=(" << pixmap.width() << "x" << pixmap.height() << ")"; 00073 00074 ENGAUGE_CHECK_PTR(m_imageItem); 00075 00076 m_imageItem->setPixmap (pixmap); 00077 00078 // Reset scene rectangle or else small image after large image will be off-center 00079 m_scene.setSceneRect (m_imageItem->boundingRect ()); 00080 00081 m_image = pixmap.toImage(); 00082 }