forked from blue/squawk
some methods to cVard
This commit is contained in:
parent
e7be046e9f
commit
c4d22c9c14
5 changed files with 139 additions and 38 deletions
|
@ -19,19 +19,13 @@
|
|||
#include <QDebug>
|
||||
#include "image.h"
|
||||
|
||||
Image::Image(const QString& path, QWidget* parent):
|
||||
Image::Image(const QString& path, quint16 p_minWidth, QWidget* parent):
|
||||
QLabel(parent),
|
||||
pixmap(path),
|
||||
aspectRatio(0)
|
||||
aspectRatio(0),
|
||||
minWidth(p_minWidth)
|
||||
{
|
||||
|
||||
qreal height = pixmap.height();
|
||||
qreal width = pixmap.width();
|
||||
aspectRatio = width / height;
|
||||
setPixmap(pixmap);
|
||||
setScaledContents(true);
|
||||
setMinimumHeight(50 / aspectRatio);
|
||||
setMinimumWidth(50);
|
||||
}
|
||||
|
||||
Image::~Image()
|
||||
|
@ -42,7 +36,6 @@ Image::~Image()
|
|||
int Image::heightForWidth(int width) const
|
||||
{
|
||||
int height = width / aspectRatio;
|
||||
//qDebug() << height << width << aspectRatio;
|
||||
return height;
|
||||
}
|
||||
|
||||
|
@ -50,3 +43,27 @@ bool Image::hasHeightForWidth() const
|
|||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void Image::recalculateAspectRatio()
|
||||
{
|
||||
qreal height = pixmap.height();
|
||||
qreal width = pixmap.width();
|
||||
aspectRatio = width / height;
|
||||
setPixmap(pixmap);
|
||||
setMinimumHeight(minWidth / aspectRatio);
|
||||
setMinimumWidth(minWidth);
|
||||
}
|
||||
|
||||
void Image::setMinWidth(quint16 p_minWidth)
|
||||
{
|
||||
if (minWidth != p_minWidth) {
|
||||
minWidth = p_minWidth;
|
||||
recalculateAspectRatio();
|
||||
}
|
||||
}
|
||||
|
||||
void Image::setPath(const QString& path)
|
||||
{
|
||||
pixmap = QPixmap(path);
|
||||
recalculateAspectRatio();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue