~ubuntu-branches/ubuntu/breezy/koffice/breezy

« back to all changes in this revision

Viewing changes to kontour/OptionDialog.cc

  • Committer: Bazaar Package Importer
  • Author(s): Ben Burton
  • Date: 2004-05-09 11:33:00 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040509113300-vfrdadqsvjfuhn3b
Tags: 1:1.3.1-1
* New upstream bugfix release.
* Built against newer imagemagick (closes: #246623).
* Made koffice-libs/kformula recommend/depend on latex-xft-fonts, which
  provides mathematical fonts that the formula editor can use.  Also
  patched the kformula part to make these fonts the default.
* Changed kword menu hint from "WordProcessors" to "Word processors"
  (closes: #246209).
* Spellchecker configuration is now fixed (closes: #221256, #227568).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- C++ -*-
2
 
 
3
 
  $Id: OptionDialog.cc,v 1.22 2001/07/18 18:45:56 buis Exp $
4
 
 
5
 
  This file is part of KIllustrator.
6
 
  Copyright (C) 1998-99 Kai-Uwe Sattler (kus@iti.cs.uni-magdeburg.de)
7
 
 
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
10
 
  published by
11
 
  the Free Software Foundation; either version 2 of the License, or
12
 
  (at your option) any later version.
13
 
 
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.
18
 
 
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.
22
 
 
23
 
*/
24
 
 
25
 
#include <qlabel.h>
26
 
#include <qlayout.h>
27
 
#include <qvgroupbox.h>
28
 
#include <qhbox.h>
29
 
#include <qcombobox.h>
30
 
#include <qcheckbox.h>
31
 
#include <kcolorbutton.h>
32
 
 
33
 
#include <klocale.h>
34
 
 
35
 
#include <UnitBox.h>
36
 
#include <PStateManager.h>
37
 
 
38
 
#include "OptionDialog.h"
39
 
#include "GDocument.h"
40
 
#include "GPage.h"
41
 
 
42
 
OptionDialog::OptionDialog (GDocument *adoc,QWidget* parent, const char* name) :
43
 
    KDialogBase(KDialogBase::TreeList, i18n("Option"),
44
 
                Ok|Apply|Cancel, Ok,
45
 
                parent, name, true),doc(adoc),modified(false)
46
 
{
47
 
  QStringList list;
48
 
  createGeneralWidget(addPage(i18n("General")));
49
 
  createEditWidget(addPage(i18n("Edit")));
50
 
  list.clear();
51
 
  list << i18n("Document") << i18n("Grid");
52
 
  createGridWidget(addPage(list));
53
 
  list.clear();
54
 
  list << i18n("Document") << i18n("Background");
55
 
  createBGWidget(addPage(list));
56
 
  list.clear();
57
 
  list << i18n("Document") << i18n("Helplines") << i18n("Vertical");
58
 
  createVertLineWidget(addPage(list));
59
 
  list.clear();
60
 
  list << i18n("Document") << i18n("Helplines") << i18n("Horizontal");
61
 
  createHorizLineWidget(addPage(list));
62
 
  list.clear();
63
 
 
64
 
  horizLines = doc->horizHelplines();
65
 
  vertLines = doc->vertHelplines();
66
 
  initHelplinesLists();
67
 
}
68
 
 
69
 
void OptionDialog::createGeneralWidget (QWidget* parent)
70
 
{
71
 
 
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);
75
 
 
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);
86
 
 
87
 
    unit->setCurrentItem ((int)
88
 
                          PStateManager::instance ()->defaultMeasurementUnit ());
89
 
}
90
 
 
91
 
void OptionDialog::createEditWidget (QWidget* parent)
92
 
{
93
 
 
94
 
    QBoxLayout *layout=new QVBoxLayout(parent, KDialogBase::marginHint(), KDialogBase::spacingHint());
95
 
    QGroupBox *box = new QGroupBox(i18n("Duplicate Offset"), parent);
96
 
    layout->addWidget(box);
97
 
 
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);
103
 
 
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);
109
 
 
110
 
    label = new QLabel(i18n("Vertical:"), box);
