arbeit
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

CanvasImage.cpp

Go to the documentation of this file.
00001 //------------------------------------------------------------------------
00002 //
00003 //   Joe Kniss
00004 //     6-20-03
00005 //                   ________    ____   ___ 
00006 //                  |        \  /    | /  /
00007 //                  +---+     \/     |/  /
00008 //                  +--+|  |\    /|     < 
00009 //                  |  ||  | \  / |  |\  \ 
00010 //                  |      |  \/  |  | \  \ 
00011 //                   \_____|      |__|  \__\
00012 //                       Copyright  2003 
00013 //                      Joe Michael Kniss
00014 //                   <<< jmk@cs.utah.edu >>>
00015 //               "All Your Base are Belong to Us"
00016 //-------------------------------------------------------------------------
00017 
00018 /// CanvasImage.cpp
00019 ///  simianUI
00020 
00021 
00022 #include "CanvasImage.h"
00023 #include <iostream>
00024 
00025 using namespace std;
00026 
00027 //////////////////////////////////////////////////////////////////////////
00028 /// construction
00029 //////////////////////////////////////////////////////////////////////////
00030 CanvasImage::CanvasImage(QCanvas *canvas)
00031 : QCanvasRectangle(canvas), 
00032   _image(0),
00033   _pixmap(0)
00034 {
00035 
00036 }
00037 
00038 //////////////////////////////////////////////////////////////////////////
00039 /// destruction
00040 //////////////////////////////////////////////////////////////////////////
00041 CanvasImage::~CanvasImage()
00042 {
00043    if(_image)  delete _image;
00044    if(_pixmap) delete _pixmap;
00045 }
00046 
00047 //////////////////////////////////////////////////////////////////////////
00048 /// setImage
00049 //////////////////////////////////////////////////////////////////////////
00050 void CanvasImage::setImage(QImage *img)
00051 {
00052    
00053    if(!img)
00054    {
00055       if(_pixmap) delete _pixmap;
00056       if(_image) delete _image;
00057       return;
00058    }
00059 
00060    setSize(img->width(), img->height());
00061 
00062    #if !defined(Q_WS_QWS)
00063       if(!_pixmap) _pixmap = new QPixmap();
00064       _pixmap->convertFromImage(*img, OrderedAlphaDither);
00065    #endif
00066    
00067    if(_image) delete _image; 
00068       _image = img;
00069 
00070 }
00071 
00072 //////////////////////////////////////////////////////////////////////////
00073 /// draw shape
00074 //////////////////////////////////////////////////////////////////////////
00075 void CanvasImage::drawShape( QPainter &p)
00076 {
00077    if(_pixmap)
00078    {
00079       p.drawPixmap( 0, 0, *_pixmap);
00080    }
00081    else if(_image)
00082    {
00083       p.drawImage( 0, 0, *_image);
00084    }
00085   
00086 }
00087 
00088 

Send questions, comments, and bug reports to:
jmk