Files
tenmon/imagescrollareagl.h
T
2022-05-18 17:33:20 +02:00

121 lines
3.3 KiB
C++

#ifndef IMAGESCROLLAREAGL_H
#define IMAGESCROLLAREAGL_H
#include <memory>
#include <QObject>
#include <QOpenGLWidget>
#include <QOpenGLFunctions_3_3_Core>
#include <QOpenGLShaderProgram>
#include <QOpenGLBuffer>
#include <QOpenGLTexture>
#include <QOpenGLVertexArrayObject>
#include <QScrollBar>
#include <QTimer>
#include "rawimage.h"
#include "imageringlist.h"
struct ImageThumb
{
QString name;
QSize size;
bool selected;
};
class ImageWidget : public QOpenGLWidget
{
Q_OBJECT
QOpenGLFunctions *f;
QOpenGLFunctions_3_3_Core *f3;
QTimer *m_updateTimer;
std::unique_ptr<QOpenGLShaderProgram> m_program;
std::unique_ptr<QOpenGLShaderProgram> m_thumbnailProgram;
std::unique_ptr<QOpenGLBuffer> m_buffer;
std::unique_ptr<QOpenGLBuffer> m_bufferSizes;
std::unique_ptr<QOpenGLTexture> m_image;
std::unique_ptr<QOpenGLVertexArrayObject> m_vao;
std::unique_ptr<QOpenGLVertexArrayObject> m_vaoThumb;
std::unique_ptr<QOpenGLPixelTransferOptions> m_transferOptions;
std::unique_ptr<QOpenGLTexture> m_thumbnailTexture;
int m_width, m_height;
int m_imgWidth, m_imgHeight;
int m_currentImg;
float m_low;
float m_mid;
float m_high;
float m_range;
float m_dx, m_dy;
float m_scale;
bool m_blockRepaint;
bool m_bwImg;
bool m_invert;
bool m_superpixel;
bool m_showThumbnails;
bool m_selecting;
int m_thumbnailCount;
QVector<ImageThumb> m_thumnails;
public:
explicit ImageWidget(QWidget *parent = nullptr);
~ImageWidget();
void setImage(const RawImage *image, int index);
void setImage(const QPixmap &pixmap);
void setScale(float scale);
void blockRepaint(bool block);
void allocateThumbnails(const QStringList &names);
public slots:
void setMTFParams(float low, float mid, float high);
void setOffset(int dx, int dy);
void superPixel(bool enable);
void invert(bool enable);
QImage renderToImage();
void thumbnailLoaded(const Image *image);
void showThumbnail(bool enable);
protected:
void paintGL();
void resizeGL(int w, int h);
void initializeGL();
void dragEnterEvent(QDragEnterEvent *event);
void dropEvent(QDropEvent *event);
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
void thumbSelect(QMouseEvent *event);
signals:
void fileDropped(const QString &path);
void thumbSelected(int index);
};
class ImageScrollAreaGL : public QWidget
{
Q_OBJECT
QScrollBar *m_verticalScrollBar;
QScrollBar *m_horizontalScrollBar;
ImageWidget *m_imageWidget;
int m_imgWidth, m_imgHeight;
QPoint m_lastPos;
float m_scale;
bool m_bestFit;
int m_thumbCount;
public:
explicit ImageScrollAreaGL(QWidget *parent = nullptr);
~ImageScrollAreaGL();
void setImage(RawImage *image, int index);
ImageWidget* imageWidget();
void setThumbnails(int count);
protected:
void updateScrollbars(bool zoom = false);
void resizeEvent(QResizeEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void mousePressEvent(QMouseEvent *event);
void wheelEvent(QWheelEvent *event);
void zoom(float delta);
public slots:
void zoomIn();
void zoomOut();
void bestFit();
void oneToOne();
protected slots:
void scrollEvent();
};
#endif // IMAGESCROLLAREAGL_H