~ubuntu-branches/ubuntu/maverick/scidavis/maverick

« back to all changes in this revision

Viewing changes to scidavis/src/LineDialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Ruben Molina
  • Date: 2009-09-06 11:34:04 UTC
  • Revision ID: james.westby@ubuntu.com-20090906113404-4awaey82l3686w4q
Tags: upstream-0.2.3
ImportĀ upstreamĀ versionĀ 0.2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
    File                 : LineDialog.cpp
 
3
    Project              : SciDAVis
 
4
    --------------------------------------------------------------------
 
5
    Copyright            : (C) 2006 by Ion Vasilief
 
6
    Email (use @ for *)  : ion_vasilief*yahoo.fr
 
7
    Description          : Line options dialog
 
8
 
 
9
 ***************************************************************************/
 
10
 
 
11
/***************************************************************************
 
12
 *                                                                         *
 
13
 *  This program is free software; you can redistribute it and/or modify   *
 
14
 *  it under the terms of the GNU General Public License as published by   *
 
15
 *  the Free Software Foundation; either version 2 of the License, or      *
 
16
 *  (at your option) any later version.                                    *
 
17
 *                                                                         *
 
18
 *  This program is distributed in the hope that it will be useful,        *
 
19
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
 
20
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
 
21
 *  GNU General Public License for more details.                           *
 
22
 *                                                                         *
 
23
 *   You should have received a copy of the GNU General Public License     *
 
24
 *   along with this program; if not, write to the Free Software           *
 
25
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
 
26
 *   Boston, MA  02110-1301  USA                                           *
 
27
 *                                                                         *
 
28
 ***************************************************************************/
 
29
#include "LineDialog.h"
 
30
#include "ColorButton.h"
 
31
#include "ArrowMarker.h"
 
32
#include "Graph.h"
 
33
#include "Plot.h"
 
34
#include "ApplicationWindow.h"
 
35
 
 
36
#include <qwt_plot.h>
 
37
 
 
38
#include <QMessageBox>
 
39
#include <QLayout>
 
40
#include <QGroupBox>
 
41
#include <QSpinBox>
 
42
#include <QCheckBox>
 
43
#include <QPushButton>
 
44
#include <QLabel>
 
45
#include <QLineEdit>
 
46
#include <QComboBox>
 
47
#include <QColorDialog>
 
48
#include <QTabWidget>
 
49
 
 
50
LineDialog::LineDialog( ArrowMarker *line, QWidget* parent, Qt::WFlags fl )
 
51
    : QDialog( parent, fl )
 
