| 1 | /*************************************************************************** | 
|---|
| 2 |                           QImageWidget.cpp  -  description | 
|---|
| 3 |                              ------------------- | 
|---|
| 4 |     begin                : Fri Nov 17 2000 | 
|---|
| 5 |     copyright            : (C) 2000 by Rainer Lehrig | 
|---|
| 6 |     email                : lehrig@t-online.de | 
|---|
| 7 |  ***************************************************************************/ | 
|---|
| 8 |  | 
|---|
| 9 | /*************************************************************************** | 
|---|
| 10 |  *                                                                         * | 
|---|
| 11 |  *   This program is free software; you can redistribute it and/or modify  * | 
|---|
| 12 |  *   it under the terms of the GNU General Public License as published by  * | 
|---|
| 13 |  *   the Free Software Foundation; either version 2 of the License, or     * | 
|---|
| 14 |  *   (at your option) any later version.                                   * | 
|---|
| 15 |  *                                                                         * | 
|---|
| 16 |  ***************************************************************************/ | 
|---|
| 17 | #include "q_image_widget.h" | 
|---|
| 18 | #include <QtGui/QPainter> | 
|---|
| 19 | #include <QtGui/QPaintEvent> | 
|---|
| 20 |  | 
|---|
| 21 | QImageWidget::QImageWidget( QWidget *parent) | 
|---|
| 22 |              : QWidget( parent) | 
|---|
| 23 | { | 
|---|
| 24 |   image = QImage(); // construct a null image | 
|---|
| 25 |   x = y = w = h = 0; | 
|---|
| 26 | } | 
|---|
| 27 |  | 
|---|
| 28 | QImageWidget::~QImageWidget() | 
|---|
| 29 | { | 
|---|
| 30 | } | 
|---|
| 31 |  | 
|---|
| 32 | void QImageWidget::setImage(const QImage& newimage) | 
|---|
| 33 | { | 
|---|
| 34 |   this->image = newimage.copy(); | 
|---|
| 35 |   w = this->image.width(); | 
|---|
| 36 |   h = this->image.height(); | 
|---|
| 37 |   this->setMinimumSize(w, h); | 
|---|
| 38 | } | 
|---|
| 39 |  | 
|---|
| 40 | void QImageWidget::paintEvent( QPaintEvent *e ) | 
|---|
| 41 | { | 
|---|
| 42 |   if( !image.isNull() ) | 
|---|
| 43 |   { | 
|---|
| 44 |     QPainter p; | 
|---|
| 45 |     p.begin(this); | 
|---|
| 46 |     p.setClipRect(e->rect()); | 
|---|
| 47 |     p.drawLine(0,0,100,100); | 
|---|
| 48 |     p.drawImage(QPoint(0,0), this->image); | 
|---|
| 49 |     p.end(); | 
|---|
| 50 |     /* | 
|---|
| 51 |     QPainter painter(this); | 
|---|
| 52 |     painter.setClipRect(e->rect()); | 
|---|
| 53 |     painter.drawImage(QPoint(0,0), image); | 
|---|
| 54 |     */ | 
|---|
| 55 |   } | 
|---|
| 56 | } | 
|---|
| 57 |  | 
|---|
| 58 | void QImageWidget::setGeometry(int nx, int ny, int nw, int nh) | 
|---|
| 59 | { | 
|---|
| 60 |   x = nx; | 
|---|
| 61 |   y = ny; | 
|---|
| 62 |   w = nw; | 
|---|
| 63 |   h = nh; | 
|---|
| 64 |   move(x,y); | 
|---|
| 65 |   resize(w,h); | 
|---|
| 66 |   repaint(0,0,w,h); | 
|---|
| 67 | } | 
|---|