shortwords.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <QCheckBox>
00019 #include <QCursor>
00020 #include <QDir>
00021 #include <QFile>
00022 #include <QMessageBox>
00023 #include <QProgressBar>
00024 #include <QTextCodec>
00025
00026 #include <QPixmap>
00027
00028 #include "shortwords.h"
00029
00030 #include "version.h"
00031 #include "vlnadialog.h"
00032 #include "configuration.h"
00033 #include "parse.h"
00034 #include "page.h"
00035 #include "swprefsgui.h"
00036 #include "scpaths.h"
00037 #include "scribus.h"
00038 #include "util_icon.h"
00039
00040 int scribusshortwords_getPluginAPIVersion()
00041 {
00042 return PLUGIN_API_VERSION;
00043 }
00044
00045 ScPlugin* scribusshortwords_getPlugin()
00046 {
00047 ShortWordsPlugin* plug = new ShortWordsPlugin();
00048 Q_CHECK_PTR(plug);
00049 return plug;
00050 }
00051
00052 void scribusshortwords_freePlugin(ScPlugin* plugin)
00053 {
00054 ShortWordsPlugin* plug = dynamic_cast<ShortWordsPlugin*>(plugin);
00055 Q_ASSERT(plug);
00056 delete plug;
00057 }
00058
00059 ShortWordsPlugin::ShortWordsPlugin() : ScActionPlugin()
00060 {
00061
00062
00063 languageChange();
00064 }
00065
00066 ShortWordsPlugin::~ShortWordsPlugin() {};
00067
00068 void ShortWordsPlugin::languageChange()
00069 {
00070
00071
00072
00073 m_actionInfo.name = "ShortWords";
00074
00075 m_actionInfo.text = tr("Short &Words...", "short words plugin");
00076
00077 m_actionInfo.menu = "Extras";
00078 m_actionInfo.enabledOnStartup = false;
00079 m_actionInfo.needsNumObjects = -1;
00080 }
00081
00082 const QString ShortWordsPlugin::fullTrName() const
00083 {
00084 return QObject::tr("Short Words");
00085 }
00086
00087 const ScActionPlugin::AboutData* ShortWordsPlugin::getAboutData() const
00088 {
00089 AboutData* about = new AboutData;
00090 Q_CHECK_PTR(about);
00091 about->authors = QString::fromUtf8("Petr Van\xc4\x9bk <petr@scribus.info>, "
00092 "Łukasz [DeeJay1] Jernaś <deejay1@nsj.srem.pl>, "
00093 "Maciej Hanski, Zdenko Podobny, Mikolaj Machowski <mikmach@wp.pl>, "
00094 "Ludi Maciel, Frederico Guimarães, "
00095 "Claudio Beccari <claudio.beccari@polito.it>, "
00096 "Christoph Schäfer <christoph-schaefer@gmx.de>, "
00097 "intrigeri <intrigeri@boum.org>");
00098 about->shortDescription = tr("Short Words");
00099 about->description = tr("Special plug-in for adding non-breaking spaces before or after so called short words. Available in the following languages: ") + SWConfig::getAvailableLanguages();
00100
00101
00102
00103 about->license = "GPL";
00104 return about;
00105 }
00106
00107 void ShortWordsPlugin::deleteAboutData(const AboutData* about) const
00108 {
00109 Q_ASSERT(about);
00110 delete about;
00111 }
00112
00113 bool ShortWordsPlugin::run(ScribusDoc* doc, QString target)
00114 {
00115 if (doc==NULL)
00116 return false;
00117 Q_ASSERT(target.isEmpty());
00118
00119 uint originalPage = doc->currentPage()->pageNr();
00120 SWDialog *dlg = new SWDialog(doc->scMW());
00121 if (dlg->exec() == QDialog::Accepted) {
00122 SWParse *parse = new SWParse();
00123 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
00124 doc->scMW()->setStatusBarInfoText(QObject::tr("Short Words processing. Wait please...", "short words plugin"));
00125 switch (dlg->actionSelected) {
00126 case 0:
00127 parse->parseSelection(doc);
00128 break;
00129 case 1:
00130 parse->parsePage(doc, doc->currentPage()->pageNr());
00131 break;
00132 case 2:
00133 parse->parseAll(doc);
00134 break;
00135 }
00136
00137 if (parse->modify > 0)
00138 doc->changed();
00139 delete parse;
00140
00141 doc->view()->DrawNew();
00142 QApplication::restoreOverrideCursor();
00143 doc->scMW()->setStatusBarInfoText(QObject::tr("Short Words processing. Done.", "short words plugin"));
00144 doc->scMW()->mainWindowProgressBar->reset();
00145
00146 doc->view()->GotoPage(originalPage);
00147 }
00148 delete dlg;
00149 return true;
00150 }
00151
00152 bool ShortWordsPlugin::newPrefsPanelWidget(QWidget* parent,
00153 PrefsPanel*& panel,
00154 QString& caption,
00155 QPixmap& icon)
00156 {
00157 panel = new SWPrefsGui(parent);
00158 Q_CHECK_PTR(panel);
00159 caption = tr("Short Words");
00160 icon = loadIcon("shortwords.png");
00161 return true;
00162 }
00163