Show error message in main window when image fail to load

This commit is contained in:
2024-01-14 14:32:01 +01:00
parent 6539c78c57
commit a8a1509db7
2 changed files with 25 additions and 4 deletions
+24 -4
View File
@@ -90,14 +90,27 @@ ImageWidget::~ImageWidget()
void ImageWidget::setImage(std::shared_ptr<RawImage> image, int index) void ImageWidget::setImage(std::shared_ptr<RawImage> image, int index)
{ {
if(image == nullptr)return; m_currentImg = index;
if(!image || !image->valid())
{
m_imgWidth = 0;
m_imgHeight = 0;
m_error = tr("Failed to load image");
m_rawImage.reset();
update();
return;
}
m_error.clear();
makeCurrent(); makeCurrent();
m_rawImage = image; m_rawImage = image;
m_rawImage->downscaleTo(m_maxTextureSize); if((int)image->width() > m_maxTextureSize || (int)image->height() > m_maxTextureSize)
m_rawImage->resize(std::min(m_maxTextureSize, (int)image->width()), std::min(m_maxTextureSize, (int)image->height()));
m_imgWidth = image->width(); m_imgWidth = image->width();
m_imgHeight = image->height(); m_imgHeight = image->height();
m_currentImg = index;
if(!m_image)return; if(!m_image)return;
@@ -290,7 +303,7 @@ void ImageWidget::thumbnailLoaded(const Image *image)
{ {
makeCurrent(); makeCurrent();
const RawImage *raw = image->thumbnail(); const RawImage *raw = image->thumbnail();
if(!raw)return; if(!raw || !raw->valid())return;
m_thumbnailTexture->setData(0, image->number(), QOpenGLTexture::RGBA, QOpenGLTexture::UInt16, raw->data(), m_transferOptions.get()); m_thumbnailTexture->setData(0, image->number(), QOpenGLTexture::RGBA, QOpenGLTexture::UInt16, raw->data(), m_transferOptions.get());
float a = raw->thumbAspect(); float a = raw->thumbAspect();
int sizes[3] = { std::max(1, a > 1.0f ? THUMB_SIZE : (int)(THUMB_SIZE * a)), std::max(1, a < 1.0f ? THUMB_SIZE : (int)(THUMB_SIZE / a)), image->number() }; int sizes[3] = { std::max(1, a > 1.0f ? THUMB_SIZE : (int)(THUMB_SIZE * a)), std::max(1, a < 1.0f ? THUMB_SIZE : (int)(THUMB_SIZE / a)), image->number() };
@@ -375,6 +388,13 @@ void ImageWidget::paintGL()
} }
} }
} }
else if(!m_error.isEmpty())
{
QPainter painter(this);
painter.setPen(Qt::red);
painter.setFont(QFont("Sans", 24, QFont::Bold));
painter.drawText(0, 0, width(), height(), Qt::AlignCenter | Qt::AlignHCenter, m_error);
}
else else
{ {
debayer(); debayer();
+1
View File
@@ -69,6 +69,7 @@ class ImageWidget : public QOpenGLWidget
QVector<ImageThumb> m_thumnails; QVector<ImageThumb> m_thumnails;
Database *m_database = nullptr; Database *m_database = nullptr;
QPointF m_lastPos; QPointF m_lastPos;
QString m_error;
public: public:
explicit ImageWidget(Database *database, QWidget *parent = nullptr); explicit ImageWidget(Database *database, QWidget *parent = nullptr);
~ImageWidget() override; ~ImageWidget() override;