imagepreview.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "imagepreview.h"
00021
00022 #include <qpainter.h>
00023 #include <qpixmap.h>
00024 #include <qpaintdevice.h>
00025
00026
00027 QImage convertImage(const QImage& image, int hue, int saturation, int brightness, int gamma);
00028
00029 ImagePreview::ImagePreview(QWidget *parent, const char *name ) : QWidget(parent,name) {
00030 brightness_ = 100;
00031 hue_ = 0;
00032 saturation_ = 100;
00033 gamma_ = 1000;
00034 bw_ = false;
00035
00036 setBackgroundMode(NoBackground);
00037 }
00038
00039 ImagePreview::~ImagePreview(){
00040 }
00041
00042 void ImagePreview::setImage(const QImage& image){
00043 image_ = image.convertDepth(32);
00044 image_.detach();
00045 resize(image_.size());
00046 update();
00047 }
00048
00049 void ImagePreview::setParameters(int brightness, int hue, int saturation, int gamma){
00050 brightness_ = brightness;
00051 hue_ = hue;
00052 saturation_ = saturation;
00053 gamma_ = gamma;
00054 repaint();
00055 }
00056
00057 void ImagePreview::paintEvent(QPaintEvent*){
00058 QImage tmpImage = convertImage(image_,hue_,(bw_ ? 0 : saturation_),brightness_,gamma_);
00059 int x = (width()-tmpImage.width())/2, y = (height()-tmpImage.height())/2;
00060
00061 QPixmap buffer(width(), height());
00062 buffer.fill(parentWidget(), 0, 0);
00063 QPainter p(&buffer);
00064 p.drawImage(x,y,tmpImage);
00065 p.end();
00066
00067 bitBlt(this, QPoint(0, 0), &buffer, buffer.rect(), Qt::CopyROP);
00068 }
00069
00070 void ImagePreview::setBlackAndWhite(bool on){
00071 bw_ = on;
00072 update();
00073 }
00074
00075 QSize ImagePreview::minimumSizeHint() const
00076 {
00077 return image_.size();
00078 }
|