-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathaspectratiopixmap.cpp
More file actions
39 lines (33 loc) · 899 Bytes
/
aspectratiopixmap.cpp
File metadata and controls
39 lines (33 loc) · 899 Bytes
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
#include "aspectratiopixmap.h"
AspectRatioPixmap::AspectRatioPixmap(QWidget *parent) :
QLabel(parent)
{
this->setMinimumSize(1,1);
setScaledContents(false);
}
void AspectRatioPixmap::setPixmap ( const QPixmap & p)
{
pix = p;
QLabel::setPixmap(scaledPixmap());
}
int AspectRatioPixmap::heightForWidth( int width ) const
{
return pix.isNull() ? this->height() : ((qreal)pix.height()*width)/pix.width();
}
QSize AspectRatioPixmap::sizeHint() const
{
int w = this->width();
return QSize( w, heightForWidth(w) );
}
QPixmap AspectRatioPixmap::scaledPixmap() const
{
if(!pix.isNull())
return pix.scaled(this->size(), Qt::KeepAspectRatio, Qt::FastTransformation);
else
return pix;
}
void AspectRatioPixmap::resizeEvent(QResizeEvent * e)
{
if(!pix.isNull())
QLabel::setPixmap(scaledPixmap());
}