Qtopia library API Documentation

imageedit.cpp

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 #include <qpainter.h>
00022 
00023 ImageEdit::ImageEdit( QWidget *parent, const char *name)
00024     : QScrollView( parent, name, WNorthWestGravity | WResizeNoErase ), buffer()
00025 {
00026     buffer.resize( size() );
00027     buffer.fill( colorGroup().color( QColorGroup::Base ) );
00028 }
00029 
00030 ImageEdit::~ImageEdit()
00031 {
00032     
00033 }
00034 
00035 void ImageEdit::contentsMousePressEvent( QMouseEvent *e )
00036 {
00037     lastPos = e->pos();
00038 }
00039 
00040 void ImageEdit::contentsMouseMoveEvent( QMouseEvent *e )
00041 {
00042     QPainter pw( viewport() );
00043     QPainter pb( &buffer );
00044     pb.drawLine( lastPos, e->pos() );
00045     pw.drawLine( contentsToViewport( lastPos ),
00046          contentsToViewport( e->pos() ) );
00047     lastPos = e->pos();
00048 }
00049 
00050 void ImageEdit::contentsMouseReleaseEvent( QMouseEvent * )
00051 {
00052 }
00053 
00054 void ImageEdit::viewportResizeEvent( QResizeEvent *e )
00055 {
00056     enlargeBuffer(e->size());
00057 }
00058 
00059 void ImageEdit::enlargeBuffer( const QSize& sz )
00060 {
00061     QSize osz = buffer.size();
00062     QSize nsz( QMAX( osz.width(), sz.width() ), QMAX( osz.height(), sz.height() ) );
00063     buffer.resize( nsz.width(), nsz.height() );
00064     // clear new area
00065     QPainter p( &buffer );
00066     if ( sz.width() > osz.width() )
00067     p.fillRect( osz.width(), 0, sz.width() - osz.width(), nsz.height(), colorGroup().color( QColorGroup::Base ) );
00068     if ( sz.height() > osz.height() )
00069     p.fillRect( 0, osz.height(), nsz.width(), sz.height() - osz.height(), colorGroup().color( QColorGroup::Base ) );
00070     p.end();
00071 }
00072 
00073 void ImageEdit::drawContents( QPainter *p, int cx, int cy, int cw, int ch )
00074 {
00075     p->drawPixmap( cx, cy, buffer, cx, cy, cw, ch );
00076 }
00077 
00078 void ImageEdit::setPixmap( const QPixmap &pm )
00079 {
00080     QSize osz = buffer.size();
00081     if ( pm.width() < osz.width() || pm.height() < osz.height() ) {
00082     buffer.fill(white);
00083     enlargeBuffer( pm.size() );
00084     QPainter p(&buffer);
00085     p.drawPixmap(0,0,pm);
00086     } else {
00087     buffer = pm;
00088     }
00089     resizeContents( buffer.width(), buffer.height() );
00090     viewport()->repaint( FALSE );
00091 }
00092 
00093 QPixmap ImageEdit::pixmap() const
00094 {
00095     return buffer;
00096 }
00097 
KDE Logo
This file is part of the documentation for OPIE Version 1.5.5.
Documentation copyright © 1997-2003 the KDE developers. 2003 OPIE developers
Generated on Tue Feb 10 20:24:05 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001