~ubuntu-branches/ubuntu/maverick/scribus-ng/maverick-backports

1 by Oleksandr Moskalenko
Import upstream version 1.3.3.2.dfsg
1
/*
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.
6
*/
7
/***************************************************************************
8
                          pageitem.cpp  -  description
9
                             -------------------
10
    begin                : Sat Apr 7 2001
11
    copyright            : (C) 2001 by Franz Schmid
12
    email                : Franz.Schmid@altmuehlnet.de
13
 ***************************************************************************/
14
15
/***************************************************************************
16
 *                                                                         *
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.                                   *
21
 *                                                                         *
22
 ***************************************************************************/
23
24
#include "pageitem_polyline.h"
25
#include "pageitem_polyline.moc"
26
#include <qpainter.h>
27
#include <qpen.h>
28
#include <qfont.h>
29
#include <qregion.h>
30
#include <qpoint.h>
31
#include <qfileinfo.h>
32
#include <qdrawutil.h>
33
#include <qbitmap.h>
34
#include <qregexp.h>
35
#include <qmessagebox.h>
36
#include <cmath>
37
#include <cassert>
38
39
#include "mpalette.h"
40
#include "page.h"
41
#include "pageitem.h"
42
#include "prefsmanager.h"
43
#include "scpaths.h"
44
#include "scribus.h"
45
#include "scribusstructs.h"
46
#include "scribusdoc.h"
47
#include "commonstrings.h"
48
#include "undomanager.h"
49
#include "undostate.h"
50
#include "scconfig.h"
51
52
#include "util.h"
53
54
using namespace std;
55
56
PageItem_PolyLine::PageItem_PolyLine(ScribusDoc *pa, double x, double y, double w, double h, double w2, QString fill, QString outline)
57
	: PageItem(pa, PageItem::PolyLine, x, y, w, h, w2, fill, outline)
