~ubuntu-branches/ubuntu/warty/koffice/warty

« back to all changes in this revision

Viewing changes to kontour/HelplineDialog.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: HelplineDialog.cc,v 1.16 2001/06/01 16:15:33 rm Exp $
4
 
 
5
 
  This file is part of KIllustrator.
6
 
  Copyright (C) 1998 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 <HelplineDialog.h>
26
 
 
27
 
#include <qlistbox.h>
28
 
#include <qpushbutton.h>
29
 
#include <qlayout.h>
30
 
 
31
 
#include <klocale.h>
32
 
#include <kdebug.h>
33
 
 
34
 
#include <Canvas.h>
35
 
#include <UnitBox.h>
36
 
#include <units.h>
37
 
#include <PStateManager.h>
38
 
 
39
 
HelplineDialog::HelplineDialog (Canvas* c, QWidget* parent,
40
 
                                const char* name) : KDialogBase(KDialogBase::Tabbed,
41
 
                                                                i18n("Setup Helplines"),
42
 
                                                                KDialogBase::Ok | KDialogBase::Cancel,
43
 
                                                                KDialogBase::Ok, parent, name, true) {
44
 
  canvas = c;
45
 
  horizLines = canvas->getHorizHelplines ();
46
 
  vertLines = canvas->getVertHelplines ();
47
 
 
48
 
  createHorizLineWidget(addPage(i18n("Horizontal")));
49
 
  createVertLineWidget(addPage(i18n("Vertical")));
50
 
  initLists ();
51
 
}
52
 
 
53
 
void HelplineDialog::createHorizLineWidget (QWidget* parent) {
54
 
 
55
 
    QBoxLayout *layout=new QHBoxLayout(parent, KDialogBase::marginHint(), KDialogBase::spacingHint());
56
 
    QBoxLayout *left=new QVBoxLayout(layout);
57
 
 
58
 
    horizValue = new UnitBox (parent);
59
 
    horizValue->setRange (-1000.0, 1000.0);
60
 
    horizValue->setStep (0.1);
61
 
    horizValue->setEditable (true);
62
 
    horizValue->setValue(0.0);
63
 
    left->addWidget(horizValue);
64
 
 
65
 
    horizList = new QListBox (parent);
66
 
    horizList->setMultiSelection (false);
67
 
    connect (horizList, SIGNAL(highlighted(int)),
68
 
             this, SLOT(horizLineSelected(int)));
69
 
    left->addWidget(horizList);
70
 
    layout->addSpacing(KDialogBase::spacingHint()*2);
71
 
 
72
 
    QBoxLayout *right=new QVBoxLayout(layout);
73
 
    QPushButton *button = new QPushButton (i18n("Add"), parent);
74
 
    connect (button, SIGNAL(clicked ()), this, SLOT(addHorizLine ()));
75
 
    right->addWidget(button);
76
 
 
77
 
    button = new QPushButton(i18n("Update"), parent);
78
 
    connect (button, SIGNAL(clicked ()), this, SLOT(updateHorizLine ()));
79
 
    right->addWidget(button);
80
 
 
81
 
    button = new QPushButton(i18n("Delete"), parent);
82
 
    connect (button, SIGNAL(clicked ()), this, SLOT(deleteHorizLine ()));
83
 
    right->addWidget(button);
84
 
    right->addStretch();
85
 
}
86
 
 
87
 
void HelplineDialog::createVertLineWidget (QWidget* parent) {
88
 
 
89
 
    QBoxLayout *layout=new QHBoxLayout(parent, KDialogBase::marginHint(), KDialogBase::spacingHint());
90
 
    QBoxLayout *left=new QVBoxLayout(layout);
91
 
 
92
 
    vertValue = new UnitBox (parent);
93
 
    vertValue->setRange (-1000.0, 1000.0);
94
 
    vertValue->setStep (0.1);
95
 
    vertValue->setEditable (true);
96
 
    vertValue->setValue(0.0);
97
 
    left->addWidget(vertValue);
98
 
 
99
 
    vertList = new QListBox(parent);
100
 
    vertList->setMultiSelection (false);
101
 
    connect (vertList, SIGNAL(highlighted (int)),
102
 
             this, SLOT(vertLineSelected(int)));
103
 
    left->addWidget(vertList);
104
 
    layout->addSpacing(KDialogBase::spacingHint()*2);
105
 
 
106
 
    QBoxLayout *right=new QVBoxLayout(layout);
107
 
    QPushButton *button = new QPushButton(i18n("Add"), parent);
108
 
    connect (button, SIGNAL(clicked ()), this, SLOT(addVertLine ()));
109
 
    right->addWidget(button);
110
 
 
111
 
    button = new QPushButton(i18n("Update"), parent);
112
 
    connect (button, SIGNAL(clicked ()), this, SLOT(updateVertLine ()));
113
 
    right->addWidget(button);
114
 
 
115
 
    button = new QPushButton(i18n("Delete"), parent);
116
 
    connect (button, SIGNAL(clicked ()), this, SLOT(deleteVertLine ()));
117
 
    right->addWidget(button);
118
 
    right->addStretch();
119
 
}
120
 
 
121
 
void HelplineDialog::applyPressed ()
122
 
{
123
 
    canvas->setHorizHelplines (horizLines);
124
 
    canvas->setVertHelplines (vertLines);
125
 
//    canvas->saveGridProperties();
126
 
}
127
 
 
128
 
