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.
7
#include "editformats.h"
8
#include "editformats.moc"
9
#include "edit1format.h"
10
#include <qmessagebox.h>
13
#include "commonstrings.h"
14
#include "scribusdoc.h"
15
#include "customfdialog.h"
16
#include "prefsmanager.h"
17
#include "prefsfile.h"
18
#include "fileloader.h"
20
#include "sccombobox.h"
23
extern QPixmap loadIcon(QString nam);
26
DelStyle::DelStyle(QWidget* parent, StyleSet<ParagraphStyle>& sty, QString styleName)
27
: QDialog( parent, "DelStyle", true, 0 )
29
setName( "DelStyle" );
30
setCaption( tr( "Delete Style" ) );
31
setIcon(loadIcon("AppIcon.png"));
32
dialogLayout = new QVBoxLayout( this, 10, 5 );
33
delStyleLayout = new QGridLayout;
34
delStyleLayout->setSpacing( 5 );
35
delStyleLayout->setMargin( 5 );
36
deleteLabel = new QLabel( tr( "Delete Style:" ), this, "deleteLabel" );
37
delStyleLayout->addWidget( deleteLabel, 0, 0 );
38
styleToDelLabel = new QLabel( styleName, this, "colorToDelLabel" );
39
delStyleLayout->addWidget( styleToDelLabel, 0, 1 );
40
replaceLabel = new QLabel( tr( "Replace With:" ), this, "replaceLabel" );
41
delStyleLayout->addWidget( replaceLabel, 1, 0 );
42
replacementStyleData = new ScComboBox(false, this);
43
replacementStyleData->insertItem( tr("No Style"));
45
// sort the names in language specific order (PV)
46
QStringList existingStyles;
47
for (uint x = 0; x < sty.count(); ++x)
49
if (sty[x].name() != styleName)
50
existingStyles.append(sty[x].name());
52
existingStyles = sortQStringList(existingStyles);
53
replacementStyleData->insertStringList(existingStyles);
55
delStyleLayout->addWidget( replacementStyleData, 1, 1 );
56
replacementStyle = replacementStyleData->text(0);
57
dialogLayout->addLayout( delStyleLayout );
58
okCancelLayout = new QHBoxLayout;
59
okCancelLayout->setSpacing( 6 );
60
okCancelLayout->setMargin( 0 );
61
QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
62
okCancelLayout->addItem( spacer );
63
okButton = new QPushButton( CommonStrings::tr_OK, this, "okButton" );
64
okCancelLayout->addWidget( okButton );
65
cancelButton = new QPushButton( CommonStrings::tr_Cancel, this, "PushButton13" );
66
cancelButton->setDefault( true );
67
okCancelLayout->addWidget( cancelButton );
68
dialogLayout->addLayout( okCancelLayout );
69
setMaximumSize(sizeHint());
71
connect( okButton, SIGNAL( clicked() ), this, SLOT( accept() ) );
72
connect( cancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) );
73
connect( replacementStyleData, SIGNAL(activated(int)), this, SLOT( ReplaceStyle(int) ) );
76
void DelStyle::ReplaceStyle(int id)
78
replacementStyle = replacementStyleData->text(id);
81
const QString DelStyle::getReplacementStyle()
83
return replacementStyle;
86
ChooseStyles::ChooseStyles( QWidget* parent, StyleSet<ParagraphStyle> *styleList, StyleSet<ParagraphStyle> *styleOld)
87
: QDialog( parent, "ChooseStyles", true, 0 )
89
setCaption( tr( "Choose Styles" ) );
90
setIcon(loadIcon("AppIcon.png"));
91
ChooseStylesLayout = new QVBoxLayout( this, 10, 5, "ChooseStylesLayout");
92
StyleView = new QListView( this, "StyleView" );
94
StyleView->addColumn( tr( "Available Styles" ) );
95
StyleView->header()->setClickEnabled( false, StyleView->header()->count() - 1 );
96
StyleView->header()->setResizeEnabled( false, StyleView->header()->count() - 1 );
97
StyleView->setSorting(-1);
99
// bool tabEQ = false;
100
for (uint x = 0; x < styleList->count(); ++x)
102
ParagraphStyle& vg ((*styleList)[x]);
103
const ParagraphStyle* vg2 = static_cast<const ParagraphStyle*>(styleOld->resolve(vg.name()));
104
bool found = vg2 && vg.equiv(*vg2);
108
vg.setName("Copy of "+vg2->name());
109
QCheckListItem *item = new QCheckListItem (StyleView, vg.name(), QCheckListItem::CheckBox);
111
storedStyles.insert(item, counter);
113
qDebug(QString("load styles: found %1 dup %2 equiv %3").arg(vg.name()).arg((ulong)vg2).arg(found));
116
StyleView->setSorting(0);
117
ChooseStylesLayout->addWidget( StyleView );
118
layout2 = new QHBoxLayout( 0, 0, 5, "layout2");
119
QSpacerItem* spacer1 = new QSpacerItem( 71, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
120
layout2->addItem( spacer1 );
121
OkButton = new QPushButton( CommonStrings::tr_OK, this, "OkButton" );
122
layout2->addWidget( OkButton );
123
CancelButton = new QPushButton( CommonStrings::tr_Cancel, this, "CancelButton" );
124
layout2->addWidget( CancelButton );
125
ChooseStylesLayout->addLayout( layout2 );
127
clearWState( WState_Polished );
128
connect(CancelButton, SIGNAL(clicked()), this, SLOT(reject()));
129
connect(OkButton, SIGNAL(clicked()), this, SLOT(accept()));
132
StilFormate::StilFormate( QWidget* parent, ScribusDoc *doc) : QDialog( parent, "Formate", true, 0)
135
setCaption( tr( "Edit Styles" ) );
136
setIcon(loadIcon("AppIcon.png"));
139
StilFormateLayout = new QHBoxLayout( this );
140
StilFormateLayout->setSpacing( 5 );
141
StilFormateLayout->setMargin( 10 );
143
ListBox1 = new QListBox( this, "ListBox1" );
144
ListBox1->setMinimumSize( QSize( 200, 240 ) );
145
StilFormateLayout->addWidget( ListBox1 );
147
Layout15 = new QVBoxLayout;
148
Layout15->setSpacing( 6 );
149
Layout15->setMargin( 0 );
151
LoadS = new QPushButton( tr( "&Import" ), this, "LoadF" );
152
Layout15->addWidget( LoadS );
154
NewB = new QPushButton( tr( "&New" ), this, "NewB" );
155
Layout15->addWidget( NewB );
157
EditB = new QPushButton( tr( "&Edit" ), this, "EditB" );
158
EditB->setDefault( true );
159
EditB->setEnabled(false);
160
Layout15->addWidget( EditB );
162
DublicateB = new QPushButton( tr( "D&uplicate" ), this, "DublicateB" );
163
DublicateB->setEnabled(false);
164
Layout15->addWidget( DublicateB );
166
DeleteB = new QPushButton( tr( "&Delete" ), this, "DeleteB" );
167
DeleteB->setEnabled(false);
168
Layout15->addWidget( DeleteB );
170
SaveB = new QPushButton( CommonStrings::tr_Save, this, "SaveB" );
171
Layout15->addWidget( SaveB );
173
ExitB = new QPushButton( CommonStrings::tr_OK, this, "ExitB" );
174
Layout15->addWidget( ExitB );
176
CancelB = new QPushButton( CommonStrings::tr_Cancel, this, "CancelB" );
177
Layout15->addWidget( CancelB );
178
QSpacerItem* spacer = new QSpacerItem( 0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding );
179
Layout15->addItem( spacer );
180
StilFormateLayout->addLayout( Layout15 );
182
// signals and slots connections
183
connect(CancelB, SIGNAL(clicked()), this, SLOT(reject()));
184
connect(SaveB, SIGNAL(clicked()), this, SLOT(saveIt()));
185
connect(ExitB, SIGNAL(clicked()), this, SLOT(accept()));
186
connect(EditB, SIGNAL(clicked()), this, SLOT(editFormat()));
187
connect(NewB, SIGNAL(clicked()), this, SLOT(neuesFormat()));
188
connect(LoadS, SIGNAL(clicked()), this, SLOT(loadStyles()));
189
connect(DublicateB, SIGNAL(clicked()), this, SLOT(dupFormat()));
190
connect(DeleteB, SIGNAL(clicked()), this, SLOT(deleteFormat()));
191
connect(ListBox1, SIGNAL(highlighted(QListBoxItem*)), this, SLOT(selFormat(QListBoxItem*)));
192
connect(ListBox1, SIGNAL(selected(QListBoxItem*)), this, SLOT(selEditFormat(QListBoxItem*)));
194
TempVorl.redefine(doc->paragraphStyles());
198
void StilFormate::saveIt()
200
emit saveStyle(this);
203
void StilFormate::selFormat(QListBoxItem *c)
205
for (uint x = 0; x < TempVorl.count(); ++x)
207
if (TempVorl[x].name() == c->text())
213
EditB->setEnabled(true);
214
DublicateB->setEnabled(true);
215
DeleteB->setEnabled(true);
218
void StilFormate::selEditFormat(QListBoxItem *c)
220
for (uint x = 0; x < TempVorl.count(); ++x)
222
if (TempVorl[x].name() == c->text())
228
EditB->setEnabled(true);
229
DublicateB->setEnabled(true);
230
DeleteB->setEnabled(true);
234
void StilFormate::dupFormat()
236
ParagraphStyle * sty = new ParagraphStyle(TempVorl[sFnumber]);
237
sty->setName( tr("Copy of %1").arg(TempVorl[sFnumber].name()));
238
TempVorl.append(sty);
239
sFnumber = TempVorl.count()-1;
240
EditStyle* dia2 = new EditStyle(this, &TempVorl[sFnumber], TempVorl, true,
241
static_cast<double>(Docu->typographicSettings.autoLineSpacing), Docu->unitIndex(), Docu);
243
TempVorl.remove(sFnumber);
248
void StilFormate::neuesFormat()
250
int selectedIndex=ListBox1->currentItem();
251
int topIndex=ListBox1->topItem();
253
sty.setName( tr("New Style"));
255
sty.setLineSpacingMode(static_cast<ParagraphStyle::LineSpacingMode>(0));
256
sty.setLineSpacing(((Docu->toolSettings.defSize / 10.0) *
257
static_cast<double>(Docu->typographicSettings.autoLineSpacing) / 100)
258
+ (Docu->toolSettings.defSize / 10.0));
259
sty.setAlignment(ParagraphStyle::Leftaligned);
260
sty.setLeftMargin(0);
261
sty.setRightMargin(0);
262
sty.setFirstIndent(0);
265
sty.charStyle() = CharStyle(PrefsManager::instance()->appPrefs.AvailFonts[Docu->toolSettings.defFont],
266
Docu->toolSettings.defSize);
267
// sty.tabValues().clear();
268
sty.setHasDropCap(false);
269
sty.setDropCapLines(2);
270
sty.setDropCapOffset(0);
271
sty.charStyle().setFillColor(Docu->toolSettings.dPenText);
272
sty.charStyle().setFillShade(Docu->toolSettings.dTextPenShade);
273
sty.charStyle().setStrokeColor(Docu->toolSettings.dStrokeText);
274
sty.charStyle().setStrokeShade(Docu->toolSettings.dTextStrokeShade);
275
sty.setUseBaselineGrid(false);
276
sty.charStyle().setShadowXOffset(50);
277
sty.charStyle().setShadowYOffset(-50);
278
sty.charStyle().setOutlineWidth(10);
279
sty.charStyle().setUnderlineOffset(Docu->typographicSettings.valueUnderlinePos);
280
sty.charStyle().setUnderlineWidth(Docu->typographicSettings.valueUnderlineWidth);
281
sty.charStyle().setStrikethruOffset(Docu->typographicSettings.valueStrikeThruPos);
282
sty.charStyle().setStrikethruWidth(Docu->typographicSettings.valueStrikeThruPos);
283
sty.charStyle().setScaleH(1000);
284
sty.charStyle().setScaleV(1000);
285
sty.charStyle().setBaselineOffset(0);
286
sty.charStyle().setTracking(0);
288
TempVorl.create(sty);
289
sFnumber = TempVorl.count()-1;
290
EditStyle* dia2 = new EditStyle(this, &TempVorl[sFnumber], TempVorl, true, static_cast<double>(Docu->typographicSettings.autoLineSpacing), Docu->unitIndex(), Docu);
292
TempVorl.remove(sFnumber);
295
ListBox1->setSelected(selectedIndex, true);
296
ListBox1->setTopItem(topIndex);
299
void StilFormate::editFormat()
301
int selectedIndex=ListBox1->currentItem();
302
int topIndex=ListBox1->topItem();
303
EditStyle* dia = new EditStyle(this, &TempVorl[sFnumber], TempVorl, false,
304
static_cast<double>(Docu->typographicSettings.autoLineSpacing), Docu->unitIndex(), Docu);
308
ListBox1->setSelected(selectedIndex, true);
309
ListBox1->setTopItem(topIndex);
312
void StilFormate::deleteFormat()
314
/* int exit=QMessageBox::warning(this,
315
CommonStrings::trWarning,
316
tr("Do you really want to delete this style?"),
320
/* PFJ - 29.02.04 - Altered to use the correct QMessageBox value. It was 1 */
321
/* FS - 13.03.04 the 1 is correct in this version of QMessageBox, it returns the Nr of the clicked Button either 0 or 1 or 2 */
323
int selectedIndex=ListBox1->currentItem();
324
int topIndex=ListBox1->topItem();
325
DelStyle *dia = new DelStyle(this, TempVorl, TempVorl[sFnumber].name());
328
if (ReplaceList.values().contains(TempVorl[sFnumber].name()))
330
QMap<QString,QString>::Iterator it;
331
for (it = ReplaceList.begin(); it != ReplaceList.end(); ++it)
333
if (it.data() == TempVorl[sFnumber].name())
334
it.data() = dia->getReplacementStyle();
337
ReplaceList.insert(TempVorl[sFnumber].name(), dia->getReplacementStyle());
338
ListBox1->removeItem(sFnumber);
339
// this might be unsafe...
340
TempVorl.remove(sFnumber);
344
int listBoxCount=ListBox1->count();
345
if (listBoxCount>selectedIndex)
346
ListBox1->setSelected(selectedIndex, true);
347
if (listBoxCount>topIndex)
348
ListBox1->setTopItem(topIndex);
351
void StilFormate::loadStyles()
353
PrefsContext* dirs = PrefsManager::instance()->prefsFile->getContext("dirs");
354
QString wdir = dirs->get("editformats", ".");
355
CustomFDialog dia(this, wdir, tr("Open"), tr("Documents (*.sla *.sla.gz *.scd *.scd.gz);;All Files (*)"));
356
if (dia.exec() == QDialog::Accepted)
358
QString selectedFile = dia.selectedFile();
359
dirs->set("editformats", selectedFile.left(selectedFile.findRev("/")));
360
StyleSet<ParagraphStyle> TempVorl2;
361
Docu->loadStylesFromFile(selectedFile, &TempVorl2);
362
ChooseStyles* dia2 = new ChooseStyles(this, &TempVorl2, &TempVorl);
365
QStringList neededColors;
366
neededColors.clear();
367
QMap<QCheckListItem*, int>::Iterator it;
368
for (it = dia2->storedStyles.begin(); it != dia2->storedStyles.end(); ++it)
370
const ParagraphStyle& sty(TempVorl2[it.data()]);
371
if (it.key()->isOn())
373
// sty = TempVorl2[it.data()];
374
qDebug(QString("load style %1").arg(sty.name()));
375
TempVorl.create(sty);
376
if ((!Docu->PageColors.contains(sty.charStyle().strokeColor())) && (!neededColors.contains(sty.charStyle().strokeColor())))
377
neededColors.append(sty.charStyle().strokeColor());
378
if ((!Docu->PageColors.contains(sty.charStyle().fillColor())) && (!neededColors.contains(sty.charStyle().fillColor())))
379
neededColors.append(sty.charStyle().fillColor());
382
if (!neededColors.isEmpty())
384
FileLoader fl(selectedFile);
385
if (fl.TestFile() == -1)
386
//TODO put in nice user warning
389
if (fl.ReadColors(selectedFile, LColors))
391
ColorList::Iterator itc;
392
for (itc = LColors.begin(); itc != LColors.end(); ++itc)
394
if (neededColors.contains(itc.key()))
395
Docu->PageColors.insert(itc.key(), itc.data());
401
// TempVorl.redefine(TempVorl2, false);
408
void StilFormate::UpdateFList()
411
if (TempVorl.count() == 0)
413
for (uint x = 0; x < TempVorl.count(); ++x)
414
ListBox1->insertItem(TempVorl[x].name());
415
if (ListBox1->currentItem() == -1)
417
DublicateB->setEnabled(false);
418
EditB->setEnabled(false);
419
DeleteB->setEnabled(false);
421
ListBox1->sort( true );
422
ListBox1->setSelected(ListBox1->currentItem(), false);