image_widget.cpp
Go to the documentation of this file.
00001 
00016 #include <QtGui>
00017 #include <iostream>
00018 
00019 #include <color_table/image_widget.h>
00020 #include <color_table/common.h>
00021 
00022 namespace color_table {
00023 
00024   ImageWidget::ImageWidget(QWidget *parent) : QWidget(parent) {
00025     img = new QImage(IMAGE_WIDTH,IMAGE_HEIGHT,QImage::Format_RGB32);
00026     img->fill(Qt::black);
00027   }
00028 
00029   void ImageWidget::reduceImageSize(int factor){
00030     img = new QImage(IMAGE_WIDTH/factor,IMAGE_HEIGHT/factor,QImage::Format_RGB32);
00031     img->fill(Qt::black);
00032   }
00033    
00034   void ImageWidget::paintEvent(QPaintEvent *event) {
00035     QPainter painter;
00036     painter.begin(this);
00037 
00038     painter.drawImage(event->rect(), *img);
00039     painter.end();
00040   }
00041 
00042   void ImageWidget::mousePressEvent(QMouseEvent *event) {
00043     if (event->button() != Qt::LeftButton && event->button() != Qt::RightButton) return;
00044     float x=(float)event->x()/(float)width()*IMAGE_WIDTH;
00045     float y=(float)event->y()/(float)height()*IMAGE_HEIGHT;
00046     emit clicked((int)x,(int)y, (int) event->button());
00047   }
00048 
00049   void ImageWidget::mouseMoveEvent(QMouseEvent *event) {
00050     float x=(float)event->x()/(float)width()*IMAGE_WIDTH;
00051     float y=(float)event->y()/(float)height()*IMAGE_HEIGHT;
00052     emit mouseXY((int)x,(int)y);
00053   }
00054 
00055 }


color_table
Author(s): Piyush Khandelwal
autogenerated on Mon Jan 6 2014 11:54:34