132 lines
4.6 KiB
C++
132 lines
4.6 KiB
C++
#pragma once
|
|
#include "../RenderAble.h"
|
|
#include "../Axis/AbsAxis.h"
|
|
|
|
namespace YSG {
|
|
struct HoverInfoRenderState;
|
|
struct HoverInfoRenderAbleInterFace;
|
|
struct LIB_DECL HoverInfoRenderState {
|
|
virtual ~HoverInfoRenderState() = default;
|
|
HoverInfoRenderState() {
|
|
hoverInfoBrush = QBrush(Qt::white);
|
|
}
|
|
int hoverInfoLeft = 4, hoverInfoTop = 4, hoverInfoRight = 4, hoverInfoBottom = 4;
|
|
QBrush hoverInfoBrush;
|
|
QFont hoverInfoFont;
|
|
QPen hoverInfoPen;
|
|
bool useHoverInfo = true;
|
|
bool hoverInfoActive = false;
|
|
QPoint hoverInfoPos;
|
|
HoverInfoRenderAbleInterFace *renderAble{};
|
|
void drawHover(QPainter* painter, AbsAxis *h, AbsAxis *v);
|
|
bool hoverOK(RenderAble* able) const;
|
|
};
|
|
struct LIB_DECL HoverInfoRenderAbleInterFace {
|
|
virtual QVector<QString> createHoverString(AbsAxis* h, AbsAxis* v, QPoint pos);
|
|
virtual ~HoverInfoRenderAbleInterFace() = default;
|
|
virtual void drawHover(QPainter* painter, AbsAxis *h, AbsAxis *v) {
|
|
return hoverState(SRC::Render)->drawHover(painter, h, v);
|
|
}
|
|
virtual bool hoverOK(RenderAble* able) {
|
|
return hoverState(SRC::Render)->hoverOK(able);
|
|
}
|
|
virtual bool hoverTest(QPoint pos) {
|
|
return true;
|
|
}
|
|
bool useHoverInfo(SRC src = SRC::Edit) {
|
|
return hoverState(src)->useHoverInfo;
|
|
}
|
|
void setUseHoverInfo(bool use) {
|
|
SpinLockGuard g(lock());
|
|
hoverState(SRC::Edit)->useHoverInfo = use;
|
|
markHoverInfoDirty();
|
|
}
|
|
void setHoverInfoFont(const QFont& font) {
|
|
SpinLockGuard g(lock());
|
|
hoverState(SRC::Edit)->hoverInfoFont = font;
|
|
markHoverInfoDirty();
|
|
}
|
|
QFont HoverInfoFont(SRC src = SRC::Edit) {
|
|
return hoverState(src)->hoverInfoFont;
|
|
}
|
|
QBrush hoverInfoBackgroundBrush(SRC src = SRC::Edit) {
|
|
return hoverState(src)->hoverInfoBrush;
|
|
}
|
|
void setHoverInfoBackgroundBrush(const QBrush& brush) {
|
|
SpinLockGuard g(lock());
|
|
hoverState(SRC::Edit)->hoverInfoBrush = brush.color().isValid() ? brush : Qt::NoBrush;
|
|
markHoverInfoDirty();
|
|
}
|
|
QPen hoverInfoPen(SRC src = SRC::Edit) {
|
|
return hoverState(src)->hoverInfoPen;
|
|
}
|
|
void setHoverInfoPen(const QPen& pen) {
|
|
SpinLockGuard g(lock());
|
|
hoverState(SRC::Edit)->hoverInfoPen = pen.color().isValid() ? pen : Qt::NoPen;
|
|
markHoverInfoDirty();
|
|
}
|
|
void getHoverInfoContentsMargins(int& left, int& top, int& right, int& bottom, SRC src) {
|
|
auto s = hoverState(src);
|
|
left = s->hoverInfoLeft;
|
|
top = s->hoverInfoTop;
|
|
right = s->hoverInfoRight;
|
|
bottom = s->hoverInfoBottom;
|
|
}
|
|
|
|
void setHoverInfoContentsMargins(int left, int top, int right, int bottom) {
|
|
SpinLockGuard g(lock());
|
|
auto sc = hoverState(SRC::Edit);
|
|
sc->hoverInfoLeft = left;
|
|
sc->hoverInfoTop = top;
|
|
sc->hoverInfoRight = right;
|
|
sc->hoverInfoBottom = bottom;
|
|
markHoverInfoDirty();
|
|
}
|
|
protected:
|
|
virtual HoverInfoRenderState* hoverState(SRC src) = 0;
|
|
virtual SpinLock* lock() = 0;
|
|
virtual void markHoverInfoDirty() {}
|
|
};
|
|
struct LIB_DECL HoverInfoIndependRenderAble : HoverInfoRenderAbleInterFace {
|
|
private:
|
|
SpinLock mtx;
|
|
HoverInfoRenderState s, sc;
|
|
SpinLock* lock() override {
|
|
return &mtx;
|
|
}
|
|
HoverInfoRenderState* hoverState(SRC src) override {
|
|
if(src == SRC::Edit) {
|
|
return ≻
|
|
}
|
|
return &s;
|
|
}
|
|
public:
|
|
void drawHover(QPainter* painter, AbsAxis* h, AbsAxis* v) override {
|
|
s.renderAble = this;
|
|
sc.renderAble = this;
|
|
{
|
|
SpinLockGuard g(lock());
|
|
s = sc;
|
|
}
|
|
HoverInfoRenderAbleInterFace::drawHover(painter, h, v);
|
|
}
|
|
};
|
|
template <typename That>
|
|
struct LIB_DECL HoverInfoRenderAble : HoverInfoRenderAbleInterFace {
|
|
private:
|
|
That *that() {
|
|
return static_cast<That*>(this);
|
|
}
|
|
SpinLock* lock() override {
|
|
return &that()->dPtr->mBufferLock;
|
|
}
|
|
HoverInfoRenderState* hoverState(SRC src) override {
|
|
auto t = that();
|
|
return dynamic_cast<HoverInfoRenderState*>(t->dPtr->state(src));
|
|
}
|
|
void markHoverInfoDirty() override {
|
|
that()->markStateDirty();
|
|
}
|
|
};
|
|
}
|