Draw file name under thumbnail
This commit is contained in:
+33
-36
@@ -9,6 +9,7 @@
|
||||
#include <QMimeData>
|
||||
#include <QMessageBox>
|
||||
#include <QCoreApplication>
|
||||
#include <QPainter>
|
||||
|
||||
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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user