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_regularpolygon.cpp  -  description
9                              -------------------
10     begin                : Fri Dec 31 2010
11     copyright            : (C) 2010 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 #if defined(_MSC_VER) && !defined(_USE_MATH_DEFINES)
25 #define _USE_MATH_DEFINES
26 #endif
27 #include <cmath>
28 #include <cassert>
29 
30 #include "pageitem.h"
31 #include "pageitem_regularpolygon.h"
32 #include "prefsmanager.h"
33 #include "scpage.h"
34 #include "scpainter.h"
35 #include "scpaths.h"
36 #include "scraction.h"
37 
38 #include "scribusstructs.h"
39 #include "scribusdoc.h"
40 
41 #include "undomanager.h"
42 #include "undostate.h"
43 #include "scconfig.h"
44 
45 #include "util.h"
46 #include "util_math.h"
47 
48 using namespace std;
49 
PageItem_RegularPolygon(ScribusDoc * pa,double x,double y,double w,double h,double w2,const QString & fill,const QString & outline)50 PageItem_RegularPolygon::PageItem_RegularPolygon(ScribusDoc *pa, double x, double y, double w, double h, double w2, const QString& fill, const QString& outline)
51 	: PageItem(pa, PageItem::RegularPolygon, x, y, w, h, w2, fill, outline)
52 {
53 	polyCorners = m_Doc->itemToolPrefs().polyCorners;
54 	polyFactor = m_Doc->itemToolPrefs().polyFactor;
55 	polyUseFactor = m_Doc->itemToolPrefs().polyUseFactor;
56 	polyRotation = m_Doc->itemToolPrefs().polyRotation;
57 	polyCurvature = m_Doc->itemToolPrefs().polyCurvature;
58 	polyInnerRot = m_Doc->itemToolPrefs().polyInnerRot;
59 	polyOuterCurvature = m_Doc->itemToolPrefs().polyOuterCurvature;
60 	QPainterPath path = regularPolygonPath(w, h, polyCorners, polyUseFactor, polyFactor, polyRotation, polyCurvature, polyInnerRot, polyOuterCurvature);
61 	PoLine.fromQPainterPath(path);
62 	Clip = flattenPath(PoLine, Segments);
63 }
64 
DrawObj_Item(ScPainter * p,QRectF)65 void PageItem_RegularPolygon::DrawObj_Item(ScPainter *p, QRectF /*e*/)
66 {
67 	if (!m_Doc->RePos)
68 	{
69 		p->setupPolygon(&PoLine);
70 		p->fillPath();
71 	}
72 }
73 
recalcPath()74 void PageItem_RegularPolygon::recalcPath()
75 {
76 	QPainterPath path = regularPolygonPath(width(), height(), polyCorners, polyUseFactor, polyFactor, polyRotation, polyCurvature, polyInnerRot, polyOuterCurvature);
77 	PoLine.fromQPainterPath(path);
78 	Clip = flattenPath(PoLine, Segments);
79 }
80 
applicableActions(QStringList & actionList)81 void PageItem_RegularPolygon::applicableActions(QStringList & actionList)
82 {
83 	actionList << "itemConvertToBezierCurve";
84 	actionList << "itemConvertToPolygon";
85 	actionList << "itemConvertToImageFrame";
86 	actionList << "itemConvertToTextFrame";
87 }
88 
infoDescription() const89 QString PageItem_RegularPolygon::infoDescription() const
90 {
91 	return QString();
92 }
93