Subversion Repositories Scribus

Rev

Rev 4603 | Rev 4786 | 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
*/
4070 subik 7
#include "scribus.h"
8
#include "sampleitem.h"
9
#include "loremipsum.h"
4077 subik 10
#include "scribusdoc.h"
4150 subik 11
#include "undomanager.h"
4546 subik 12
#include "commonstrings.h"
4070 subik 13
#include <qcolor.h>
14
#include <qstring.h>
15
 
16
extern ScribusMainWindow* ScMW;
17
 
18
 
4077 subik 19
SampleItem::SampleItem() : QObject()
4070 subik 20
{
4077 subik 21
        used = true;
22
        if (ScMW->doc == NULL)
23
        {
4150 subik 24
                ScMW->doFileNew(//pageWidth, pageHeight,
4077 subik 25
                                                                        0,0,
26
                                                                        //topMargin, leftMargin, rightMargin, bottomMargin,
27
                                                                        1, 1, 1, 1,
28
                                                                        // autoframes. It's disabled in python
29
                                                                        // columnDistance, numberCols, autoframes,
30
                                                                        0, 1, false,
31
                                                                        //pagesType, unit, firstPageOrder,
32
                                                                        1, 1, 1,
33
                                                                        //orientation, firstPageNr, "Custom");
34
                                                                        1, 1, "custom");
35
                ScMW->doc->pageSets[1/*pagesType*/].FirstPage = 1;//firstPageOrder;
36
                used = false;
37
        }
38
        doc = ScMW->doc;
4467 subik 39
        // tmp colors. to be removed in descrictor
40
        ScMW->doc->PageColors.insert("__blackforpreview__", ScColor(0, 0, 0, 255));
41
        ScMW->doc->PageColors.insert("__whiteforpreview__", ScColor(0, 0, 0, 0));
4614 fschmid 42
        ScMW->doc->PageColors.insert("__whiteforpreviewbg__", ScColor(0, 0, 0, 0));
43
        bgShade = 100;
4070 subik 44
        tmpStyle.Vname = "(preview temporary)";
45
        tmpStyle.LineSpaMode = 0;
4077 subik 46
        tmpStyle.LineSpa = ((doc->toolSettings.defSize / 10.0) * static_cast<double>(doc->typographicSettings.autoLineSpacing) / 100) + (doc->toolSettings.defSize / 10.0);
4070 subik 47
        tmpStyle.textAlignment = 0;
48
        tmpStyle.Indent = 0;
49
        tmpStyle.First = 0;
50
        tmpStyle.gapBefore = 0;
51
        tmpStyle.gapAfter = 0;
4077 subik 52
        tmpStyle.Font = doc->toolSettings.defFont;
53
        tmpStyle.FontSize = doc->toolSettings.defSize;
4070 subik 54
        tmpStyle.TabValues.clear();
55
        tmpStyle.Drop = false;
4467 subik 56
        tmpStyle.DropLin = 0;//2;
4070 subik 57
        tmpStyle.DropDist = 0;
58
        tmpStyle.FontEffect = 0;
4467 subik 59
        tmpStyle.FColor = "__blackforpreview__";
60
        tmpStyle.FShade = 100; //doc->toolSettings.dShade;
61
        tmpStyle.SColor = "__whiteforpreview__";
62
        tmpStyle.SShade = 100; //doc->toolSettings.dShade2;
4070 subik 63
        tmpStyle.BaseAdj = false;
64
        tmpStyle.txtShadowX = 50;
65
        tmpStyle.txtShadowY = -50;
66
        tmpStyle.txtOutline = 10;
4467 subik 67
        tmpStyle.txtUnderPos = 0; //doc->typographicSettings.valueUnderlinePos;
68
        tmpStyle.txtUnderWidth = 0; //doc->typographicSettings.valueUnderlineWidth;
69
        tmpStyle.txtStrikePos = 0; //doc->typographicSettings.valueStrikeThruPos;
70
        tmpStyle.txtStrikeWidth = 0; //doc->typographicSettings.valueStrikeThruPos;
4070 subik 71
        tmpStyle.scaleH = 1000;
72
        tmpStyle.scaleV = 1000;
73
        tmpStyle.baseOff = 0;
74
        tmpStyle.kernVal = 0;
75
}
76
 
77
SampleItem::~SampleItem()
78
{
4467 subik 79
        cleanupTemporary();
80
        // clean tmp document
4077 subik 81
        if (used == false)
82
        {
83
                doc->setModified(false);
4150 subik 84
                ScMW->slotFileClose();
4077 subik 85
        }
4070 subik 86
}
87
 
