Subversion Repositories Scribus

Rev

Rev 14657 | Rev 16729 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4430 cbradney 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
*/
3422 subik 7
/* This is the Scribus Short Words plugin interface implementation.
1239 subik 8
 
9
This code is based on the Scribus-Vlna plug in rewritten for
10
international use.
11
 
12
2004 Petr Vanek <petr@yarpen.cz>
13
 
14
This program is free software - see LICENSE file in the distribution
15
or documentation
16
*/
17
 
10223 cbradney 18
#include <QCheckBox>
19
#include <QCursor>
20
#include <QDir>
21
#include <QFile>
22
#include <QMessageBox>
10017 fschmid 23
#include <QProgressBar>
10223 cbradney 24
#include <QTextCodec>
8501 cbradney 25
#include <QPixmap>
3809 cbradney 26
 
1239 subik 27
#include "shortwords.h"
28
#include "version.h"
14627 cbradney 29
#include "swdialog.h"
3207 craig 30
#include "configuration.h"
31
#include "parse.h"
3670 cbradney 32
#include "page.h"
3422 subik 33
#include "swprefsgui.h"
14621 cbradney 34
#include "prefs_shortwords.h"
2986 craig 35
#include "scpaths.h"
1295 cbradney 36
#include "scribus.h"
13805 jghali 37
#include "scribusdoc.h"
10200 cbradney 38
#include "util_icon.h"
1239 subik 39
 
3207 craig 40
int scribusshortwords_getPluginAPIVersion()
1239 subik 41
{
3207 craig 42
        return PLUGIN_API_VERSION;
1239 subik 43
}
44
 
3207 craig 45
ScPlugin* scribusshortwords_getPlugin()
1239 subik 46
{
3207 craig 47
        ShortWordsPlugin* plug = new ShortWordsPlugin();
48
        Q_CHECK_PTR(plug);
49
        return plug;
1239 subik 50
}
51
 
3207 craig 52
void scribusshortwords_freePlugin(ScPlugin* plugin)
1239 subik 53
{
3207 craig 54
        ShortWordsPlugin* plug = dynamic_cast<ShortWordsPlugin*>(plugin);
55
        Q_ASSERT(plug);
56
        delete plug;
1239 subik 57
}
58
 
3487 craig 59
ShortWordsPlugin::ShortWordsPlugin() : ScActionPlugin()
1280 cbradney 60
{
3207 craig 61
        // Set action info in languageChange, so we only have to do
62
        // it in one place.
63
        languageChange();
1280 cbradney 64
}
65
 
3207 craig 66
ShortWordsPlugin::~ShortWordsPlugin() {};
67
 
68
void ShortWordsPlugin::languageChange()
1280 cbradney 69
{
3207 craig 70
        // Note that we leave the unused members unset. They'll be initialised
71
        // with their default ctors during construction.
72
        // Action name
73
        m_actionInfo.name = "ShortWords";
74
        // Action text for menu, including accel
75
        m_actionInfo.text = tr("Short &Words...", "short words plugin");
76
        // Menu
77
        m_actionInfo.menu = "Extras";
11164 cbradney 78
        m_actionInfo.enabledOnStartup = false;
10956 fschmid 79
        m_actionInfo.needsNumObjects = -1;
1280 cbradney 80
}
81
 
3207 craig 82
const QString ShortWordsPlugin::fullTrName() const
1280 cbradney 83
{
3207 craig 84
        return QObject::tr("Short Words");
1280 cbradney 85
}
86
 
3207 craig 87
const ScActionPlugin::AboutData* ShortWordsPlugin::getAboutData() const
1280 cbradney 88
{
3241 craig 89
        AboutData* about = new AboutData;
90
        Q_CHECK_PTR(about);
3352 subik 91
        about->authors = QString::fromUtf8("Petr Van\xc4\x9bk <petr@scribus.info>, "
92
                        "Łukasz [DeeJay1] Jernaś <deejay1@nsj.srem.pl>, "
93
                        "Maciej Hanski, Zdenko Podobny, Mikolaj Machowski <mikmach@wp.pl>, "
94
                        "Ludi Maciel, Frederico Guimarães, "
95
                        "Claudio Beccari <claudio.beccari@polito.it>, "
3452 subik 96
                        "Christoph Schäfer <christoph-schaefer@gmx.de>, "
97
                        "intrigeri <intrigeri@boum.org>");
3352 subik 98
        about->shortDescription = tr("Short Words");
6525 subik 99
        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();
3352 subik 100
        // about->version
101
        // about->releaseDate
102
        // about->copyright
103
        about->license = "GPL";
3241 craig 104
        return about;
1280 cbradney 105
}
106
 
