~ubuntu-branches/debian/sid/kxstitch/sid

« back to all changes in this revision

Viewing changes to kxstitch/patternpropertiesdialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): eric pareja
  • Date: 2005-02-19 12:37:22 UTC
  • Revision ID: james.westby@ubuntu.com-20050219123722-kt3ru1nqvllietee
Tags: upstream-0.6
ImportĀ upstreamĀ versionĀ 0.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2003 by Stephen Allewell                                *
 
3
 *   stephen@mirramar.fsnet.co.uk                                          *
 
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
#include <qcombobox.h>
 
12
#include <qlineedit.h>
 
13
#include <qmultilineedit.h>
 
14
#include <qcheckbox.h>
 
15
#include <kdebug.h>
 
16
#include <knuminput.h>
 
17
#include <kcolorbutton.h>
 
18
#include <kapplication.h>
 
19
#include <klocale.h>
 
20
#include "kxstitch.h"
 
21
#include "patternpropertiesdialog.h"
 
22
#include "configuration.h"
 
23
 
 
24
PatternPropertiesDialog::PatternPropertiesDialog(QWidget* parent)
 
25
  : PatternPropertiesDlg(parent)
 
26
{
 
27
  reset();
 
28
  connect(SizeUnits,SIGNAL(activated(const QString&)),this,SLOT(slotUnitsChanged(const QString&)));
 
29
  connect(HelpButton,SIGNAL(clicked()),this,SLOT(slotContextHelp()));
 
30
}
 
31
 
 
32
void PatternPropertiesDialog::show()
 
33
{
 
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);
 
42
  FlossScheme->clear();
 
43
  FlossScheme->insertStringList(((KXStitchApplication*)kapp)->schemes());
 
44
  Configuration::setComboBoxItem(FlossScheme,m_flossScheme);
 
45
  PatternInstructions->setText(m_patternInstructions);
 
46
  SetDefault->setChecked(false);
 
47
  PatternPropertiesDlg::show();
 
48
}
 
49
 
 
50
void PatternPropertiesDialog::reset()
 
51
{
 
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;
 
64
}
 
65
 
 
66
void PatternPropertiesDialog::setUnits(QString sizeUnits)
 
67
{
 
68
  m_sizeDisplayUnits = m_sizeUnits = sizeUnits;
 
69
}
 
70
 
 
71
void PatternPropertiesDialog::setPatternWidth(int width)
 
72
{
 
73
  m_sizeWidth = width;
 
74
}
 
75
 
 
76
void PatternPropertiesDialog::setPatternHeight(int height)
 
77
{
 
78
  m_sizeHeight = height;
 
79
}
 
80
 
 
81
void PatternPropertiesDialog::setPatternSize(int width,int height)
 
82
{
 
83
  m_sizeWidth = width;
 
84
  m_sizeHeight = height;
 
85
}
 
86
 
 
87
void PatternPropertiesDialog::setClothCount(double clothCount)
 
88
{
 
89
  m_clothCount = clothCount;
 
90
}
 
91
 
 
92
void PatternPropertiesDialog::setClothCountUnits(QString clothCountUnits)
 
93
{
 
94
  m_clothCountUnits = clothCountUnits;
 
95
}
 
96
 
 
97
void PatternPropertiesDialog::setTitle(QString title)
 
98
{
 
99
  m_patternTitle = title;
 
100
}
 
101
 
 
102
void PatternPropertiesDialog::setAuthor(QString author)
 
103
{
 
104
  m_patternAuthor = author;
 
105
}
 
106
 
 
107
void PatternPropertiesDialog::setCopyright(QString copyright)
 
108
{
 
109
  m_patternCopyright = copyright;
 
110
}
 
111
 
 
112
void PatternPropertiesDialog::setFabric(QString fabric)
 
113
{
 
114
  m_patternFabric = fabric;
 
115
}
 
116
 
 
117
void PatternPropertiesDialog::setFabricColor(QColor fabricColor)
 
118
{
 
119
  m_fabricColor = fabricColor;
 
120
}
 
121
 
 
122
void PatternPropertiesDialog::setScheme(QString scheme)
 
123
{
 
124
  m_flossScheme = scheme;
 
125
}
 
126
 
 
127
void PatternPropertiesDialog::setInstructions(QString instructions)
 
128
{
 
129
  m_patternInstructions = instructions;
 
130
}
 
131
 
 
132
QString PatternPropertiesDialog::units()
 
133
{
 
134
  return m_sizeUnits;
 
135
}
 
