1 /*
2  * Copyright (C) 2010-2015 by Stephen Allewell
3  * steve.allewell@gmail.com
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  */
10 
11 
12 #ifndef Stitch_H
13 #define Stitch_H
14 
15 #include <QDataStream>
16 #include <QPoint>
17 #include <QQueue>
18 
19 
20 class Stitch
21 {
22 public:
23     enum Type {
24         Delete = 0,
25         TLQtr = 1,
26         TRQtr = 2,
27         BLQtr = 4,
28         BTHalf = 6,
29         TL3Qtr = 7,
30         BRQtr = 8,
31         TBHalf = 9,
32         TR3Qtr = 11,
33         BL3Qtr = 13,
34         BR3Qtr = 14,
35         Full = 15,
36         TLSmallHalf = 65,
37         TRSmallHalf = 66,
38         BLSmallHalf = 68,
39         BRSmallHalf = 72,
40         TLSmallFull = 129,
41         TRSmallFull = 130,
42         BLSmallFull = 132,
43         BRSmallFull = 136,
44         FrenchKnot = 255
45     };
46 
47     Stitch();
48     Stitch(Stitch::Type, int);
49 
50     static const int version = 100;
51 
52     Stitch::Type    type;
53     int     colorIndex;
54 };
55 
56 
57 QDataStream &operator<<(QDataStream &, const Stitch &);
58 QDataStream &operator>>(QDataStream &, Stitch &);
59 
60 
61 class StitchQueue : public QQueue<Stitch *>
62 {
63 public:
64     StitchQueue();
65     explicit StitchQueue(StitchQueue *);
66     ~StitchQueue();
67 
68     int add(Stitch::Type, int);
69     Stitch *find(Stitch::Type, int);
70     int remove(Stitch::Type, int);
71 
72     static const int version = 100;
73 };
74 
75 
76 QDataStream &operator<<(QDataStream &, const StitchQueue &);
77 QDataStream &operator>>(QDataStream &, StitchQueue &);
78 
79 
80 class Backstitch
81 {
82 public:
83     Backstitch();
84     Backstitch(const QPoint &, const QPoint &, int);
85 
86     bool contains(const QPoint &) const;
87     void move(int, int);
88     void move(const QPoint &);
89 
90     static const int version = 100;
91 
92     QPoint  start;
93     QPoint  end;
94     int colorIndex;
95 };
96 
97 
98 QDataStream &operator<<(QDataStream &, const Backstitch &);
99 QDataStream &operator>>(QDataStream &, Backstitch &);
100 
101 
102 class Knot
103 {
104 public:
105     Knot();
106     Knot(const QPoint &, int);
107 
108     void move(int, int);
109     void move(const QPoint &);
110 
111     static const int version = 100;
112 
113     QPoint  position;
114     int colorIndex;
115 };
116 
117 
118 QDataStream &operator<<(QDataStream &, const Knot &);
119 QDataStream &operator>>(QDataStream &, Knot &);
120 
121 
122 const Stitch::Type stitchMap[][4] = {
123     {
124         Stitch::TLQtr,
125         Stitch::TRQtr,
126         Stitch::BLQtr,
127         Stitch::BRQtr
128     },
129     {
130         Stitch::TBHalf,
131         Stitch::BTHalf,
132         Stitch::BTHalf,
133         Stitch::TBHalf
134     },
135     {
136         Stitch::TL3Qtr,
137         Stitch::TR3Qtr,
138         Stitch::BL3Qtr,
139         Stitch::BR3Qtr
140     },
141     {
142         Stitch::Full,
143         Stitch::Full,
144         Stitch::Full,
145         Stitch::Full
146     },
147     {
148         Stitch::TLSmallHalf,
149         Stitch::TRSmallHalf,
150         Stitch::BLSmallHalf,
151         Stitch::BRSmallHalf
152     },
153     {
154         Stitch::TLSmallFull,
155         Stitch::TRSmallFull,
156         Stitch::BLSmallFull,
157         Stitch::BRSmallFull
158     }
159 };
160 
161 
162 #endif // Stitch_H
163