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();
|
||||
}
|
||||
|
|
|
@ -28,34 +28,22 @@
|
|||
class Image : public QLabel
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
Image(const QString& path, QWidget* parent = nullptr);
|
||||
Image(const QString& path, quint16 minWidth = 50, QWidget* parent = nullptr);
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
~Image();
|
||||
|
||||
/**
|
||||
* @todo write docs
|
||||
*
|
||||
* @param TODO
|
||||
* @return TODO
|
||||
*/
|
||||
int heightForWidth(int width) const override;
|
||||
|
||||
/**
|
||||
* @todo write docs
|
||||
*
|
||||
* @return TODO
|
||||
*/
|
||||
virtual bool hasHeightForWidth() const;
|
||||
bool hasHeightForWidth() const override;
|
||||
void setPath(const QString& path);
|
||||
void setMinWidth(quint16 minWidth);
|
||||
|
||||
private:
|
||||
QPixmap pixmap;
|
||||
qreal aspectRatio;
|
||||
quint16 minWidth;
|
||||
|
||||
private:
|
||||
void recalculateAspectRatio();
|
||||
};
|
||||
|
||||
#endif // IMAGE_H
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue