1
/***************************************************************************
4
--------------------------------------------------------------------
5
Copyright : (C) 2006 by Ion Vasilief
6
Email (use @ for *) : ion_vasilief*yahoo.fr
7
Description : Line options dialog
9
***************************************************************************/
11
/***************************************************************************
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. *
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. *
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 *
28
***************************************************************************/
29
#include "LineDialog.h"
30
#include "ColorButton.h"
31
#include "ArrowMarker.h"
34
#include "ApplicationWindow.h"
38
#include <QMessageBox>
43
#include <QPushButton>
47
#include <QColorDialog>
50
LineDialog::LineDialog( ArrowMarker *line, QWidget* parent, Qt::WFlags fl )
51
: QDialog( parent, fl )
53
setWindowTitle( tr( "Line options" ) );
57
QGroupBox *gb1 = new QGroupBox();
58
QGridLayout *gl1 = new QGridLayout();
60
gl1->addWidget(new QLabel(tr("Color")), 0, 0);
61
colorBox = new ColorButton();
62
colorBox->setColor(lm->color());
63
gl1->addWidget(colorBox, 0, 1);
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);
74
setLineStyle(lm->style());
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);
88
startBox = new QCheckBox();
89
startBox->setText( tr( "Arrow at &start" ) );
90
startBox->setChecked(lm->hasStartArrow());
91
gl1->addWidget(startBox, 3, 0);
93
endBox = new QCheckBox();
94
endBox->setText( tr( "Arrow at &end" ) );
95
endBox->setChecked(lm->hasEndArrow());
96
gl1->addWidget(endBox, 3, 1);
100
QHBoxLayout* hl1 = new QHBoxLayout();
103
options = new QWidget();
104
options->setLayout(hl1);
106
tw = new QTabWidget();
107
tw->addTab(options, tr( "Opti&ons" ) );
109
QGroupBox *gb2 = new QGroupBox();
110
QGridLayout *gl2 = new QGridLayout();
112
gl2->addWidget(new QLabel(tr("Length")), 0, 0);
113
boxHeadLength = new QSpinBox();
114
boxHeadLength->setValue(lm->headLength());
115
gl2->addWidget(boxHeadLength, 0, 1);
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);
124
filledBox = new QCheckBox();
125
filledBox->setText( tr( "&Filled" ) );
126
filledBox->setChecked(lm->filledArrowHead());
127
gl2->addWidget(filledBox, 2, 1);
131
QHBoxLayout* hl2 = new QHBoxLayout();
134
head = new QWidget();
135
head->setLayout(hl2);
136
tw->addTab(head, tr("Arrow &Head"));
140
buttonDefault = new QPushButton( tr( "Set &Default" ) );
141
btnApply = new QPushButton( tr( "&Apply" ) );
142
btnOk = new QPushButton(tr( "&Ok" ) );
143
btnOk->setDefault(true);
145
QBoxLayout *bl1 = new QBoxLayout (QBoxLayout::LeftToRight);
147
bl1->addWidget(buttonDefault);
148
bl1->addWidget(btnApply);
149
bl1->addWidget(btnOk);
151
QVBoxLayout* vl = new QVBoxLayout();
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()));
165
void LineDialog::initGeometryTab()
167
unitBox = new QComboBox();
168
unitBox->insertItem(tr("Scale Coordinates"));
169
unitBox->insertItem(tr("Pixels"));
171
QBoxLayout *bl1 = new QBoxLayout (QBoxLayout::LeftToRight);
172
bl1->addWidget(new QLabel(tr( "Unit" )));
173
bl1->addWidget(unitBox);
175
QGroupBox *gb1 = new QGroupBox(tr("Start Point"));
176
xStartBox = new QLineEdit();
177
yStartBox = new QLineEdit();
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);
186
QGroupBox *gb2 = new QGroupBox(tr("End Point"));
187
xEndBox = new QLineEdit();
188
yEndBox = new QLineEdit();
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);
197
QBoxLayout *bl2 = new QBoxLayout (QBoxLayout::LeftToRight);
201
QVBoxLayout* vl = new QVBoxLayout();
205
geometry = new QWidget();
206
geometry->setLayout(vl);
207
tw->addTab(geometry, tr( "&Geometry" ) );
209
connect( unitBox, SIGNAL( activated(int) ), this, SLOT(displayCoordinates(int) ) );
210
displayCoordinates(0);
213
void LineDialog::displayCoordinates(int unit)
215
if (unit == ScaleCoordinates)
217
QwtDoublePoint sp = lm->startPointCoord();
218
xStartBox->setText(QString::number(sp.x()));
219
yStartBox->setText(QString::number(sp.y()));
221
QwtDoublePoint ep = lm->endPointCoord();
222
xEndBox->setText(QString::number(ep.x()));
223
yEndBox->setText(QString::number(ep.y()));
227
QPoint startPoint = lm->startPoint();
228
QPoint endPoint = lm->endPoint();
230
xStartBox->setText(QString::number(startPoint.x()));
231
yStartBox->setText(QString::number(startPoint.y()));
233
xEndBox->setText(QString::number(endPoint.x()));
234
yEndBox->setText(QString::number(endPoint.y()));
238
void LineDialog::setCoordinates(int unit)
240
if (unit == ScaleCoordinates)
242
lm->setStartPoint(xStartBox->text().replace(",", ".").toDouble(),
243
yStartBox->text().replace(",", ".").toDouble());
244
lm->setEndPoint(xEndBox->text().replace(",", ".").toDouble(),
245
yEndBox->text().replace(",", ".").toDouble());
249
lm->setStartPoint(QPoint(xStartBox->text().toInt(), yStartBox->text().toInt()));
250
lm->setEndPoint(QPoint(xEndBox->text().toInt(), yEndBox->text().toInt()));
254
void LineDialog::apply()
256
if (tw->currentWidget()==(QWidget *)options)
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());
264
else if (tw->currentWidget()==(QWidget *)head)
266
if (lm->headLength() != boxHeadLength->value())
267
lm->setHeadLength( boxHeadLength->value() );
269
if (lm->headAngle() != boxHeadAngle->value())
270
lm->setHeadAngle( boxHeadAngle->value() );
272
if (lm->filledArrowHead() != filledBox->isChecked())
273
lm->fillArrowHead( filledBox->isChecked() );
275
else if (tw->currentWidget()==(QWidget *)geometry)
276
setCoordinates(unitBox->currentItem());
278
QwtPlot *plot = lm->plot();
279
Graph *g = (Graph *)plot->parent();
286
void LineDialog::accept()
292
void LineDialog::setLineStyle(Qt::PenStyle style)
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);
306
void LineDialog::enableHeadTab()
308
if (startBox->isChecked() || endBox->isChecked())
309
tw->setTabEnabled (head, true);
311
tw->setTabEnabled (head, false);
314
void LineDialog::pickColor()
316
QColor c = QColorDialog::getColor(colorBox->color(), this);
317
if ( !c.isValid() || c == colorBox->color() )
320
colorBox->setColor ( c ) ;
323
void LineDialog::setDefaultValues()
325
ApplicationWindow *app = (ApplicationWindow *)this->parent();
329
app->setArrowDefaultSettings(widthBox->currentText().toInt(), colorBox->color(),
330
Graph::getPenStyle(styleBox->currentItem()),
331
boxHeadLength->value(), boxHeadAngle->value(), filledBox->isChecked());
334
void LineDialog::enableButtonDefault(QWidget *w)
337
buttonDefault->setEnabled(false);
339
buttonDefault->setEnabled(true);