-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Scale image if the photo widget size is set to 0/0
- Loading branch information
Showing
5 changed files
with
125 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/*************************************************************************** | ||
---------------------------------------------------- | ||
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 ) | ||
{ | ||
mPixmap = p; | ||
QLabel::setPixmap( p ); | ||
} | ||
|
||
int QgsPixmapLabel::heightForWidth( int width ) const | ||
{ | ||
return (( qreal )mPixmap.height()*width ) / mPixmap.width(); | ||
} | ||
|
||
QSize QgsPixmapLabel::sizeHint() const | ||
{ | ||
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 ) ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/*************************************************************************** | ||
---------------------------------------------------- | ||
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. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSPIXMAPLABEL_H | ||
#define QGSPIXMAPLABEL_H | ||
|
||
#include <QLabel> | ||
|
||
/** | ||
* @brief The QgsPixmapLabel class shows a pixmap and adjusts its size to the space given | ||
* to the widget by the layout and keeping its aspect ratio. | ||
*/ | ||
class QgsPixmapLabel : public QLabel | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
explicit QgsPixmapLabel( QWidget *parent = 0 ); | ||
/** | ||
* Calculates the height for the given width. | ||
* | ||
* @param width The width for the widget | ||
* @return An appropriate height | ||
*/ | ||
virtual int heightForWidth( int width ) const; | ||
|
||
/** | ||
* An optimal size for the widget. Effectively using the height | ||
* determined from the width with the given aspect ratio. | ||
* @return A size hint | ||
*/ | ||
virtual QSize sizeHint() const; | ||
|
||
public slots: | ||
void setPixmap( const QPixmap & ); | ||
void resizeEvent( QResizeEvent * ); | ||
private: | ||
QPixmap mPixmap; | ||
}; | ||
|
||
#endif // QGSPIXMAPLABEL_H |