-
Notifications
You must be signed in to change notification settings - Fork 4
/
imagewidget.cpp
46 lines (42 loc) · 1013 Bytes
/
imagewidget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "imagewidget.h"
#include <QPainter>
#include <QPaintEvent>
#include <QtDebug> //DBG only
/*!
* \class ImageWidget
* \brief Widget for showing Pixmaps
*/
ImageWidget::ImageWidget(QWidget *parent) :
QWidget(parent),
mPixmapOffset(0,0)
{
setAttribute( Qt::WA_NoSystemBackground);
}
void ImageWidget:: setPixmap( const QPixmap& pixmap)
{
mPixmap = pixmap;
setMinimumSize( pixmap.size());
updatePixmapOffset();
updateGeometry();
update();
}
QSize ImageWidget:: sizeHint()
{
return mPixmap.size();
}
void ImageWidget:: paintEvent( QPaintEvent *event)
{
Q_UNUSED(event)
QPainter painter(this);
painter.drawPixmap( mPixmapOffset, mPixmap);
}
void ImageWidget:: resizeEvent( QResizeEvent *event)
{
Q_UNUSED(event)
updatePixmapOffset();
}
void ImageWidget:: updatePixmapOffset()
{
mPixmapOffset.setX( (width() - mPixmap.width()) / 2 );
mPixmapOffset.setY( (height() - mPixmap.height()) / 2 );
}