52
{
 
53
    setWindowTitle( tr( "Line options" ) );
 
54
 
 
55
        lm = line;
 
56
 
 
57
        QGroupBox *gb1 = new QGroupBox();
 
58
    QGridLayout *gl1 = new QGridLayout();
 
59
 
 
60
    gl1->addWidget(new QLabel(tr("Color")), 0, 0);
 
61
        colorBox = new ColorButton();
 
62
        colorBox->setColor(lm->color());
 
63
        gl1->addWidget(colorBox, 0, 1);
 
64
 
 
65
        gl1->addWidget(new QLabel(tr("Line type")), 1, 0);
 
66
    styleBox = new QComboBox( FALSE);
 
67
        styleBox->insertItem("_____");
 
68
        styleBox->insertItem("- - -");
 
69
        styleBox->insertItem(".....");
 
70
        styleBox->insertItem("_._._");
 
71
        styleBox->insertItem("_.._..");
 
72
        gl1->addWidget(styleBox, 1, 1);
 
73
 
 
74
        setLineStyle(lm->style());
 
75
 
 
76
        gl1->addWidget(new QLabel(tr("Line width")), 2, 0);
 
77
    widthBox = new QComboBox( FALSE );
 
78
        widthBox->insertItem( tr( "1" ) );
 
79
    widthBox->insertItem( tr( "2" ) );
 
80
    widthBox->insertItem( tr( "3" ) );
 
81
    widthBox->insertItem( tr( "4" ) );
 
82
    widthBox->insertItem( tr( "5" ) );
 
83
        widthBox->setEditable (true);
 
84
        widthBox->setCurrentIndex(0);
 
85
        widthBox->setEditText(QString::number(lm->width()));
 
86
        gl1->addWidget(widthBox, 2, 1);
 
87
 
 
88
        startBox = new QCheckBox();
 
89
    startBox->setText( tr( "Arrow at &start" ) );
 
90
        startBox->setChecked(lm->hasStartArrow());
 
91
        gl1->addWidget(startBox, 3, 0);
 
92
 
 
93
        endBox = new QCheckBox();
 
94
    endBox->setText( tr( "Arrow at &end" ) );
 
95
        endBox->setChecked(lm->hasEndArrow());
 
96
        gl1->addWidget(endBox, 3, 1);
 
97
 
 
98
        gb1->setLayout(gl1);
 
99
 
 
100
        QHBoxLayout* hl1 = new QHBoxLayout();
 
101
    hl1->addWidget(gb1);
 
102
 
 
103
        options = new QWidget();
 
104
    options->setLayout(hl1);
 
105
 
 
106
        tw = new QTabWidget();
 
107
        tw->addTab(options, tr( "Opti&ons" ) );
 
108
 
 
109
    QGroupBox *gb2 = new QGroupBox();
 
110
    QGridLayout *gl2 = new QGridLayout();
 
111
 
 
112
    gl2->addWidget(new QLabel(tr("Length")), 0, 0);
 
113
        boxHeadLength = new QSpinBox();
 
114
        boxHeadLength->setValue(lm->headLength());
 
115
        gl2->addWidget(boxHeadLength, 0, 1);
 
116
 
 
117
        gl2->addWidget(new QLabel(tr( "Angle" )), 1, 0 );
 
118
        boxHeadAngle = new QSpinBox();
 
119
        boxHeadAngle->setRange(0, 85);
 
120
        boxHeadAngle->setSingleStep(5);
 
121
        boxHeadAngle->setValue(lm->headAngle());
 
122
        gl2->addWidget(boxHeadAngle, 1, 1);
 
123
 
 
124
        filledBox = new QCheckBox();
 
125
    filledBox->setText( tr( "&Filled" ) );
 
126
        filledBox->setChecked(lm->filledArrowHead());
 
127
        gl2->addWidget(filledBox, 2, 1);
 
128
 
 
129
        gb2->setLayout(gl2);
 
130
 
 
131
        QHBoxLayout* hl2 = new QHBoxLayout();
 
132
    hl2->addWidget(gb2);
 
133
 
 
134
    head = new QWidget();
 
135
    head->setLayout(hl2);
 
136
        tw->addTab(head, tr("Arrow &Head"));
 
137
 
 
138
        initGeometryTab();
 
139
 
 
140
        buttonDefault = new QPushButton( tr( "Set &Default" ) );
 
141
        btnApply = new QPushButton( tr( "&Apply" ) );
 
142
        btnOk = new QPushButton(tr( "&Ok" ) );
 
143
    btnOk->setDefault(true);
 
144
 
 
145
    QBoxLayout *bl1 = new QBoxLayout (QBoxLayout::LeftToRight);
 
146
    bl1->addStretch();
 
147
        bl1->addWidget(buttonDefault);
 
148
        bl1->addWidget(btnApply);
 
149
        bl1->addWidget(btnOk);
 
150
 
 
151
        QVBoxLayout* vl = new QVBoxLayout();
 
152
    vl->addWidget(tw);
 
153
        vl->addLayout(bl1);
 
154
        setLayout(vl);
 
155
 
 
156
        enableHeadTab();
 
157
 
 
158
        connect( colorBox, SIGNAL( clicked() ), this, SLOT(pickColor() ) );
 
159
        connect( btnOk, SIGNAL( clicked() ), this, SLOT(accept() ) );
 
160
        connect( btnApply, SIGNAL( clicked() ), this, SLOT(apply() ) );
 
161
        connect( tw, SIGNAL(currentChanged (QWidget *)), this, SLOT(enableButtonDefault(QWidget *)));
 
162
        connect( buttonDefault, SIGNAL(clicked()), this, SLOT(setDefaultValues()));
 
163
}
 
