⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rs_painterqt.cpp

📁 qcad2.05可用于windows和linux的源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************** $Id: rs_painterqt.cpp 2244 2005-03-14 23:00:19Z andrew $**** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.**** This file is part of the qcadlib Library project.**** This file may be distributed and/or modified under the terms of the** GNU General Public License version 2 as published by the Free Software** Foundation and appearing in the file LICENSE.GPL included in the** packaging of this file.**** Licensees holding valid qcadlib Professional Edition licenses may use ** this file in accordance with the qcadlib Commercial License** Agreement provided with the Software.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.**** See http://www.ribbonsoft.com for further details.**** Contact info@ribbonsoft.com if any conditions of this licensing are** not clear to you.************************************************************************/#include <stdio.h>#include <qpaintdevicemetrics.h>#include "rs_painterqt.h"#include "rs_math.h"#include "rs_application.h"#include "rs_color.h"//#include "rs_settings.h"/** * Constructor. */RS_PainterQt::RS_PainterQt(const QPaintDevice* pd)        : QPainter(pd), RS_Painter() {}/** * Destructor */RS_PainterQt::~RS_PainterQt() {}		void RS_PainterQt::moveTo(int x, int y) {	QPainter::moveTo(x, y);}void RS_PainterQt::lineTo(int x, int y) {	QPainter::lineTo(x, y);}/** * Draws a grid point at (x1, y1). */void RS_PainterQt::drawGridPoint(const RS_Vector& p) {    QPainter::drawPoint(toScreenX(p.x), toScreenY(p.y));}/** * Draws a point at (x1, y1). */void RS_PainterQt::drawPoint(const RS_Vector& p) {    QPainter::drawLine(toScreenX(p.x-1), toScreenY(p.y),                       toScreenX(p.x+1), toScreenY(p.y));    QPainter::drawLine(toScreenX(p.x), toScreenY(p.y-1),                       toScreenX(p.x), toScreenY(p.y+1));}/** * Draws a line from (x1, y1) to (x2, y2). */void RS_PainterQt::drawLine(const RS_Vector& p1, const RS_Vector& p2) {#ifdef __APPLE__	int w2 = (int)getPen().getScreenWidth()/2;    QPainter::drawLine(toScreenX(p1.x-w2), toScreenY(p1.y-w2),                       toScreenX(p2.x-w2), toScreenY(p2.y-w2));#else    QPainter::drawLine(toScreenX(p1.x), toScreenY(p1.y),                       toScreenX(p2.x), toScreenY(p2.y));#endif}/** * Draws a rectangle with corners p1, p2. *//*void RS_PainterQt::drawRect(const RS_Vector& p1, const RS_Vector& p2) {	/ *QPainter::drawRect(toScreenX(p1.x), toScreenY(p1.y),					   abs(toScreenX(p2.x) - toScreenX(p1.x)), 					   abs(toScreenY(p2.y) - toScreenY(p1.y)));* /	QPainter::drawLine(toScreenX(p1.x), toScreenY(p1.y),                       toScreenX(p2.x), toScreenY(p1.y));    QPainter::drawLine(toScreenX(p2.x), toScreenY(p1.y),                       toScreenX(p2.x), toScreenY(p2.y));    QPainter::drawLine(toScreenX(p2.x), toScreenY(p2.y),                       toScreenX(p1.x), toScreenY(p2.y));    QPainter::drawLine(toScreenX(p1.x), toScreenY(p2.y),                       toScreenX(p1.x), toScreenY(p1.y));}*//** * Draws an arc which starts / ends exactly at the given coordinates. * * @param cx center in x * @param cy center in y * @param radius Radius * @param a1 Angle 1 in rad * @param a2 Angle 2 in rad * @param x1 startpoint x * @param y1 startpoint y * @param x2 endpoint x * @param y2 endpoint y * @param reversed true: clockwise, false: counterclockwise */void RS_PainterQt::drawArc(const RS_Vector& cp, double radius,                           double a1, double a2,                           const RS_Vector& p1, const RS_Vector& p2,                           bool reversed) {    /*    QPainter::drawArc(cx-radius, cy-radius,                      2*radius, 2*radius,                      a1*16, (a2-a1)*16);    */    if(radius<=0.5) {        drawGridPoint(cp);    } else {#ifdef __APPLE__		drawArcMac(cp, radius, a1, a2, reversed);#else        int   cix;            // Next point on circle        int   ciy;            //        double aStep;         // Angle Step (rad)        double a;             // Current Angle (rad)        double linStep;       // linear step (pixels)        if (drawingMode==RS2::ModePreview) {            linStep = 20.0;        } else {            linStep = 6.0;        }        if (fabs(linStep/radius)<=1.0) {            aStep=asin(linStep/radius);        } else {            aStep=1.0;        }        if (aStep<0.05) {            aStep = 0.05;        }        if(!reversed) {            // Arc Counterclockwise:            if(a1>a2-1.0e-10) {                a2+=2*M_PI;            }            //moveTo(toScreenX(p1.x), toScreenY(p1.y));            QPointArray pa;            int i=0;            pa.resize(i+1);            pa.setPoint(i++, toScreenX(p1.x), toScreenY(p1.y));            for(a=a1+aStep; a<=a2; a+=aStep) {                cix = toScreenX(cp.x+cos(a)*radius);                ciy = toScreenY(cp.y-sin(a)*radius);                //lineTo(cix, ciy);                pa.resize(i+1);                pa.setPoint(i++, cix, ciy);            }            //lineTo(toScreenX(p2.x), toScreenY(p2.y));            pa.resize(i+1);            pa.setPoint(i++, toScreenX(p2.x), toScreenY(p2.y));            drawPolyline(pa);        } else {            // Arc Clockwise:            if(a1<a2+1.0e-10) {                a2-=2*M_PI;            }            QPointArray pa;            int i=0;            pa.resize(i+1);            pa.setPoint(i++, toScreenX(p1.x), toScreenY(p1.y));            //moveTo(toScreenX(p1.x), toScreenY(p1.y));            for(a=a1-aStep; a>=a2; a-=aStep) {                cix = toScreenX(cp.x+cos(a)*radius);                ciy = toScreenY(cp.y-sin(a)*radius);                //lineTo(cix, ciy);                pa.resize(i+1);                pa.setPoint(i++, cix, ciy);            }            //lineTo(toScreenX(p2.x), toScreenY(p2.y));            pa.resize(i+1);            pa.setPoint(i++, toScreenX(p2.x), toScreenY(p2.y));            drawPolyline(pa);        }#endif    }}/** * Draws an arc. * * @param cx center in x * @param cy center in y * @param radius Radius * @param a1 Angle 1 in rad * @param a2 Angle 2 in rad * @param reversed true: clockwise, false: counterclockwise */void RS_PainterQt::drawArc(const RS_Vector& cp, double radius,                           double a1, double a2,                           bool reversed) {    if(radius<=0.5) {        drawGridPoint(cp);    } else {#ifdef __APPLE__		drawArcMac(cp, radius, a1, a2, reversed);#else        QPointArray pa;        createArc(pa, cp, radius, a1, a2, reversed);        drawPolyline(pa);#endif    }}/** * Draws an arc on apple.  * * @param cx center in x * @param cy center in y * @param radius Radius * @param a1 Angle 1 in rad * @param a2 Angle 2 in rad * @param reversed true: clockwise, false: counterclockwise */void RS_PainterQt::drawArcMac(const RS_Vector& cp, double radius,                           double a1, double a2,                           bool reversed) {	RS_DEBUG->print("RS_PainterQt::drawArcMac");    if(radius<=0.5) {        drawGridPoint(cp);    } else {        //QPointArray pa;        //createArc(pa, cp, radius, a1, a2, reversed);              double cix;            // Next point on circle              double ciy;            //              double aStep;         // Angle Step (rad)              double a;             // Current Angle (rad)			  double ox;			  double oy;              if(2.0/radius<=1.0) {                  aStep=asin(2.0/radius);              } else {                  aStep=1.0;              }              if (aStep<0.05) {                  aStep = 0.05;              }              //QPointArray pa;              //int i=0;              //pa.resize(i+1);              //pa.setPoint(i++, toScreenX(cp.x+cos(a1)*radius),              //            toScreenY(cp.y-sin(a1)*radius));              //moveTo(toScreenX(cp.x+cos(a1)*radius),              //       toScreenY(cp.y-sin(a1)*radius));              ox = cp.x+cos(a1)*radius;              oy = cp.y-sin(a1)*radius;              if(!reversed) {                  // Arc Counterclockwise:                  if(a1>a2-1.0e-10) {                      a2+=2*M_PI;                  }                  for(a=a1+aStep; a<=a2; a+=aStep) {                      cix = cp.x+cos(a)*radius;                      ciy = cp.y-sin(a)*radius;                      //lineTo(cix, ciy);					  drawLine(RS_Vector(ox, oy), RS_Vector(cix, ciy));					  ox = cix;					  oy = ciy;                      //pa.resize(i+1);                      //pa.setPoint(i++, cix, ciy);                  }              } else {                  // Arc Clockwise:                  if(a1<a2+1.0e-10) {                      a2-=2*M_PI;                  }                  for(a=a1-aStep; a>=a2; a-=aStep) {                      cix = cp.x+cos(a)*radius;                      ciy = cp.y-sin(a)*radius;                      drawLine(RS_Vector(ox, oy), RS_Vector(cix, ciy));					  ox = cix;					  oy = ciy;					  //lineTo(cix, ciy);                      //pa.resize(i+1);                      //pa.setPoint(i++, cix, ciy);                  }              }              drawLine(RS_Vector(ox, oy), 			  		RS_Vector(cp.x+cos(a2)*radius,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -