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 *   Copyright (C) 2007 by Franz Schmid                                     *
9 *   franz.schmid@altmuehlnet.de                                            *
10 *                                                                          *
11 *   This program is free software; you can redistribute it and/or modify   *
12 *   it under the terms of the GNU General Public License as published by   *
13 *   the Free Software Foundation; either version 2 of the License, or      *
14 *   (at your option) any later version.                                    *
15 *                                                                          *
16 *   This program is distributed in the hope that it will be useful,        *
17 *   but WITHOUT ANY WARRANTY; without even the implied warranty of         *
18 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
19 *   GNU General Public License for more details.                           *
20 *                                                                          *
21 *   You should have received a copy of the GNU General Public License      *
22 *   along with this program; if not, write to the                          *
23 *   Free Software Foundation, Inc.,                                        *
24 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.              *
25 ****************************************************************************/
26 
27 #include "lenseffects.h"
28 #include "lensdialog.h"
29 #include "scribuscore.h"
30 #include "selection.h"
31 #include "scribusview.h"
32 
lenseffects_getPluginAPIVersion()33 int lenseffects_getPluginAPIVersion()
34 {
35 	return PLUGIN_API_VERSION;
36 }
37 
lenseffects_getPlugin()38 ScPlugin* lenseffects_getPlugin()
39 {
40 	LensEffectsPlugin* plug = new LensEffectsPlugin();
41 	Q_CHECK_PTR(plug);
42 	return plug;
43 }
44 
lenseffects_freePlugin(ScPlugin * plugin)45 void lenseffects_freePlugin(ScPlugin* plugin)
46 {
47 	LensEffectsPlugin* plug = qobject_cast<LensEffectsPlugin*>(plugin);
48 	Q_ASSERT(plug);
49 	delete plug;
50 }
51 
LensEffectsPlugin()52 LensEffectsPlugin::LensEffectsPlugin()
53 {
54 	// Set action info in languageChange, so we only have to do
55 	// it in one place.
56 	languageChange();
57 }
58 
~LensEffectsPlugin()59 LensEffectsPlugin::~LensEffectsPlugin() {};
60 
languageChange()61 void LensEffectsPlugin::languageChange()
62 {
63 	// Note that we leave the unused members unset. They'll be initialised
64 	// with their default ctors during construction.
65 	// Action name
66 	m_actionInfo.name = "LensEffects";
67 	// Action text for menu, including accel
68 	m_actionInfo.text = tr("Lens Effects...");
69 	// Menu
70 	m_actionInfo.menu = "ItemPathOps";
71 	m_actionInfo.parentMenu = "Item";
72 	m_actionInfo.subMenuName = tr("Path Tools");
73 	m_actionInfo.enabledOnStartup = false;
74 	m_actionInfo.notSuitableFor.append(PageItem::Line);
75 	m_actionInfo.notSuitableFor.append(PageItem::TextFrame);
76 	m_actionInfo.notSuitableFor.append(PageItem::ImageFrame);
77 	m_actionInfo.notSuitableFor.append(PageItem::PathText);
78 	m_actionInfo.notSuitableFor.append(PageItem::LatexFrame);
79 	m_actionInfo.notSuitableFor.append(PageItem::Symbol);
80 	m_actionInfo.notSuitableFor.append(PageItem::RegularPolygon);
81 	m_actionInfo.notSuitableFor.append(PageItem::Arc);
82 	m_actionInfo.notSuitableFor.append(PageItem::Spiral);
83 	m_actionInfo.needsNumObjects = 3;
84 }
85 
fullTrName() const86 QString LensEffectsPlugin::fullTrName() const
87 {
88 	return QObject::tr("Lens Effects");
89 }
90 
getAboutData() const91 const ScActionPlugin::AboutData* LensEffectsPlugin::getAboutData() const
92 {
93 	AboutData* about = new AboutData;
94 	Q_CHECK_PTR(about);
95 	about->authors = QString::fromUtf8("Franz Schmid <Franz.Schmid@altmuehlnet.de>");
96 	about->shortDescription = tr("Lens Effects");
97 	about->description = tr("Apply fancy lens effects");
98 	// about->version
99 	// about->releaseDate
100 	// about->copyright
101 	about->license = "GPL";
102 	return about;
103 }
104 
deleteAboutData(const AboutData * about) const105 void LensEffectsPlugin::deleteAboutData(const AboutData* about) const
106 {
107 	Q_ASSERT(about);
108 	delete about;
109 }
110 
run(ScribusDoc * doc,const QString &)111 bool LensEffectsPlugin::run(ScribusDoc* doc, const QString&)
112 {
113 	ScribusDoc* currDoc = doc;
114 	if (currDoc == nullptr)
115 		currDoc = ScCore->primaryMainWindow()->doc;
116 	if (currDoc->m_Selection->count() > 0)
117 	{
118 		LensDialog *dia = new LensDialog(currDoc->scMW(), currDoc);
119 		if (dia->exec())
120 		{
121 			for (int a = 0; a < dia->origPathItem.count(); a++)
122 			{
123 				PageItem *currItem = dia->origPageItem[a];
124 				if (currItem->itemType() == PageItem::Line)
125 					continue;
126 				QPainterPath path = dia->origPathItem[a]->path();
127 				FPointArray points;
128 				points.fromQPainterPath(path);
129 				currItem->PoLine = points;
130 				currItem->ClipEdited = true;
131 				currItem->FrameType = 3;
132 				double oW = currItem->width();
133 				double oH = currItem->height();
134 				currDoc->adjustItemSize(currItem, true);
135 				currItem->OldB2 = currItem->width();
136 				currItem->OldH2 = currItem->height();
137 				if (currItem->isGroup())
138 				{
139 					currItem->groupWidth = currItem->groupWidth * (currItem->OldB2 / oW);
140 					currItem->groupHeight = currItem->groupHeight * (currItem->OldH2 / oH);
141 				}
142 				currItem->updateClip();
143 				if (currItem->isGroup())
144 				{
145 					currDoc->resizeGroupToContents(currItem);
146 					currItem->SetRectFrame();
147 				}
148 				currItem->ContourLine = currItem->PoLine.copy();
149 			}
150 			if (currDoc->m_Selection->count() > 0)
151 			{
152 				PageItem *m_patternItem = currDoc->m_Selection->itemAt(0);
153 				if (m_patternItem->isGroup())
154 				{
155 					currDoc->resizeGroupToContents(m_patternItem);
156 					m_patternItem->SetRectFrame();
157 				}
158 			}
159 			currDoc->changed();
160 			currDoc->view()->DrawNew();
161 		}
162 		delete dia;
163 	}
164 	return true;
165 }
166