source: pacpussensors/trunk/StdDbtPlayerComponents/ImageViewer.cpp@ 55

Last change on this file since 55 was 16, checked in by DHERBOMEZ Gérald, 11 years ago

add standards replay components for some sensors that has to be used with DBITEPlayer application: StdDbtPlayerComponents

File size: 2.8 KB
RevLine 
[16]1/*********************************************************************
2// created: 2006/06/09 - 9:40
3// filename: ImageViewer.cpp
4//
5// author: Gerald Dherbomez
6// Copyright Heudiasyc UMR UTC/CNRS 6599
7//
8// version: $Id$
9//
10// purpose: Definition of the ImageViewer class
11//
12// todo : - think how to display geometric forms in the viewer (line,
13// circles, points, etc.)
14*********************************************************************/
15
16#define DEFAULT_IMAGE_WIDTH 320
17#define DEFAULT_IMAGE_HEIGHT 240
18#define DEFAULT_IMAGE_DEPTH 32
19
20#include "ImageViewer.h"
21
22#include <iostream>
23
24#include <QDebug>
25#include <QImage>
26#include <QMutex>
27#include <QPainter>
28#include <QPaintEvent>
29#include <QPixmap>
30
31using namespace std;
32
33//////////////////////////////////////////////////////////////////////////
34// constructor
35//////////////////////////////////////////////////////////////////////////
36ImageViewer::ImageViewer() : imageBuffer_(NULL)
37{
38 // setBackgroundMode(Qt::NoBackground);
39 setBackgroundRole(QPalette::Window);
40 imageBuffer_ = new QPixmap(DEFAULT_IMAGE_WIDTH, DEFAULT_IMAGE_HEIGHT);
41 resize(imageBuffer_->size());
42}
43
44
45//////////////////////////////////////////////////////////////////////////
46// destructor
47
48//////////////////////////////////////////////////////////////////////////
49ImageViewer::~ImageViewer()
50{
51 delete imageBuffer_;
52}
53
54//////////////////////////////////////////////////////////////////////////
55// slot
56// connect this to the signal that will send the image
57//////////////////////////////////////////////////////////////////////////
58void ImageViewer::display(QImage * image)
59{
60 //tic();
61 imageMutex_->lock();
62 if ( (image == NULL) || (image->isNull()) )
63 {
64 qDebug() << "ImageViewer: image is no more valid, not displayed";
65 }
66 else
67 {
68 if (imageBuffer_->size() != image->size())
69 resize(image->size());
70 *imageBuffer_ = QPixmap::fromImage(*image);
71 update();
72 }
73 imageMutex_->unlock();
74 //toc("imageViewer");
75
76}
77
78
79
80//////////////////////////////////////////////////////////////////////////
81// slot
82// activated when repaint() is called
83//////////////////////////////////////////////////////////////////////////
84void ImageViewer::paintEvent(QPaintEvent * e)
85{
86 QPainter painter(this);
87 painter.setClipRect(e->rect());
88 if (imageBuffer_) {
89 painter.drawPixmap(0,0,*imageBuffer_);
90 }
91}
92
93//////////////////////////////////////////////////////////////////////////
94void ImageViewer::setMutex(QMutex * imageMutex)
95{
96 imageMutex_ = imageMutex;
97}
98
99void ImageViewer::tic()
100{
101 tic_ = road_time();
102}
103
104void ImageViewer::toc(char * text)
105{
106 cout << "duration = " << (int)(road_time() - tic_) << " " << text << "\n";
107}
Note: See TracBrowser for help on using the repository browser.