#include <qpixmap.h>
#include <qpainter.h>
#include <qimage.h>
#include <qcursor.h>
#include "PixmapWidget.h"
PixmapWidget
::PixmapWidget( const char* fileName,
QWidget* w,
QWidget *parent
) {
m_zoomWindow = w;
pasteRect
= QRect(this
->geometry
().
left(), this
->geometry
().
top(),
100,
100);
m_pm = 0;
QImage img
(fileName
);
//fileName is the name of image
if( ! img.isNull() )
{
}
zoomFactor = 0.30001;
setMinimumSize( m_pm->width()*zoomFactor, m_pm->height()*zoomFactor );
setMouseTracking(true);
}
PixmapWidget::~PixmapWidget()
{
delete m_pm;
}
{
p.save();
p.scale( zoomFactor, zoomFactor );
p.drawPixmap( 0, 0, *m_pm );
p.restore();
}
{
//Show a rectangle for debugging. This code will be removed later
// The rectangle is shown on image to know how much area of image is
//covered
QPen pen
( foregroundColor
(),
1 );
paint.begin( this );
paint.setPen( pen );
paint.setRasterOp( NotXorROP );
// erase the oldRect
paint.drawRect( oldRect );
pasteRect.
moveTopLeft( ( ((QMouseEvent *)e
)->pos
() ) );
paint.drawRect( pasteRect );
oldRect = pasteRect;
paint.end();
//Draw the image on zoomWindow which is window2
//I'm stuck here!!!!
//how do I get the part of image where the mouse pointer is
//
p.begin( m_zoomWindow );
p.setRasterOp( NotXorROP );
p.drawPixmap( pasteRect, *m_pm );
p.end();
}
#include <qpixmap.h>
#include <qpainter.h>
#include <qimage.h>
#include <qcursor.h>
#include "PixmapWidget.h"
PixmapWidget::PixmapWidget( const char* fileName, QWidget* w, QWidget *parent )
: QWidget( parent )
{
m_zoomWindow = w;
oldRect = QRect();
pasteRect = QRect(this->geometry().left(), this->geometry().top(), 100, 100);
m_pm = 0;
QImage img(fileName);//fileName is the name of image
if( ! img.isNull() )
{
m_pm = new QPixmap( img );
}
zoomFactor = 0.30001;
setMinimumSize( m_pm->width()*zoomFactor, m_pm->height()*zoomFactor );
setMouseTracking(true);
}
PixmapWidget::~PixmapWidget()
{
delete m_pm;
}
void PixmapWidget::paintEvent( QPaintEvent *event )
{
QPainter p( this );
p.save();
p.scale( zoomFactor, zoomFactor );
p.drawPixmap( 0, 0, *m_pm );
p.restore();
}
void PixmapWidget::mouseMoveEvent( QMouseEvent *e )
{
//Show a rectangle for debugging. This code will be removed later
// The rectangle is shown on image to know how much area of image is
//covered
QPen pen( foregroundColor(), 1 );
QPainter paint;
paint.begin( this );
paint.setPen( pen );
paint.setRasterOp( NotXorROP );
// erase the oldRect
paint.drawRect( oldRect );
pasteRect.moveTopLeft( ( ((QMouseEvent *)e)->pos() ) );
paint.drawRect( pasteRect );
oldRect = pasteRect;
paint.end();
//Draw the image on zoomWindow which is window2
//I'm stuck here!!!!
//how do I get the part of image where the mouse pointer is
//
QPainter p;
p.begin( m_zoomWindow );
p.setRasterOp( NotXorROP );
p.drawPixmap( pasteRect, *m_pm );
p.end();
}
To copy to clipboard, switch view to plain text mode
Bookmarks