111
 
    grid->addWidget(label, 1, 0);
112
 
 
113
 
    vert = new UnitBox(box);
114
 
    vert->setRange (-1000.0, 1000.0);
115
 
    vert->setStep (0.1);
116
 
    vert->setEditable (true);
117
 
    grid->addWidget(vert, 1, 1);
118
 
 
119
 
    box = new QGroupBox(i18n("Step Distance"), parent);
120
 
    layout->addWidget(box);
121
 
 
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);
127
 
 
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);
133
 
 
134
 
    label = new QLabel(i18n("Big step:"), box);
135
 
    grid->addWidget(label, 1, 0);
136
 
 
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);
142
 
 
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 ());
148
 
}
149
 
 
150
 
/*Background*/
151
 
void OptionDialog::createBGWidget(QWidget* parent)
152
 
{
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);
160
 
}
161
 
 
162
 
/*Grid*/
163
 
 
164
 
void OptionDialog::createGridWidget (QWidget* parent)
165
 
{
166
 
  QGridLayout *layout=new QGridLayout(parent, 3, 2, KDialogBase::marginHint(), KDialogBase::spacingHint());
167
 
 
168
 
  QGroupBox *box=new QGroupBox(i18n("Distance"), parent);
169
 
  layout->addMultiCellWidget(box, 0, 0, 0, 1);
170
 
 
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);
176
 
 
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);
183
 
 
184
 
  label = new QLabel(i18n("Vertically"), box);
185
 
  grid->addWidget(label, 1, 0);
186
 
 
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);
193
 
 
194
 
  hspinbox->setValue(doc->horizGridDistance());
195
 
  vspinbox->setValue(doc->vertGridDistance());
196
 
 
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);
201
 
 
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);
206
 
 
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);
213
 
}
214
 
 
215
 
/*Helplines*/
216
 
void OptionDialog::createHorizLineWidget(QWidget* parent)
217
 
{
218
 
 
219
 
    QBoxLayout *layout=new QHBoxLayout(parent, KDialogBase::marginHint(), KDialogBase::spacingHint());
220
 
    QBoxLayout *left=new QVBoxLayout(layout);
221
 
 
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);
228
 
 
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);
235
 
 
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);
240
 
 
241
 
    updateHorizHelpLine = new QPushButton(i18n("Update"), parent);
242
 
    connect (updateHorizHelpLine, SIGNAL(clicked ()), this, SLOT(updateHorizLine ()));
243
 
    right->addWidget(updateHorizHelpLine);
244
 
 
245
 
    delHorizHelpLine = new QPushButton(i18n("Delete"), parent);
246
 
    connect (delHorizHelpLine, SIGNAL(clicked ()), this, SLOT(deleteHorizLine ()));
247
 
    right->addWidget(delHorizHelpLine);
248
 
    right->addStretch();
249
 
}
250
 
 
251
 
void OptionDialog::createVertLineWidget(QWidget* parent)
252
 
{
253
 
    QBoxLayout *layout=new QHBoxLayout(parent, KDialogBase::marginHint(), KDialogBase::spacingHint());
254
 
    QBoxLayout *left=new QVBoxLayout(layout);
255
 
 
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);
262
 
 
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);
269
 
 
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);
274
 
 
275
 
    updateVertHelpLine = new QPushButton(i18n("Update"), parent);
276
 
    connect (updateVertHelpLine, SIGNAL(clicked ()), this, SLOT(updateVertLine ()));
277
 
    right->addWidget(updateVertHelpLine);
278
 
 
279
 
    delVertHelpLine = new QPushButton(i18n("Delete"), parent);
280
 
    connect (delVertHelpLine, SIGNAL(clicked ()), this, SLOT(deleteVertLine ()));
281
 
    right->addWidget(delVertHelpLine);
282
 
    right->addStretch();
283
 
}
284
 
 
285
 
void OptionDialog::initHelplinesLists()
286
 