136
 
 
137
int PatternPropertiesDialog::patternWidth()
 
138
{
 
139
  return m_sizeWidth;
 
140
}
 
141
 
 
142
int PatternPropertiesDialog::patternHeight()
 
143
{
 
144
  return m_sizeHeight;
 
145
}
 
146
 
 
147
QSize PatternPropertiesDialog::patternSize()
 
148
{
 
149
  return QSize(m_sizeWidth,m_sizeHeight);
 
150
}
 
151
 
 
152
double PatternPropertiesDialog::clothCount()
 
153
{
 
154
  return m_clothCount;
 
155
}
 
156
 
 
157
QString PatternPropertiesDialog::clothCountUnits()
 
158
{
 
159
  return m_clothCountUnits;
 
160
}
 
161
 
 
162
QString PatternPropertiesDialog::title()
 
163
{
 
164
  return m_patternTitle;
 
165
}
 
166
 
 
167
QString PatternPropertiesDialog::author()
 
168
{
 
169
  return m_patternAuthor;
 
170
}
 
171
 
 
172
QString PatternPropertiesDialog::copyright()
 
173
{
 
174
  return m_patternCopyright;
 
175
}
 
176
 
 
177
QString PatternPropertiesDialog::fabric()
 
178
{
 
179
  return m_patternFabric;
 
180
}
 
181
 
 
182
QColor PatternPropertiesDialog::fabricColor()
 
183
{
 
184
  return m_fabricColor;
 
185
}
 
186
 
 
187
QString PatternPropertiesDialog::scheme()
 
188
{
 
189
  return m_flossScheme;
 
190
}
 
191
 
 
192
QString PatternPropertiesDialog::instructions()
 
193
{
 
194
  return m_patternInstructions;
 
195
}
 
196
 
 
197
void PatternPropertiesDialog::accept()
 
198
{
 
199
  double w = SizeWidth->value();
 
200
  double h = SizeHeight->value();
 
201
  double cc = ClothCount->value();
 
202
  if (m_sizeDisplayUnits != "Stitches")
 
203
  {
 
204
    w *= cc;
 
205
    h *= cc;
 
206
  }
 
207
  m_sizeUnits = m_sizeDisplayUnits;
 
208
  m_sizeWidth = int(w);
 
209
  m_sizeHeight = int(h);
 
210
  m_clothCount = cc;
 
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())
 
220
  {
 
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();
 
234
  }
 
235
  PatternPropertiesDlg::accept();
 
236
}
 
237
 
 
238
void PatternPropertiesDialog::slotContextHelp()
 
239
{
 
240
  kapp->invokeHelp("PatternPropertiesDialog");
 
241
}
 
242
 
 
243
void PatternPropertiesDialog::slotUnitsChanged(const QString& sizeUnits)
 
244
{
 
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"))
 
250
  {
 
251
    w *= cc;
 
252
    h *= cc;
 
253
  }
 
254
  if (sizeUnits == i18n("CM"))
 
255
  {
 
256
    if (ccu == "/in")
 
257
    {
 
258
      ccu = "/cm";
 
259
      cc /= 2.54;
 
260
    }
 
261
  }
 
262
  if (sizeUnits == i18n("Inches"))
 
263
  {
 
264
    if (ccu == "/cm")
 
265
    {
 
266
      ccu = "/in";
 
267
      cc = (double)(int)(cc*2.54);
 
268
    }
 
269
  }
 
270
  m_sizeDisplayUnits = sizeUnits;
 
271
  calculateSizes(int(w),int(h),cc,ccu);
 
272
}
 
273
 
 
274
void PatternPropertiesDialog::calculateSizes(int w,int h,double cc,QString ccu)
 
275
{
 
276
  double  scale = cc;
 
277
  double  sizeStep = 0.01;
 
278
  if (SizeUnits->currentText() == i18n("Stitches"))
 
279
  {
 
280
    scale = 1.0;
 
281
    sizeStep = 1.0;
 
282
  }
 
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);
 
290
}
 
291
 
 
292
QDataStream& operator<<(QDataStream& stream,const PatternPropertiesDialog& properties)
 
293
{
 
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;
 
306
  return stream;
 
307
}
 
308
 
 
309
QDataStream& operator>>(QDataStream& stream,PatternPropertiesDialog& properties)
 
310
{
 
311
  Q_INT32 w,h;
 
312
  stream >> properties.m_sizeUnits;
 
313
  stream >> w;
 
314
  properties.m_sizeWidth = w;
 
315
  stream >> h;
 
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;
 
326
  return stream;
 
327
}