void HelplineDialog::initLists () {
129
 
    QValueList<float>::Iterator i;
130
 
    QString buf;
131
 
    MeasurementUnit unit =
132
 
        PStateManager::instance ()->defaultMeasurementUnit ();
133
 
 
134
 
    for (i = horizLines.begin (); i != horizLines.end (); ++i) {
135
 
        buf=QString::number(cvtPtToUnit (unit, *i), 'f', 3);
136
 
        buf+=" ";
137
 
        buf+=unitToString (unit);
138
 
        horizList->insertItem (buf);
139
 
    }
140
 
    if(!horizLines.isEmpty())
141
 
        horizValue->setValue(horizLines[0]);
142
 
 
143
 
    for (i = vertLines.begin (); i != vertLines.end (); ++i) {
144
 
        buf=QString::number(cvtPtToUnit (unit, *i), 'f', 3);
145
 
        buf+=" ";
146
 
        buf+=unitToString (unit);
147
 
        vertList->insertItem (buf);
148
 
    }
149
 
    if(!vertLines.isEmpty())
150
 
        vertValue->setValue(vertLines[0]);
151
 
}
152
 
 
153
 
void HelplineDialog::addHorizLine () {
154
 
  float value = horizValue->getValue ();
155
 
  horizLines.append(value);
156
 
  MeasurementUnit unit = PStateManager::instance ()->defaultMeasurementUnit ();
157
 
  QString buf=QString::number(cvtPtToUnit (unit, value), 'f', 3);
158
 
  buf+=" ";
159
 
  buf+=unitToString (unit);
160
 
  horizList->insertItem (buf);
161
 
}
162
 
 
163
 
void HelplineDialog::updateHorizLine () {
164
 
    if(horizLines.isEmpty())
165
 
        return;
166
 
    int idx = horizList->currentItem ();
167
 
    if (idx != -1) {
168
 
        float value = horizValue->getValue ();
169
 
        MeasurementUnit unit =
170
 
            PStateManager::instance ()->defaultMeasurementUnit ();
171
 
        QString buf=QString::number(cvtPtToUnit (unit, value), 'f', 3);
172
 
        buf+=" ";
173
 
        buf+=unitToString (unit);
174
 
        horizList->blockSignals(true);
175
 
        horizList->changeItem (buf, idx);
176
 
        horizList->blockSignals(false);
177
 
        horizLines[idx] = value;
178
 
    }
179
 
}
180
 
 
181
 
void HelplineDialog::deleteHorizLine () {
182
 
    if(horizLines.isEmpty())
183
 
        return;
184
 
    int idx = horizList->currentItem ();
185
 
    if (idx != -1) {
186
 
        horizLines.remove(horizLines.at(idx));
187
 
        horizList->removeItem(idx);
188
 
    }
189
 
}
190
 
 
191
 
void HelplineDialog::addVertLine () {
192
 
    float value = vertValue->getValue ();
193
 
    vertLines.append(value);
194
 
    MeasurementUnit unit =
195
 
        PStateManager::instance ()->defaultMeasurementUnit ();
196
 
    QString buf=QString::number(cvtPtToUnit (unit, value), 'f', 3);
197
 
    buf+=" ";
198
 
    buf+=unitToString (unit);
199
 
    vertList->insertItem (buf);
200
 
}
201
 
 
202
 
void HelplineDialog::updateVertLine () {
203
 
    if(vertLines.isEmpty())
204
 
        return;
205
 
    int idx = vertList->currentItem ();
206
 
    if (idx != -1) {
207
 
        float value = vertValue->getValue ();
208
 
        MeasurementUnit unit =
209
 
            PStateManager::instance ()->defaultMeasurementUnit ();
210
 
        QString buf=QString::number(cvtPtToUnit (unit, value), 'f', 3);
211
 
        buf+=" ";
212
 
        buf+=unitToString (unit);
213
 
        vertList->blockSignals(true);
214
 
        vertList->changeItem (buf, idx);
215
 
        vertList->blockSignals(false);
216
 
        vertLines[idx] = value;
217
 
    }
218
 
}
219
 
 
220
 
void HelplineDialog::deleteVertLine () {
221
 
    if(vertLines.isEmpty())
222
 
        return;
223
 
    int idx = vertList->currentItem ();
224
 
    if (idx != -1) {
225
 
        vertLines.remove(vertLines.at(idx));
226
 
        vertList->removeItem (idx);
227
 
    }
228
 
}
229
 
 
230
 
void HelplineDialog::horizLineSelected (int idx) {
231
 
    if(!horizLines.isEmpty())
232
 
        horizValue->setValue(*horizLines.at(idx));
233
 
}
234
 
 
235
 
void HelplineDialog::vertLineSelected (int idx) {
236
 
    if(!vertLines.isEmpty())
237
 
        vertValue->setValue (*vertLines.at(idx));
238
 
}
239
 
 
240
 
void HelplineDialog::setup (Canvas *c)
241
 
{
242
 
  HelplineDialog *dialog = new HelplineDialog (c, 0L);
243
 
  if(dialog->exec()==Accepted)
244
 
      dialog->applyPressed();
245
 
  delete dialog;
246
 
}
247
 
 
248
 
#include <HelplineDialog.moc>