3
$Id: OptionDialog.cc,v 1.22 2001/07/18 18:45:56 buis Exp $
5
This file is part of KIllustrator.
6
Copyright (C) 1998-99 Kai-Uwe Sattler (kus@iti.cs.uni-magdeburg.de)
8
This program is free software; you can redistribute it and/or modify
9
it under the terms of the GNU Library General Public License as
11
the Free Software Foundation; either version 2 of the License, or
12
(at your option) any later version.
14
This program is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
GNU General Public License for more details.
19
You should have received a copy of the GNU Library General Public License
20
along with this program; if not, write to the Free Software
21
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27
#include <qvgroupbox.h>
29
#include <qcombobox.h>
30
#include <qcheckbox.h>
31
#include <kcolorbutton.h>
36
#include <PStateManager.h>
38
#include "OptionDialog.h"
39
#include "GDocument.h"
42
OptionDialog::OptionDialog (GDocument *adoc,QWidget* parent, const char* name) :
43
KDialogBase(KDialogBase::TreeList, i18n("Option"),
45
parent, name, true),doc(adoc),modified(false)
48
createGeneralWidget(addPage(i18n("General")));
49
createEditWidget(addPage(i18n("Edit")));
51
list << i18n("Document") << i18n("Grid");
52
createGridWidget(addPage(list));
54
list << i18n("Document") << i18n("Background");
55
createBGWidget(addPage(list));
57
list << i18n("Document") << i18n("Helplines") << i18n("Vertical");
58
createVertLineWidget(addPage(list));
60
list << i18n("Document") << i18n("Helplines") << i18n("Horizontal");
61
createHorizLineWidget(addPage(list));
64
horizLines = doc->horizHelplines();
65
vertLines = doc->vertHelplines();
69
void OptionDialog::createGeneralWidget (QWidget* parent)
72
QGridLayout *layout=new QGridLayout(parent, 2, 2, KDialogBase::marginHint(), KDialogBase::spacingHint());
73
QLabel *label = new QLabel(i18n("Unit:"), parent);
74
layout->addWidget(label, 0, 0);
76
unit = new QComboBox (parent);
77
unit->insertItem (unitToString (UnitPoint));
78
unit->insertItem (unitToString (UnitMillimeter));
79
unit->insertItem (unitToString (UnitInch));
80
unit->insertItem (unitToString (UnitPica));
81
unit->insertItem (unitToString (UnitCentimeter));
82
unit->insertItem (unitToString (UnitDidot));
83
unit->insertItem (unitToString (UnitCicero));
84
layout->addWidget(unit, 0, 1);
85
layout->setRowStretch(1, 1);
87
unit->setCurrentItem ((int)
88
PStateManager::instance ()->defaultMeasurementUnit ());
91
void OptionDialog::createEditWidget (QWidget* parent)
94
QBoxLayout *layout=new QVBoxLayout(parent, KDialogBase::marginHint(), KDialogBase::spacingHint());
95
QGroupBox *box = new QGroupBox(i18n("Duplicate Offset"), parent);
96
layout->addWidget(box);
98
QBoxLayout *vboxlayout=new QVBoxLayout(box, KDialogBase::marginHint(), KDialogBase::spacingHint());
99
vboxlayout->addSpacing(box->fontMetrics().height()/2);
100
QGridLayout *grid=new QGridLayout(vboxlayout, 2, 2);
101
QLabel *label = new QLabel(i18n("Horizontal:"), box);
102
grid->addWidget(label, 0, 0);
104
horiz = new UnitBox(box);
105
horiz->setRange (-1000.0, 1000.0);
106
horiz->setStep (0.1);
107
horiz->setEditable (true);
108
grid->addWidget(horiz, 0, 1);
110
label = new QLabel(i18n("Vertical:"), box);
111
grid->addWidget(label, 1, 0);
113
vert = new UnitBox(box);
114
vert->setRange (-1000.0, 1000.0);
116
vert->setEditable (true);
117
grid->addWidget(vert, 1, 1);
119
box = new QGroupBox(i18n("Step Distance"), parent);
120
layout->addWidget(box);
122
vboxlayout=new QVBoxLayout(box, KDialogBase::marginHint(), KDialogBase::spacingHint());
123
vboxlayout->addSpacing(box->fontMetrics().height()/2);
124
grid=new QGridLayout(vboxlayout, 2, 2);
125
label = new QLabel(i18n("Small step:"), box);
126
grid->addWidget(label, 0, 0);
128
smallStep = new UnitBox(box);
129
smallStep->setRange (-1000.0, 1000.0);
130
smallStep->setStep (0.1);
131
smallStep->setEditable (true);
132
grid->addWidget(smallStep, 0, 1);
134
label = new QLabel(i18n("Big step:"), box);
135
grid->addWidget(label, 1, 0);
137
bigStep = new UnitBox(box);
138
bigStep->setRange (-1000.0, 1000.0);
139
bigStep->setStep (0.1);
140
bigStep->setEditable (true);
141
grid->addWidget(bigStep, 1, 1);
143
PStateManager *psm = PStateManager::instance ();
144
horiz->setValue (psm->duplicateXOffset ());
145
vert->setValue (psm->duplicateYOffset ());
146
smallStep->setValue (psm->smallStepSize ());
147
bigStep->setValue (psm->bigStepSize ());
151
void OptionDialog::createBGWidget(QWidget* parent)
153
QBoxLayout *layout=new QHBoxLayout(parent, KDialogBase::marginHint(), KDialogBase::spacingHint());
154
QLabel* clabel = new QLabel(i18n("Background Color"), parent);
155
bgbutton = new KColorButton(parent);
156
connect (bgbutton, SIGNAL(changed (const QColor&)), this, SLOT(slotSetModified()));
157
bgbutton->setColor(doc->activePage()->bgColor());
158
layout->addWidget(clabel);
159
layout->addWidget(bgbutton);
164
void OptionDialog::createGridWidget (QWidget* parent)
166
QGridLayout *layout=new QGridLayout(parent, 3, 2, KDialogBase::marginHint(), KDialogBase::spacingHint());
168
QGroupBox *box=new QGroupBox(i18n("Distance"), parent);
169
layout->addMultiCellWidget(box, 0, 0, 0, 1);
171
QBoxLayout *vboxlayout=new QVBoxLayout(box, KDialogBase::marginHint(), KDialogBase::spacingHint());
172
vboxlayout->addSpacing(box->fontMetrics().height()/2);
173
QGridLayout *grid=new QGridLayout(vboxlayout, 2, 2);
174
QLabel* label = new QLabel(i18n("Horizontally"), box);
175
grid->addWidget(label, 0, 0);
177
hspinbox = new UnitBox(box);
178
hspinbox->setFormatString ("%-3.3f");
179
hspinbox->setEditable (true);
180
hspinbox->setRange (0, 1000);
181
connect (hspinbox, SIGNAL(valueChanged (float)), this, SLOT(slotSetModified()));
182
grid->addWidget(hspinbox, 0, 1);
184
label = new QLabel(i18n("Vertically"), box);
185
grid->addWidget(label, 1, 0);
187
vspinbox = new UnitBox (box);
188
vspinbox->setFormatString ("%-3.3f");
189
vspinbox->setEditable (true);
190
vspinbox->setRange (0, 1000);
191
connect (vspinbox, SIGNAL(valueChanged (float)), this, SLOT(slotSetModified()));
192
grid->addWidget(vspinbox, 1, 1);
194
hspinbox->setValue(doc->horizGridDistance());
195
vspinbox->setValue(doc->vertGridDistance());
197
gbutton = new QCheckBox(i18n("Snap To Grid"), parent);
198
gbutton->setDown(doc->snapToGrid());
199
connect (gbutton, SIGNAL(stateChanged (int)), this, SLOT(slotSetModified()));
200
layout->addWidget(gbutton, 1, 0);
202
sbutton = new QCheckBox(i18n("Show Grid"), parent);
203
sbutton->setDown(doc->showGrid());
204
connect (sbutton, SIGNAL(stateChanged (int)), this, SLOT(slotSetModified()));
205
layout->addWidget(sbutton, 1, 1);
207
cbutton = new KColorButton(parent);
208
cbutton->setColor(doc->gridColor());
209
QLabel* clabel = new QLabel(i18n("Grid Color"), parent);
210
connect (cbutton, SIGNAL(changed (const QColor&)), this, SLOT(slotSetModified()));
211
layout->addWidget(cbutton, 2, 1);
212
layout->addWidget(clabel, 2, 0);
216
void OptionDialog::createHorizLineWidget(QWidget* parent)
219
QBoxLayout *layout=new QHBoxLayout(parent, KDialogBase::marginHint(), KDialogBase::spacingHint());
220
QBoxLayout *left=new QVBoxLayout(layout);
222
horizValue = new UnitBox (parent);
223
horizValue->setRange (-1000.0, 1000.0);
224
horizValue->setStep (0.1);
225
horizValue->setEditable (true);
226
horizValue->setValue(0.0);
227
left->addWidget(horizValue);
229
horizList = new QListBox (parent);
230
horizList->setMultiSelection (false);
231
connect (horizList, SIGNAL(highlighted(int)),
232
this, SLOT(horizLineSelected(int)));
233
left->addWidget(horizList);
234
layout->addSpacing(KDialogBase::spacingHint()*2);
236
QBoxLayout *right=new QVBoxLayout(layout);
237
addHorizHelpLine = new QPushButton (i18n("Add"), parent);
238
connect (addHorizHelpLine, SIGNAL(clicked ()), this, SLOT(addHorizLine ()));
239
right->addWidget(addHorizHelpLine);
241
updateHorizHelpLine = new QPushButton(i18n("Update"), parent);
242
connect (updateHorizHelpLine, SIGNAL(clicked ()), this, SLOT(updateHorizLine ()));
243
right->addWidget(updateHorizHelpLine);
245
delHorizHelpLine = new QPushButton(i18n("Delete"), parent);
246
connect (delHorizHelpLine, SIGNAL(clicked ()), this, SLOT(deleteHorizLine ()));
247
right->addWidget(delHorizHelpLine);
251
void OptionDialog::createVertLineWidget(QWidget* parent)
253
QBoxLayout *layout=new QHBoxLayout(parent, KDialogBase::marginHint(), KDialogBase::spacingHint());
254
QBoxLayout *left=new QVBoxLayout(layout);
256
vertValue = new UnitBox (parent);
257
vertValue->setRange (-1000.0, 1000.0);
258
vertValue->setStep (0.1);
259
vertValue->setEditable (true);
260
vertValue->setValue(0.0);
261
left->addWidget(vertValue);
263
vertList = new QListBox(parent);
264
vertList->setMultiSelection (false);
265
connect (vertList, SIGNAL(highlighted (int)),
266
this, SLOT(vertLineSelected(int)));
267
left->addWidget(vertList);
268
layout->addSpacing(KDialogBase::spacingHint() * 2);
270
QBoxLayout *right=new QVBoxLayout(layout);
271
addVertHelpLine = new QPushButton(i18n("Add"), parent);
272
connect (addVertHelpLine, SIGNAL(clicked ()), this, SLOT(addVertLine ()));
273
right->addWidget(addVertHelpLine);
275
updateVertHelpLine = new QPushButton(i18n("Update"), parent);
276
connect (updateVertHelpLine, SIGNAL(clicked ()), this, SLOT(updateVertLine ()));
277
right->addWidget(updateVertHelpLine);
279
delVertHelpLine = new QPushButton(i18n("Delete"), parent);
280
connect (delVertHelpLine, SIGNAL(clicked ()), this, SLOT(deleteVertLine ()));
281
right->addWidget(delVertHelpLine);
285
void OptionDialog::initHelplinesLists()
287
QValueList<float>::Iterator i;
289
MeasurementUnit unit = PStateManager::instance ()->defaultMeasurementUnit ();
291
for (i = horizLines.begin (); i != horizLines.end (); ++i)
293
buf=QString::number(cvtPtToUnit (unit, *i), 'f', 3);
295
buf+=unitToString (unit);
296
horizList->insertItem (buf);
298
if(!horizLines.isEmpty())
299
horizValue->setValue(horizLines[0]);
302
updateHorizHelpLine->setEnabled(false);
303
delHorizHelpLine->setEnabled(false);
306
for (i = vertLines.begin (); i != vertLines.end (); ++i)
308
buf=QString::number(cvtPtToUnit (unit, *i), 'f', 3);
310
buf+=unitToString (unit);
311
vertList->insertItem (buf);
313
if(!vertLines.isEmpty())
314
vertValue->setValue(vertLines[0]);
317
updateVertHelpLine->setEnabled(false);
318
delVertHelpLine->setEnabled(false);
322
void OptionDialog::addHorizLine()
324
float value = horizValue->getValue ();
325
horizLines.append(value);
326
MeasurementUnit unit = PStateManager::instance ()->defaultMeasurementUnit ();
327
QString buf=QString::number(cvtPtToUnit (unit, value), 'f', 3);
329
buf+=unitToString (unit);
330
horizList->insertItem (buf);
331
updateHorizHelpLine->setEnabled(true);
332
delHorizHelpLine->setEnabled(true);
336
void OptionDialog::updateHorizLine()
338
if(horizLines.isEmpty())
340
int idx = horizList->currentItem ();
343
float value = horizValue->getValue ();
344
MeasurementUnit unit = PStateManager::instance ()->defaultMeasurementUnit ();
345
QString buf=QString::number(cvtPtToUnit (unit, value), 'f', 3);
347
buf+=unitToString (unit);
348
horizList->blockSignals(true);
349
horizList->changeItem (buf, idx);
350
horizList->blockSignals(false);
351
horizLines[idx] = value;
355
void OptionDialog::deleteHorizLine()
357
if(horizLines.isEmpty())
359
int idx = horizList->currentItem ();
362
horizLines.remove(horizLines.at(idx));
363
horizList->removeItem(idx);
365
if(horizLines.isEmpty())
367
updateHorizHelpLine->setEnabled(false);
368
delHorizHelpLine->setEnabled(false);
374
void OptionDialog::addVertLine()
376
float value = vertValue->getValue ();
377
vertLines.append(value);
378
MeasurementUnit unit = PStateManager::instance ()->defaultMeasurementUnit ();
379
QString buf=QString::number(cvtPtToUnit (unit, value), 'f', 3);
381
buf+=unitToString (unit);
382
vertList->insertItem (buf);
383
delVertHelpLine->setEnabled(true);
384
updateVertHelpLine->setEnabled(true);
388
void OptionDialog::updateVertLine()
390
if(vertLines.isEmpty())
392
int idx = vertList->currentItem ();
395
float value = vertValue->getValue ();
396
MeasurementUnit unit = PStateManager::instance ()->defaultMeasurementUnit ();
397
QString buf=QString::number(cvtPtToUnit (unit, value), 'f', 3);
399
buf+=unitToString (unit);
400
vertList->blockSignals(true);
401
vertList->changeItem (buf, idx);
402
vertList->blockSignals(false);
403
vertLines[idx] = value;
407
void OptionDialog::deleteVertLine()
409
if(vertLines.isEmpty())
411
int idx = vertList->currentItem ();
414
vertLines.remove(vertLines.at(idx));
415
vertList->removeItem (idx);
417
if(vertLines.isEmpty())
419
delVertHelpLine->setEnabled(false);
420
updateVertHelpLine->setEnabled(false);
425
void OptionDialog::horizLineSelected(int idx)
427
if(!horizLines.isEmpty())
428
horizValue->setValue(*horizLines.at(idx));
431
void OptionDialog::vertLineSelected(int idx)
433
if(!vertLines.isEmpty())
434
vertValue->setValue (*vertLines.at(idx));
438
void OptionDialog::slotSetModified()
443
void OptionDialog::slotApply()
445
/*Document settings*/
448
doc->activePage()->bgColor(bgbutton->color());
450
doc->setGridDistance(hspinbox->getValue(), vspinbox->getValue());
451
doc->showGrid(sbutton->isOn());
452
doc->snapToGrid(gbutton->isOn());
453
doc->gridColor(cbutton->color());
455
doc->setHorizHelplines(horizLines);
456
doc->setVertHelplines(vertLines);
467
void OptionDialog::slotOk()
470
KDialogBase::slotOk();
473
int OptionDialog::setup (GDocument *adoc)
476
OptionDialog dialog (adoc, 0L, "Options");
478
int res=dialog.exec();
479
if(res == QDialog::Accepted)
481
int selection = dialog.unit->currentItem ();
482
PStateManager* psm = PStateManager::instance ();
486
psm->setDefaultMeasurementUnit (UnitPoint);
489
psm->setDefaultMeasurementUnit (UnitMillimeter);
492
psm->setDefaultMeasurementUnit (UnitInch);
495
psm->setDefaultMeasurementUnit (UnitPica);
498
psm->setDefaultMeasurementUnit (UnitCentimeter);
501
psm->setDefaultMeasurementUnit (UnitDidot);
504
psm->setDefaultMeasurementUnit (UnitCicero);
509
psm->setStepSizes (dialog.smallStep->getValue (),dialog.bigStep->getValue ());
510
psm->setDuplicateOffsets (dialog.horiz->getValue (),dialog.vert->getValue ());
515
#include <OptionDialog.moc>