summaryrefslogtreecommitdiffstats
path: root/scribus/plugins
diff options
context:
space:
mode:
authorcraig <craig@11d20701-8431-0410-a711-e3c959e3b870>2012-04-30 21:42:55 +0000
committercraig <craig@11d20701-8431-0410-a711-e3c959e3b870>2012-04-30 21:42:55 +0000
commit03f92217ee2336adcbf9b1343ea03edac490ade5 (patch)
tree54300e6b248f5b341d8de29649d4175edfae5742 /scribus/plugins
parent8f5f4c57942487fafbeced90e981810b20c809b5 (diff)
downloadscribus-03f92217ee2336adcbf9b1343ea03edac490ade5.tar.gz
scribus-03f92217ee2336adcbf9b1343ea03edac490ade5.tar.xz
scribus-03f92217ee2336adcbf9b1343ea03edac490ade5.zip
Update hunspell plugin, plugin manager to allow SE to see plugins, scplugin to have SE plugin attributes
git-svn-id: svn://scribus.net/branches/Version14x/Scribus@17485 11d20701-8431-0410-a711-e3c959e3b870
Diffstat (limited to 'scribus/plugins')
-rw-r--r--scribus/plugins/tools/hunspellcheck/hunspelldialog.cpp10
-rw-r--r--scribus/plugins/tools/hunspellcheck/hunspelldialog.h6
-rw-r--r--scribus/plugins/tools/hunspellcheck/hunspellplugin.cpp17
-rw-r--r--scribus/plugins/tools/hunspellcheck/hunspellplugin.h3
-rw-r--r--scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp54
-rw-r--r--scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.h11
6 files changed, 80 insertions, 21 deletions
diff --git a/scribus/plugins/tools/hunspellcheck/hunspelldialog.cpp b/scribus/plugins/tools/hunspellcheck/hunspelldialog.cpp
index d36b08b..7c2c5a7 100644
--- a/scribus/plugins/tools/hunspellcheck/hunspelldialog.cpp
+++ b/scribus/plugins/tools/hunspellcheck/hunspelldialog.cpp
@@ -11,7 +11,7 @@ for which a new license (GPL+exception) is in place.
#include "hunspelldialog.h"
-HunspellDialog::HunspellDialog(QWidget *parent, ScribusDoc *doc, PageItem *frameToCheck)
+HunspellDialog::HunspellDialog(QWidget *parent, ScribusDoc *doc, StoryText *iText)
{
setupUi( this );
setModal( true );
@@ -23,7 +23,7 @@ HunspellDialog::HunspellDialog(QWidget *parent, ScribusDoc *doc, PageItem *frame
m_doc=doc;
m_docChanged=false;
- fTC=frameToCheck;
+ m_Itext=iText;
}
void HunspellDialog::set(QStringList *dictEntries, Hunspell **hspellers, QList<WordsFound> *wfList)
@@ -66,7 +66,7 @@ void HunspellDialog::goToNextWord(int i)
suggestionsListWidget->setCurrentRow(0);
int sentencePos=0;
- QString sentence(fTC->itemText.sentence(currWF.start, sentencePos));
+ QString sentence(m_Itext->sentence(currWF.start, sentencePos));
sentence.insert(currWF.end-sentencePos+currWF.changeOffset,"</b></font>");
sentence.insert(currWF.start-sentencePos+currWF.changeOffset,"<font color=red><b>");
sentenceTextEdit->setText(sentence);
@@ -89,7 +89,6 @@ void HunspellDialog::changeWord()
if(m_wfList->at(wfListIndex).ignore || m_wfList->at(wfListIndex).changed)
goToNextWord();
replaceWord(wfListIndex);
- m_docChanged=true;
goToNextWord();
}
@@ -102,7 +101,6 @@ void HunspellDialog::changeAllWords()
for(int i=0;i<m_wfList->count();++i)
if(m_wfList->at(i).w==wordToChange)
replaceWord(i);
- m_docChanged=true;
goToNextWord();
}
@@ -110,7 +108,7 @@ void HunspellDialog::replaceWord(int i)
{
//qDebug()<<"Replacing word"<<i<m_wfList->at(i).w<<m_wfList->at(i).start;
QString newText(suggestionsListWidget->currentItem()->text());
- int lengthDiff=fTC->itemText.replaceWord(m_wfList->at(i).start+m_wfList->at(i).changeOffset, newText);
+ int lengthDiff=m_Itext->replaceWord(m_wfList->at(i).start+m_wfList->at(i).changeOffset, newText);
if (lengthDiff!=0)
{
for (int k=i; k<m_wfList->count();++k)
diff --git a/scribus/plugins/tools/hunspellcheck/hunspelldialog.h b/scribus/plugins/tools/hunspellcheck/hunspelldialog.h
index 668966d..634490c 100644
--- a/scribus/plugins/tools/hunspellcheck/hunspelldialog.h
+++ b/scribus/plugins/tools/hunspellcheck/hunspelldialog.h
@@ -11,7 +11,7 @@
#include "pluginapi.h"
#include "hunspellpluginstructs.h"
#include "scribusdoc.h"
-#include "pageitem.h"
+#include "text/storytext.h"
#include "ui_hunspelldialogbase.h"
@@ -20,7 +20,7 @@ class PLUGIN_API HunspellDialog : public QDialog, private Ui::HunspellDialogBase
Q_OBJECT
public:
- HunspellDialog(QWidget* parent, ScribusDoc *doc, PageItem* frameToCheck);
+ HunspellDialog(QWidget* parent, ScribusDoc *doc, StoryText* iText);
~HunspellDialog() {};
void set(QStringList* dictEntries, Hunspell **hspellers, QList<WordsFound>* wfList);
bool docChanged() {return m_docChanged;}
@@ -34,7 +34,7 @@ class PLUGIN_API HunspellDialog : public QDialog, private Ui::HunspellDialogBase
private:
ScribusDoc* m_doc;
- PageItem* fTC;
+ StoryText* m_Itext;
QStringList* m_dictEntries;
Hunspell **m_hspellers;
QList<WordsFound>* m_wfList;
diff --git a/scribus/plugins/tools/hunspellcheck/hunspellplugin.cpp b/scribus/plugins/tools/hunspellcheck/hunspellplugin.cpp
index 5b089a7..b4fbaab 100644
--- a/scribus/plugins/tools/hunspellcheck/hunspellplugin.cpp
+++ b/scribus/plugins/tools/hunspellcheck/hunspellplugin.cpp
@@ -7,6 +7,7 @@ for which a new license (GPL+exception) is in place.
#include "hunspellplugin.h"
#include "hunspellpluginimpl.h"
#include "scribuscore.h"
+#include "storyeditor.h"
// See scplugin.h and pluginmanager.{cpp,h} for detail on what these methods
// do. That documentatation is not duplicated here.
@@ -29,9 +30,11 @@ void HunspellPlugin::languageChange()
// Action name
m_actionInfo.name = "HunspellPlugin";
// Action text for menu, including &accel
- m_actionInfo.text = tr("Hunspell &Plugin");
+ m_actionInfo.text = tr("Check Spelling...");
// Menu
m_actionInfo.menu = "Item";
+ // Story Editor Menu
+ m_actionInfo.seMenu = "Edit";
// If needed, what item to add the menu item after
//m_actionInfo.menuAfterName = "ColorWheel"
// If needed, the keyboard shortcut for the plugin
@@ -39,6 +42,7 @@ void HunspellPlugin::languageChange()
// Should the menu item be enabled when the app starts
// (even without a document open) ?
m_actionInfo.enabledOnStartup = false;
+ m_actionInfo.enabledForStoryEditor = true;
m_actionInfo.notSuitableFor.append(PageItem::Line);
m_actionInfo.notSuitableFor.append(PageItem::Polygon);
m_actionInfo.notSuitableFor.append(PageItem::ImageFrame);
@@ -74,6 +78,17 @@ bool HunspellPlugin::run(ScribusDoc* doc, QString target)
return result;
}
+bool HunspellPlugin::run(QWidget *parent, ScribusDoc *doc, QString target)
+{
+ HunspellPluginImpl *hunspellPluginImpl = new HunspellPluginImpl();
+ Q_CHECK_PTR(hunspellPluginImpl);
+ if (parent)
+ hunspellPluginImpl->setRunningForSE(true, dynamic_cast<StoryEditor*>(parent));
+ bool result = hunspellPluginImpl->run(target, doc);
+ delete hunspellPluginImpl;
+ return result;
+}
+
// Low level plugin API
int hunspellplugin_getPluginAPIVersion()
{
diff --git a/scribus/plugins/tools/hunspellcheck/hunspellplugin.h b/scribus/plugins/tools/hunspellcheck/hunspellplugin.h
index 0b89101..8102cfa 100644
--- a/scribus/plugins/tools/hunspellcheck/hunspellplugin.h
+++ b/scribus/plugins/tools/hunspellcheck/hunspellplugin.h
@@ -24,6 +24,7 @@ class PLUGIN_API HunspellPlugin : public ScActionPlugin
virtual ~HunspellPlugin();
//! \brief main method to run the plug
virtual bool run(ScribusDoc* doc, QString target = QString::null);
+ virtual bool run(QWidget* p, ScribusDoc* doc, QString target = QString::null);
virtual const QString fullTrName() const;
virtual const AboutData* getAboutData() const;
virtual void deleteAboutData(const AboutData* about) const;
@@ -31,6 +32,8 @@ class PLUGIN_API HunspellPlugin : public ScActionPlugin
virtual void addToMainWindowMenu(ScribusMainWindow *) {};
// Special features (none)
+
+ QWidget *m_parent;
};
extern "C" PLUGIN_API int hunspellplugin_getPluginAPIVersion();
diff --git a/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp b/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp
index 1b169e7..8fff975 100644
--- a/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp
+++ b/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp
@@ -12,6 +12,7 @@ for which a new license (GPL+exception) is in place.
#include "scpaths.h"
#include "scribusdoc.h"
#include "scribus.h"
+#include "storyeditor.h"
#include "text/specialchars.h"
#include "util.h"
@@ -31,6 +32,8 @@ HunspellPluginImpl::HunspellPluginImpl() : QObject(0)
{
hspellers=NULL;
numDicts=0;
+ m_runningForSE=false;
+ m_SE=NULL;
}
HunspellPluginImpl::~HunspellPluginImpl()
@@ -55,7 +58,17 @@ bool HunspellPluginImpl::run(const QString & target, ScribusDoc* doc)
qDebug()<<"Hunspell Init Ok:"<<initOk;
if (!initOk)
return false;
- bool spellCheckOk=checkWithHunspell();
+ bool spellCheckOk=false;
+ if (m_runningForSE)
+ {
+ //qDebug()<<"Running for StoryEditor";
+ spellCheckOk=checkWithHunspellSE();
+ }
+ else
+ {
+ //qDebug()<<"Running for ScribusMainWindow";
+ spellCheckOk=checkWithHunspell();
+ }
if (!spellCheckOk)
return false;
return true;
@@ -126,19 +139,26 @@ bool HunspellPluginImpl::checkWithHunspell()
for( int i = 0; i < m_doc->m_Selection->count(); ++i )
{
frameToCheck = m_doc->m_Selection->itemAt(i);
- parseTextFrame(frameToCheck);
- openGUIForTextFrame(frameToCheck);
+ StoryText *iText=&frameToCheck->itemText;
+ parseTextFrame(iText);
+ openGUIForTextFrame(iText);
m_doc->view()->DrawNew();
}
return true;
}
-bool HunspellPluginImpl::parseTextFrame(PageItem *frameToCheck)
+bool HunspellPluginImpl::checkWithHunspellSE()
+{
+ StoryText *iText=&(m_SE->Editor->StyledText);
+ parseTextFrame(iText);
+ openGUIForStoryEditor(iText);
+ m_SE->Editor->updateAll();
+ return true;
+}
+
+bool HunspellPluginImpl::parseTextFrame(StoryText *iText)
{
- StoryText *iText=&frameToCheck->itemText;
int len=iText->length();
- QString text=iText->text(0,len);
-// qDebug()<<text;
int wordCount=0,wordNo=0,errorCount=0;
int currPos=0;
while (currPos<len)
@@ -185,9 +205,9 @@ bool HunspellPluginImpl::parseTextFrame(PageItem *frameToCheck)
return true;
}
-bool HunspellPluginImpl::openGUIForTextFrame(PageItem *frameToCheck)
+bool HunspellPluginImpl::openGUIForTextFrame(StoryText *iText)
{
- HunspellDialog hsDialog(m_doc->scMW(), m_doc, frameToCheck);
+ HunspellDialog hsDialog(m_doc->scMW(), m_doc, iText);
hsDialog.set(&dictEntries, hspellers, &wordsToCorrect);
hsDialog.exec();
if (hsDialog.docChanged())
@@ -195,3 +215,19 @@ bool HunspellPluginImpl::openGUIForTextFrame(PageItem *frameToCheck)
return true;
}
+bool HunspellPluginImpl::openGUIForStoryEditor(StoryText *iText)
+{
+ m_SE->setSpellActive(true);
+ HunspellDialog hsDialog(m_SE, m_doc, iText);
+ hsDialog.set(&dictEntries, hspellers, &wordsToCorrect);
+ hsDialog.exec();
+ m_SE->setSpellActive(false);
+ return true;
+}
+
+void HunspellPluginImpl::setRunningForSE(bool rfSE, StoryEditor *sE)
+{
+ m_runningForSE=rfSE;
+ m_SE=sE;
+}
+
diff --git a/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.h b/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.h
index d664682..0443c10 100644
--- a/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.h
+++ b/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.h
@@ -17,6 +17,8 @@ for which a new license (GPL+exception) is in place.
class QString;
class ScribusDoc;
class PageItem;
+class StoryText;
+class StoryEditor;
@@ -30,8 +32,11 @@ class HunspellPluginImpl : public QObject
bool findDictionaries();
bool initHunspell();
bool checkWithHunspell();
- bool parseTextFrame(PageItem *frameToCheck);
- bool openGUIForTextFrame(PageItem *frameToCheck);
+ bool checkWithHunspellSE();
+ bool parseTextFrame(StoryText *);
+ bool openGUIForTextFrame(StoryText *iText);
+ bool openGUIForStoryEditor(StoryText *iText);
+ void setRunningForSE(bool rfSE, StoryEditor *sE);
QList<WordsFound> wordsToCorrect;
protected:
@@ -42,6 +47,8 @@ class HunspellPluginImpl : public QObject
QStringList dictEntries;
QStringList affEntries;
ScribusDoc* m_doc;
+ bool m_runningForSE;
+ StoryEditor* m_SE;
};
#endif