~ubuntu-branches/ubuntu/maverick/scribus-ng/maverick-backports

« back to all changes in this revision

Viewing changes to scribus/editformats.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Oleksandr Moskalenko
  • Date: 2009-02-09 09:25:18 UTC
  • mfrom: (5.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20090209092518-iqsxmh3pjspgrdyd
Tags: 1.3.5.dfsg~svn20090208-2
debian/control: Use "type-handling -n arm,armel,armeb any" to generate the
list of architectures to build on.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
*/
7
 
#include "editformats.h"
8
 
#include "editformats.moc"
9
 
#include "edit1format.h"
10
 
#include <qmessagebox.h>
11
 
#include <qheader.h>
12
 
 
13
 
#include "commonstrings.h"
14
 
#include "scribusdoc.h"
15
 
#include "customfdialog.h"
16
 
#include "prefsmanager.h"
17
 
#include "prefsfile.h"
18
 
#include "fileloader.h"
19
 
#include "page.h"
20
 
#include "sccombobox.h"
21
 
#include "util.h"
22
 
 
23
 
extern QPixmap loadIcon(QString nam);
24
 
 
25
 
 
26
 
DelStyle::DelStyle(QWidget* parent, StyleSet<ParagraphStyle>& sty, QString styleName)
27
 
                : QDialog( parent, "DelStyle", true, 0 )
28
 
{
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"));
44
 
 
45
 
        // sort the names in language specific order (PV)
46
 
        QStringList existingStyles;
47
 
        for (uint x = 0; x < sty.count(); ++x)
48
 
        {
49
 
                if (sty[x].name() != styleName)
50
 
                        existingStyles.append(sty[x].name());
51
 
        }
52
 
        existingStyles = sortQStringList(existingStyles);
53
 
        replacementStyleData->insertStringList(existingStyles);
54
 
 
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());
70
 
 
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) ) );
74
 
}
75
 
 
76
 
void DelStyle::ReplaceStyle(int id)
77
 
{
78
 
        replacementStyle = replacementStyleData->text(id);
79
 
}
80
 
 
81
 
const QString DelStyle::getReplacementStyle()
82
 
{
83
 
        return replacementStyle;
84
 
}
85
 
 
86
 
ChooseStyles::ChooseStyles( QWidget* parent, StyleSet<ParagraphStyle> *styleList, StyleSet<ParagraphStyle> *styleOld)
87
 
                : QDialog( parent, "ChooseStyles", true, 0 )
88
 
{
89
 
        setCaption( tr( "Choose Styles" ) );
90
 
        setIcon(loadIcon("AppIcon.png"));
91
 
        ChooseStylesLayout = new QVBoxLayout( this, 10, 5, "ChooseStylesLayout");
92
 
        StyleView = new QListView( this, "StyleView" );
93
 
        StyleView->clear();
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);
98
 
        int counter = 0;
99
 
//      bool tabEQ = false;
100
 
        for (uint x = 0; x < styleList->count(); ++x)
101
 
        {
102
 
                ParagraphStyle& vg ((*styleList)[x]);
103
 
                const ParagraphStyle* vg2 = static_cast<const ParagraphStyle*>(styleOld->resolve(vg.name()));
104
 
                bool found = vg2 && vg.equiv(*vg2);
105
 
                if (!found)
106
 
                {
107
 
                        if (vg2)
108
 
                                vg.setName("Copy of "+vg2->name());
109
 
                        QCheckListItem *item = new QCheckListItem (StyleView, vg.name(), QCheckListItem::CheckBox);
110
 
                        item->setOn(true);
111
 
                        storedStyles.insert(item, counter);
112
 
                }
113
 
                qDebug(QString("load styles: found %1 dup %2 equiv %3").arg(vg.name()).arg((ulong)vg2).arg(found));
114
 
                counter++;
115
 
        }
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 );
126
 
        resize(230, 280);
127
 
        clearWState( WState_Polished );
128
 
        connect(CancelButton, SIGNAL(clicked()), this, SLOT(reject()));
129
 
        connect(OkButton, SIGNAL(clicked()), this, SLOT(accept()));
130
 
}
131
 
 
132
 
StilFormate::StilFormate( QWidget* parent, ScribusDoc *doc) : QDialog( parent, "Formate", true, 0)
133
 
