Subversion Repositories Scribus

Rev

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