imageedit.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
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
This file is part of the documentation for OPIE Version 1.5.5.