File indexing completed on 2024-04-28 04:32:08
0001 /* 0002 * Copyright (C) 2010-2015 by Stephen Allewell 0003 * steve.allewell@gmail.com 0004 * 0005 * This program is free software; you can redistribute it and/or modify 0006 * it under the terms of the GNU General Public License as published by 0007 * the Free Software Foundation; either version 2 of the License, or 0008 * (at your option) any later version. 0009 */ 0010 0011 #ifndef Stitch_H 0012 #define Stitch_H 0013 0014 #include <QDataStream> 0015 #include <QPoint> 0016 #include <QQueue> 0017 0018 class Stitch 0019 { 0020 public: 0021 enum Type { 0022 Delete = 0, 0023 TLQtr = 1, 0024 TRQtr = 2, 0025 BLQtr = 4, 0026 BTHalf = 6, 0027 TL3Qtr = 7, 0028 BRQtr = 8, 0029 TBHalf = 9, 0030 TR3Qtr = 11, 0031 BL3Qtr = 13, 0032 BR3Qtr = 14, 0033 Full = 15, 0034 TLSmallHalf = 65, 0035 TRSmallHalf = 66, 0036 BLSmallHalf = 68, 0037 BRSmallHalf = 72, 0038 TLSmallFull = 129, 0039 TRSmallFull = 130, 0040 BLSmallFull = 132, 0041 BRSmallFull = 136, 0042 FrenchKnot = 255 0043 }; 0044 0045 Stitch(); 0046 Stitch(Stitch::Type, int); 0047 0048 static const int version = 100; 0049 0050 Stitch::Type type; 0051 int colorIndex; 0052 }; 0053 0054 QDataStream &operator<<(QDataStream &, const Stitch &); 0055 QDataStream &operator>>(QDataStream &, Stitch &); 0056 0057 class StitchQueue : public QQueue<Stitch *> 0058 { 0059 public: 0060 StitchQueue(); 0061 explicit StitchQueue(StitchQueue *); 0062 ~StitchQueue(); 0063 0064 int add(Stitch::Type, int); 0065 Stitch *find(Stitch::Type, int); 0066 int remove(Stitch::Type, int); 0067 0068 static const int version = 100; 0069 }; 0070 0071 QDataStream &operator<<(QDataStream &, const StitchQueue &); 0072 QDataStream &operator>>(QDataStream &, StitchQueue &); 0073 0074 class Backstitch 0075 { 0076 public: 0077 Backstitch(); 0078 Backstitch(const QPoint &, const QPoint &, int); 0079 0080 bool contains(const QPoint &) const; 0081 void move(int, int); 0082 void move(const QPoint &); 0083 0084 static const int version = 100; 0085 0086 QPoint start; 0087 QPoint end; 0088 int colorIndex; 0089 }; 0090 0091 QDataStream &operator<<(QDataStream &, const Backstitch &); 0092 QDataStream &operator>>(QDataStream &, Backstitch &); 0093 0094 class Knot 0095 { 0096 public: 0097 Knot(); 0098 Knot(const QPoint &, int); 0099 0100 void move(int, int); 0101 void move(const QPoint &); 0102 0103 static const int version = 100; 0104 0105 QPoint position; 0106 int colorIndex; 0107 }; 0108 0109 QDataStream &operator<<(QDataStream &, const Knot &); 0110 QDataStream &operator>>(QDataStream &, Knot &); 0111 0112 const Stitch::Type stitchMap[][4] = {{Stitch::TLQtr, Stitch::TRQtr, Stitch::BLQtr, Stitch::BRQtr}, 0113 {Stitch::TBHalf, Stitch::BTHalf, Stitch::BTHalf, Stitch::TBHalf}, 0114 {Stitch::TL3Qtr, Stitch::TR3Qtr, Stitch::BL3Qtr, Stitch::BR3Qtr}, 0115 {Stitch::Full, Stitch::Full, Stitch::Full, Stitch::Full}, 0116 {Stitch::TLSmallHalf, Stitch::TRSmallHalf, Stitch::BLSmallHalf, Stitch::BRSmallHalf}, 0117 {Stitch::TLSmallFull, Stitch::TRSmallFull, Stitch::BLSmallFull, Stitch::BRSmallFull}}; 0118 0119 #endif // Stitch_H