2
For general Scribus (>=1.3.2) copyright and licensing information please refer
3
to the COPYING file provided with the program. Following this notice may exist
4
a copyright and/or license notice that predates the release of Scribus 1.3.2
5
for which a new license (GPL+exception) is in place.
7
/***************************************************************************
8
gradienteditor - description
10
begin : Mit Mai 26 2004
11
copyright : (C) 2004 by Franz Schmid
12
email : Franz.Schmid@altmuehlnet.de
13
***************************************************************************/
15
/***************************************************************************
17
* This program is free software; you can redistribute it and/or modify *
18
* it under the terms of the GNU General Public License as published by *
19
* the Free Software Foundation; either version 2 of the License, or *
20
* (at your option) any later version. *
22
***************************************************************************/
24
#include "dasheditor.h"
26
#include <QApplication>
29
#include <QMouseEvent>
30
#include <QPaintEvent>
36
#include "scpainter.h"
38
#include "util_icon.h"
40
DashPreview::DashPreview(QWidget *pa) : QFrame(pa)
42
setFrameShape( QFrame::Panel );
43
setFrameShadow( QFrame::Sunken );
45
setMinimumSize(QSize(200, 35));
46
setMaximumSize(QSize(3000, 35));
47
setMouseTracking(true);
54
DashValues.append(4.0);
55
DashValues.append(2.0);
58
void DashPreview::paintEvent(QPaintEvent *e)
62
int pWidth = width()-20;
63
QImage pixm(pWidth, 10, QImage::Format_ARGB32);
64
ScPainter *p = new ScPainter(&pixm, pWidth, 10);
65
p->clear(QColor(128, 128, 128));
69
p->setBrush(Qt::black);
70
for (int a = 0; a < DashValues.count(); a++)
73
p->setBrush(Qt::black);
75
p->setBrush(Qt::white);
76
double w = DashValues[a] * 10;
77
p->drawRect(startX, 0, w, 10);
85
p->drawRect(0, 0, pWidth, 10);
90
pw.drawImage(10, 5, pixm);
91
for (int a = 0; a < StopM.count(); ++a)
93
double center = StopM[a]+10;
94
pw.setPen(QPen(Qt::black, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
97
emit currStep(DashValues[ActStop]);
101
pw.setBrush(Qt::blue);
103
cr.setPoints(3, qRound(center), 16, qRound(center-4), 29, qRound(center+4), 29);
107
QFrame::paintEvent(e);
111
void DashPreview::mousePressEvent(QMouseEvent *m)
118
for (int yg = 0; yg < StopM.count(); ++yg)
120
fpo = QRect(static_cast<int>(StopM[yg]) + 6, 16, 8, 13);
121
if (fpo.contains(m->pos()))
124
emit currStep(DashValues[ActStop]);
131
void DashPreview::mouseReleaseEvent(QMouseEvent *m)
134
if ((Mpressed) && (StopM.count() > 2) && (outside || m->y() > 30))
136
StopM.removeAt(ActStop);
139
for (int yg = 0; yg < StopM.count(); ++yg)
141
double w = StopM[yg] / 10.0 - startX;
142
DashValues.append(w);
149
emit currStep(DashValues[ActStop]);
153
if ((m->y() < height()) && (m->y() > 16) && (m->x() > 0) && (m->x() < width()))
157
if (m_moveTimer.elapsed() < 250)
162
StopM[ActStop] = m->x()-10;
166
if (DashValues.count() < 10)
167
StopM.append(m->x()-10);
168
qSort(StopM.begin(), StopM.end());
170
for (int yg = 0; yg < StopM.count(); ++yg)
172
QRect fpo = QRect(static_cast<int>(StopM[yg]) + 6, 16, 8, 13);
173
if (fpo.contains(m->pos()))
182
for (int yg = 0; yg < StopM.count(); ++yg)
184
double w = StopM[yg] / 10.0 - startX;
185
DashValues.append(w);
190
emit currStep(DashValues[ActStop]);
196
void DashPreview::mouseMoveEvent(QMouseEvent *m)
200
qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
201
if ((!Mpressed) && (m->y() < height()) && (m->y() > 16) && (m->x() > 9) && (m->x() < width()-9) && (DashValues.count() < 10))
203
qApp->changeOverrideCursor(QCursor(loadIcon("AddPoint.png"), 1, 1));
204
for (int yg = 0; yg < StopM.count(); ++yg)
206
fpo = QRect(static_cast<int>(StopM[yg])+6, 16, 8, 13);
207
if (fpo.contains(m->pos()))
209
qApp->changeOverrideCursor(QCursor(Qt::SizeHorCursor));
214
if ((Mpressed) && (m->y() < height()) && (m->y() > 16) && (m->x() > 9) && (m->x() < width()-9) && (ActStop != -1))
216
qApp->changeOverrideCursor(QCursor(Qt::SizeHorCursor));
219
if (static_cast<int>(StopM[ActStop-1]+10)+2 >= m->x())
222
if (ActStop < static_cast<int>(StopM.count()-2))
224
if (static_cast<int>(StopM[ActStop+1]+10)-2 < m->x())
227
StopM[ActStop] = m->x()-10;
230
for (int yg = 0; yg < StopM.count(); ++yg)
232
double w = StopM[yg] / 10.0 - startX;
233
DashValues.append(w);
239
for (int yg = 0; yg < ActStop; ++yg)
241
startX += StopM[yg] / 10.0 - startX;
243
emit currStep(StopM[ActStop] / 10.0 - startX);
245
if ((Mpressed) && (outside || m->y() > 30) && (ActStop >= 0) && (StopM.count() > 2))
246
qApp->changeOverrideCursor(QCursor(loadIcon("DelPoint.png"), 1, 1));
249
void DashPreview::leaveEvent(QEvent*)
251
if ((Mpressed) && (ActStop >= 0) && (StopM.count() > 2))
252
qApp->changeOverrideCursor(QCursor(loadIcon("DelPoint.png"), 1, 1));
254
qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
258
void DashPreview::enterEvent(QEvent*)
263
void DashPreview::setActStep(double t)
267
DashValues[ActStop] = t;
273
void DashPreview::setDashValues(QVector<double> vals)
279
if (StopM.count() != 0)
280
emit currStep(StopM[0] / 10.0);
283
DashEditor::DashEditor(QWidget *pa) : QFrame(pa)
285
setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum));
286
setFrameShape( QFrame::Panel );
288
QGridLayout *gridLayout = new QGridLayout(this);
289
gridLayout->setSpacing(2);
290
gridLayout->setMargin(2);
292
Preview = new DashPreview(this);
293
gridLayout->addWidget(Preview, 0, 0, 1, 2);
295
Position = new QDoubleSpinBox( this );
296
Position->setDecimals(1);
297
Position->setMinimum(0);
298
Position->setMaximum(100);
299
Position->setSingleStep(0.1);
300
Position->setValue(0);
301
Desc = new QLabel( this );
303
Offset = new QDoubleSpinBox( this );
304
Offset->setDecimals(1);
305
Offset->setMinimum(0);
306
Offset->setMaximum(100);
307
Offset->setSingleStep(0.1);
309
Desc2 = new QLabel( this );
312
gridLayout->addWidget(Desc, 1, 0, 1, 1);
313
gridLayout->addWidget(Position, 1, 1, 1, 1);
314
gridLayout->addWidget(Desc2, 2, 0, 1, 1);
315
gridLayout->addWidget(Offset, 2, 1, 1, 1);
317
connect(Position, SIGNAL(valueChanged(double)), Preview, SLOT(setActStep(double)));
318
connect(Offset, SIGNAL(valueChanged(double)), this, SIGNAL(dashChanged()));
319
connect(Preview, SIGNAL(currStep(double)), this, SLOT(setPos(double)));
320
connect(Preview, SIGNAL(dashChanged()), this, SIGNAL(dashChanged()));
323
void DashEditor::setPos(double p)
325
disconnect(Position, SIGNAL(valueChanged(double)), Preview, SLOT(setActStep(double)));
326
Position->setValue(p);
327
connect(Position, SIGNAL(valueChanged(double)), Preview, SLOT(setActStep(double)));
330
void DashEditor::setDashValues(QVector<double> vals, double linewidth, double offset)
333
for (int a = 0; a < vals.count(); a++)
335
tmp.append(vals[a] / linewidth);
337
Preview->setDashValues(tmp);
338
disconnect(Offset, SIGNAL(valueChanged(double)), this, SIGNAL(dashChanged()));
339
Offset->setValue(offset / linewidth);
340
connect(Offset, SIGNAL(valueChanged(double)), this, SIGNAL(dashChanged()));
343
QVector<double> DashEditor::getDashValues(double linewidth)
346
for (int a = 0; a < Preview->DashValues.count(); a++)
348
tmp.append(Preview->DashValues[a] * linewidth);
353
void DashEditor::changeEvent(QEvent *e)
355
if (e->type() == QEvent::LanguageChange)
358
QWidget::changeEvent(e);
361
void DashEditor::languageChange()
363
Desc->setText( tr( "Value:" ) );
364
Desc2->setText( tr( "Offset:" ) );