📄 rs_painterqt.cpp
字号:
cp.y-sin(a2)*radius)); //lineTo(toScreenX(cp.x+cos(a2)*radius), // toScreenY(cp.y-sin(a2)*radius)); //pa.resize(i+1); //pa.setPoint(i++, // toScreenX(cp.x+cos(a2)*radius), // toScreenY(cp.y-sin(a2)*radius)); //drawPolyline(pa); }}/** * Draws a circle. * @param cx center in x * @param cy center in y * @param radius Radius */void RS_PainterQt::drawCircle(const RS_Vector& cp, double radius) { if (drawingMode==RS2::ModeXOR && radius<500) { // This is _very_ slow for large arcs: QPainter::drawEllipse(toScreenX(cp.x-radius), toScreenY(cp.y-radius), RS_Math::round(2.0*radius), RS_Math::round(2.0*radius)); } else {#ifdef __APPLE__ drawArcMac(cp, radius, 0.0, 2*M_PI, false);#else drawArc(cp, radius, 0.0, 2*M_PI, cp + RS_Vector(radius, 0.0), cp + RS_Vector(radius, 0.0), false);#endif }}/** * Draws a rotated ellipse arc. */void RS_PainterQt::drawEllipse(const RS_Vector& cp, double radius1, double radius2, double angle, double a1, double a2, bool reversed) { //if(radius1<=0.5 && radius2<=0.5) { // drawGridPoint((int)cp.x, (int)cp.y); //} else { //int cix; // Next point on arc //int ciy; // double aStep; // Angle Step (rad) double a; // Current Angle (rad) // Angle step in rad /* if (radius1<radius2) { if (radius1<RS_TOLERANCE) { aStep=1.0; } else { if (fabs(2.0/radius1)<=1.0) { aStep=asin(2.0/radius1); } else { aStep = 1.0; } } } else { if (radius2<RS_TOLERANCE) { aStep=1.0; } else { if (fabs(2.0/radius2)<=1.0) { aStep=asin(2.0/radius2); } else { aStep = 1.0; } } } if(aStep<0.05) { aStep = 0.05; } */ aStep=0.01; RS_Vector vp; RS_Vector vc(cp.x, cp.y); vp.set(cp.x+cos(a1)*radius1, cp.y-sin(a1)*radius2); vp.rotate(vc, -angle); moveTo(toScreenX(vp.x), toScreenY(vp.y)); if(!reversed) { // Arc Counterclockwise: if(a1>a2-RS_TOLERANCE) { a2+=2*M_PI; } for(a=a1+aStep; a<=a2; a+=aStep) { vp.set(cp.x+cos(a)*radius1, cp.y-sin(a)*radius2); vp.rotate(vc, -angle); lineTo(toScreenX(vp.x), toScreenY(vp.y)); } } else { // Arc Clockwise: if(a1<a2+RS_TOLERANCE) { a2-=2*M_PI; } for(a=a1-aStep; a>=a2; a-=aStep) { vp.set(cp.x+cos(a)*radius1, cp.y-sin(a)*radius2); vp.rotate(vc, -angle); lineTo(toScreenX(vp.x), toScreenY(vp.y)); } } vp.set(cp.x+cos(a2)*radius1, cp.y-sin(a2)*radius2); vp.rotate(vc, -angle); lineTo(toScreenX(vp.x), toScreenY(vp.y)); //}}/** * Draws image. */void RS_PainterQt::drawImg(RS_Img& img, const RS_Vector& pos, double angle, const RS_Vector& factor, int sx, int sy, int sw, int sh) {#if QT_VERSION>=0x030000 save(); QWMatrix wm; wm.translate(pos.x, pos.y); wm.scale(factor.x, factor.y); wm.rotate(RS_Math::rad2deg(-angle)); setWorldMatrix(wm);#else RS_DEBUG->print(RS_Debug::D_WARNING, "RS_PainterQt::drawImg: rotated images not supported");#endif if (fabs(angle)<1.0e-4) { drawImage(0+sx,-img.height()+sy, img, sx, sy, sw, sh); } else { drawImage(0,-img.height(), img); } restore();}void RS_PainterQt::drawTextH(int x1, int y1, int x2, int y2, const QString& text) { drawText(x1, y1, x2, y2, Qt::AlignRight|Qt::AlignVCenter, text);}void RS_PainterQt::drawTextV(int x1, int y1, int x2, int y2, const QString& text) {#if QT_VERSION>=0x030000 save(); QWMatrix wm = worldMatrix(); wm.rotate(-90.0); setWorldMatrix(wm); //rotate(-90.0); drawText(x1, y1, x2, y2, Qt::AlignRight|Qt::AlignVCenter, text); restore();#else RS_DEBUG->print(RS_Debug::D_WARNING, "RS_PainterQt::drawTextV: not supported");#endif}void RS_PainterQt::fillRect(int x1, int y1, int w, int h, const RS_Color& col) { QPainter::fillRect(x1, y1, w, h, col);}void RS_PainterQt::fillTriangle(const RS_Vector& p1, const RS_Vector& p2, const RS_Vector& p3) { QPointArray arr(3); arr.putPoints(0, 3, toScreenX(p1.x),toScreenY(p1.y), toScreenX(p2.x),toScreenY(p2.y), toScreenX(p3.x),toScreenY(p3.y)); setBrush(pen().color()); drawPolygon(arr);}void RS_PainterQt::erase() { QPainter::eraseRect(0,0,getWidth(),getHeight());}int RS_PainterQt::getWidth() { QPaintDeviceMetrics m(device()); return m.width();}int RS_PainterQt::getHeight() { QPaintDeviceMetrics m(device()); return m.height();}void RS_PainterQt::setPreviewPen() { setPen(QColor(0,255,255));}RS_Pen RS_PainterQt::getPen() { return lpen; //RS_Pen p(pen().color(), // RS2::qw(pen().width()), // RS2::qw(pen().style())); //return QPainter::pen(); //return p;}void RS_PainterQt::setPen(const RS_Pen& pen) { lpen = pen; if (drawingMode==RS2::ModeBW) { lpen.setColor(RS_Color(0,0,0)); } QPen p(lpen.getColor(), RS_Math::round(lpen.getScreenWidth()), RS2::rsToQtLineType(lpen.getLineType())); p.setJoinStyle(Qt::RoundJoin); p.setCapStyle(Qt::RoundCap); QPainter::setPen(p);}void RS_PainterQt::setPen(const RS_Color& color) { if (drawingMode==RS2::ModeBW) { lpen.setColor(RS_Color(0,0,0)); QPainter::setPen(RS_Color(0,0,0)); } else { lpen.setColor(color); QPainter::setPen(color); }}void RS_PainterQt::setPen(int r, int g, int b) { if (drawingMode==RS2::ModeBW) { setPen(QColor(0, 0, 0)); } else { setPen(QColor(r, g, b)); }}void RS_PainterQt::disablePen() { lpen = RS_Pen(RS2::FlagInvalid); QPainter::setPen(Qt::NoPen);}void RS_PainterQt::setBrush(const RS_Color& color) { if (drawingMode==RS2::ModeBW) { QPainter::setBrush(QColor(0, 0, 0)); } else { QPainter::setBrush(color); }}void RS_PainterQt::drawPolygon(const RS_PointArray& a) { QPainter::drawPolygon(a);}//void RS_PainterQt::setColor(const QColor& color) {// setPen(color);//}void RS_PainterQt::setXORMode() { setRasterOp(XorROP);}void RS_PainterQt::setNormalMode() { setRasterOp(CopyROP);}void RS_PainterQt::setClipRect(int x, int y, int w, int h) { QPainter::setClipRect(x, y, w, h); setClipping(true);}void RS_PainterQt::resetClipping() { setClipping(false);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -