blob: a34aca1fc70b58f8e4d2fc56e5be713ca2a91ded (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
|
/*
For general Scribus (>=1.3.2) copyright and licensing information please refer
to the COPYING file provided with the program. Following this notice may exist
a copyright and/or license notice that predates the release of Scribus 1.3.2
for which a new license (GPL+exception) is in place.
*/
#include "scplugin.h"
#include "deferredtask.h"
#include "scribus.h"
#include "scribusapp.h"
#include "prefspanel.h"
#include "selection.h"
//=====================================================//
// ScPlugin //
//=====================================================//
ScPlugin::ScPlugin()
: QObject(0)
{
}
ScPlugin::~ScPlugin()
{
}
bool ScPlugin::newPrefsPanelWidget( QWidget* /* parent */,
PrefsPanel*& /* panel */,
QString& /* caption */,
QPixmap& /* icon */)
{
return false;
}
const QString & ScPlugin::lastError() const
{
return m_lastError;
}
bool ScPlugin::hasLastError() const
{
return (!m_lastError.isEmpty());
}
void ScPlugin::clearLastError()
{
m_lastError.clear();
}
const QString ScPlugin::pluginTypeName() const
{
// These tests must be in reverse order of inheritance,
// ie most specific to least specific.
if (inherits("LoadSavePlugin"))
return tr("Load/Save/Import/Export");
else if (inherits("ScPersistentPlugin"))
return tr("Persistent", "plugin manager plugin type");
else if (inherits("ScActionPlugin"))
return tr("Action", "plugin manager plugin type");
else
{
qDebug("Unknown plugin type: %s", metaObject()->className());
return tr("Unknown");
}
}
void ScPlugin::setDoc(ScribusDoc* )
{
}
void ScPlugin::unsetDoc()
{
}
void ScPlugin::changedDoc(ScribusDoc* )
{
}
//=====================================================//
// ScActionPlugin //
//=====================================================//
ScActionPlugin::ScActionPlugin() : ScPlugin()
{
m_actionInfo.name = "";
m_actionInfo.text = "";
m_actionInfo.keySequence = "";
m_actionInfo.menu = "";
m_actionInfo.menuAfterName = "";
m_actionInfo.parentMenu = "";
m_actionInfo.subMenuName = "";
m_actionInfo.toolbar = "";
m_actionInfo.toolBarName = "";
m_actionInfo.icon1 = QPixmap();
m_actionInfo.icon2 = QPixmap();
m_actionInfo.notSuitableFor.clear();
m_actionInfo.forAppMode.clear();
m_actionInfo.needsNumObjects = -1;
m_actionInfo.firstObjectType.clear();
m_actionInfo.secondObjectType.clear();
m_actionInfo.enabledOnStartup = false;
m_actionInfo.enabledForStoryEditor = false;
m_actionInfo.seMenu = "";
m_actionInfo.seParentMenu = "";
m_actionInfo.seKeySequence = "";
}
ScActionPlugin::~ScActionPlugin()
{
}
// Stub for plugins that don't implement this method to inherit
bool ScActionPlugin::run(ScribusDoc* /*doc*/, QIODevice* /* target */)
{
return false;
}
bool ScActionPlugin::run(QWidget *, ScribusDoc* /*doc*/, QString /* target */)
{
return false;
}
// Stub for plugins that don't implement this method to inherit
DeferredTask* ScActionPlugin::runAsync(QString /* target */)
{
return 0;
}
// Stub for plugins that don't implement this method to inherit
DeferredTask* ScActionPlugin::runAsync(QIODevice* /* target */)
{
return 0;
}
// Legacy code support; avoid relying on in new code.
const QString & ScActionPlugin::runResult() const
{
return m_runResult;
}
const ScActionPlugin::ActionInfo & ScActionPlugin::actionInfo() const
{
Q_ASSERT(!m_actionInfo.text.isNull());
return m_actionInfo;
}
bool ScActionPlugin::handleSelection(ScribusDoc* doc, int SelectedType)
{
const uint docSelectionCount=doc->m_Selection->count();
ActionInfo ai(actionInfo());
if (SelectedType != -1)
{
bool correctAppMode = false;
if (ai.forAppMode.count() == 0)
correctAppMode = true;
else if (ai.forAppMode.contains(doc->appMode))
correctAppMode = true;
if (correctAppMode)
{
if (ai.needsNumObjects == -1)
return true;
else
{
if (ai.needsNumObjects > 2)
{
bool setter = true;
for (uint bx = 0; bx < docSelectionCount; ++bx)
{
if (ai.notSuitableFor.contains(doc->m_Selection->itemAt(bx)->itemType()))
setter = false;
}
return setter;
}
else
{
if (docSelectionCount == static_cast<uint>(ai.needsNumObjects))
{
if (ai.needsNumObjects == 2)
{
int sel1 = doc->m_Selection->itemAt(0)->itemType();
int sel2 = doc->m_Selection->itemAt(1)->itemType();
if (ai.notSuitableFor.contains(sel1))
return false;
else if (ai.notSuitableFor.contains(sel2))
return false;
else
{
if ((ai.firstObjectType.count() == 0) && (ai.secondObjectType.count() == 0))
return true;
else if ((ai.firstObjectType.count() == 0) && (ai.secondObjectType.count() != 0))
{
if ((ai.secondObjectType.contains(sel2)) || (ai.secondObjectType.contains(sel1)))
return true;
}
else if ((ai.firstObjectType.count() != 0) && (ai.secondObjectType.count() == 0))
{
if ((ai.firstObjectType.contains(sel2)) || (ai.firstObjectType.contains(sel1)))
return true;
}
if (((ai.firstObjectType.contains(sel1)) && (ai.secondObjectType.contains(sel2))) || ((ai.firstObjectType.contains(sel2)) && (ai.secondObjectType.contains(sel1))))
return true;
}
}
else if (!ai.notSuitableFor.contains(SelectedType))
return true;
else
return false;
}
else
return false;
}
}
}
else
return false;
}
else
{
bool correctAppMode = false;
if (ai.forAppMode.count() == 0)
correctAppMode = true;
else if (ai.forAppMode.contains(doc->appMode))
correctAppMode = true;
if (correctAppMode)
{
if ((ai.needsNumObjects == -1) || (ai.needsNumObjects > 2))
return true;
else
return false;
}
else
return false;
}
return false;
}
//=====================================================//
// ScActionPlugin //
//=====================================================//
ScPersistentPlugin::ScPersistentPlugin()
: ScPlugin()
{
}
ScPersistentPlugin::~ScPersistentPlugin()
{
}
|