Subversion Repositories Scribus

Rev

Rev 4459 | Rev 4546 | 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"
4459 subik 12
//#include "prefsmanager.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
        bgColor = QColor(255, 255, 255);
4467 subik 74
 
4070 subik 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
{
108
        bgColor = c;
109
}
110
 
111
void SampleItem::setLineSpaMode(int lineSpaMode)
112
{
113
        tmpStyle.LineSpaMode = lineSpaMode;
114
}
115
 
116
void SampleItem::setLineSpa(double lineSpa)
117
{
118
        tmpStyle.LineSpa = lineSpa;
119
}
120
 
121
void SampleItem::setTextAlignment(int textAlignment)
122
{
123
        tmpStyle.textAlignment = textAlignment;
124
}
125
 
126
void SampleItem::setIndent(double indent)
127
{
128
        tmpStyle.Indent = indent;
129
}
130
 
131
void SampleItem::setFirst(double first)
132
{
133
        tmpStyle.First = first;
134
}
135
 
136
void SampleItem::setGapBefore(double gapBefore)
137
{
138
        tmpStyle.gapBefore = gapBefore;
139
}
140
 
141
void SampleItem::setGapAfter(double gapAfter)
142
{
143
        tmpStyle.gapAfter = gapAfter;
144
}
145
 
146
void SampleItem::setFont(QString font)
147
{
148
        tmpStyle.Font = font;
149
}
150
 
4077 subik 151
void SampleItem::setFontSize(int fontSize, bool autoLineSpa)
4070 subik 152
{
153
        tmpStyle.FontSize = fontSize;
4077 subik 154
        if (autoLineSpa)
155
                tmpStyle.LineSpa = ((fontSize / 10)  * (doc->typographicSettings.autoLineSpacing / 100) + (fontSize / 10));
4070 subik 156
}
157
 
158
/*void SampleItem::setTabValues(QValueList<PageItem::TabRecord> tabValues)
159
{
160
        tmpStyle.TabValues = tabValues;
161
}*/
162
 
163
void SampleItem::setDrop(bool drop)
164
{
165
        tmpStyle.Drop = drop;
166
}
167
 
168
void SampleItem::setDropLin(int dropLin)
169
{
170
        tmpStyle.DropLin = dropLin;
171
}
172
 
173
void SampleItem::setDropDist(double dropDist)
174
{
175
        tmpStyle.DropDist = dropDist;
176
}
177
 
178
void SampleItem::setFontEffect(int fontEffect)
179
{
180
        tmpStyle.FontEffect = fontEffect;
181
}
182
 
183
void SampleItem::setFColor(QString fColor)
184
{
185
        tmpStyle.FColor = fColor;
186
}
187
 
188
void SampleItem::setFShade(int fShade)
189
{
190
        tmpStyle.FShade = fShade;
191
}
192
 
193
void SampleItem::setSColor(QString sColor)
194
{
195
        tmpStyle.SColor = sColor;
196
}
197
 
198
void SampleItem::setSShade(int sShade)
199
{
200
        tmpStyle.SShade = sShade;
201
}
202
 
203
void SampleItem::setBaseAdj(bool baseAdj)
204
{
205
        tmpStyle.BaseAdj = baseAdj;
206
}
207
 
208
void SampleItem::setTxtShadowX(int txtShadowX)
209
{
210
        tmpStyle.txtShadowX = txtShadowX;
211
}
212
 
213
void SampleItem::setTxtShadowY(int txtShadowY)
214
{
215
        tmpStyle.txtShadowY = txtShadowY;
216
}
217
 
218
void SampleItem::setTxtOutline(int txtOutline)
219
{
220
        tmpStyle.txtOutline = txtOutline;
221
}
222
 
223
void SampleItem::setTxtUnderPos(int txtUnderPos)
224
{
225
        tmpStyle.txtUnderPos = txtUnderPos;
226
}
227
 
228
void SampleItem::setTxtUnderWidth(int txtUnderWidth)
229
{
230
        tmpStyle.txtUnderWidth = txtUnderWidth;
231
}
232
 
