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 #include "hunspellplugin.h"
8 #include "hunspellpluginimpl.h"
9 #include "scribuscore.h"
10 #include "ui/storyeditor.h"
11
12 // See scplugin.h and pluginmanager.{cpp,h} for detail on what these methods
13 // do. That documentatation is not duplicated here.
14 // Please don't implement the functionality of your plugin here; do that
15 // in mypluginimpl.h and mypluginimpl.cpp .
16
HunspellPlugin()17 HunspellPlugin::HunspellPlugin()
18 {
19 // Set action info in languageChange, so we only have to do
20 // it in one place.
21 languageChange();
22 }
23
24 HunspellPlugin::~HunspellPlugin() = default;
25
languageChange()26 void HunspellPlugin::languageChange()
27 {
28 // Note that we leave the unused members unset. They'll be initialised
29 // with their default ctors during construction.
30 // Action name
31 m_actionInfo.name = "HunspellPlugin";
32 // Action text for menu, including &accel
33 m_actionInfo.text = tr("Check Spelling...");
34 // Menu
35 m_actionInfo.menu = "Extras";
36 m_actionInfo.menuAfterName = "extrasDeHyphenateText";
37 // Story Editor Menu
38 m_actionInfo.seMenu = "Edit";
39 // If needed, what item to add the menu item after
40 //m_actionInfo.menuAfterName = "ColorWheel"
41 // If needed, the keyboard shortcut for the plugin
42 m_actionInfo.keySequence = "SHIFT+F7";
43 // Should the menu item be enabled when the app starts
44 // (even without a document open) ?
45 m_actionInfo.enabledOnStartup = false;
46 m_actionInfo.enabledForStoryEditor = true;
47 m_actionInfo.notSuitableFor.append(PageItem::Line);
48 m_actionInfo.notSuitableFor.append(PageItem::Polygon);
49 m_actionInfo.notSuitableFor.append(PageItem::ImageFrame);
50 m_actionInfo.notSuitableFor.append(PageItem::PathText);
51 m_actionInfo.notSuitableFor.append(PageItem::LatexFrame);
52 m_actionInfo.notSuitableFor.append(PageItem::Symbol);
53 m_actionInfo.notSuitableFor.append(PageItem::RegularPolygon);
54 m_actionInfo.notSuitableFor.append(PageItem::Arc);
55 m_actionInfo.notSuitableFor.append(PageItem::Spiral);
56 m_actionInfo.needsNumObjects = 1;
57 }
58
fullTrName() const59 QString HunspellPlugin::fullTrName() const
60 {
61 return QObject::tr("Hunspell Plugin");
62 }
63
getAboutData() const64 const ScActionPlugin::AboutData* HunspellPlugin::getAboutData() const
65 {
66 AboutData* about = new AboutData;
67 Q_CHECK_PTR(about);
68 return about;
69 }
70
deleteAboutData(const AboutData * about) const71 void HunspellPlugin::deleteAboutData(const AboutData* about) const
72 {
73 Q_ASSERT(about);
74 delete about;
75 }
76
run(ScribusDoc * doc,const QString & target)77 bool HunspellPlugin::run(ScribusDoc* doc, const QString& target)
78 {
79 HunspellPluginImpl *hunspellPluginImpl = new HunspellPluginImpl();
80 Q_CHECK_PTR(hunspellPluginImpl);
81 bool result = hunspellPluginImpl->run(target, doc);
82 delete hunspellPluginImpl;
83 return result;
84 }
85
run(QWidget * parent,ScribusDoc * doc,const QString & target)86 bool HunspellPlugin::run(QWidget *parent, ScribusDoc *doc, const QString& target)
87 {
88 HunspellPluginImpl *hunspellPluginImpl = new HunspellPluginImpl();
89 Q_CHECK_PTR(hunspellPluginImpl);
90 bool result = false;
91 if (parent)
92 {
93 StoryEditor* se = dynamic_cast<StoryEditor*>(parent);
94 if (se)
95 hunspellPluginImpl->setRunningForSE(true, se);
96 }
97 result = hunspellPluginImpl->run(target, doc);
98 delete hunspellPluginImpl;
99 return result;
100 }
101
102 // Low level plugin API
hunspellplugin_getPluginAPIVersion()103 int hunspellplugin_getPluginAPIVersion()
104 {
105 return PLUGIN_API_VERSION;
106 }
107
hunspellplugin_getPlugin()108 ScPlugin* hunspellplugin_getPlugin()
109 {
110 HunspellPlugin* plug = new HunspellPlugin();
111 Q_CHECK_PTR(plug);
112 return plug;
113 }
114
hunspellplugin_freePlugin(ScPlugin * plugin)115 void hunspellplugin_freePlugin(ScPlugin* plugin)
116 {
117 HunspellPlugin* plug = qobject_cast<HunspellPlugin*>(plugin);
118 Q_ASSERT(plug);
119 delete plug;
120 }
121