Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

imageedit.cpp

Go to the documentation of this file.
00001 /**********************************************************************
00002 ** Copyright (C) 2000-2002 Trolltech AS.  All rights reserved.
00003 **
00004 ** This file is part of the Qtopia Environment.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00015 **
00016 ** Contact info@trolltech.com if any conditions of this licensing are
00017 ** not clear to you.
00018 **
00019 **********************************************************************/
00020 #include "imageedit.h"
00021 
00022 ImageEdit::ImageEdit( QWidget *parent, const char *name)
00023     : QScrollView( parent, name, WNorthWestGravity | WResizeNoErase ), buffer()
00024 {
00025     buffer.resize( size() );
00026     buffer.fill( colorGroup().color( QColorGroup::Base ) );
00027 }
00028 
00029 ImageEdit::~ImageEdit()
00030 {
00031     
00032 }
00033 
00034 void ImageEdit::contentsMousePressEvent( QMouseEvent *e )
00035 {
00036     lastPos = e->pos();
00037 }
00038 
00039 void ImageEdit::contentsMouseMoveEvent( QMouseEvent *e )
00040 {
00041     QPainter pw( viewport() );
00042     QPainter pb( &buffer );
00043     pb.drawLine( lastPos, e->pos() );
00044     pw.drawLine( contentsToViewport( lastPos ),
00045                  contentsToViewport( e->pos() ) );
00046     lastPos = e->pos();
00047 }
00048 
00049 void ImageEdit::contentsMouseReleaseEvent( QMouseEvent * )
00050 {
00051 }
00052 
00053 void ImageEdit::viewportResizeEvent( QResizeEvent *e )
00054 {
00055     enlargeBuffer(e->size());
00056 }
00057 
00058 void ImageEdit::enlargeBuffer( const QSize& sz )
00059 {
00060     QSize osz = buffer.size();
00061     QSize nsz( QMAX( osz.width(), sz.width() ), QMAX( osz.height(), sz.height() ) );
00062     buffer.resize( nsz.width(), nsz.height() );
00063     // clear new area
00064     QPainter p( &buffer );
00065     if ( sz.width() > osz.width() )
00066         p.fillRect( osz.width(), 0, sz.width() - osz.width(), nsz.height(), colorGroup().color( QColorGroup::Base ) );
00067     if ( sz.height() > osz.height() )
00068         p.fillRect( 0, osz.height(), nsz.width(), sz.height() - osz.height(), colorGroup().color( QColorGroup::Base ) );
00069     p.end();
00070 }
00071 
00072 void ImageEdit::drawContents( QPainter *p, int cx, int cy, int cw, int ch )
00073 {
00074     p->drawPixmap( cx, cy, buffer, cx, cy, cw, ch );
00075 }
00076 
00077 void ImageEdit::setPixmap( const QPixmap &pm )
00078 {
00079     QSize osz = buffer.size();
00080     if ( pm.width() < osz.width() || pm.height() < osz.height() ) {
00081         buffer.fill(white);
00082         enlargeBuffer( pm.size() );
00083         QPainter p(&buffer);
00084         p.drawPixmap(0,0,pm);
00085     } else {
00086         buffer = pm;
00087     }
00088     resizeContents( buffer.width(), buffer.height() );
00089     viewport()->repaint( FALSE );
00090 }
00091 
00092 QPixmap ImageEdit::pixmap() const
00093 {
00094     return buffer;
00095 }
00096 

Generated on Sat Nov 5 16:16:36 2005 for OPIE by  doxygen 1.4.2