164
 
 
165
void LineDialog::initGeometryTab()
 
166
{
 
167
        unitBox = new QComboBox();
 
168
        unitBox->insertItem(tr("Scale Coordinates"));
 
169
        unitBox->insertItem(tr("Pixels"));
 
170
 
 
171
        QBoxLayout *bl1 = new QBoxLayout (QBoxLayout::LeftToRight);
 
172
        bl1->addWidget(new QLabel(tr( "Unit" )));
 
173
        bl1->addWidget(unitBox);
 
174
 
 
175
    QGroupBox *gb1 = new QGroupBox(tr("Start Point"));
 
176
        xStartBox = new QLineEdit();
 
177
        yStartBox = new QLineEdit();
 
178
 
 
179
    QGridLayout *gl1 = new QGridLayout();
 
180
    gl1->addWidget(new QLabel( tr("X")), 0, 0);
 
181
    gl1->addWidget(xStartBox, 0, 1);
 
182
    gl1->addWidget(new QLabel(tr("To")), 1, 0);
 
183
    gl1->addWidget(yStartBox, 1, 1);
 
184
    gb1->setLayout(gl1);
 
185
 
 
186
    QGroupBox *gb2 = new QGroupBox(tr("End Point"));
 
187
    xEndBox = new QLineEdit();
 
188
        yEndBox = new QLineEdit();
 
189
 
 
190
    QGridLayout *gl2 = new QGridLayout();
 
191
    gl2->addWidget(new QLabel( tr("X")), 0, 0);
 
192
    gl2->addWidget(xEndBox, 0, 1);
 
193
    gl2->addWidget(new QLabel(tr("To")), 1, 0);
 
194
    gl2->addWidget(yEndBox, 1, 1);
 
195
    gb2->setLayout(gl2);
 
196
 
 
197
    QBoxLayout *bl2 = new QBoxLayout (QBoxLayout::LeftToRight);
 
198
        bl2->addWidget(gb1);
 
199
        bl2->addWidget(gb2);
 
200
 
 
201
        QVBoxLayout* vl = new QVBoxLayout();
 
202
    vl->addLayout(bl1);
 
203
    vl->addLayout(bl2);
 
204
 
 
205
    geometry = new QWidget();
 
206
    geometry->setLayout(vl);
 
207
        tw->addTab(geometry, tr( "&Geometry" ) );
 
208
 
 
209
        connect( unitBox, SIGNAL( activated(int) ), this, SLOT(displayCoordinates(int) ) );
 
210
        displayCoordinates(0);
 
211
}
 
212
 
 
213
void LineDialog::displayCoordinates(int unit)
 
214
{
 
215
if (unit == ScaleCoordinates)
 
216
        {
 
217
        QwtDoublePoint sp = lm->startPointCoord();
 
218
        xStartBox->setText(QString::number(sp.x()));
 
219
        yStartBox->setText(QString::number(sp.y()));
 
220
 
 
221
        QwtDoublePoint ep = lm->endPointCoord();
 
222
        xEndBox->setText(QString::number(ep.x()));
 
223
        yEndBox->setText(QString::number(ep.y()));
 
224
        }
 
225
else
 
226
        {
 
227
        QPoint startPoint = lm->startPoint();
 
228
        QPoint endPoint = lm->endPoint();
 
229
 
 
230
        xStartBox->setText(QString::number(startPoint.x()));
 
231
        yStartBox->setText(QString::number(startPoint.y()));
 
232
 
 
233
        xEndBox->setText(QString::number(endPoint.x()));
 
234
        yEndBox->setText(QString::number(endPoint.y()));
 
235
        }
 
236
}
 
237
 
 
238
void LineDialog::setCoordinates(int unit)
 
