Scribus Developer Documentation - API
logo-pen

Scribus Developer Documentation - API

shortwords.cpp

Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 /* This is the Scribus Short Words plugin interface implementation.
00008 
00009 This code is based on the Scribus-Vlna plug in rewritten for
00010 international use.
00011 
00012 2004 Petr Vanek <petr@yarpen.cz>
00013 
00014 This program is free software - see LICENSE file in the distribution
00015 or documentation
00016 */
00017 
00018 #include <QCheckBox>
00019 #include <QCursor>
00020 #include <QDir>
00021 #include <QFile>
00022 #include <QMessageBox>
00023 #include <QProgressBar>
00024 #include <QTextCodec>
00025 //Added by qt3to4:
00026 #include <QPixmap>
00027 
00028 #include "shortwords.h"
00029 //#include "shortwords.moc"
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     // Set action info in languageChange, so we only have to do
00062     // it in one place.
00063     languageChange();
00064 }
00065 
00066 ShortWordsPlugin::~ShortWordsPlugin() {};
00067 
00068 void ShortWordsPlugin::languageChange()
00069 {
00070     // Note that we leave the unused members unset. They'll be initialised
00071     // with their default ctors during construction.
00072     // Action name
00073     m_actionInfo.name = "ShortWords";
00074     // Action text for menu, including accel
00075     m_actionInfo.text = tr("Short &Words...", "short words plugin");
00076     // Menu
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     // about->version
00101     // about->releaseDate
00102     // about->copyright
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         } // switch
00136         // enable "Save" icon
00137         if (parse->modify > 0)
00138             doc->changed();
00139         delete parse;
00140         // redraw document
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         // set page where user calls vlna
00146         doc->view()->GotoPage(originalPage);
00147     } // action
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 
Created with personalized Doxygen. This is documentation for GPL software Scribus - Open Source Desktop Publishing.