Subversion Repositories Scribus

Rev

Rev 18047 | Rev 20072 | 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
*/
5781 cbradney 7
#include "scribuscore.h"
4070 subik 8
#include "sampleitem.h"
13650 cbradney 9
#include "ui/loremipsum.h"
10601 mrdocs 10
#include "scpainter.h"
4077 subik 11
#include "scribusdoc.h"
4150 subik 12
#include "undomanager.h"
4546 subik 13
#include "commonstrings.h"
10601 mrdocs 14
#include "pageitem_textframe.h"
5184 avox 15
#include "prefsmanager.h"
10223 cbradney 16
#include <QColor>
17
#include <QString>
18
#include <QCursor>
8501 cbradney 19
//Added by qt3to4:
20
#include <QPixmap>
4070 subik 21
 
14807 fschmid 22
SampleItem::SampleItem() : QObject()
4070 subik 23
{
14807 fschmid 24
        m_Doc = new ScribusDoc();
25
        if (!m_Doc)
26
                return;
27
        m_Doc->setup(0, 1, 1, 1, 1, "Custom", "Custom");
28
        m_Doc->setPage(1, 1, 0, 0, 0, 0, 0, 0, false, false);
29
        m_Doc->addPage(0);
30
        m_Doc->setGUI(false, ScCore->primaryMainWindow(), 0);
4467 subik 31
        // tmp colors. to be removed in descrictor
5781 cbradney 32
        m_Doc->PageColors.insert("__blackforpreview__", ScColor(0, 0, 0, 255));
33
        m_Doc->PageColors.insert("__whiteforpreview__", ScColor(0, 0, 0, 0));
34
        m_Doc->PageColors.insert("__whiteforpreviewbg__", ScColor(0, 0, 0, 0));
4614 fschmid 35
        bgShade = 100;
5184 avox 36
        tmpStyle.setName("(preview temporary)");
37
        tmpStyle.setLineSpacingMode(ParagraphStyle::FixedLineSpacing);
17223 jghali 38
        tmpStyle.setLineSpacing((m_Doc->itemToolPrefs().textSize / 10.0) * (static_cast<double>(m_Doc->typographicPrefs().autoLineSpacing) / 100));
6733 avox 39
        tmpStyle.setAlignment(ParagraphStyle::Leftaligned);
5184 avox 40
        tmpStyle.setLeftMargin(0);
41
        tmpStyle.setFirstIndent(0);
5698 avox 42
        tmpStyle.setRightMargin(0);
5184 avox 43
        tmpStyle.setGapBefore(0);
44
        tmpStyle.setGapAfter(0);
14932 cbradney 45
        tmpStyle.charStyle().setFont(PrefsManager::instance()->appPrefs.fontPrefs.AvailFonts[m_Doc->itemToolPrefs().textFont]);
46
        tmpStyle.charStyle().setFontSize(m_Doc->itemToolPrefs().textSize);
6733 avox 47
//      tmpStyle.tabValues().clear();
5184 avox 48
        tmpStyle.setHasDropCap(false);
18047 craig 49
        tmpStyle.setHasBullet(false);
50
        tmpStyle.setHasNum(false);
5184 avox 51
        tmpStyle.setDropCapLines(0);//2;
18047 craig 52
        tmpStyle.setParEffectOffset(0);
9607 avox 53
        tmpStyle.charStyle().setFeatures(QStringList(CharStyle::INHERIT));
5691 avox 54
        tmpStyle.charStyle().setFillColor("__blackforpreview__");
5781 cbradney 55
        tmpStyle.charStyle().setFillShade(100); //m_Doc->toolSettings.dShade;
5691 avox 56
        tmpStyle.charStyle().setStrokeColor("__whiteforpreview__");
5781 cbradney 57
        tmpStyle.charStyle().setStrokeShade(100); //m_Doc->toolSettings.dShade2;
5691 avox 58
        tmpStyle.charStyle().setShadowXOffset(50);
59
        tmpStyle.charStyle().setShadowYOffset(-50);
60
        tmpStyle.charStyle().setOutlineWidth(10);
5781 cbradney 61
        tmpStyle.charStyle().setUnderlineOffset(0); //m_Doc->typographicSettings.valueUnderlinePos;
62
        tmpStyle.charStyle().setUnderlineWidth(0); //m_Doc->typographicSettings.valueUnderlineWidth;
63
        tmpStyle.charStyle().setStrikethruOffset(0); //m_Doc->typographicSettings.valueStrikeThruPos;
64
        tmpStyle.charStyle().setStrikethruWidth(0); //m_Doc->typographicSettings.valueStrikeThruPos;
5691 avox 65
        tmpStyle.charStyle().setScaleH(1000);
66
        tmpStyle.charStyle().setScaleV(1000);
67
        tmpStyle.charStyle().setBaselineOffset(0);
68
        tmpStyle.charStyle().setTracking(0);
4070 subik 69
}
70
 
