From 94466a6b9b0304224a06de52f187996892b946ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Du=C5=A1an=20Poizl?= Date: Mon, 9 May 2022 22:56:06 +0200 Subject: [PATCH] Draw file name under thumbnail --- imageringlist.cpp | 8 +++++ imageringlist.h | 1 + imagescrollareagl.cpp | 69 +++++++++++++++++++++---------------------- imagescrollareagl.h | 9 +++--- mainwindow.cpp | 6 ++-- rawimage.h | 1 + thumb.vert | 2 +- 7 files changed, 52 insertions(+), 44 deletions(-) diff --git a/imageringlist.cpp b/imageringlist.cpp index 9c06bfc..f6c2f66 100644 --- a/imageringlist.cpp +++ b/imageringlist.cpp @@ -257,6 +257,14 @@ int ImageRingList::imageCount() const return m_images.size(); } +QStringList ImageRingList::imageNames() const +{ + QStringList ret; + for(auto &img : m_images) + ret.push_back(QFileInfo(img->name()).fileName()); + return ret; +} + QModelIndex ImageRingList::index(int row, int column, const QModelIndex &parent) const { return createIndex(row, column, m_images.at(row).get()); diff --git a/imageringlist.h b/imageringlist.h index c73c45f..40ea6da 100644 --- a/imageringlist.h +++ b/imageringlist.h @@ -74,6 +74,7 @@ public: void loadThumbnails(); void stopLoading(); int imageCount() const; + QStringList imageNames() const; QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; QModelIndex parent(const QModelIndex &child) const override; diff --git a/imagescrollareagl.cpp b/imagescrollareagl.cpp index abb7d7b..9898cf9 100644 --- a/imagescrollareagl.cpp +++ b/imagescrollareagl.cpp @@ -9,6 +9,7 @@ #include #include #include +#include struct RawImageType { @@ -78,12 +79,13 @@ ImageWidget::~ImageWidget() makeCurrent(); } -void ImageWidget::setImage(const RawImage *image) +void ImageWidget::setImage(const RawImage *image, int index) { if(image == nullptr)return; m_imgWidth = image->width(); m_imgHeight = image->height(); + m_currentImg = index; const RawImageType &rawImageType = rawImageTypes[image->type()]; @@ -102,22 +104,6 @@ void ImageWidget::setImage(const RawImage *image) update(); } -void ImageWidget::setImage(const QPixmap &pixmap) -{ - QImage img = pixmap.toImage(); - - m_imgWidth = pixmap.width(); - m_imgHeight = pixmap.height(); - - m_image->destroy(); - m_image->setData(img); - m_image->setMinMagFilters(QOpenGLTexture::LinearMipMapLinear, QOpenGLTexture::Linear); - m_image->setWrapMode(QOpenGLTexture::ClampToBorder); - m_image->setBorderColor(0, 0, 0, 0); - m_bwImg = false; - update(); -} - void ImageWidget::setScale(float scale) { m_scale = scale; @@ -130,13 +116,15 @@ void ImageWidget::blockRepaint(bool block) if(!block)update(); } -void ImageWidget::allocateThumbnails(int count) +void ImageWidget::allocateThumbnails(const QStringList &&names) { + int count = names.size(); + m_Names = std::move(names); m_thumbnailTexture->destroy(); m_thumbnailTexture->create(); m_thumbnailTexture->setFormat(QOpenGLTexture::RGB16_UNorm); m_thumbnailTexture->setSize(THUMB_SIZE, THUMB_SIZE); - m_thumbnailTexture->setLayers(count); + m_thumbnailTexture->setLayers(names.size()); m_thumbnailTexture->allocateStorage(); m_bufferSizes->bind(); float *tmp = new float[count*3]; @@ -237,6 +225,24 @@ void ImageWidget::paintGL() mvp.ortho(rect()); m_thumbnailProgram->setUniformValue("mvp", mvp); if(f3)f3->glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, m_thumbnailCount); + + QPainter painter(this); + int w = width()/THUMB_SIZE_BORDER; + for(int i=0; i < m_thumbnailCount; i++) + { + float x = (i % w) * THUMB_SIZE_BORDER; + float y = i / w * THUMB_SIZE_BORDER_Y + THUMB_SIZE - m_dy; + QRectF rect(x, y, THUMB_SIZE_BORDER, 32); + painter.drawText(rect, Qt::AlignCenter | Qt::TextWrapAnywhere, QString(m_Names.at(i))); + if(m_currentImg == i) + { + int off = (THUMB_SIZE_BORDER - THUMB_SIZE) / 2; + painter.save(); + painter.setPen(QPen(Qt::red, 2.0)); + painter.drawRect((i % w) * THUMB_SIZE_BORDER + off, i / w * THUMB_SIZE_BORDER_Y - m_dy + off, THUMB_SIZE, THUMB_SIZE); + painter.restore(); + } + } } else { @@ -416,24 +422,15 @@ ImageScrollAreaGL::~ImageScrollAreaGL() } -void ImageScrollAreaGL::setImage(RawImage *image) +void ImageScrollAreaGL::setImage(RawImage *image, int index) { - m_imageWidget->setImage(image); + m_imageWidget->setImage(image, index); m_imgWidth = image->width(); m_imgHeight = image->height(); if(m_bestFit)bestFit(); updateScrollbars(); } -void ImageScrollAreaGL::setImage(const QPixmap &pixmap) -{ - m_imageWidget->setImage(pixmap); - m_imgWidth = pixmap.width(); - m_imgHeight = pixmap.height(); - if(m_bestFit)bestFit(); - updateScrollbars(); -} - ImageWidget *ImageScrollAreaGL::imageWidget() { return m_imageWidget; @@ -444,8 +441,8 @@ void ImageScrollAreaGL::setThumbnails(int count) m_thumbCount = count; if(m_thumbCount) { - m_verticalScrollBar->setRange(0, m_thumbCount / (m_imageWidget->width() / THUMB_SIZE_BORDER) * THUMB_SIZE_BORDER); - m_verticalScrollBar->setPageStep(THUMB_SIZE_BORDER); + m_verticalScrollBar->setRange(0, m_thumbCount / (m_imageWidget->width() / THUMB_SIZE_BORDER) * THUMB_SIZE_BORDER_Y); + m_verticalScrollBar->setPageStep(THUMB_SIZE_BORDER_Y); } else { @@ -461,8 +458,8 @@ void ImageScrollAreaGL::updateScrollbars(bool zoom) { m_horizontalScrollBar->hide(); m_verticalScrollBar->show(); - m_verticalScrollBar->setRange(0, m_thumbCount / (m_imageWidget->width() / THUMB_SIZE_BORDER) * THUMB_SIZE_BORDER); - m_verticalScrollBar->setPageStep(THUMB_SIZE_BORDER); + m_verticalScrollBar->setRange(0, m_thumbCount / (m_imageWidget->width() / THUMB_SIZE_BORDER) * THUMB_SIZE_BORDER_Y); + m_verticalScrollBar->setPageStep(THUMB_SIZE_BORDER_Y); } else { @@ -484,8 +481,8 @@ void ImageScrollAreaGL::resizeEvent(QResizeEvent *event) QWidget::resizeEvent(event); if(m_thumbCount) { - m_verticalScrollBar->setRange(0, m_thumbCount / (m_imageWidget->width() / THUMB_SIZE_BORDER) * THUMB_SIZE_BORDER); - m_verticalScrollBar->setPageStep(THUMB_SIZE_BORDER); + m_verticalScrollBar->setRange(0, m_thumbCount / (m_imageWidget->width() / THUMB_SIZE_BORDER) * THUMB_SIZE_BORDER_Y); + m_verticalScrollBar->setPageStep(THUMB_SIZE_BORDER_Y); } else { diff --git a/imagescrollareagl.h b/imagescrollareagl.h index dc0c924..e9dad90 100644 --- a/imagescrollareagl.h +++ b/imagescrollareagl.h @@ -40,6 +40,7 @@ class ImageWidget : public QOpenGLWidget std::unique_ptr m_thumbnailTexture; int m_width, m_height; int m_imgWidth, m_imgHeight; + int m_currentImg; float m_low; float m_mid; float m_high; @@ -52,14 +53,15 @@ class ImageWidget : public QOpenGLWidget bool m_superpixel; bool m_showThumbnails; int m_thumbnailCount; + QStringList m_Names; public: explicit ImageWidget(QWidget *parent = nullptr); ~ImageWidget(); - void setImage(const RawImage *image); + void setImage(const RawImage *image, int index); void setImage(const QPixmap &pixmap); void setScale(float scale); void blockRepaint(bool block); - void allocateThumbnails(int count); + void allocateThumbnails(const QStringList &&names); public slots: void setMTFParams(float low, float mid, float high); void setOffset(int dx, int dy); @@ -92,8 +94,7 @@ class ImageScrollAreaGL : public QWidget public: explicit ImageScrollAreaGL(QWidget *parent = nullptr); ~ImageScrollAreaGL(); - void setImage(RawImage *image); - void setImage(const QPixmap &pixmap); + void setImage(RawImage *image, int index); ImageWidget* imageWidget(); void setThumbnails(int count); protected: diff --git a/mainwindow.cpp b/mainwindow.cpp index 92b41ee..0c03fb3 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -120,7 +120,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) viewMenu->addAction(tr("100%"), m_imageGL, SLOT(oneToOne())); viewMenu->addAction(tr("Fullscreen"), this, SLOT(toggleFullScreen()), Qt::CTRL + Qt::Key_F11); QAction *thumbnailsAction = viewMenu->addAction(tr("Thumbnails"), [this](bool checked){ - m_imageGL->imageWidget()->allocateThumbnails(m_ringList->imageCount()); + m_imageGL->imageWidget()->allocateThumbnails(m_ringList->imageNames()); m_imageGL->imageWidget()->showThumbnail(checked); m_imageGL->setThumbnails(checked ? m_ringList->imageCount() : 0); if(checked)m_ringList->loadThumbnails(); @@ -153,7 +153,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) QAction *statsAction = analyzeGroup->addAction(tr("Image statistics")); QAction *peakAction = analyzeGroup->addAction(tr("Peak finder")); - QAction *starAction = analyzeGroup->addAction("Star finder"); + QAction *starAction = analyzeGroup->addAction(tr("Star finder")); statsAction->setCheckable(true); peakAction->setCheckable(true); starAction->setCheckable(true); @@ -339,7 +339,7 @@ void MainWindow::pixmapLoaded(Image *image) //m_image->setImage(image->pixmap()); if(image->rawImage()) { - m_imageGL->setImage(image->rawImage()); + m_imageGL->setImage(image->rawImage(), image->number()); } } diff --git a/rawimage.h b/rawimage.h index 9d1f3bb..41a53ac 100644 --- a/rawimage.h +++ b/rawimage.h @@ -11,6 +11,7 @@ const int THUMB_SIZE = 128; const int THUMB_SIZE_BORDER = 138; +const int THUMB_SIZE_BORDER_Y = 158; class Peak { diff --git a/thumb.vert b/thumb.vert index 687eebe..b026072 100644 --- a/thumb.vert +++ b/thumb.vert @@ -13,7 +13,7 @@ void main(void) vec2 pos = qt_Vertex * 0.5; pos.y *= -1.0; pos = pos * imageSize_num.xy + 69; - ivec2 off = ivec2(imageSize_num.z % viewport_row.z, imageSize_num.z / viewport_row.z) * 138; + ivec2 off = ivec2(imageSize_num.z % viewport_row.z, imageSize_num.z / viewport_row.z) * ivec2(138, 158); gl_Position = mvp * vec4(pos - offset + off, 0.0, 1.0); qt_TexCoord0 = vec3(qt_MultiTexCoord0, imageSize_num.z + 0.1);