{
134
 
        resize( 327, 260 );
135
 
        setCaption( tr( "Edit Styles" ) );
136
 
        setIcon(loadIcon("AppIcon.png"));
137
 
        Docu = doc;
138
 
        ReplaceList.clear();
139
 
        StilFormateLayout = new QHBoxLayout( this );
140
 
        StilFormateLayout->setSpacing( 5 );
141
 
        StilFormateLayout->setMargin( 10 );
142
 
 
143
 
        ListBox1 = new QListBox( this, "ListBox1" );
144
 
        ListBox1->setMinimumSize( QSize( 200, 240 ) );
145
 
        StilFormateLayout->addWidget( ListBox1 );
146
 
 
147
 
        Layout15 = new QVBoxLayout;
148
 
        Layout15->setSpacing( 6 );
149
 
        Layout15->setMargin( 0 );
150
 
 
151
 
        LoadS = new QPushButton( tr( "&Import" ), this, "LoadF" );
152
 
        Layout15->addWidget( LoadS );
153
 
 
154
 
        NewB = new QPushButton( tr( "&New" ), this, "NewB" );
155
 
        Layout15->addWidget( NewB );
156
 
 
157
 
        EditB = new QPushButton( tr( "&Edit" ), this, "EditB" );
158
 
        EditB->setDefault( true );
159
 
        EditB->setEnabled(false);
160
 
        Layout15->addWidget( EditB );
161
 
 
162
 
        DublicateB = new QPushButton( tr( "D&uplicate" ), this, "DublicateB" );
163
 
        DublicateB->setEnabled(false);
164
 
        Layout15->addWidget( DublicateB );
165
 
 
166
 
        DeleteB = new QPushButton( tr( "&Delete" ), this, "DeleteB" );
167
 
        DeleteB->setEnabled(false);
168
 
        Layout15->addWidget( DeleteB );
169
 
 
170
 
        SaveB = new QPushButton( CommonStrings::tr_Save, this, "SaveB" );
171
 
        Layout15->addWidget( SaveB );
172
 
 
173
 
        ExitB = new QPushButton( CommonStrings::tr_OK, this, "ExitB" );
174
 
        Layout15->addWidget( ExitB );
175
 
 
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 );
181
 
 
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*)));
193
 
        TempVorl.clear();
194
 
        TempVorl.redefine(doc->paragraphStyles());
195
 
        UpdateFList();
196
 
}
197
 
 
198
 
void StilFormate::saveIt()
199
 
{
200
 
        emit saveStyle(this);
201
 
}
202
 
 
203
 
void StilFormate::selFormat(QListBoxItem *c)
204
 
{
205
 
        for (uint x = 0; x < TempVorl.count(); ++x)
206
 
        {
207
 
                if (TempVorl[x].name() == c->text())
208
 
                {
209
 
                        sFnumber = x;
210
 
                        break;
211
 
                }
212
 
        }
213
 
        EditB->setEnabled(true);
214
 
        DublicateB->setEnabled(true);
215
 
        DeleteB->setEnabled(true);
216
 
}
217
 
 
218
 
void StilFormate::selEditFormat(QListBoxItem *c)
219
 
{
220
 
        for (uint x = 0; x < TempVorl.count(); ++x)
221
 
        {
222
 
                if (TempVorl[x].name() == c->text())
223
 
                {
224
 
                        sFnumber = x;
225
 
                        break;
226
 
                }
227
 
        }
228
 
        EditB->setEnabled(true);
229
 
        DublicateB->setEnabled(true);
230
 
        DeleteB->setEnabled(true);
231
 
        editFormat();
232
 
}
233
 
 
234
 
void StilFormate::dupFormat()
235
 
{
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);
242
 
        if (!dia2->exec())
243
 
                TempVorl.remove(sFnumber);
244
 
        delete dia2;
245
 
        UpdateFList();
246
 
}
247
 
 
248
 
void StilFormate::neuesFormat()
249
 
{
250
 
        int selectedIndex=ListBox1->currentItem();
251
 
        int topIndex=ListBox1->topItem();
252
 
        ParagraphStyle sty;
253
 
        sty.setName( tr("New Style"));
254
 
        /*
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);
263
 
        sty.setGapBefore(0);
264
 
        sty.setGapAfter(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);
287
 
         */
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);
291
 
        if (!dia2->exec())
292
 
                TempVorl.remove(sFnumber);
293
 
        delete dia2;
294
 
        UpdateFList();
295
 
        ListBox1->setSelected(selectedIndex, true);
296
 
        ListBox1->setTopItem(topIndex);