88
void SampleItem::setText(QString aText)
89
{
90
        text = aText;
91
}
92
 
93
void SampleItem::setLoremIpsum(int para)
94
{
95
        LoremParser *m = new LoremParser("loremipsum.xml");
96
        text = m->createLorem(para);
97
        text = QString::fromUtf8(text);
98
        delete m;
99
}
100
 
101
void SampleItem::setStyle(ParagraphStyle aStyle)
102
{
103
        tmpStyle = aStyle;
104
}
105
 
106
void SampleItem::setBgColor(QColor c)
107
{
4614 fschmid 108
        ScMW->doc->PageColors["__whiteforpreviewbg__"].fromQColor(c);
4070 subik 109
}
110
 
4614 fschmid 111
void SampleItem::setBgShade(int c)
112
{
113
        bgShade = c;
114
}
115
 
116
void SampleItem::setTxColor(QColor c)
117
{
118
        ScMW->doc->PageColors["__blackforpreview__"].fromQColor(c);
119
}
120
 
121
void SampleItem::setTxShade(int c)
122
{
123
        tmpStyle.FShade = c;
124
}
125
 
4070 subik 126
void SampleItem::setLineSpaMode(int lineSpaMode)
127
{
128
        tmpStyle.LineSpaMode = lineSpaMode;
129
}
130
 
131
void SampleItem::setLineSpa(double lineSpa)
132
{
133
        tmpStyle.LineSpa = lineSpa;
134
}
135
 
136
void SampleItem::setTextAlignment(int textAlignment)
137
{
138
        tmpStyle.textAlignment = textAlignment;
139
}
140
 
141
void SampleItem::setIndent(double indent)
142
{
143
        tmpStyle.Indent = indent;
144
}
145
 
146
void SampleItem::setFirst(double first)
147
{
148
        tmpStyle.First = first;
149
}
150
 
151
void SampleItem::setGapBefore(double gapBefore)
152
{
153
        tmpStyle.gapBefore = gapBefore;
154
}
155
 
156
void SampleItem::setGapAfter(double gapAfter)
157
{
158
        tmpStyle.gapAfter = gapAfter;
159
}
160
 
161
void SampleItem::setFont(QString font)
162
{
163
        tmpStyle.Font = font;
164
}
165
 
4077 subik 166
void SampleItem::setFontSize(int fontSize, bool autoLineSpa)
4070 subik 167
{
168
        tmpStyle.FontSize = fontSize;
4077 subik 169
        if (autoLineSpa)
170
                tmpStyle.LineSpa = ((fontSize / 10)  * (doc->typographicSettings.autoLineSpacing / 100) + (fontSize / 10));
4070 subik 171
}
172
 
173
/*void SampleItem::setTabValues(QValueList<PageItem::TabRecord> tabValues)
174
{
175
        tmpStyle.TabValues = tabValues;
176
}*/
177
 
178
void SampleItem::setDrop(bool drop)
179
{
180
        tmpStyle.Drop = drop;
181
}
182
 
183
void SampleItem::setDropLin(int dropLin)
184
{
185
        tmpStyle.DropLin = dropLin;
186
}
187
 
188
void SampleItem::setDropDist(double dropDist)
189
{
190
        tmpStyle.DropDist = dropDist;
191
}
192
 
193
void SampleItem::setFontEffect(int fontEffect)
194
{
195
        tmpStyle.FontEffect = fontEffect;
196
}
197
 
198
void SampleItem::setFColor(QString fColor)
199
{
200
        tmpStyle.FColor = fColor;
201
}
202
 
203
void SampleItem::setFShade(int fShade)
204
{
205
        tmpStyle.FShade = fShade;
206
}
207
 
208
void SampleItem::setSColor(QString sColor)
209
{
210
        tmpStyle.SColor = sColor;
211
}
212
 
213
void SampleItem::setSShade(int sShade)
214
{
215
        tmpStyle.SShade = sShade;
216
}
217
 
218
void SampleItem::setBaseAdj(bool baseAdj)
219
{
220
        tmpStyle.BaseAdj = baseAdj;
221
}
222
 
223
void SampleItem::setTxtShadowX(int txtShadowX)
224
{
225
        tmpStyle.txtShadowX = txtShadowX;
226
}
227
 
228
void SampleItem::setTxtShadowY(int txtShadowY)
229
{
230
        tmpStyle.txtShadowY = txtShadowY;
231
}
232
 
233
void SampleItem::setTxtOutline(int txtOutline)
234
{
235
        tmpStyle.txtOutline = txtOutline;
236
}
237
 