58
{
59
}
60
0.1.1 by Oleksandr Moskalenko
Import upstream version 1.3.4.dfsg+svn20071115
61
void PageItem_PolyLine::DrawObj_Item(ScPainter *p, QRect /*e*/, double /*sc*/)
1 by Oleksandr Moskalenko
Import upstream version 1.3.3.2.dfsg
62
{
63
	if (!m_Doc->RePos && PoLine.size()>=4)
64
	{
0.1.1 by Oleksandr Moskalenko
Import upstream version 1.3.4.dfsg+svn20071115
65
		if (!m_Doc->layerOutline(LayerNr))
66
		{
67
			if ((fillColor() != CommonStrings::None) || (GrType != 0))
68
			{
69
				FPointArray cli;
70
				FPoint Start;
71
				bool firstp = true;
72
				for (uint n = 0; n < PoLine.size()-3; n += 4)
73
				{
74
					if (firstp)
75
					{
76
						Start = PoLine.point(n);
77
						firstp = false;
78
					}
79
					if (PoLine.point(n).x() > 900000)
80
					{
81
						cli.addPoint(PoLine.point(n-2));
82
						cli.addPoint(PoLine.point(n-2));
83
						cli.addPoint(Start);
84
						cli.addPoint(Start);
85
						cli.setMarker();
86
						firstp = true;
87
						continue;
88
					}
89
					cli.addPoint(PoLine.point(n));
90
					cli.addPoint(PoLine.point(n+1));
91
					cli.addPoint(PoLine.point(n+2));
92
					cli.addPoint(PoLine.point(n+3));
93
				}
94
				if (cli.size() > 2)
95
				{
96
					FPoint l1 = cli.point(cli.size()-2);
97
					cli.addPoint(l1);
98
					cli.addPoint(l1);
99
					cli.addPoint(Start);
100
					cli.addPoint(Start);
101
				}
102
				p->setupPolygon(&cli);
103
				p->fillPath();
104
			}
105
			p->setupPolygon(&PoLine, false);
106
			if (NamedLStyle.isEmpty())
107
				p->strokePath();
108
			else
109
			{
110
				multiLine ml = m_Doc->MLineStyles[NamedLStyle];
111
				QColor tmp;
112
				for (int it = ml.size()-1; it > -1; it--)
113
				{
114
					if ((ml[it].Color != CommonStrings::None) && (ml[it].Width != 0))
115
					{
116
						SetFarbe(&tmp, ml[it].Color, ml[it].Shade);
117
						p->setPen(tmp, ml[it].Width, static_cast<PenStyle>(ml[it].Dash), static_cast<PenCapStyle>(ml[it].LineEnd), static_cast<PenJoinStyle>(ml[it].LineJoin));
118
						p->strokePath();
119
					}
1.1.2 by Oleksandr Moskalenko
Import upstream version 1.3.3.5.dfsg
120
				}
1 by Oleksandr Moskalenko
Import upstream version 1.3.3.2.dfsg
121
			}
122
		}
123
		if (m_startArrowIndex != 0)
124
		{
125
			FPoint Start = PoLine.point(0);
126
			for (uint xx = 1; xx < PoLine.size(); xx += 2)
127
			{
128
				FPoint Vector = PoLine.point(xx);
129
				if ((Start.x() != Vector.x()) || (Start.y() != Vector.y()))
130
				{
131
					double r = atan2(Start.y()-Vector.y(),Start.x()-Vector.x())*(180.0/M_PI);
132
					QWMatrix arrowTrans;
133
					FPointArray arrow = (*m_Doc->arrowStyles.at(m_startArrowIndex-1)).points.copy();
134
					arrowTrans.translate(Start.x(), Start.y());
135
					arrowTrans.rotate(r);
136
					arrowTrans.scale(m_lineWidth, m_lineWidth);
137
					arrow.map(arrowTrans);
138
					p->setupPolygon(&arrow);
0.1.1 by Oleksandr Moskalenko
Import upstream version 1.3.4.dfsg+svn20071115
139
					if (m_Doc->layerOutline(LayerNr))
140
						p->strokePath();
141
					else
142
					{
143
						p->setBrush(p->pen());
144
						p->setBrushOpacity(1.0 - lineTransparency());
145
						p->setLineWidth(0);
146
						p->setFillMode(ScPainter::Solid);
147
						p->fillPath();
148
					}
1 by Oleksandr Moskalenko
Import upstream version 1.3.3.2.dfsg
149
					break;
150
				}
151
			}
152
		}
153
		if (m_endArrowIndex != 0)
154
		{
155
			FPoint End = PoLine.point(PoLine.size()-2);
156
			for (uint xx = PoLine.size()-1; xx > 0; xx -= 2)
157
			{
158
				FPoint Vector = PoLine.point(xx);
159
				if ((End.x() != Vector.x()) || (End.y() != Vector.y()))
160
				{
161
					double r = atan2(End.y()-Vector.y(),End.x()-Vector.x())*(180.0/M_PI);
162
					QWMatrix arrowTrans;
163
					FPointArray arrow = (*m_Doc->arrowStyles.at(m_endArrowIndex-1)).points.copy();
164
					arrowTrans.translate(End.x(), End.y());
165
					arrowTrans.rotate(r);
166
					arrowTrans.scale(m_lineWidth, m_lineWidth);
167
					arrow.map(arrowTrans);
168
					p->setupPolygon(&arrow);
0.1.1 by Oleksandr Moskalenko
Import upstream version 1.3.4.dfsg+svn20071115
169
					if (m_Doc->layerOutline(LayerNr))
170
						p->strokePath();
171
					else
172
					{
173
						p->setBrush(p->pen());
174
						p->setBrushOpacity(1.0 - lineTransparency());
175
						p->setLineWidth(0);
176
						p->setFillMode(ScPainter::Solid);
177
						p->fillPath();
178
					}
1 by Oleksandr Moskalenko
Import upstream version 1.3.3.2.dfsg
179
					break;
180
				}
181
			}
182
		}
183
	}
184
}
185