bunch of stuff. very basic drag/drop now working
This commit is contained in:
36
aspectratiopixmaplabel.cpp
Normal file
36
aspectratiopixmaplabel.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#include "aspectratiopixmaplabel.hpp"
|
||||
|
||||
AspectRatioPixmapLabel::AspectRatioPixmapLabel(QWidget *parent) :
|
||||
QLabel(parent)
|
||||
{
|
||||
this->setMinimumSize(1,1);
|
||||
setScaledContents(false);
|
||||
}
|
||||
|
||||
void AspectRatioPixmapLabel::setPixmap ( const QPixmap & p)
|
||||
{
|
||||
pix = p;
|
||||
QLabel::setPixmap(scaledPixmap());
|
||||
}
|
||||
|
||||
int AspectRatioPixmapLabel::heightForWidth( int width ) const
|
||||
{
|
||||
return pix.isNull() ? this->height() : ((qreal)pix.height()*width)/pix.width();
|
||||
}
|
||||
|
||||
QSize AspectRatioPixmapLabel::sizeHint() const
|
||||
{
|
||||
int w = this->width();
|
||||
return QSize( w, heightForWidth(w) );
|
||||
}
|
||||
|
||||
QPixmap AspectRatioPixmapLabel::scaledPixmap() const
|
||||
{
|
||||
return pix.scaled(this->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
}
|
||||
|
||||
void AspectRatioPixmapLabel::resizeEvent(QResizeEvent * e)
|
||||
{
|
||||
if(!pix.isNull())
|
||||
QLabel::setPixmap(scaledPixmap());
|
||||
}
|
||||
Reference in New Issue
Block a user