Add status bar with color value
This commit is contained in:
+29
-3
@@ -75,6 +75,8 @@ ImageWidget::ImageWidget(Database *database, QWidget *parent) : QOpenGLWidget(pa
|
||||
QCoreApplication::exit(-1);
|
||||
}
|
||||
});
|
||||
|
||||
setMouseTracking(true);
|
||||
}
|
||||
|
||||
ImageWidget::~ImageWidget()
|
||||
@@ -82,10 +84,12 @@ ImageWidget::~ImageWidget()
|
||||
makeCurrent();
|
||||
}
|
||||
|
||||
void ImageWidget::setImage(const RawImage *image, int index)
|
||||
void ImageWidget::setImage(std::shared_ptr<RawImage> &image, int index)
|
||||
{
|
||||
if(image == nullptr)return;
|
||||
|
||||
m_rawImage = image;
|
||||
|
||||
m_imgWidth = image->width();
|
||||
m_imgHeight = image->height();
|
||||
m_currentImg = index;
|
||||
@@ -100,7 +104,7 @@ void ImageWidget::setImage(const RawImage *image, int index)
|
||||
m_image->setMinMagFilters(QOpenGLTexture::LinearMipMapLinear, QOpenGLTexture::Linear);
|
||||
m_image->setWrapMode(QOpenGLTexture::ClampToEdge);
|
||||
m_image->setBorderColor(0, 0, 0, 0);
|
||||
m_image->setData(0, rawImageType.pixelFormat, rawImageType.dataType, image->data(), m_transferOptions.get());
|
||||
m_image->setData(0, rawImageType.pixelFormat, rawImageType.dataType, (const void*)image->data(), m_transferOptions.get());
|
||||
m_image->setLevelOfDetailRange(m_superpixel ? 1 : 0, m_image->mipMaxLevel());
|
||||
m_image->generateMipMaps();
|
||||
m_bwImg = rawImageType.bw;
|
||||
@@ -437,6 +441,28 @@ void ImageWidget::mouseMoveEvent(QMouseEvent *event)
|
||||
}
|
||||
else
|
||||
event->ignore();
|
||||
|
||||
if(m_rawImage)
|
||||
{
|
||||
float dx = m_dx;
|
||||
float dy = m_dy;
|
||||
if(width() > m_image->width()*m_scale)
|
||||
dx = -width()*0.5f + m_image->width()*m_scale*0.5f;
|
||||
if(height() > m_image->height()*m_scale)
|
||||
dy = -height()*0.5f + m_image->height()*m_scale*0.5f;
|
||||
|
||||
QVector2D offset(dx, dy);
|
||||
QVector2D pos = QVector2D(event->pos());
|
||||
QVector2D pix = (pos + offset) / m_scale;
|
||||
QVector3D rgb;
|
||||
if(m_rawImage->pixel(pix.x(), pix.y(), rgb))
|
||||
{
|
||||
if(m_bwImg)
|
||||
emit status(tr("L: %1").arg(rgb.x()));
|
||||
else
|
||||
emit status(tr("R: %1 G: %2 B: %3").arg(rgb.x()).arg(rgb.y()).arg(rgb.z()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ImageWidget::mouseReleaseEvent(QMouseEvent *event)
|
||||
@@ -524,7 +550,7 @@ ImageScrollAreaGL::~ImageScrollAreaGL()
|
||||
|
||||
}
|
||||
|
||||
void ImageScrollAreaGL::setImage(RawImage *image, int index)
|
||||
void ImageScrollAreaGL::setImage(std::shared_ptr<RawImage> image, int index)
|
||||
{
|
||||
m_imageWidget->setImage(image, index);
|
||||
m_imgWidth = image->width();
|
||||
|
||||
Reference in New Issue
Block a user