Back to index

scribus-ng  1.3.4.dfsg+svn20071115
pageitem_polyline.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 /***************************************************************************
00008                           pageitem.cpp  -  description
00009                              -------------------
00010     begin                : Sat Apr 7 2001
00011     copyright            : (C) 2001 by Franz Schmid
00012     email                : Franz.Schmid@altmuehlnet.de
00013  ***************************************************************************/
00014 
00015 /***************************************************************************
00016  *                                                                         *
00017  *   This program is free software; you can redistribute it and/or modify  *
00018  *   it under the terms of the GNU General Public License as published by  *
00019  *   the Free Software Foundation; either version 2 of the License, or     *
00020  *   (at your option) any later version.                                   *
00021  *                                                                         *
00022  ***************************************************************************/
00023 
00024 #include "pageitem_polyline.h"
00025 #include "pageitem_polyline.moc"
00026 #include <qpainter.h>
00027 #include <qpen.h>
00028 #include <qfont.h>
00029 #include <qregion.h>
00030 #include <qpoint.h>
00031 #include <qfileinfo.h>
00032 #include <qdrawutil.h>
00033 #include <qbitmap.h>
00034 #include <qregexp.h>
00035 #include <qmessagebox.h>
00036 #include <cmath>
00037 #include <cassert>
00038 
00039 #include "mpalette.h"
00040 #include "page.h"
00041 #include "pageitem.h"
00042 #include "prefsmanager.h"
00043 #include "scpaths.h"
00044 #include "scribus.h"
00045 #include "scribusstructs.h"
00046 #include "scribusdoc.h"
00047 #include "commonstrings.h"
00048 #include "undomanager.h"
00049 #include "undostate.h"
00050 #include "scconfig.h"
00051 
00052 #include "util.h"
00053 
00054 using namespace std;
00055 
00056 PageItem_PolyLine::PageItem_PolyLine(ScribusDoc *pa, double x, double y, double w, double h, double w2, QString fill, QString outline)
00057        : PageItem(pa, PageItem::PolyLine, x, y, w, h, w2, fill, outline)
00058 {
00059 }
00060 
00061 void PageItem_PolyLine::DrawObj_Item(ScPainter *p, QRect /*e*/, double /*sc*/)
00062 {
00063        if (!m_Doc->RePos && PoLine.size()>=4)
00064        {
00065               if (!m_Doc->layerOutline(LayerNr))
00066               {
00067                      if ((fillColor() != CommonStrings::None) || (GrType != 0))
00068                      {
00069                             FPointArray cli;
00070                             FPoint Start;
00071                             bool firstp = true;
00072                             for (uint n = 0; n < PoLine.size()-3; n += 4)
00073                             {
00074                                    if (firstp)
00075                                    {
00076                                           Start = PoLine.point(n);
00077                                           firstp = false;
00078                                    }
00079                                    if (PoLine.point(n).x() > 900000)
00080                                    {
00081                                           cli.addPoint(PoLine.point(n-2));
00082                                           cli.addPoint(PoLine.point(n-2));
00083                                           cli.addPoint(Start);
00084                                           cli.addPoint(Start);
00085                                           cli.setMarker();
00086                                           firstp = true;
00087                                           continue;
00088                                    }
00089                                    cli.addPoint(PoLine.point(n));
00090                                    cli.addPoint(PoLine.point(n+1));
00091                                    cli.addPoint(PoLine.point(n+2));
00092                                    cli.addPoint(PoLine.point(n+3));
00093                             }
00094                             if (cli.size() > 2)
00095                             {
00096                                    FPoint l1 = cli.point(cli.size()-2);
00097                                    cli.addPoint(l1);
00098                                    cli.addPoint(l1);
00099                                    cli.addPoint(Start);
00100                                    cli.addPoint(Start);
00101                             }
00102                             p->setupPolygon(&cli);
00103                             p->fillPath();
00104                      }
00105                      p->setupPolygon(&PoLine, false);
00106                      if (NamedLStyle.isEmpty())
00107                             p->strokePath();
00108                      else
00109                      {
00110                             multiLine ml = m_Doc->MLineStyles[NamedLStyle];
00111                             QColor tmp;
00112                             for (int it = ml.size()-1; it > -1; it--)
00113                             {
00114                                    if ((ml[it].Color != CommonStrings::None) && (ml[it].Width != 0))
00115                                    {
00116                                           SetFarbe(&tmp, ml[it].Color, ml[it].Shade);
00117                                           p->setPen(tmp, ml[it].Width, static_cast<PenStyle>(ml[it].Dash), static_cast<PenCapStyle>(ml[it].LineEnd), static_cast<PenJoinStyle>(ml[it].LineJoin));
00118                                           p->strokePath();
00119                                    }
00120                             }
00121                      }
00122               }
00123               if (m_startArrowIndex != 0)
00124               {
00125                      FPoint Start = PoLine.point(0);
00126                      for (uint xx = 1; xx < PoLine.size(); xx += 2)
00127                      {
00128                             FPoint Vector = PoLine.point(xx);
00129                             if ((Start.x() != Vector.x()) || (Start.y() != Vector.y()))
00130                             {
00131                                    double r = atan2(Start.y()-Vector.y(),Start.x()-Vector.x())*(180.0/M_PI);
00132                                    QWMatrix arrowTrans;
00133                                    FPointArray arrow = (*m_Doc->arrowStyles.at(m_startArrowIndex-1)).points.copy();
00134                                    arrowTrans.translate(Start.x(), Start.y());
00135                                    arrowTrans.rotate(r);
00136                                    arrowTrans.scale(m_lineWidth, m_lineWidth);
00137                                    arrow.map(arrowTrans);
00138                                    p->setupPolygon(&arrow);
00139                                    if (m_Doc->layerOutline(LayerNr))
00140                                           p->strokePath();
00141                                    else
00142                                    {
00143                                           p->setBrush(p->pen());
00144                                           p->setBrushOpacity(1.0 - lineTransparency());
00145                                           p->setLineWidth(0);
00146                                           p->setFillMode(ScPainter::Solid);
00147                                           p->fillPath();
00148                                    }
00149                                    break;
00150                             }
00151                      }
00152               }
00153               if (m_endArrowIndex != 0)
00154               {
00155                      FPoint End = PoLine.point(PoLine.size()-2);
00156                      for (uint xx = PoLine.size()-1; xx > 0; xx -= 2)
00157                      {
00158                             FPoint Vector = PoLine.point(xx);
00159                             if ((End.x() != Vector.x()) || (End.y() != Vector.y()))
00160                             {
00161                                    double r = atan2(End.y()-Vector.y(),End.x()-Vector.x())*(180.0/M_PI);
00162                                    QWMatrix arrowTrans;
00163                                    FPointArray arrow = (*m_Doc->arrowStyles.at(m_endArrowIndex-1)).points.copy();
00164                                    arrowTrans.translate(End.x(), End.y());
00165                                    arrowTrans.rotate(r);
00166                                    arrowTrans.scale(m_lineWidth, m_lineWidth);
00167                                    arrow.map(arrowTrans);
00168                                    p->setupPolygon(&arrow);
00169                                    if (m_Doc->layerOutline(LayerNr))
00170                                           p->strokePath();
00171                                    else
00172                                    {
00173                                           p->setBrush(p->pen());
00174                                           p->setBrushOpacity(1.0 - lineTransparency());
00175                                           p->setLineWidth(0);
00176                                           p->setFillMode(ScPainter::Solid);
00177                                           p->fillPath();
00178                                    }
00179                                    break;
00180                             }
00181                      }
00182               }
00183        }
00184 }
00185