Subversion Repositories Scribus

Rev

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