1 /****************************************************************************
2 **
3 ** This file is part of the LibreCAD project, a 2D CAD program
4 **
5 ** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
6 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
7 **
8 **
9 ** This file may be distributed and/or modified under the terms of the
10 ** GNU General Public License version 2 as published by the Free Software
11 ** Foundation and appearing in the file gpl-2.0.txt included in the
12 ** packaging of this file.
13 **
14 ** This program is distributed in the hope that it will be useful,
15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 ** GNU General Public License for more details.
18 **
19 ** You should have received a copy of the GNU General Public License
20 ** along with this program; if not, write to the Free Software
21 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 **
23 ** This copyright notice MUST APPEAR in all copies of the script!
24 **
25 **********************************************************************/
26 
27 
28 #ifndef RS_PAINTERQT_H
29 #define RS_PAINTERQT_H
30 
31 #include <QPainter>
32 #include <QPainterPath>
33 
34 #include "rs_painter.h"
35 #include "rs_pen.h"
36 
37 /**
38  * The Qt implementation of a painter. It can draw objects such as
39  * lines or arcs in a widget. All coordinates are screen coordinates
40  * and have nothing to do with the graphic view.
41  */
42 class RS_PainterQt: public QPainter, public RS_Painter {
43 
44 public:
45     RS_PainterQt( QPaintDevice* pd);
46     virtual ~RS_PainterQt()=default;
47 
48     virtual void moveTo(int x, int y);
49     virtual void lineTo(int x, int y);
50     virtual void drawGridPoint(const RS_Vector& p);
51     virtual void drawPoint(const RS_Vector& p);
52     virtual void drawLine(const RS_Vector& p1, const RS_Vector& p2);
53     //virtual void drawRect(const RS_Vector& p1, const RS_Vector& p2);
54     virtual void fillRect ( const QRectF & rectangle, const RS_Color & color );
55     virtual void fillRect ( const QRectF & rectangle, const QBrush & brush );
56     virtual void drawArc(const RS_Vector& cp, double radius,
57                          double a1, double a2,
58                          const RS_Vector& p1, const RS_Vector& p2,
59                          bool reversed);
60 
61     virtual void drawArc(const RS_Vector& cp, double radius,
62                          double a1, double a2,
63                          bool reversed);
64     virtual void drawArcMac(const RS_Vector& cp, double radius,
65                          double a1, double a2,
66                          bool reversed);
67     virtual void drawCircle(const RS_Vector&, double radius);
68     virtual void drawEllipse(const RS_Vector& cp,
69                              double radius1, double radius2,
70                              double angle,
71                              double a1, double a2,
72                              bool reversed);
73         virtual void drawImg(QImage& img, const RS_Vector& pos,
74             double angle, const RS_Vector& factor);
75     virtual void drawTextH(int x1, int y1, int x2, int y2,
76                            const QString& text);
77     virtual void drawTextV(int x1, int y1, int x2, int y2,
78                            const QString& text);
79 
80     virtual void fillRect(int x1, int y1, int w, int h,
81                           const RS_Color& col);
82 
83     virtual void fillTriangle(const RS_Vector& p1,
84                               const RS_Vector& p2,
85                               const RS_Vector& p3);
86 
87     virtual void drawPolygon(const QPolygon& a,Qt::FillRule rule=Qt::WindingFill);
88     virtual void drawPath ( const QPainterPath & path );
89     virtual void erase();
90     virtual int getWidth() const;
91     /** get Density per millimeter on screen/print device
92       *@return density per millimeter in pixel/mm
93       */
94     virtual double getDpmm() const;
95     virtual int getHeight() const;
96 
97 
98     virtual RS_Pen getPen() const;
99     virtual void setPen(const RS_Pen& pen);
100     virtual void setPen(const RS_Color& color);
101     virtual void setPen(int r, int g, int b);
102     virtual void disablePen();
103     //virtual void setColor(const QColor& color);
104     virtual const QBrush& brush() const;
105     virtual void setBrush(const RS_Color& color);
106     virtual void setBrush(const QBrush& color);
107 
108     virtual void setClipRect(int x, int y, int w, int h);
109     virtual void resetClipping();
110 
111 protected:
112     RS_Pen lpen;
113     long rememberX; // Used for the moment because QPainter doesn't support moveTo anymore, thus we need to remember ourselves the moveTo positions
114     long rememberY;
115 };
116 
117 #endif
118 
119