Files
tenmon/imagescrollareagl.h
T

130 lines
3.8 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"
#include "database.h"
struct ImageThumb
{
QString name;
QString path;
QSize size;
bool selected;
bool dirty;
};
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;
std::shared_ptr<RawImage> m_rawImage;
std::shared_ptr<WCSData> m_wcs;
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;
bool m_sizesDirty;
bool m_srgb;
int m_thumbnailCount;
QVector<ImageThumb> m_thumnails;
Database *m_database;
public:
explicit ImageWidget(Database *database, QWidget *parent = nullptr);
~ImageWidget() override;
void setImage(std::shared_ptr<RawImage> image, int index);
void setImage(const QPixmap &pixmap);
void setWCS(std::shared_ptr<WCSData> wcs);
void setScale(float scale);
void blockRepaint(bool block);
void allocateThumbnails(const QStringList &paths);
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() override;
void resizeGL(int w, int h) override;
void initializeGL() override;
void dragEnterEvent(QDragEnterEvent *event) override;
void dropEvent(QDropEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
void thumbSelect(QMouseEvent *event);
signals:
void fileDropped(const QString &path);
void status(const QString &value, const QString &pixelCoords, const QString &celestialCoords);
};
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(Database *database, QWidget *parent = nullptr);
~ImageScrollAreaGL() override;
void setImage(Image *image);
ImageWidget* imageWidget();
void setThumbnails(int count);
protected:
void updateScrollbars(bool zoom = false);
void resizeEvent(QResizeEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
void wheelEvent(QWheelEvent *event) override;
void zoom(float delta);
public slots:
void zoomIn();
void zoomOut();
void bestFit();
void oneToOne();
protected slots:
void scrollEvent();
};
#endif // IMAGESCROLLAREAGL_H