mirror of
https://github.com/redstrate/Novus.git
synced 2025-04-25 21:27:45 +00:00
Add texpart for viewing textures
This commit is contained in:
parent
93b6380b3d
commit
718ea74c1f
3 changed files with 67 additions and 0 deletions
|
@ -5,3 +5,4 @@ add_subdirectory(exd)
|
|||
add_subdirectory(exl)
|
||||
add_subdirectory(hex)
|
||||
add_subdirectory(mdl)
|
||||
add_subdirectory(tex)
|
42
parts/tex/imagelabel.cpp
Normal file
42
parts/tex/imagelabel.cpp
Normal file
|
@ -0,0 +1,42 @@
|
|||
// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
|
||||
//
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "imagelabel.h"
|
||||
|
||||
ImageLabel::ImageLabel(QWidget *parent)
|
||||
: QLabel(parent)
|
||||
{
|
||||
this->setMinimumSize(1, 1);
|
||||
setScaledContents(false);
|
||||
}
|
||||
|
||||
void ImageLabel::setQPixmap(const QPixmap &p)
|
||||
{
|
||||
pix = p;
|
||||
QLabel::setPixmap(scaledPixmap());
|
||||
}
|
||||
|
||||
int ImageLabel::heightForWidth(int width) const
|
||||
{
|
||||
return pix.isNull() ? height() : (pix.height() * width) / pix.width();
|
||||
}
|
||||
|
||||
QSize ImageLabel::sizeHint() const
|
||||
{
|
||||
const int w = this->width();
|
||||
return {w, heightForWidth(w)};
|
||||
}
|
||||
|
||||
QPixmap ImageLabel::scaledPixmap() const
|
||||
{
|
||||
return pix.scaled(this->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
}
|
||||
|
||||
void ImageLabel::resizeEvent(QResizeEvent *e)
|
||||
{
|
||||
Q_UNUSED(e);
|
||||
if (!pix.isNull()) {
|
||||
QLabel::setPixmap(scaledPixmap());
|
||||
}
|
||||
}
|
24
parts/tex/imagelabel.h
Normal file
24
parts/tex/imagelabel.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QLabel>
|
||||
|
||||
class ImageLabel : public QLabel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ImageLabel(QWidget *parent = nullptr);
|
||||
|
||||
[[nodiscard]] int heightForWidth(int width) const override;
|
||||
[[nodiscard]] QSize sizeHint() const override;
|
||||
[[nodiscard]] QPixmap scaledPixmap() const;
|
||||
|
||||
public Q_SLOTS:
|
||||
void setQPixmap(const QPixmap &);
|
||||
void resizeEvent(QResizeEvent *) override;
|
||||
|
||||
private:
|
||||
QPixmap pix;
|
||||
};
|
Loading…
Add table
Reference in a new issue