{
287
 
  QValueList<float>::Iterator i;
288
 
  QString buf;
289
 
  MeasurementUnit unit = PStateManager::instance ()->defaultMeasurementUnit ();
290
 
 
291
 
  for (i = horizLines.begin (); i != horizLines.end (); ++i)
292
 
  {
293
 
    buf=QString::number(cvtPtToUnit (unit, *i), 'f', 3);
294
 
    buf+=" ";
295
 
    buf+=unitToString (unit);
296
 
    horizList->insertItem (buf);
297
 
  }
298
 
  if(!horizLines.isEmpty())
299
 
    horizValue->setValue(horizLines[0]);
300
 
  else
301
 
  {
302
 
      updateHorizHelpLine->setEnabled(false);
303
 
      delHorizHelpLine->setEnabled(false);
304
 
  }
305
 
 
306
 
  for (i = vertLines.begin (); i != vertLines.end (); ++i)
307
 
  {
308
 
    buf=QString::number(cvtPtToUnit (unit, *i), 'f', 3);
309
 
    buf+=" ";
310
 
    buf+=unitToString (unit);
311
 
    vertList->insertItem (buf);
312
 
  }
313
 
  if(!vertLines.isEmpty())
314
 
    vertValue->setValue(vertLines[0]);
315
 
  else
316
 
  {
317
 
      updateVertHelpLine->setEnabled(false);
318
 
      delVertHelpLine->setEnabled(false);
319
 
  }
320
 
}
321
 
 
322
 
void OptionDialog::addHorizLine()
323
 
{
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);
328
 
  buf+=" ";
329
 
  buf+=unitToString (unit);
330
 
  horizList->insertItem (buf);
331
 
  updateHorizHelpLine->setEnabled(true);
332
 
  delHorizHelpLine->setEnabled(true);
333
 
  modified = true;
334
 
}
335
 
 
336
 
void OptionDialog::updateHorizLine()
337
 
{
338
 
  if(horizLines.isEmpty())
339
 
    return;
340
 
  int idx = horizList->currentItem ();
341
 
  if (idx != -1)
342
 
  {
343
 
    float value = horizValue->getValue ();
344
 
    MeasurementUnit unit = PStateManager::instance ()->defaultMeasurementUnit ();
345
 
    QString buf=QString::number(cvtPtToUnit (unit, value), 'f', 3);
346
 
    buf+=" ";
347
 
    buf+=unitToString (unit);
348
 
    horizList->blockSignals(true);
349
 
    horizList->changeItem (buf, idx);
350
 
    horizList->blockSignals(false);
351
 
    horizLines[idx] = value;
352
 
  }
353
 
}
354
 
 
355
 
void OptionDialog::deleteHorizLine()
356
 
{
357
 
  if(horizLines.isEmpty())
358
 
    return;
359
 
  int idx = horizList->currentItem ();
360
 
  if (idx != -1)
361
 
  {
362
 
    horizLines.remove(horizLines.at(idx));
363
 
    horizList->removeItem(idx);
364
 
    modified = true;
365
 
    if(horizLines.isEmpty())
366
 
    {
367
 
        updateHorizHelpLine->setEnabled(false);
368
 
        delHorizHelpLine->setEnabled(false);
369
 
    }
370
 
  }
371
 
 
372
 
}
373
 
 
374
 
void OptionDialog::addVertLine()
375
 
{
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);
380
 
  buf+=" ";
381
 
  buf+=unitToString (unit);
382
 
  vertList->insertItem (buf);
383
 
  delVertHelpLine->setEnabled(true);
384
 
  updateVertHelpLine->setEnabled(true);
385
 
  modified = true;
386
 
}
387
 
 
388
 
void OptionDialog::updateVertLine()
389
 
{
390
 
  if(vertLines.isEmpty())
391
 
    return;
392
 
  int idx = vertList->currentItem ();
393
 
  if (idx != -1)
394
 
  {
395
 
    float value = vertValue->getValue ();
396
 
    MeasurementUnit unit = PStateManager::instance ()->defaultMeasurementUnit ();
397
 
    QString buf=QString::number(cvtPtToUnit (unit, value), 'f', 3);
398
 
    buf+=" ";
399
 
    buf+=unitToString (unit);
400
 
    vertList->blockSignals(true);
401
 
    vertList->changeItem (buf, idx);
402
 
    vertList->blockSignals(false);
403
 
    vertLines[idx] = value;
404
 
  }
405
 
}
406
 
 
407
 