297
 
}
298
 
 
299
 
void StilFormate::editFormat()
300
 
{
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);
305
 
        dia->exec();
306
 
        delete dia;
307
 
        UpdateFList();
308
 
        ListBox1->setSelected(selectedIndex, true);
309
 
        ListBox1->setTopItem(topIndex);
310
 
}
311
 
 
312
 
void StilFormate::deleteFormat()
313
 
{
314
 
/*      int exit=QMessageBox::warning(this,
315
 
                                      CommonStrings::trWarning,
316
 
                                      tr("Do you really want to delete this style?"),
317
 
                                      tr("No"),
318
 
                                      tr("Yes"),
319
 
                                      0, 0, 0); */
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 */
322
 
//      if (exit == 1)
323
 
        int selectedIndex=ListBox1->currentItem();
324
 
        int topIndex=ListBox1->topItem();
325
 
        DelStyle *dia = new DelStyle(this, TempVorl, TempVorl[sFnumber].name());
326
 
        if (dia->exec())
327
 
        {
328
 
                if (ReplaceList.values().contains(TempVorl[sFnumber].name()))
329
 
                {
330
 
                        QMap<QString,QString>::Iterator it;
331
 
                        for (it = ReplaceList.begin(); it != ReplaceList.end(); ++it)
332
 
                        {
333
 
                                if (it.data() == TempVorl[sFnumber].name())
334
 
                                        it.data() = dia->getReplacementStyle();
335
 
                        }
336
 
                }
337
 
                ReplaceList.insert(TempVorl[sFnumber].name(), dia->getReplacementStyle());
338
 
                ListBox1->removeItem(sFnumber);
339
 
                // this might be unsafe...
340
 
                TempVorl.remove(sFnumber);
341
 
                UpdateFList();
342
 
        }
343
 
        delete dia;
344
 
        int listBoxCount=ListBox1->count();
345
 
        if (listBoxCount>selectedIndex)
346
 
                ListBox1->setSelected(selectedIndex, true);
347
 
        if (listBoxCount>topIndex)
348
 
                ListBox1->setTopItem(topIndex);
349
 
}
350
 
 
351
 
void StilFormate::loadStyles()
352
 
{
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)
357
 
        {
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);
363
 
                if (dia2->exec())
364
 
                {
365
 
                        QStringList neededColors;
366
 
                        neededColors.clear();
367
 
                        QMap<QCheckListItem*, int>::Iterator it;
368
 
                        for (it = dia2->storedStyles.begin(); it != dia2->storedStyles.end(); ++it)
369
 
                        {
370
 
                                const ParagraphStyle& sty(TempVorl2[it.data()]);
371
 
                                if (it.key()->isOn())
372
 
                                {
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());
380
 
                                }
381
 
                        }
382
 
                        if (!neededColors.isEmpty())
383
 
                        {
384
 
                                FileLoader fl(selectedFile);
385
 
                                if (fl.TestFile() == -1)
386
 
                                //TODO put in nice user warning
387
 
                                        return;
388
 
                                ColorList LColors;
389
 
                                if (fl.ReadColors(selectedFile, LColors))
390
 
                                {
391
 
                                        ColorList::Iterator itc;
392
 
                                        for (itc = LColors.begin(); itc != LColors.end(); ++itc)
393
 
                                        {
394
 
                                                if (neededColors.contains(itc.key()))
395
 
                                                        Docu->PageColors.insert(itc.key(), itc.data());
396
 
                                        }
397
 
                                }
398
 
                        }
399
 
                }
400
 
                delete dia2;
401
 
//              TempVorl.redefine(TempVorl2, false);
402
 
                UpdateFList();
403
 
        }
404
 
        else
405
 
                return;
406
 
}
407
 
 
408
 
void StilFormate::UpdateFList()
409
 
{
410
 
        ListBox1->clear();
411
 
        if (TempVorl.count() == 0)
412
 
                return;
413
 
        for (uint x = 0; x < TempVorl.count(); ++x)
414
 
                ListBox1->insertItem(TempVorl[x].name());
415
 
        if (ListBox1->currentItem() == -1)
416
 
        {
417
 
                DublicateB->setEnabled(false);
418
 
                EditB->setEnabled(false);
419
 
                DeleteB->setEnabled(false);
420
 
        }
421
 
        ListBox1->sort( true );
422
 
        ListBox1->setSelected(ListBox1->currentItem(), false);
423
 
}