-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
qgspixmaplabel.cpp
61 lines (49 loc) · 1.9 KB
/
qgspixmaplabel.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/***************************************************************************
----------------------------------------------------
date : 7.9.2015
copyright : (C) 2015 by Matthias Kuhn
email : matthias (at) opengis.ch
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgspixmaplabel.h"
QgsPixmapLabel::QgsPixmapLabel( QWidget *parent ) :
QLabel( parent )
{
this->setMinimumSize( 1, 1 );
}
void QgsPixmapLabel::setPixmap( const QPixmap & p )
{
bool sizeChanged = ( p.size() != mPixmap.size() );
mPixmap = p;
if ( sizeChanged )
{
updateGeometry();
}
QLabel::setPixmap( mPixmap.scaled( this->size(),
Qt::KeepAspectRatio, Qt::SmoothTransformation ) );
}
int QgsPixmapLabel::heightForWidth( int width ) const
{
if ( mPixmap.isNull() )
return 0;
return (( qreal )mPixmap.height()*width ) / mPixmap.width();
}
QSize QgsPixmapLabel::sizeHint() const
{
if ( mPixmap.isNull() )
return QSize( 0, 0 );
int w = this->width();
return QSize( w, heightForWidth( w ) );
}
void QgsPixmapLabel::resizeEvent( QResizeEvent * e )
{
QLabel::resizeEvent( e );
QLabel::setPixmap( mPixmap.scaled( this->size(),
Qt::KeepAspectRatio, Qt::SmoothTransformation ) );
}