239
{
 
240
if (unit == ScaleCoordinates)
 
241
        {
 
242
        lm->setStartPoint(xStartBox->text().replace(",", ".").toDouble(),
 
243
                                                        yStartBox->text().replace(",", ".").toDouble());
 
244
        lm->setEndPoint(xEndBox->text().replace(",", ".").toDouble(),
 
245
                                                yEndBox->text().replace(",", ".").toDouble());
 
246
        }
 
247
else
 
248
        {
 
249
        lm->setStartPoint(QPoint(xStartBox->text().toInt(), yStartBox->text().toInt()));
 
250
        lm->setEndPoint(QPoint(xEndBox->text().toInt(), yEndBox->text().toInt()));
 
251
        }
 
252
}
 
253
 
 
254
void LineDialog::apply()
 
255
{
 
256
if (tw->currentWidget()==(QWidget *)options)
 
257
        {
 
258
        lm->setStyle(Graph::getPenStyle(styleBox->currentItem()));
 
259
        lm->setColor(colorBox->color());
 
260
        lm->setWidth(widthBox->currentText().toInt());
 
261
        lm->drawEndArrow(endBox->isChecked());
 
262
        lm->drawStartArrow(startBox->isChecked());
 
263
        }
 
264
else if (tw->currentWidget()==(QWidget *)head)
 
265
        {
 
266
        if (lm->headLength() != boxHeadLength->value())
 
267
                lm->setHeadLength( boxHeadLength->value() );
 
268
 
 
269
        if (lm->headAngle() != boxHeadAngle->value())
 
270
                lm->setHeadAngle( boxHeadAngle->value() );
 
271
 
 
272
        if (lm->filledArrowHead() != filledBox->isChecked())
 
273
                lm->fillArrowHead( filledBox->isChecked() );
 
274
        }
 
275
else if (tw->currentWidget()==(QWidget *)geometry)
 
276
        setCoordinates(unitBox->currentItem());
 
277
 
 
278
QwtPlot *plot = lm->plot();
 
279
Graph *g = (Graph *)plot->parent();
 
280
plot->replot();
 
281
g->notifyChanges();
 
282
 
 
283
enableHeadTab();
 
284
}
 
285
 
 
286
void LineDialog::accept()
 
287
{
 
288
apply();
 
289
close();
 
290
}
 
291
 
 
292
void LineDialog::setLineStyle(Qt::PenStyle style)
 
293
{
 
294
if (style==Qt::SolidLine)
 
295
        styleBox->setCurrentIndex(0);
 
296
else if (style==Qt::DashLine)
 
297
        styleBox->setCurrentIndex(1);
 
298
else if (style==Qt::DotLine)
 
299
        styleBox->setCurrentIndex(2);
 
300
else if (style==Qt::DashDotLine)
 
301
        styleBox->setCurrentIndex(3);
 
302
else if (style==Qt::DashDotDotLine)
 
303
        styleBox->setCurrentIndex(4);
 
304
}
 
305
 
 
306
void LineDialog::enableHeadTab()
 
307
{
 
308
if (startBox->isChecked() || endBox->isChecked())
 
309
        tw->setTabEnabled (head, true);
 
310
else
 
311
        tw->setTabEnabled (head, false);
 
312
}
 
313
 
 
314
void LineDialog::pickColor()
 
315
{
 
316
QColor c = QColorDialog::getColor(colorBox->color(), this);
 
317
if ( !c.isValid() || c == colorBox->color() )
 
318
        return;
 
319
 
 
320
colorBox->setColor ( c ) ;
 
321
}
 
322
 
 
323
void LineDialog::setDefaultValues()
 
324
{
 
325
ApplicationWindow *app = (ApplicationWindow *)this->parent();
 
326
if (!app)
 
327
        return;
 
328
 
 
329
app->setArrowDefaultSettings(widthBox->currentText().toInt(), colorBox->color(),
 
330
                                                        Graph::getPenStyle(styleBox->currentItem()),
 
331
                                                        boxHeadLength->value(), boxHeadAngle->value(), filledBox->isChecked());
 
332
}
 
333
 
 
334
void LineDialog::enableButtonDefault(QWidget *w)
 
335
{
 
336
if (w == geometry)
 
337
        buttonDefault->setEnabled(false);
 
338
else
 
339
        buttonDefault->setEnabled(true);
 
340
}
 
341