Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* A QLabel that rescales the set pixmap with respect of the current aspect ratio
|
||||
* $Id: flm_preview_file_dialog.cpp 52224 2020-09-30 12:31:15Z ojog_i $
|
||||
* $HeadURL: svn://192.168.133.21/TDS/branches/product/iterations/21_01_chaos/Lts/Plugins/FileManagement/Gui/Explorer/flm_preview_file_dialog.cpp $
|
||||
* $Author: ojog_i $
|
||||
*
|
||||
* Created by Mike Wille, SLTE, 2020-03-03
|
||||
*/
|
||||
|
||||
#include "RatioAwareLabel.h"
|
||||
|
||||
|
||||
RatioAwareLabel::RatioAwareLabel(QWidget *parent)
|
||||
: QLabel(parent)
|
||||
{
|
||||
setScaledContents(false);
|
||||
}
|
||||
|
||||
|
||||
void RatioAwareLabel::setPixmap(const QPixmap &pixmap)
|
||||
{
|
||||
m_pixmap = pixmap;
|
||||
scale();
|
||||
}
|
||||
|
||||
|
||||
int RatioAwareLabel::heightRatio(int width) const
|
||||
{
|
||||
if (m_pixmap.isNull())
|
||||
return height();
|
||||
return (m_pixmap.height() * width / m_pixmap.width());
|
||||
}
|
||||
|
||||
|
||||
QSize RatioAwareLabel::sizeHint() const
|
||||
{
|
||||
int w = width();
|
||||
return QSize(w, heightRatio(w));
|
||||
}
|
||||
|
||||
|
||||
void RatioAwareLabel::scale()
|
||||
{
|
||||
if (m_pixmap.isNull())
|
||||
return;
|
||||
QLabel::setPixmap(m_pixmap.scaled(size(), Qt::KeepAspectRatio, Qt::FastTransformation));
|
||||
}
|
||||
|
||||
|
||||
void RatioAwareLabel::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
QLabel::resizeEvent(event);
|
||||
scale();
|
||||
}
|
||||
Reference in new issue
Block a user