File indexing completed on 2024-04-28 04:31:57

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 #include "DocumentFloss.h"
0012 
0013 #include <QMap>
0014 
0015 #include <KLocalizedString>
0016 
0017 #include "Exceptions.h"
0018 #include "SymbolLibrary.h"
0019 #include "SymbolManager.h"
0020 
0021 DocumentFloss::DocumentFloss()
0022 {
0023 }
0024 
0025 DocumentFloss::DocumentFloss(const QString &flossName, qint16 stitchSymbol, Qt::PenStyle backstitchSymbol, int stitchStrands, int backstitchStrands)
0026     : m_flossName(flossName)
0027     , m_stitchSymbol(stitchSymbol)
0028     , m_backstitchSymbol(backstitchSymbol)
0029     , m_stitchStrands(stitchStrands)
0030     , m_backstitchStrands(backstitchStrands)
0031 {
0032 }
0033 
0034 DocumentFloss::DocumentFloss(const DocumentFloss *other)
0035     : m_flossName(other->m_flossName)
0036     , m_flossColor(other->m_flossColor)
0037     , m_stitchSymbol(other->m_stitchSymbol)
0038     , m_backstitchSymbol(other->m_backstitchSymbol)
0039     , m_stitchStrands(other->m_stitchStrands)
0040     , m_backstitchStrands(other->m_backstitchStrands)
0041 {
0042 }
0043 
0044 QString DocumentFloss::flossName() const
0045 {
0046     return m_flossName;
0047 }
0048 
0049 QColor DocumentFloss::flossColor() const
0050 {
0051     return m_flossColor;
0052 }
0053 
0054 qint16 DocumentFloss::stitchSymbol() const
0055 {
0056     return m_stitchSymbol;
0057 }
0058 
0059 Qt::PenStyle DocumentFloss::backstitchSymbol() const
0060 {
0061     return m_backstitchSymbol;
0062 }
0063 
0064 int DocumentFloss::stitchStrands() const
0065 {
0066     return m_stitchStrands;
0067 }
0068 
0069 int DocumentFloss::backstitchStrands() const
0070 {
0071     return m_backstitchStrands;
0072 }
0073 
0074 void DocumentFloss::setFlossName(const QString &flossName)
0075 {
0076     m_flossName = flossName;
0077 }
0078 
0079 void DocumentFloss::setFlossColor(const QColor &flossColor)
0080 {
0081     m_flossColor = flossColor;
0082 }
0083 
0084 void DocumentFloss::setStitchSymbol(qint16 stitchSymbol)
0085 {
0086     m_stitchSymbol = stitchSymbol;
0087 }
0088 
0089 void DocumentFloss::setBackstitchSymbol(Qt::PenStyle backstitchSymbol)
0090 {
0091     m_backstitchSymbol = backstitchSymbol;
0092 }
0093 
0094 void DocumentFloss::setStitchStrands(int stitchStrands)
0095 {
0096     m_stitchStrands = stitchStrands;
0097 }
0098 
0099 void DocumentFloss::setBackstitchStrands(int backstitchStrands)
0100 {
0101     m_backstitchStrands = backstitchStrands;
0102 }
0103 
0104 bool DocumentFloss::operator==(const DocumentFloss &other) const
0105 {
0106     return ((m_flossName == other.m_flossName) && (m_flossColor == other.m_flossColor) && (m_stitchSymbol == other.m_stitchSymbol)
0107             && (m_backstitchSymbol == other.m_backstitchSymbol) && (m_stitchStrands == other.m_stitchStrands)
0108             && (m_backstitchStrands == other.m_backstitchStrands));
0109 }
0110 
0111 bool DocumentFloss::operator!=(const DocumentFloss &other) const
0112 {
0113     return !(*this == other);
0114 }
0115 
0116 QDataStream &operator<<(QDataStream &stream, const DocumentFloss &documentFloss)
0117 {
0118     stream << qint32(documentFloss.version);
0119 
0120     stream << documentFloss.m_flossName;
0121     stream << documentFloss.m_flossColor;
0122     stream << documentFloss.m_stitchSymbol;
0123     stream << qint32(documentFloss.m_backstitchSymbol);
0124     stream << qint32(documentFloss.m_stitchStrands);
0125     stream << qint32(documentFloss.m_backstitchStrands);
0126 
0127     return stream;
0128 }
0129 
0130 QDataStream &operator>>(QDataStream &stream, DocumentFloss &documentFloss)
0131 {
0132     qint32 version;
0133     qint32 backstitchSymbol;
0134     qint32 stitchStrands;
0135     qint32 backstitchStrands;
0136     QChar oldStitchSymbol;
0137 
0138     stream >> version;
0139 
0140     switch (version) {
0141     case 101:
0142         stream >> documentFloss.m_flossName;
0143         stream >> documentFloss.m_flossColor;
0144         stream >> documentFloss.m_stitchSymbol;
0145         stream >> backstitchSymbol;
0146         stream >> stitchStrands;
0147         stream >> backstitchStrands;
0148         documentFloss.m_backstitchSymbol = Qt::PenStyle(backstitchSymbol);
0149         documentFloss.m_stitchStrands = stitchStrands;
0150         documentFloss.m_backstitchStrands = backstitchStrands;
0151         break;
0152 
0153     case 100:
0154         stream >> documentFloss.m_flossName;
0155         stream >> documentFloss.m_flossColor;
0156         stream >> oldStitchSymbol;
0157         stream >> backstitchSymbol;
0158         stream >> stitchStrands;
0159         stream >> backstitchStrands;
0160         documentFloss.m_backstitchSymbol = Qt::PenStyle(backstitchSymbol);
0161         documentFloss.m_stitchStrands = stitchStrands;
0162         documentFloss.m_backstitchStrands = backstitchStrands;
0163         documentFloss.m_stitchSymbol = 0;
0164         break;
0165 
0166     default:
0167         throw InvalidFileVersion(QString(i18n("Document floss version %1", version)));
0168         break;
0169     }
0170 
0171     return stream;
0172 }