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 00014 BackgroundStateAbstractBase::BackgroundStateAbstractBase(BackgroundStateContext &context, 00015 GraphicsScene &scene) : 00016 m_context (context), 00017 m_scene (scene), 00018 m_imageItem (0) 00019 { 00020 // Create an image but do not show it until the appropriate state is reached 00021 QPixmap dummy; 00022 m_imageItem = m_scene.addPixmap (dummy); 00023 m_imageItem->setVisible (false); 00024 m_imageItem->setData (DATA_KEY_IDENTIFIER, "view"); 00025 m_imageItem->setData (DATA_KEY_GRAPHICS_ITEM_TYPE, GRAPHICS_ITEM_TYPE_IMAGE); 00026 } 00027 00028 BackgroundStateAbstractBase::~BackgroundStateAbstractBase() 00029 { 00030 } 00031 00032 BackgroundStateContext &BackgroundStateAbstractBase::context() 00033 { 00034 return m_context; 00035 } 00036 00037 const BackgroundStateContext &BackgroundStateAbstractBase::context() const 00038 { 00039 return m_context; 00040 } 00041 00042 QImage BackgroundStateAbstractBase::image () const 00043 { 00044 return m_image; 00045 } 00046 00047 QGraphicsPixmapItem &BackgroundStateAbstractBase::imageItem () const 00048 { 00049 return *m_imageItem; 00050 } 00051 00052 GraphicsScene &BackgroundStateAbstractBase::scene() 00053 { 00054 return m_scene; 00055 } 00056 00057 const GraphicsScene &BackgroundStateAbstractBase::scene() const 00058 { 00059 return m_scene; 00060 } 00061 00062 void BackgroundStateAbstractBase::setImageVisible (bool visible) 00063 { 00064 m_imageItem->setVisible (visible); 00065 } 00066 00067 void BackgroundStateAbstractBase::setProcessedPixmap (const QPixmap &pixmap) 00068 { 00069 LOG4CPP_INFO_S ((*mainCat)) << "BackgroundStateAbstractBase::setProcessedPixmap" 00070 << " map=(" << pixmap.width() << "x" << pixmap.height() << ")"; 00071 00072 ENGAUGE_CHECK_PTR(m_imageItem); 00073 00074 m_imageItem->setPixmap (pixmap); 00075 00076 // Reset scene rectangle or else small image after large image will be off-center 00077 m_scene.setSceneRect (m_imageItem->boundingRect ()); 00078 00079 m_image = pixmap.toImage(); 00080 }