71
SampleItem::~SampleItem()
72
{
14807 fschmid 73
        delete m_Doc;
4070 subik 74
}
75
 
76
void SampleItem::setText(QString aText)
77
{
78
        text = aText;
79
}
80
 
81
void SampleItem::setLoremIpsum(int para)
82
{
83
        LoremParser *m = new LoremParser("loremipsum.xml");
84
        text = m->createLorem(para);
10554 fschmid 85
// really needed ??
86
//      text = QString::fromUtf8(text);
4070 subik 87
        delete m;
88
}
89
 
5698 avox 90
void SampleItem::setStyle(const ParagraphStyle& aStyle)
4070 subik 91
{
92
        tmpStyle = aStyle;
93
}
94
 
95
void SampleItem::setBgColor(QColor c)
96
{
5781 cbradney 97
        m_Doc->PageColors["__whiteforpreviewbg__"].fromQColor(c);
4070 subik 98
}
99
 
4614 fschmid 100
void SampleItem::setBgShade(int c)
101
{
102
        bgShade = c;
103
}
104
 
14491 jghali 105
void SampleItem::setBgColorMgmt(bool enable)
7054 jghali 106
{
107
        m_Doc->PageColors["__whiteforpreviewbg__"].setSpotColor(!enable);
108
}
109
 
4614 fschmid 110
void SampleItem::setTxColor(QColor c)
111
{
5781 cbradney 112
        m_Doc->PageColors["__blackforpreview__"].fromQColor(c);
4614 fschmid 113
}
114
 
115
void SampleItem::setTxShade(int c)
116
{
5691 avox 117
        tmpStyle.charStyle().setFillShade(c);
4614 fschmid 118
}
119
 
4070 subik 120
void SampleItem::setLineSpaMode(int lineSpaMode)
121
{
5184 avox 122
        tmpStyle.setLineSpacingMode(static_cast<ParagraphStyle::LineSpacingMode>(lineSpaMode));
4070 subik 123
}
124
 
125
void SampleItem::setLineSpa(double lineSpa)
126
{
5184 avox 127
        tmpStyle.setLineSpacing(lineSpa);
4070 subik 128
}
129
 
130
void SampleItem::setTextAlignment(int textAlignment)
131
{
6733 avox 132
        tmpStyle.setAlignment(static_cast<ParagraphStyle::AlignmentType>(textAlignment));
4070 subik 133
}
134
 
135
void SampleItem::setIndent(double indent)
136
{
5184 avox 137
        tmpStyle.setLeftMargin(indent);
4070 subik 138
}
139
 
140
void SampleItem::setFirst(double first)
141
{
5184 avox 142
        tmpStyle.setFirstIndent(first);
4070 subik 143
}
144
 
145
void SampleItem::setGapBefore(double gapBefore)
146
{
5184 avox 147
        tmpStyle.setGapBefore(gapBefore);
4070 subik 148
}
149
 
150
void SampleItem::setGapAfter(double gapAfter)
151
{
5184 avox 152
        tmpStyle.setGapAfter(gapAfter);
4070 subik 153
}
154
 