238
void SampleItem::setTxtUnderPos(int txtUnderPos)
239
{
240
        tmpStyle.txtUnderPos = txtUnderPos;
241
}
242
 
243
void SampleItem::setTxtUnderWidth(int txtUnderWidth)
244
{
245
        tmpStyle.txtUnderWidth = txtUnderWidth;
246
}
247
 
248
void SampleItem::setTxtStrikePos(int txtStrikePos)
249
{
250
        tmpStyle.txtStrikePos = txtStrikePos;
251
}
252
 
253
void SampleItem::setTxtStrikeWidth(int txtStrikeWidth)
254
{
255
        tmpStyle.txtStrikeWidth = txtStrikeWidth;
256
}
257
 
258
void SampleItem::setScaleH(int scaleH)
259
{
260
        tmpStyle.scaleH = scaleH;
261
}
262
 
263
void SampleItem::setScaleV(int scaleV)
264
{
265
        tmpStyle.scaleV = scaleV;
266
}
267
 
268
void SampleItem::setBaseOff(int baseOff)
269
{
270
        tmpStyle.baseOff = baseOff;
271
}
272
 
273
void SampleItem::setKernVal(int kernVal)
274
{
275
        tmpStyle.kernVal = kernVal;
276
}
277
 
278
QPixmap SampleItem::getSample(int width, int height)
279
{
4150 subik 280
        UndoManager::instance()->setUndoEnabled(false); // disable undo
281
 
4614 fschmid 282
        PageItem_TextFrame *previewItem = new PageItem_TextFrame(doc, 0, 0, width, height, 0, "__whiteforpreviewbg__", "__whiteforpreview__");
4070 subik 283
        QPixmap pm(width, height);
284
        ScPainter *painter = new ScPainter(&pm, width, height, 0, 0);
4374 subik 285
        double sca = 1.0; // original scale to set back at the end...
4459 subik 286
        int userAppMode = ScMW->doc->appMode; // We need to be in normal when creating/repainting items
287
        ScMW->doc->appMode = modeNormal;
4070 subik 288
 
4077 subik 289
        if (ScMW->view != NULL)
4374 subik 290
        {
4593 cbradney 291
                sca = ScMW->view->scale();
4374 subik 292
                ScMW->view->setScale(1.0);
293
        }
4077 subik 294
 
4070 subik 295
        QFont fo = QFont(tmpStyle.Font);
4077 subik 296
        fo.setPointSize(qRound(doc->toolSettings.defSize / 10.0));
297
        doc->AddFont(tmpStyle.Font, qRound(doc->toolSettings.defSize / 10.0));
298
        doc->docParagraphStyles.append(tmpStyle);
299
        int tmpIndex = doc->docParagraphStyles.count() - 1;
4070 subik 300
 
301
        previewItem->FrameType = PageItem::TextFrame;
302
        previewItem->itemText.clear();
4073 cbradney 303
        previewItem->setFont(tmpStyle.Font);
4070 subik 304
        previewItem->Cols = 1;
305
        for (uint i = 0; i < text.length(); ++i)
306
        {
307
                ScText *hg = new ScText;
308
                hg->ch = text.at(i);
309
                if ((hg->ch == QChar(10)) || (hg->ch == QChar(5)))
310
                        hg->ch = QChar(13);
311
                previewItem->itemText.append(hg);
312
        }
4459 subik 313
 
4584 cbradney 314
        doc->chAbStyle(previewItem, tmpIndex);
4614 fschmid 315
        previewItem->setFillColor("__whiteforpreviewbg__");
316
        previewItem->setFillShade(bgShade);
317
        previewItem->SetRectFrame();
4603 fschmid 318
        previewItem->Frame = false;
4070 subik 319
        previewItem->DrawObj(painter, QRect(0, 0, width, height));
320
        painter->end();
321
        delete(painter);
4374 subik 322
        delete previewItem;
323
 
4077 subik 324
        if (ScMW->view != NULL)
325
                ScMW->view->setScale(sca);
4584 cbradney 326
        doc->appMode = userAppMode;
4077 subik 327
        doc->docParagraphStyles.remove(doc->docParagraphStyles.fromLast());
4150 subik 328
        UndoManager::instance()->setUndoEnabled(true);
4070 subik 329
        return pm;
330
}
4467 subik 331
 
332
void SampleItem::cleanupTemporary()
333
{
334
        // clear tmp colors
335
        ScMW->doc->PageColors.remove("__blackforpreview__");
336
        ScMW->doc->PageColors.remove("__whiteforpreview__");
4614 fschmid 337
        ScMW->doc->PageColors.remove("__whiteforpreviewbg__");
4467 subik 338
}