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) 2008 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 "meshdistortiondialog.h"
28 #include "meshdistortion.h"
29 #include "scribuscore.h"
30 #include "scribusview.h"
31 #include "appmodes.h"
32 #include "util.h"
33 #include "util_math.h"
34 
meshdistortion_getPluginAPIVersion()35 int meshdistortion_getPluginAPIVersion()
36 {
37 	return PLUGIN_API_VERSION;
38 }
39 
meshdistortion_getPlugin()40 ScPlugin* meshdistortion_getPlugin()
41 {
42 	MeshDistortionPlugin* plug = new MeshDistortionPlugin();
43 	Q_CHECK_PTR(plug);
44 	return plug;
45 }
46 
meshdistortion_freePlugin(ScPlugin * plugin)47 void meshdistortion_freePlugin(ScPlugin* plugin)
48 {
49 	MeshDistortionPlugin* plug = dynamic_cast<MeshDistortionPlugin*>(plugin);
50 	Q_ASSERT(plug);
51 	delete plug;
52 }
53 
MeshDistortionPlugin()54 MeshDistortionPlugin::MeshDistortionPlugin()
55 {
56 	m_doc = nullptr;
57 	m_patternItem = nullptr;
58 	// Set action info in languageChange, so we only have to do
59 	// it in one place.
60 	languageChange();
61 }
62 
~MeshDistortionPlugin()63 MeshDistortionPlugin::~MeshDistortionPlugin() {};
64 
languageChange()65 void MeshDistortionPlugin::languageChange()
66 {
67 	// Note that we leave the unused members unset. They'll be initialised
68 	// with their default ctors during construction.
69 	// Action name
70 	m_actionInfo.name = "MeshDistortion";
71 	// Action text for menu, including accel
72 	m_actionInfo.text = tr("Mesh Distortion...");
73 	// Menu
74 	m_actionInfo.menu = "ItemPathOps";
75 	m_actionInfo.parentMenu = "Item";
76 	m_actionInfo.subMenuName = tr("Path Tools");
77 	m_actionInfo.enabledOnStartup = false;
78 	m_actionInfo.forAppMode.append(modeNormal);
79 	m_actionInfo.notSuitableFor.append(PageItem::Line);
80 	m_actionInfo.notSuitableFor.append(PageItem::TextFrame);
81 	m_actionInfo.notSuitableFor.append(PageItem::ImageFrame);
82 	m_actionInfo.notSuitableFor.append(PageItem::PathText);
83 	m_actionInfo.notSuitableFor.append(PageItem::LatexFrame);
84 	m_actionInfo.notSuitableFor.append(PageItem::Symbol);
85 	m_actionInfo.notSuitableFor.append(PageItem::RegularPolygon);
86 	m_actionInfo.notSuitableFor.append(PageItem::Arc);
87 	m_actionInfo.notSuitableFor.append(PageItem::Spiral);
88 	m_actionInfo.needsNumObjects = 3;
89 }
90 
fullTrName() const91 QString MeshDistortionPlugin::fullTrName() const
92 {
93 	return QObject::tr("MeshDistortion");
94 }
95 
getAboutData() const96 const ScActionPlugin::AboutData* MeshDistortionPlugin::getAboutData() const
97 {
98 	AboutData* about = new AboutData;
99 	Q_CHECK_PTR(about);
100 	about->authors = QString::fromUtf8("Franz Schmid <Franz.Schmid@altmuehlnet.de>");
101 	about->shortDescription = tr("Mesh Distortion of Polygons");
102 	about->description = tr("Mesh Distortion of Polygons");
103 	// about->version
104 	// about->releaseDate
105 	// about->copyright
106 	about->license = "GPL";
107 	return about;
108 }
109 
deleteAboutData(const AboutData * about) const110 void MeshDistortionPlugin::deleteAboutData(const AboutData* about) const
111 {
112 	Q_ASSERT(about);
113 	delete about;
114 }
115 
run(ScribusDoc * doc,const QString &)116 bool MeshDistortionPlugin::run(ScribusDoc* doc, const QString&)
117 {
118 	m_doc = doc;
119 	if (m_doc == nullptr)
120 		m_doc = ScCore->primaryMainWindow()->doc;
121 	if (m_doc->m_Selection->count() > 0)
122 	{
123 		m_patternItem = m_doc->m_Selection->itemAt(0);
124 		MeshDistortionDialog *dia = new MeshDistortionDialog(m_doc->scMW(), m_doc);
125 		if (dia->exec())
126 		{
127 			dia->updateAndExit();
128 			if (m_patternItem->isGroup())
129 			{
130 				m_doc->resizeGroupToContents(m_patternItem);
131 				m_patternItem->SetRectFrame();
132 			}
133 			m_doc->changed();
134 			m_doc->view()->DrawNew();
135 		}
136 		delete dia;
137 	}
138 	return true;
139 }
140