155
void SampleItem::setFont(QString font)
156
{
13955 cbradney 157
        tmpStyle.charStyle().setFont(PrefsManager::instance()->appPrefs.fontPrefs.AvailFonts[font]);
4070 subik 158
}
159
 
4077 subik 160
void SampleItem::setFontSize(int fontSize, bool autoLineSpa)
4070 subik 161
{
5691 avox 162
        tmpStyle.charStyle().setFontSize(fontSize);
4077 subik 163
        if (autoLineSpa)
17223 jghali 164
                tmpStyle.setLineSpacing((fontSize / 10)  * (m_Doc->typographicPrefs().autoLineSpacing / 100.0));
4070 subik 165
}
166
 
167
/*void SampleItem::setTabValues(QValueList<PageItem::TabRecord> tabValues)
168
{
169
        tmpStyle.TabValues = tabValues;
170
}*/
171
 
172
void SampleItem::setDrop(bool drop)
173
{
5184 avox 174
        tmpStyle.setHasDropCap(drop);
4070 subik 175
}
176
 
177
void SampleItem::setDropLin(int dropLin)
178
{
5184 avox 179
        tmpStyle.setDropCapLines(dropLin);
4070 subik 180
}
181
 
18047 craig 182
void SampleItem::setParEffectDist(double dist)
4070 subik 183
{
18047 craig 184
        tmpStyle.setParEffectOffset(dist);
4070 subik 185
}
186
 
18047 craig 187
void SampleItem::setBullet(bool bul)
188
{
189
        tmpStyle.setHasBullet(bul);
190
}
191
 
192
void SampleItem::setNum(bool num)
193
{
194
        tmpStyle.setHasNum(num);
195
}
196
 
4070 subik 197
void SampleItem::setFontEffect(int fontEffect)
198
{
9607 avox 199
        tmpStyle.charStyle().setFeatures(static_cast<StyleFlag>(fontEffect).featureList());
4070 subik 200
}
201
 
202
void SampleItem::setFColor(QString fColor)
203
{
5691 avox 204
        tmpStyle.charStyle().setFillColor(fColor);
4070 subik 205
}
206
 
207
void SampleItem::setFShade(int fShade)
208
{
5691 avox 209
        tmpStyle.charStyle().setFillShade(fShade);
4070 subik 210
}
211
 
212
void SampleItem::setSColor(QString sColor)
213
{
5691 avox 214
        tmpStyle.charStyle().setStrokeColor(sColor);
4070 subik 215
}
216
 
217
void SampleItem::setSShade(int sShade)
218
{
5691 avox 219
        tmpStyle.charStyle().setStrokeShade(sShade);
4070 subik 220
}
221
 
222
void SampleItem::setBaseAdj(bool baseAdj)
223
{
8871 cbradney 224
        tmpStyle.setLineSpacingMode(baseAdj ? ParagraphStyle::BaselineGridLineSpacing : ParagraphStyle::FixedLineSpacing);
4070 subik 225
}
226
 
227
void SampleItem::setTxtShadowX(int txtShadowX)
228
{
5691 avox 229
        tmpStyle.charStyle().setShadowXOffset(txtShadowX);
4070 subik 230
}
231
 
232
void SampleItem::setTxtShadowY(int txtShadowY)
233
{
5691 avox 234
        tmpStyle.charStyle().setShadowYOffset(txtShadowY);
4070 subik 235
}
236
 
237
void SampleItem::setTxtOutline(int txtOutline)
238
{
5691 avox 239
        tmpStyle.charStyle().setOutlineWidth(txtOutline);
4070 subik 240
}
241
 
242
void SampleItem::setTxtUnderPos(int txtUnderPos)
243
{
5691 avox 244
        tmpStyle.charStyle().setUnderlineOffset(txtUnderPos);
4070 subik 245
}
246
 
247
void SampleItem::setTxtUnderWidth(int txtUnderWidth)
248
{
5691 avox 249
        tmpStyle.charStyle().setUnderlineWidth(txtUnderWidth);
4070 subik 250
}
251
 
252
void SampleItem::setTxtStrikePos(int txtStrikePos)
253
{
5691 avox 254
        tmpStyle.charStyle().setStrikethruOffset(txtStrikePos);
4070 subik 255
}
256
 
