1
/***************************************************************************
2
* Copyright (C) 2003 by Stephen Allewell *
3
* stephen@mirramar.fsnet.co.uk *
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
***************************************************************************/
11
#include <qcombobox.h>
12
#include <qlineedit.h>
13
#include <qmultilineedit.h>
14
#include <qcheckbox.h>
16
#include <knuminput.h>
17
#include <kcolorbutton.h>
18
#include <kapplication.h>
21
#include "patternpropertiesdialog.h"
22
#include "configuration.h"
24
PatternPropertiesDialog::PatternPropertiesDialog(QWidget* parent)
25
: PatternPropertiesDlg(parent)
28
connect(SizeUnits,SIGNAL(activated(const QString&)),this,SLOT(slotUnitsChanged(const QString&)));
29
connect(HelpButton,SIGNAL(clicked()),this,SLOT(slotContextHelp()));
32
void PatternPropertiesDialog::show()
34
Configuration::setComboBoxItem(SizeUnits,m_sizeUnits);
35
m_sizeDisplayUnits = m_sizeUnits;
36
calculateSizes(m_sizeWidth,m_sizeHeight,m_clothCount,m_clothCountUnits);
37
PatternTitle->setText(m_patternTitle);
38
PatternAuthor->setText(m_patternAuthor);
39
PatternCopyright->setText(m_patternCopyright);
40
PatternFabric->setText(m_patternFabric);
41
FabricColor->setColor(m_fabricColor);
43
FlossScheme->insertStringList(((KXStitchApplication*)kapp)->schemes());
44
Configuration::setComboBoxItem(FlossScheme,m_flossScheme);
45
PatternInstructions->setText(m_patternInstructions);
46
SetDefault->setChecked(false);
47
PatternPropertiesDlg::show();
50
void PatternPropertiesDialog::reset()
52
m_sizeDisplayUnits = m_sizeUnits = KXSConfig().NewPattern_Units;
53
m_sizeWidth = KXSConfig().NewPattern_Width;
54
m_sizeHeight = KXSConfig().NewPattern_Height;
55
m_clothCount = KXSConfig().NewPattern_ClothCount;
56
m_clothCountUnits = KXSConfig().NewPattern_ClothCountUnits;
57
m_patternTitle = KXSConfig().NewPattern_Title;
58
m_patternAuthor = KXSConfig().NewPattern_Author;
59
m_patternCopyright = KXSConfig().NewPattern_Copyright;
60
m_patternFabric = KXSConfig().NewPattern_Fabric;
61
m_fabricColor = KXSConfig().NewPattern_Color;
62
m_flossScheme = KXSConfig().NewPattern_FlossScheme;
63
m_patternInstructions = KXSConfig().NewPattern_Instructions;
66
void PatternPropertiesDialog::setUnits(QString sizeUnits)
68
m_sizeDisplayUnits = m_sizeUnits = sizeUnits;
71
void PatternPropertiesDialog::setPatternWidth(int width)
76
void PatternPropertiesDialog::setPatternHeight(int height)
78
m_sizeHeight = height;
81
void PatternPropertiesDialog::setPatternSize(int width,int height)
84
m_sizeHeight = height;
87
void PatternPropertiesDialog::setClothCount(double clothCount)
89
m_clothCount = clothCount;
92
void PatternPropertiesDialog::setClothCountUnits(QString clothCountUnits)
94
m_clothCountUnits = clothCountUnits;
97
void PatternPropertiesDialog::setTitle(QString title)
99
m_patternTitle = title;
102
void PatternPropertiesDialog::setAuthor(QString author)
104
m_patternAuthor = author;
107
void PatternPropertiesDialog::setCopyright(QString copyright)
109
m_patternCopyright = copyright;
112
void PatternPropertiesDialog::setFabric(QString fabric)
114
m_patternFabric = fabric;
117
void PatternPropertiesDialog::setFabricColor(QColor fabricColor)
119
m_fabricColor = fabricColor;
122
void PatternPropertiesDialog::setScheme(QString scheme)
124
m_flossScheme = scheme;
127
void PatternPropertiesDialog::setInstructions(QString instructions)
129
m_patternInstructions = instructions;
132
QString PatternPropertiesDialog::units()
137
int PatternPropertiesDialog::patternWidth()
142
int PatternPropertiesDialog::patternHeight()
147
QSize PatternPropertiesDialog::patternSize()
149
return QSize(m_sizeWidth,m_sizeHeight);
152
double PatternPropertiesDialog::clothCount()
157
QString PatternPropertiesDialog::clothCountUnits()
159
return m_clothCountUnits;
162
QString PatternPropertiesDialog::title()
164
return m_patternTitle;
167
QString PatternPropertiesDialog::author()
169
return m_patternAuthor;
172
QString PatternPropertiesDialog::copyright()
174
return m_patternCopyright;
177
QString PatternPropertiesDialog::fabric()
179
return m_patternFabric;
182
QColor PatternPropertiesDialog::fabricColor()
184
return m_fabricColor;
187
QString PatternPropertiesDialog::scheme()
189
return m_flossScheme;
192
QString PatternPropertiesDialog::instructions()
194
return m_patternInstructions;
197
void PatternPropertiesDialog::accept()
199
double w = SizeWidth->value();
200
double h = SizeHeight->value();
201
double cc = ClothCount->value();
202
if (m_sizeDisplayUnits != "Stitches")
207
m_sizeUnits = m_sizeDisplayUnits;
208
m_sizeWidth = int(w);
209
m_sizeHeight = int(h);
211
m_clothCountUnits = ClothCount->suffix();
212
m_patternTitle = PatternTitle->text();
213
m_patternAuthor = PatternAuthor->text();
214
m_patternCopyright = PatternCopyright->text();
215
m_patternFabric = PatternFabric->text();
216
m_fabricColor = FabricColor->color();
217
m_flossScheme = FlossScheme->currentText();
218
m_patternInstructions = PatternInstructions->text();
219
if (SetDefault->isChecked())
221
KXSConfig().NewPattern_Units = m_sizeUnits;
222
KXSConfig().NewPattern_Width = m_sizeWidth;
223
KXSConfig().NewPattern_Height = m_sizeHeight;
224
KXSConfig().NewPattern_ClothCount = m_clothCount;
225
KXSConfig().NewPattern_ClothCountUnits = m_clothCountUnits;
226
KXSConfig().NewPattern_Title = m_patternTitle;
227
KXSConfig().NewPattern_Author = m_patternAuthor;
228
KXSConfig().NewPattern_Copyright = m_patternCopyright;
229
KXSConfig().NewPattern_Fabric = m_patternFabric;
230
KXSConfig().NewPattern_Color = m_fabricColor;
231
KXSConfig().NewPattern_FlossScheme = m_flossScheme;
232
KXSConfig().NewPattern_Instructions = m_patternInstructions;
233
KXSConfig().writeSettings();
235
PatternPropertiesDlg::accept();
238
void PatternPropertiesDialog::slotContextHelp()
240
kapp->invokeHelp("PatternPropertiesDialog");
243
void PatternPropertiesDialog::slotUnitsChanged(const QString& sizeUnits)
245
double cc = ClothCount->value();
246
QString ccu = ClothCount->suffix();
247
double w = SizeWidth->value();
248
double h = SizeHeight->value();
249
if (m_sizeDisplayUnits != i18n("Stitches"))
254
if (sizeUnits == i18n("CM"))
262
if (sizeUnits == i18n("Inches"))
267
cc = (double)(int)(cc*2.54);
270
m_sizeDisplayUnits = sizeUnits;
271
calculateSizes(int(w),int(h),cc,ccu);
274
void PatternPropertiesDialog::calculateSizes(int w,int h,double cc,QString ccu)
277
double sizeStep = 0.01;
278
if (SizeUnits->currentText() == i18n("Stitches"))
283
SizeWidth->setRange(1,100000,sizeStep,false);
284
SizeWidth->setValue(w/scale);
285
SizeHeight->setRange(1,100000,sizeStep,false);
286
SizeHeight->setValue(h/scale);
287
ClothCount->setRange(1,55,(ccu == "/cm")?0.01:1.0,false);
288
ClothCount->setValue(cc);
289
ClothCount->setSuffix(ccu);
292
QDataStream& operator<<(QDataStream& stream,const PatternPropertiesDialog& properties)
294
stream << properties.m_sizeUnits;
295
stream << Q_INT32(properties.m_sizeWidth);
296
stream << Q_INT32(properties.m_sizeHeight);
297
stream << properties.m_clothCount;
298
stream << properties.m_clothCountUnits;
299
stream << properties.m_patternTitle;
300
stream << properties.m_patternAuthor;
301
stream << properties.m_patternCopyright;
302
stream << properties.m_patternFabric;
303
stream << properties.m_fabricColor;
304
stream << properties.m_flossScheme;
305
stream << properties.m_patternInstructions;
309
QDataStream& operator>>(QDataStream& stream,PatternPropertiesDialog& properties)
312
stream >> properties.m_sizeUnits;
314
properties.m_sizeWidth = w;
316
properties.m_sizeHeight = h;
317
stream >> properties.m_clothCount;
318
stream >> properties.m_clothCountUnits;
319
stream >> properties.m_patternTitle;
320
stream >> properties.m_patternAuthor;
321
stream >> properties.m_patternCopyright;
322
stream >> properties.m_patternFabric;
323
stream >> properties.m_fabricColor;
324
stream >> properties.m_flossScheme;
325
stream >> properties.m_patternInstructions;