#ifndef SIGNPENPAINTER_H #define SIGNPENPAINTER_H #include #include #include #include "SWPosPointcut.h" #include "signpenstructs.h" #define MaxBrushCount 2 #define MinSpeed 300 #define MaxSpeed 400 #define MaxBrush 0.2f class SignPainterCacheThread; class SignPainterCacheThread_Linux; class QPainter; class SignPenPainter : public QObject { Q_OBJECT public: SignPenPainter(); ~SignPenPainter(); void SetPainterRect(QRect rect); void SetPenType(int type); void SetPenColor(QColor penColor); void SetCurrentPageIndex(int page); void SetOffSetRect(QRect rect); void Init(); void ClearDraw(); void DrawRect(QPainter* painter,QRect currentVisibleRect); void MousePressed(CGPoint currentPoint,float radius,double force,double maxForce);//force 压感力度 void MouseMoved(CGPoint currentPoint,float radius,double force,double maxForce); void MouseReleased(CGPoint currentPoint,float radius); void SetUseCache(bool use){ isUseCache = use;} bool GetUseCache(){return isUseCache;} void SetUseDebug(bool use){ isOutDebug = use;} bool GetUseDebug(){return isOutDebug;} void SetStressSwitch(bool isStressSwitch); bool GetStressSwitch();//是否使用压感设备 QList GetAnnotPathLists(); QList GetPenPathData(QPainterPath &data, int pageIndex, QList penDataList, float factorW = 1.0, float factorH = 1.0, int offsetX = 0, int offsetY = 0); private: void SwPenPathDrawWithPainter(QPainter* bufPainter,bool isEnd); void SwPenPathDraw(bool isEnd); void SwPenPathDrawRightWithBezier(QPainterPath* bPath ,QList& elementList,SWRealPoint penPoint,CGPoint prevPoint,QList rPoints,bool end); bool CGPointEqualToPoint(const CGPoint &point1, const CGPoint &point2); void CalculatePointcutWihtPoint(CGPoint point, float radius, bool stroke, bool circle); bool GetPointValid(SWRealPoint penPoint); CGPoint ConvertToCGPoint(SWPointcut cPoint); float GetDistanceBetweenPoint(QPointF start, QPointF end); QPaintDevice *PaintDevice(); void SynToBaseDevice(); signals: void NeedsDisplay(QRect rect); void NeedsRefresh(); void ReleasedExcuted(); //记录日志 void log(QString); private: QPointF CGPointZero; int strokeSpl; float stressSpl; float penRadius; SWAnnotPath *curAnnotPath; QList drawPaths; CGPoint selectPoint; //标记上次计算贝塞尔点 CGPoint preBezierPoint; qint64 previousTimestamp; float pointSpeed; float preLineRadius; int stressSwitch;//是否开启压感 1开启 0关闭 QImage* m_BaseBuf; //渲染bug,基于m_BaseBuf从上一次倒数10个点开始绘制,绘制到倒数10个点时,数据保存回m_BaseBuf QImage* m_PaintingBuf; QSize m_Size; QRect m_PaintRect; int m_StartIndex;//渲染开始的节点 int SyncCount;// 重新绘制的数据 bool isRelease; int m_ToImageIndex;//图片后的开始渲染点 int m_FreshCount;//实时渲染的笔画数 #ifdef Q_OS_WIN SignPainterCacheThread* cacheThread; #else SignPainterCacheThread_Linux* cacheThread; #endif bool isUseCache; bool isOutDebug; }; #endif // SIGNPENPAINTER_H