Subversion Repositories Scribus

Rev

Rev 4073 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4070 subik 1
#include "scribus.h"
2
#include "sampleitem.h"
3
#include "loremipsum.h"
4
#include <qcolor.h>
5
#include <qstring.h>
6
 
7
extern ScribusMainWindow* ScMW;
8
 
9
 
10
SampleItem::SampleItem(QWidget *parent) : QObject(parent)
11
{
12
        tmpStyle.Vname = "(preview temporary)";
13
        tmpStyle.LineSpaMode = 0;
14
        tmpStyle.LineSpa = ((ScMW->doc->toolSettings.defSize / 10.0) * static_cast<double>(ScMW->doc->typographicSettings.autoLineSpacing) / 100) + (ScMW->doc->toolSettings.defSize / 10.0);
15
        tmpStyle.textAlignment = 0;
16
        tmpStyle.Indent = 0;
17
        tmpStyle.First = 0;
18
        tmpStyle.gapBefore = 0;
19
        tmpStyle.gapAfter = 0;
20
        tmpStyle.Font = ScMW->doc->toolSettings.defFont;
21
        tmpStyle.FontSize = ScMW->doc->toolSettings.defSize;
22
        tmpStyle.TabValues.clear();
23
        tmpStyle.Drop = false;
24
        tmpStyle.DropLin = 2;
25
        tmpStyle.DropDist = 0;
26
        tmpStyle.FontEffect = 0;
27
        tmpStyle.FColor = ScMW->doc->toolSettings.dBrush;
28
        tmpStyle.FShade = ScMW->doc->toolSettings.dShade;
29
        tmpStyle.SColor = ScMW->doc->toolSettings.dPen;
30
        tmpStyle.SShade = ScMW->doc->toolSettings.dShade2;
31
        tmpStyle.BaseAdj = false;
32
        tmpStyle.txtShadowX = 50;
33
        tmpStyle.txtShadowY = -50;
34
        tmpStyle.txtOutline = 10;
35
        tmpStyle.txtUnderPos = ScMW->doc->typographicSettings.valueUnderlinePos;
36
        tmpStyle.txtUnderWidth = ScMW->doc->typographicSettings.valueUnderlineWidth;
37
        tmpStyle.txtStrikePos = ScMW->doc->typographicSettings.valueStrikeThruPos;
38
        tmpStyle.txtStrikeWidth = ScMW->doc->typographicSettings.valueStrikeThruPos;
39
        tmpStyle.scaleH = 1000;
40
        tmpStyle.scaleV = 1000;
41
        tmpStyle.baseOff = 0;
42
        tmpStyle.kernVal = 0;
43
        bgColor = QColor(255, 255, 255);
44
}
45
 
46
SampleItem::~SampleItem()
47
{
48
}
49
 
50
void SampleItem::setText(QString aText)
51
{
52
        text = aText;
53
}
54
 
55
void SampleItem::setLoremIpsum(int para)
56
{
57
        LoremParser *m = new LoremParser("loremipsum.xml");
58
        text = m->createLorem(para);
59
        text = QString::fromUtf8(text);
60
        delete m;
61
}
62
 
63
void SampleItem::setStyle(ParagraphStyle aStyle)
64
{
65
        tmpStyle = aStyle;
66
}
67
 
68
void SampleItem::setBgColor(QColor c)
69
{
70
        bgColor = c;
71
}
72
 
73
void SampleItem::setLineSpaMode(int lineSpaMode)
74
{
75
        tmpStyle.LineSpaMode = lineSpaMode;
76
}
77
 
78
void SampleItem::setLineSpa(double lineSpa)
79
{
80
        tmpStyle.LineSpa = lineSpa;
81
}
82
 
83
void SampleItem::setTextAlignment(int textAlignment)
84
{
85
        tmpStyle.textAlignment = textAlignment;
86
}
87
 
88
void SampleItem::setIndent(double indent)
89
{
90
        tmpStyle.Indent = indent;
91
}
92
 
93
void SampleItem::setFirst(double first)
94
{
95
        tmpStyle.First = first;
96
}
97
 
98
void SampleItem::setGapBefore(double gapBefore)
99
{
100
        tmpStyle.gapBefore = gapBefore;
101
}
102
 
103
void SampleItem::setGapAfter(double gapAfter)
104
{
105
        tmpStyle.gapAfter = gapAfter;
106
}
107
 
108
void SampleItem::setFont(QString font)
109
{
110
        tmpStyle.Font = font;
111
}
112
 
113
void SampleItem::setFontSize(int fontSize)
114
{
115
        tmpStyle.FontSize = fontSize;
116
}
117
 
118
/*void SampleItem::setTabValues(QValueList<PageItem::TabRecord> tabValues)
119
{
120
        tmpStyle.TabValues = tabValues;
121
}*/
122
 
123
void SampleItem::setDrop(bool drop)
124
{
125
        tmpStyle.Drop = drop;
126
}
127
 
128
void SampleItem::setDropLin(int dropLin)
129
{
130
        tmpStyle.DropLin = dropLin;
131
}
132
 
133
void SampleItem::setDropDist(double dropDist)
134
{
135
        tmpStyle.DropDist = dropDist;
136
}
137
 
138
void SampleItem::setFontEffect(int fontEffect)
139
{
140
        tmpStyle.FontEffect = fontEffect;
141
}
142
 
143
void SampleItem::setFColor(QString fColor)
144
{
145
        tmpStyle.FColor = fColor;
146
}
147
 
148
void SampleItem::setFShade(int fShade)
149
{
150
        tmpStyle.FShade = fShade;
151
}
152
 
