1 /*
2     This file is part of Kig, a KDE program for Interactive Geometry...
3     SPDX-FileCopyrightText: 2002 Dominique Devriese <devriese@kde.org>
4 
5     SPDX-License-Identifier: GPL-2.0-or-later
6 */
7 
8 #ifndef KIG_MISC_COORDINATE_SYSTEM_H
9 #define KIG_MISC_COORDINATE_SYSTEM_H
10 
11 #include <qnamespace.h>
12 
13 class KigPainter;
14 class KigDocument;
15 class KigWidget;
16 class CoordinateSystem;
17 class QValidator;
18 class Coordinate;
19 class QString;
20 class QStringList;
21 
22 /**
23  * a factory to build a CoordinateSystem and a small handle to the
24  * existent CoordinateSystem's...
25  */
26 class CoordinateSystemFactory
27 {
28 public:
29   enum { Euclidean = 0, Polar = 1 };
30 
31   static QStringList names();
32   static QString setCoordinateSystemStatement( int id );
33   static CoordinateSystem* build( int which );
34   static CoordinateSystem* build( const char* type );
35 };
36 
37 /**
38  * a CoordinateSystem is what the user sees: it is kept by KigPart to
39  * show the user a grid, and to show the coordinates of points... it
40  * allows for weird CoordinateSystem's like homogeneous or
41  * projective...
42  * internally, it does nothing, it could almost have been an ordinary
43  * Object..., mapping coordinates from and to the screen to and from
44  * the internal coordinates is done elsewhere ( KigPainter and
45  * KigWidget... )
46  */
47 class CoordinateSystem
48 //  : public Qt
49 {
50 public:
51   CoordinateSystem();
52   virtual ~CoordinateSystem();
53 
54   virtual QString fromScreen ( const Coordinate& pt, const KigDocument& w ) const = 0;
55   /**
56    * This returns a notice to say in which format coordinates should
57    * be entered.  This should be something like:
58    * i18n( "Enter coordinates in the following form: \"(x,y)\", where
59    * x is the x coordinate, and y is the y coordinate." );
60    */
61   virtual QString coordinateFormatNotice() const = 0;
62   /**
63    * Like \ref coordinateFormatNotice(), but with HTML tags useful to
64    * have a rich text...
65    */
66   virtual QString coordinateFormatNoticeMarkup() const = 0;
67   virtual Coordinate toScreen (const QString& pt, bool& ok) const = 0;
68   virtual void drawGrid ( KigPainter& p, bool showgrid = true,
69                           bool showaxes = true ) const = 0;
70   virtual QValidator* coordinateValidator() const = 0;
71   virtual Coordinate snapToGrid( const Coordinate& c,
72                                  const KigWidget& w ) const = 0;
73 
74   virtual const char* type() const = 0;
75   virtual int id() const = 0;
76 };
77 
78 class EuclideanCoords
79   : public CoordinateSystem
80 {
81 public:
82   EuclideanCoords();
83   ~EuclideanCoords();
84   QString fromScreen( const Coordinate& pt, const KigDocument& w ) const override;
85   QString coordinateFormatNotice() const override;
86   QString coordinateFormatNoticeMarkup() const override;
87   Coordinate toScreen (const QString& pt, bool& ok) const override;
88   void drawGrid ( KigPainter& p, bool showgrid = true,
89                   bool showaxes = true ) const override;
90   QValidator* coordinateValidator() const override;
91   Coordinate snapToGrid( const Coordinate& c,
92                          const KigWidget& w ) const override;
93 
94   const char* type() const override;
95   int id() const override;
96 };
97 
98 class PolarCoords
99   : public CoordinateSystem
100 {
101   void drawGridLine( KigPainter& p, const Coordinate& center,
102                      double radius ) const;
103 public:
104   PolarCoords();
105   ~PolarCoords();
106   QString fromScreen( const Coordinate& pt, const KigDocument& w ) const override;
107   QString coordinateFormatNotice() const override;
108   QString coordinateFormatNoticeMarkup() const override;
109   Coordinate toScreen (const QString& pt, bool& ok) const override;
110   void drawGrid ( KigPainter& p, bool showgrid = true,
111                   bool showaxes = true ) const override;
112   QValidator* coordinateValidator() const override;
113   Coordinate snapToGrid( const Coordinate& c,
114                          const KigWidget& w ) const override;
115 
116   const char* type() const override;
117   int id() const override;
118 };
119 
120 #endif
121