257
void SampleItem::setTxtStrikeWidth(int txtStrikeWidth)
258
{
5691 avox 259
        tmpStyle.charStyle().setStrikethruWidth(txtStrikeWidth);
4070 subik 260
}
261
 
262
void SampleItem::setScaleH(int scaleH)
263
{
5691 avox 264
        tmpStyle.charStyle().setScaleH(scaleH);
4070 subik 265
}
266
 
267
void SampleItem::setScaleV(int scaleV)
268
{
5691 avox 269
        tmpStyle.charStyle().setScaleV(scaleV);
4070 subik 270
}
271
 
272
void SampleItem::setBaseOff(int baseOff)
273
{
5691 avox 274
        tmpStyle.charStyle().setBaselineOffset(baseOff);
4070 subik 275
}
276
 
277
void SampleItem::setKernVal(int kernVal)
278
{
5691 avox 279
        tmpStyle.charStyle().setTracking(kernVal);
4070 subik 280
}
281
 
282
QPixmap SampleItem::getSample(int width, int height)
283
{
5470 subik 284
        // if it's false => the used font will be removed from used fonts
285
        // after sample creating
286
        bool previouslyUsedFont = false;
287
 
5980 avox 288
        if (tmpStyle.charStyle().font().isNone())
5315 avox 289
                return QPixmap();
14724 cbradney 290
 
4150 subik 291
        UndoManager::instance()->setUndoEnabled(false); // disable undo
292
 
5781 cbradney 293
        PageItem_TextFrame *previewItem = new PageItem_TextFrame(m_Doc, 0, 0, width, height, 0, "__whiteforpreviewbg__", "__whiteforpreview__");
9319 fschmid 294
        QImage pm(width, height, QImage::Format_ARGB32);
9372 fschmid 295
        ScPainter *painter = new ScPainter(&pm, width, height, 1.0, 0);
14807 fschmid 296
        painter->setZoomFactor(PrefsManager::instance()->appPrefs.displayPrefs.displayScale);
4070 subik 297
 
5980 avox 298
        if (m_Doc->UsedFonts.contains(tmpStyle.charStyle().font().scName()))
5470 subik 299
                previouslyUsedFont = true;
300
 
14932 cbradney 301
        m_Doc->AddFont(tmpStyle.charStyle().font().scName(), qRound(m_Doc->itemToolPrefs().textSize / 10.0));
4070 subik 302
 
303
        previewItem->FrameType = PageItem::TextFrame;
304
        previewItem->itemText.clear();
5559 avox 305
//      previewItem->setFont(tmpStyle.charStyle().font()->scName());
4070 subik 306
        previewItem->Cols = 1;
5315 avox 307
        text.replace(QChar(10),QChar(13)).replace(QChar(5),QChar(13));
308
        previewItem->itemText.insertChars(0, text);
7349 avox 309
        previewItem->itemText.setDefaultStyle(tmpStyle);
4614 fschmid 310
        previewItem->setFillColor("__whiteforpreviewbg__");
311
        previewItem->setFillShade(bgShade);
312
        previewItem->SetRectFrame();
18007 craig 313
        previewItem->setSampleItem(true);
10945 jghali 314
        previewItem->DrawObj(painter, QRect());
4070 subik 315
        painter->end();
316
        delete(painter);
4374 subik 317
        delete previewItem;
318
 
5470 subik 319
        // cleanups and resets
320
        if (!previouslyUsedFont)
12993 jghali 321
        {
322
                QString fontName = tmpStyle.charStyle().font().scName();
323
                (*m_Doc->AllFonts)[fontName].decreaseUsage(); // was increased by AddFont()
324
                m_Doc->UsedFonts.remove(fontName);
325
        }
6733 avox 326
//      m_Doc->docParagraphStyles.remove(tmpIndex);
14724 cbradney 327
        UndoManager::instance()->setUndoEnabled(true);
9319 fschmid 328
        return QPixmap::fromImage(pm);
4070 subik 329
}