233
void SampleItem::setTxtStrikePos(int txtStrikePos)
234
{
235
        tmpStyle.txtStrikePos = txtStrikePos;
236
}
237
 
238
void SampleItem::setTxtStrikeWidth(int txtStrikeWidth)
239
{
240
        tmpStyle.txtStrikeWidth = txtStrikeWidth;
241
}
242
 
243
void SampleItem::setScaleH(int scaleH)
244
{
245
        tmpStyle.scaleH = scaleH;
246
}
247
 
248
void SampleItem::setScaleV(int scaleV)
249
{
250
        tmpStyle.scaleV = scaleV;
251
}
252
 
253
void SampleItem::setBaseOff(int baseOff)
254
{
255
        tmpStyle.baseOff = baseOff;
256
}
257
 
258
void SampleItem::setKernVal(int kernVal)
259
{
260
        tmpStyle.kernVal = kernVal;
261
}
262
 
263
QPixmap SampleItem::getSample(int width, int height)
264
{
4150 subik 265
        UndoManager::instance()->setUndoEnabled(false); // disable undo
266
 
4272 subik 267
        PageItem_TextFrame *previewItem = new PageItem_TextFrame(doc, 0, 0, width, width, 0, "None", "None");
4070 subik 268
        QPixmap pm(width, height);
269
        ScPainter *painter = new ScPainter(&pm, width, height, 0, 0);
4374 subik 270
        double sca = 1.0; // original scale to set back at the end...
4459 subik 271
        int userAppMode = ScMW->doc->appMode; // We need to be in normal when creating/repainting items
272
        ScMW->doc->appMode = modeNormal;
4070 subik 273
 
4077 subik 274
        if (ScMW->view != NULL)
4374 subik 275
        {
4077 subik 276
                sca = ScMW->view->getScale();
4374 subik 277
                ScMW->view->setScale(1.0);
278
        }
4077 subik 279
 
4070 subik 280
        QFont fo = QFont(tmpStyle.Font);
4077 subik 281
        fo.setPointSize(qRound(doc->toolSettings.defSize / 10.0));
282
        doc->AddFont(tmpStyle.Font, qRound(doc->toolSettings.defSize / 10.0));
283
        doc->docParagraphStyles.append(tmpStyle);
284
        int tmpIndex = doc->docParagraphStyles.count() - 1;
4070 subik 285
 
286
        previewItem->FrameType = PageItem::TextFrame;
287
        previewItem->itemText.clear();
4073 cbradney 288
        previewItem->setFont(tmpStyle.Font);
4070 subik 289
        previewItem->Cols = 1;
290
        for (uint i = 0; i < text.length(); ++i)
291
        {
292
                ScText *hg = new ScText;
293
                hg->ch = text.at(i);
294
                if ((hg->ch == QChar(10)) || (hg->ch == QChar(5)))
295
                        hg->ch = QChar(13);
4459 subik 296
//              hg->cfont = PrefsManager::instance()->appPrefs.AvailFonts[tmpStyle.Font];
4070 subik 297
                previewItem->itemText.append(hg);
298
        }
4459 subik 299
 
4374 subik 300
        ScMW->view->chAbStyle(previewItem, tmpIndex);
4070 subik 301
        previewItem->DrawObj(painter, QRect(0, 0, width, height));
302
        painter->end();
303
        delete(painter);
4374 subik 304
        delete previewItem;
305
 
4077 subik 306
        if (ScMW->view != NULL)
307
                ScMW->view->setScale(sca);
4459 subik 308
        ScMW->doc->appMode = userAppMode;
4077 subik 309
        doc->docParagraphStyles.remove(doc->docParagraphStyles.fromLast());
4150 subik 310
        UndoManager::instance()->setUndoEnabled(true);
4070 subik 311
        return pm;
312
}
4467 subik 313
 
314
void SampleItem::cleanupTemporary()
315
{
316
        // clear tmp colors
317
        ScMW->doc->PageColors.remove("__blackforpreview__");
318
        ScMW->doc->PageColors.remove("__whiteforpreview__");
319
}