3241 craig 107
void ShortWordsPlugin::deleteAboutData(const AboutData* about) const
1280 cbradney 108
{
3241 craig 109
        Q_ASSERT(about);
110
        delete about;
1280 cbradney 111
}
112
 
5781 cbradney 113
bool ShortWordsPlugin::run(ScribusDoc* doc, QString target)
1239 subik 114
{
11163 cbradney 115
        if (doc==NULL)
116
                return false;
3207 craig 117
        Q_ASSERT(target.isEmpty());
1239 subik 118
 
5781 cbradney 119
        uint originalPage = doc->currentPage()->pageNr();
9984 fschmid 120
        SWDialog *dlg = new SWDialog(doc->scMW());
1239 subik 121
        if (dlg->exec() == QDialog::Accepted) {
3468 subik 122
                SWParse *parse = new SWParse();
12658 fschmid 123
                QApplication::changeOverrideCursor(QCursor(Qt::WaitCursor));
12739 subik 124
                if (!dlg->useStyleLang())
125
                        parse->lang = dlg->lang();
126
                else
127
                        parse->lang = ""; // get it from style
128
 
5781 cbradney 129
                doc->scMW()->setStatusBarInfoText(QObject::tr("Short Words processing. Wait please...", "short words plugin"));
12739 subik 130
                switch (dlg->actionSelected()) {
1239 subik 131
                        case 0:
5781 cbradney 132
                                parse->parseSelection(doc);
1239 subik 133
                                break;
134
                        case 1:
5781 cbradney 135
                                parse->parsePage(doc, doc->currentPage()->pageNr());
1239 subik 136
                                break;
137
                        case 2:
5781 cbradney 138
                                parse->parseAll(doc);
1239 subik 139
                                break;
140
                } // switch
141
                // enable "Save" icon
142
                if (parse->modify > 0)
5781 cbradney 143
                        doc->changed();
3468 subik 144
                delete parse;
1239 subik 145
                // redraw document
5781 cbradney 146
                doc->view()->DrawNew();
12658 fschmid 147
                QApplication::changeOverrideCursor(Qt::ArrowCursor);
5781 cbradney 148
                doc->scMW()->setStatusBarInfoText(QObject::tr("Short Words processing. Done.", "short words plugin"));
149
                doc->scMW()->mainWindowProgressBar->reset();
1239 subik 150
                // set page where user calls vlna
5781 cbradney 151
                doc->view()->GotoPage(originalPage);
1239 subik 152
        } // action
153
        delete dlg;
3468 subik 154
        return true;
155
}
1239 subik 156
 
14657 cbradney 157
bool ShortWordsPlugin::newPrefsPanelWidget(QWidget* parent, PrefsPanel*& panel, QString& caption, QPixmap& icon)
1239 subik 158
{
3468 subik 159
        panel = new SWPrefsGui(parent);
160
        Q_CHECK_PTR(panel);
161
        caption = tr("Short Words");
3505 avox 162
        icon = loadIcon("shortwords.png");
3468 subik 163
        return true;
1239 subik 164
}
3468 subik 165
 
14657 cbradney 166
bool ShortWordsPlugin::newPrefsPanelWidget(QWidget* parent, Prefs_Pane*& panel, QString& caption, QPixmap& icon)
14621 cbradney 167
{
168
        panel = new Prefs_ShortWords(parent);
169
        Q_CHECK_PTR(panel);
170
        caption = tr("Short Words");
15176 cbradney 171
        icon = loadIcon("shortwords_16.png");
14621 cbradney 172
        return true;
173
}