0
0
mirror of https://github.com/yse/easy_profiler.git synced 2024-12-27 16:51:22 +08:00
easy_profiler/profiler_gui/graphics_image_item.h

97 lines
2.3 KiB
C++

#ifndef EASY_PROFILER_GRAPHICS_IMAGE_ITEM_H
#define EASY_PROFILER_GRAPHICS_IMAGE_ITEM_H
#include <QGraphicsItem>
#include <thread>
#include <atomic>
#include "easy_qtimer.h"
class GraphicsImageItem : public QGraphicsItem
{
protected:
using Parent = QGraphicsItem;
using This = GraphicsImageItem;
QRectF m_boundingRect;
QImage m_image;
EasyQTimer m_boundaryTimer;
std::thread m_workerThread;
QPointF m_mousePos;
QImage* m_workerImage;
qreal m_imageOrigin;
qreal m_imageScale;
qreal m_imageOriginUpdate;
qreal m_imageScaleUpdate;
qreal m_workerImageOrigin;
qreal m_workerImageScale;
qreal m_topValue;
qreal m_bottomValue;
qreal m_maxValue;
qreal m_minValue;
private:
EasyQTimer m_timer;
std::atomic_bool m_bReady;
bool m_bPermitImageUpdate; ///< Is false when m_workerThread is parsing input dataset (when setSource(_block_id) is called)
public:
explicit GraphicsImageItem();
~GraphicsImageItem() override;
QRectF boundingRect() const override;
virtual bool pickTopValue();
virtual bool increaseTopValue();
virtual bool decreaseTopValue();
virtual bool pickBottomValue();
virtual bool increaseBottomValue();
virtual bool decreaseBottomValue();
virtual bool updateImage();
virtual void onModeChanged();
protected:
virtual void onImageUpdated();
public:
void onValueChanged();
void setMousePos(const QPointF& pos);
void setMousePos(qreal x, qreal y);
void setBoundingRect(const QRectF& _rect);
void setBoundingRect(qreal x, qreal y, qreal w, qreal h);
bool cancelImageUpdate();
protected:
void paintImage(QPainter* _painter);
void paintImage(QPainter* _painter, qreal _scale, qreal _sceneLeft, qreal _sceneRight,
qreal _visibleRegionLeft, qreal _visibleRegionWidth);
void setImageUpdatePermitted(bool _permit);
bool isImageUpdatePermitted() const;
void cancelAnyJob();
void resetTopBottomValues();
bool isReady() const;
void setReady(bool _ready);
void startTimer();
void stopTimer();
private:
void onTimeout();
}; // end of class GraphicsImageItem.
#endif //EASY_PROFILER_GRAPHICS_IMAGE_ITEM_H