void OptionDialog::deleteVertLine()
408
 
{
409
 
  if(vertLines.isEmpty())
410
 
    return;
411
 
  int idx = vertList->currentItem ();
412
 
  if(idx != -1)
413
 
  {
414
 
    vertLines.remove(vertLines.at(idx));
415
 
    vertList->removeItem (idx);
416
 
    modified = true;
417
 
    if(vertLines.isEmpty())
418
 
    {
419
 
          delVertHelpLine->setEnabled(false);
420
 
          updateVertHelpLine->setEnabled(false);
421
 
    }
422
 
  }
423
 
}
424
 
 
425
 
void OptionDialog::horizLineSelected(int idx)
426
 
{
427
 
  if(!horizLines.isEmpty())
428
 
    horizValue->setValue(*horizLines.at(idx));
429
 
}
430
 
 
431
 
void OptionDialog::vertLineSelected(int idx)
432
 
{
433
 
  if(!vertLines.isEmpty())
434
 
    vertValue->setValue (*vertLines.at(idx));
435
 
}
436
 
 
437
 
/**/
438
 
void OptionDialog::slotSetModified()
439
 
{
440
 
  modified = true;
441
 
}
442
 
 
443
 
void OptionDialog::slotApply()
444
 
{
445
 
  /*Document settings*/
446
 
 
447
 
  /*Background*/
448
 
  doc->activePage()->bgColor(bgbutton->color());
449
 
  /*Grid*/
450
 
  doc->setGridDistance(hspinbox->getValue(), vspinbox->getValue());
451
 
  doc->showGrid(sbutton->isOn());
452
 
  doc->snapToGrid(gbutton->isOn());
453
 
  doc->gridColor(cbutton->color());
454
 
  /*Helplines*/
455
 
  doc->setHorizHelplines(horizLines);
456
 
  doc->setVertHelplines(vertLines);
457
 
 
458
 
  if(modified)
459
 
  {
460
 
    doc->setModified();
461
 
    modified = false;
462
 
  }
463
 
 
464
 
  doc->emitChanged();
465
 
}
466
 
 
467
 
void OptionDialog::slotOk()
468
 
{
469
 
  slotApply();
470
 
  KDialogBase::slotOk();
471
 
}
472
 
 
473
 
int OptionDialog::setup (GDocument *adoc)
474
 
{
475
 
 
476
 
   OptionDialog dialog (adoc, 0L, "Options");
477
 
 
478
 
   int res=dialog.exec();
479
 
   if(res == QDialog::Accepted)
480
 
   {
481
 
      int selection = dialog.unit->currentItem ();
482
 
      PStateManager* psm = PStateManager::instance ();
483
 
      switch (selection)
484
 
      {
485
 
      case 0:
486
 
         psm->setDefaultMeasurementUnit (UnitPoint);
487
 
         break;
488
 
      case 1:
489
 
         psm->setDefaultMeasurementUnit (UnitMillimeter);
490
 
         break;
491
 
      case 2:
492
 
         psm->setDefaultMeasurementUnit (UnitInch);
493
 
                break;
494
 
      case 3:
495
 
         psm->setDefaultMeasurementUnit (UnitPica);
496
 
         break;
497
 
      case 4:
498
 
         psm->setDefaultMeasurementUnit (UnitCentimeter);
499
 
         break;
500
 
      case 5:
501
 
         psm->setDefaultMeasurementUnit (UnitDidot);
502
 
         break;
503
 
      case 6:
504
 
         psm->setDefaultMeasurementUnit (UnitCicero);
505
 
         break;
506
 
      default:
507
 
         break;
508
 
      }
509
 
      psm->setStepSizes (dialog.smallStep->getValue (),dialog.bigStep->getValue ());
510
 
      psm->setDuplicateOffsets (dialog.horiz->getValue (),dialog.vert->getValue ());
511
 
   }
512
 
   return res;
513
 
}
514
 
 
515
 
#include <OptionDialog.moc>