153
void SampleItem::setSColor(QString sColor)
154
{
155
        tmpStyle.SColor = sColor;
156
}
157
 
158
void SampleItem::setSShade(int sShade)
159
{
160
        tmpStyle.SShade = sShade;
161
}
162
 
163
void SampleItem::setBaseAdj(bool baseAdj)
164
{
165
        tmpStyle.BaseAdj = baseAdj;
166
}
167
 
168
void SampleItem::setTxtShadowX(int txtShadowX)
169
{
170
        tmpStyle.txtShadowX = txtShadowX;
171
}
172
 
173
void SampleItem::setTxtShadowY(int txtShadowY)
174
{
175
        tmpStyle.txtShadowY = txtShadowY;
176
}
177
 
178
void SampleItem::setTxtOutline(int txtOutline)
179
{
180
        tmpStyle.txtOutline = txtOutline;
181
}
182
 
183
void SampleItem::setTxtUnderPos(int txtUnderPos)
184
{
185
        tmpStyle.txtUnderPos = txtUnderPos;
186
}
187
 
188
void SampleItem::setTxtUnderWidth(int txtUnderWidth)
189
{
190
        tmpStyle.txtUnderWidth = txtUnderWidth;
191
}
192
 
193
void SampleItem::setTxtStrikePos(int txtStrikePos)
194
{
195
        tmpStyle.txtStrikePos = txtStrikePos;
196
}
197
 
198
void SampleItem::setTxtStrikeWidth(int txtStrikeWidth)
199
{
200
        tmpStyle.txtStrikeWidth = txtStrikeWidth;
201
}
202
 
203
void SampleItem::setScaleH(int scaleH)
204
{
205
        tmpStyle.scaleH = scaleH;
206
}
207
 
208
void SampleItem::setScaleV(int scaleV)
209
{
210
        tmpStyle.scaleV = scaleV;
211
}
212
 
213
void SampleItem::setBaseOff(int baseOff)
214
{
215
        tmpStyle.baseOff = baseOff;
216
}
217
 
218
void SampleItem::setKernVal(int kernVal)
219
{
220
        tmpStyle.kernVal = kernVal;
221
}
222
 
223
QPixmap SampleItem::getSample(int width, int height)
224
{
225
        PageItem_TextFrame *previewItem = new PageItem_TextFrame(ScMW->doc, 0, 0, width, height, 0, "None", ScMW->doc->toolSettings.dPenText);
226
        QPixmap pm(width, height);
227
        ScPainter *painter = new ScPainter(&pm, width, height, 0, 0);
228
        double sca = ScMW->view->getScale();
229
 
230
        QFont fo = QFont(tmpStyle.Font);
231
        fo.setPointSize(qRound(ScMW->doc->toolSettings.defSize / 10.0));
232
        ScMW->doc->AddFont(tmpStyle.Font, qRound(ScMW->doc->toolSettings.defSize / 10.0));
233
        ScMW->doc->docParagraphStyles.append(tmpStyle);
234
        int tmpIndex = ScMW->doc->docParagraphStyles.count() - 1;
235
 
236
        previewItem->FrameType = PageItem::TextFrame;
237
        painter->clear(bgColor);
238
        pm.fill(bgColor);
239
        ScMW->view->setScale(1.0);
240
 
241
        previewItem->itemText.clear();
242
        previewItem->IFont = tmpStyle.Font;
243
        previewItem->Cols = 1;
244
        for (uint i = 0; i < text.length(); ++i)
245
        {
246
                ScText *hg = new ScText;
247
                hg->ch = text.at(i);
248
                if ((hg->ch == QChar(10)) || (hg->ch == QChar(5)))
249
                        hg->ch = QChar(13);
250
                hg->cfont = (*ScMW->doc->AllFonts)[tmpStyle.Font];
251
                hg->csize = tmpStyle.FontSize;
252
                hg->ccolor = tmpStyle.FColor;
253
                hg->cshade = tmpStyle.FShade;
254
                hg->cstroke = tmpStyle.SColor;
255
                hg->cshade2 = tmpStyle.SShade;
256
                hg->cscale = tmpStyle.scaleH;
257
                hg->cscalev = tmpStyle.scaleV;
258
                hg->cbase = tmpStyle.baseOff;
259
                hg->cshadowx = tmpStyle.txtShadowX;
260
                hg->cshadowy = tmpStyle.txtShadowY;
261
                hg->coutline = tmpStyle.txtOutline;
262
                hg->cunderpos = tmpStyle.txtUnderPos;
263
                hg->cunderwidth = tmpStyle.txtUnderWidth;
264
                hg->cstrikepos = tmpStyle.txtStrikePos;
265
                hg->cstrikewidth = tmpStyle.txtStrikeWidth;
266
                hg->cselect = false;
267
                hg->cstyle = tmpStyle.FontEffect;
268
                hg->cab = tmpIndex;
269
                hg->cextra = tmpStyle.kernVal;
270
                hg->xp = 0;
271
                hg->yp = 0;
272
                hg->PRot = 0;
273
                hg->PtransX = 0;
274
                hg->PtransY = 0;
275
                hg->cembedded = 0;
276
                previewItem->itemText.append(hg);
277
        }
278
 
279
        previewItem->DrawObj(painter, QRect(0, 0, width, height));
280
        painter->end();
281
        delete(painter);
282
        ScMW->view->setScale(sca);
283
        delete previewItem;
284
        ScMW->doc->docParagraphStyles.remove(ScMW->doc->docParagraphStyles.fromLast());
285
        // test pm.save("/home/subzero/devel/tests/preview.png", "PNG");
286
        return pm;
287
}