Subversion Repositories Scribus

Rev

Rev 12658 | Rev 13650 | 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"
8521 cbradney 9
//#include "sampleitem.moc"
4070 subik 10
#include "loremipsum.h"
10601 mrdocs 11
#include "scpainter.h"
4077 subik 12
#include "scribusdoc.h"
4150 subik 13
#include "undomanager.h"
4546 subik 14
#include "commonstrings.h"
10601 mrdocs 15
#include "pageitem_textframe.h"
5184 avox 16
#include "prefsmanager.h"
10223 cbradney 17
#include <QColor>
18
#include <QString>
19
#include <QCursor>
8501 cbradney 20
//Added by qt3to4:
21
#include <QPixmap>
5184 avox 22
#include "text/nlsconfig.h"
4070 subik 23
 
5781 cbradney 24
SampleItem::SampleItem(ScribusDoc* doc) :
5798 jghali 25
        QObject()
4070 subik 26
{
4077 subik 27
        used = true;
5798 jghali 28
        m_Doc=doc;
5898 subik 29
 
5890 subik 30
        if (doc==0)
4077 subik 31
        {
12658 fschmid 32
                qApp->changeOverrideCursor(QCursor(Qt::WaitCursor));
5890 subik 33
                // FIXME: main preformance issue here! PV
5781 cbradney 34
                m_Doc=ScCore->primaryMainWindow()->doFileNew(//pageWidth, pageHeight,
4077 subik 35
                                                                        0,0,
36
                                                                        //topMargin, leftMargin, rightMargin, bottomMargin,
37
                                                                        1, 1, 1, 1,
38
                                                                        // autoframes. It's disabled in python
39
                                                                        // columnDistance, numberCols, autoframes,
40
                                                                        0, 1, false,
41
                                                                        //pagesType, unit, firstPageOrder,
42
                                                                        1, 1, 1,
5798 jghali 43
                                                                        //orientation, firstPageNr, "Custom", requires gui, page count, showview);
5808 cbradney 44
                                                                        1, 1, "custom", false, 1, false);
5890 subik 45
                //m_Doc = new ScribusDoc();
5798 jghali 46
                Q_ASSERT(m_Doc!=0);
5781 cbradney 47
                if (!m_Doc)
48
                        return;
49
                m_Doc->pageSets[1/*pagesType*/].FirstPage = 1;//firstPageOrder;
4077 subik 50
                used = false;
12658 fschmid 51
                qApp->changeOverrideCursor(Qt::ArrowCursor);
4077 subik 52
        }
4467 subik 53
        // tmp colors. to be removed in descrictor
5781 cbradney 54
        m_Doc->PageColors.insert("__blackforpreview__", ScColor(0, 0, 0, 255));
55
        m_Doc->PageColors.insert("__whiteforpreview__", ScColor(0, 0, 0, 0));
56
        m_Doc->PageColors.insert("__whiteforpreviewbg__", ScColor(0, 0, 0, 0));
4614 fschmid 57
        bgShade = 100;
5184 avox 58
        tmpStyle.setName("(preview temporary)");
59
        tmpStyle.setLineSpacingMode(ParagraphStyle::FixedLineSpacing);
5781 cbradney 60
        tmpStyle.setLineSpacing((m_Doc->toolSettings.defSize / 10.0)
61
                * static_cast<double>(m_Doc->typographicSettings.autoLineSpacing) / 100
62
                + (m_Doc->toolSettings.defSize / 10.0));
6733 avox 63
        tmpStyle.setAlignment(ParagraphStyle::Leftaligned);
5184 avox 64
        tmpStyle.setLeftMargin(0);
65
        tmpStyle.setFirstIndent(0);
5698 avox 66
        tmpStyle.setRightMargin(0);
5184 avox 67
        tmpStyle.setGapBefore(0);
68
        tmpStyle.setGapAfter(0);
5781 cbradney 69
        tmpStyle.charStyle().setFont(PrefsManager::instance()->appPrefs.AvailFonts[m_Doc->toolSettings.defFont]);
70
        tmpStyle.charStyle().setFontSize(m_Doc->toolSettings.defSize);
6733 avox 71
//      tmpStyle.tabValues().clear();
5184 avox 72
        tmpStyle.setHasDropCap(false);
73
        tmpStyle.setDropCapLines(0);//2;
74
        tmpStyle.setDropCapOffset(0);
9607 avox 75
        tmpStyle.charStyle().setFeatures(QStringList(CharStyle::INHERIT));
5691 avox 76
        tmpStyle.charStyle().setFillColor("__blackforpreview__");
5781 cbradney 77
        tmpStyle.charStyle().setFillShade(100); //m_Doc->toolSettings.dShade;
5691 avox 78
        tmpStyle.charStyle().setStrokeColor("__whiteforpreview__");
5781 cbradney 79
        tmpStyle.charStyle().setStrokeShade(100); //m_Doc->toolSettings.dShade2;
5691 avox 80
        tmpStyle.charStyle().setShadowXOffset(50);
81
        tmpStyle.charStyle().setShadowYOffset(-50);
82
        tmpStyle.charStyle().setOutlineWidth(10);
5781 cbradney 83
        tmpStyle.charStyle().setUnderlineOffset(0); //m_Doc->typographicSettings.valueUnderlinePos;
84
        tmpStyle.charStyle().setUnderlineWidth(0); //m_Doc->typographicSettings.valueUnderlineWidth;
85
        tmpStyle.charStyle().setStrikethruOffset(0); //m_Doc->typographicSettings.valueStrikeThruPos;
86
        tmpStyle.charStyle().setStrikethruWidth(0); //m_Doc->typographicSettings.valueStrikeThruPos;
5691 avox 87
        tmpStyle.charStyle().setScaleH(1000);
88
        tmpStyle.charStyle().setScaleV(1000);
89
        tmpStyle.charStyle().setBaselineOffset(0);
90
        tmpStyle.charStyle().setTracking(0);
4070 subik 91
}
92
 
93
SampleItem::~SampleItem()
94
{
4467 subik 95
        cleanupTemporary();
96
        // clean tmp document
4077 subik 97
        if (used == false)
98
        {
5781 cbradney 99
                m_Doc->setModified(false);
5798 jghali 100
                //Do this manually as the sample item's doc was never put into the main windows workspace and doc list etc
101
                //m_Doc->scMW()->slotFileClose();
102
                m_Doc->view()->disconnect();
103
                m_Doc->WinHan->disconnect();
104
                m_Doc->disconnect();
105
                delete m_Doc->view();
106
                delete m_Doc->WinHan;
107
                delete m_Doc;
4077 subik 108
        }
4070 subik 109
}
110
 
111
void SampleItem::setText(QString aText)
112
{
113
        text = aText;
114
}
115
 
116
void SampleItem::setLoremIpsum(int para)
117
{
118
        LoremParser *m = new LoremParser("loremipsum.xml");
119
        text = m->createLorem(para);
10554 fschmid 120
// really needed ??
121
//      text = QString::fromUtf8(text);
4070 subik 122
        delete m;
123
}
124
 
5698 avox 125
void SampleItem::setStyle(const ParagraphStyle& aStyle)
4070 subik 126
{
127
        tmpStyle = aStyle;
128
}
129
 
130
void SampleItem::setBgColor(QColor c)
131
{
5781 cbradney 132
        m_Doc->PageColors["__whiteforpreviewbg__"].fromQColor(c);
4070 subik 133
}
134
 
4614 fschmid 135
void SampleItem::setBgShade(int c)
136
{
137
        bgShade = c;
138
}
139
 
7054 jghali 140
void SampleItem::setBgColorMngt(bool enable)
141
{
142
        m_Doc->PageColors["__whiteforpreviewbg__"].setSpotColor(!enable);
143
}
144
 
4614 fschmid 145
void SampleItem::setTxColor(QColor c)
146
{
5781 cbradney 147
        m_Doc->PageColors["__blackforpreview__"].fromQColor(c);
4614 fschmid 148
}
149
 
150
void SampleItem::setTxShade(int c)
151
{
5691 avox 152
        tmpStyle.charStyle().setFillShade(c);
4614 fschmid 153
}
154
 
4070 subik 155
void SampleItem::setLineSpaMode(int lineSpaMode)
156
{
5184 avox 157
        tmpStyle.setLineSpacingMode(static_cast<ParagraphStyle::LineSpacingMode>(lineSpaMode));
4070 subik 158
}
159
 
160
void SampleItem::setLineSpa(double lineSpa)
161
{
5184 avox 162
        tmpStyle.setLineSpacing(lineSpa);
4070 subik 163
}
164
 
165
void SampleItem::setTextAlignment(int textAlignment)
166
{
6733 avox 167
        tmpStyle.setAlignment(static_cast<ParagraphStyle::AlignmentType>(textAlignment));
4070 subik 168
}
169
 
170
void SampleItem::setIndent(double indent)
171
{
5184 avox 172
        tmpStyle.setLeftMargin(indent);
4070 subik 173
}
174
 
175
void SampleItem::setFirst(double first)
176
{
5184 avox 177
        tmpStyle.setFirstIndent(first);
4070 subik 178
}
179
 
180
void SampleItem::setGapBefore(double gapBefore)
181
{
5184 avox 182
        tmpStyle.setGapBefore(gapBefore);
4070 subik 183
}
184
 
185
void SampleItem::setGapAfter(double gapAfter)
186
{
5184 avox 187
        tmpStyle.setGapAfter(gapAfter);
4070 subik 188
}
189
 
190
void SampleItem::setFont(QString font)
191
{
5691 avox 192
        tmpStyle.charStyle().setFont(PrefsManager::instance()->appPrefs.AvailFonts[font]);
4070 subik 193
}
194
 
4077 subik 195
void SampleItem::setFontSize(int fontSize, bool autoLineSpa)
4070 subik 196
{
5691 avox 197
        tmpStyle.charStyle().setFontSize(fontSize);
4077 subik 198
        if (autoLineSpa)
5781 cbradney 199
                tmpStyle.setLineSpacing(((fontSize / 10)  * (m_Doc->typographicSettings.autoLineSpacing / 100) + (fontSize / 10)));
4070 subik 200
}
201
 
202
/*void SampleItem::setTabValues(QValueList<PageItem::TabRecord> tabValues)
203
{
204
        tmpStyle.TabValues = tabValues;
205
}*/
206
 
207
void SampleItem::setDrop(bool drop)
208
{
5184 avox 209
        tmpStyle.setHasDropCap(drop);
4070 subik 210
}
211
 
212
void SampleItem::setDropLin(int dropLin)
213
{
5184 avox 214
        tmpStyle.setDropCapLines(dropLin);
4070 subik 215
}
216
 
217
void SampleItem::setDropDist(double dropDist)
218
{
5184 avox 219
        tmpStyle.setDropCapOffset(dropDist);
4070 subik 220
}
221
 
222
void SampleItem::setFontEffect(int fontEffect)
223
{
9607 avox 224
        tmpStyle.charStyle().setFeatures(static_cast<StyleFlag>(fontEffect).featureList());
4070 subik 225
}
226
 
227
void SampleItem::setFColor(QString fColor)
228
{
5691 avox 229
        tmpStyle.charStyle().setFillColor(fColor);
4070 subik 230
}
231
 
232
void SampleItem::setFShade(int fShade)
233
{
5691 avox 234
        tmpStyle.charStyle().setFillShade(fShade);
4070 subik 235
}
236
 
237
void SampleItem::setSColor(QString sColor)
238
{
5691 avox 239
        tmpStyle.charStyle().setStrokeColor(sColor);
4070 subik 240
}
241
 
242
void SampleItem::setSShade(int sShade)
243
{
5691 avox 244
        tmpStyle.charStyle().setStrokeShade(sShade);
4070 subik 245
}
246
 
247
void SampleItem::setBaseAdj(bool baseAdj)
248
{
8871 cbradney 249
        tmpStyle.setLineSpacingMode(baseAdj ? ParagraphStyle::BaselineGridLineSpacing : ParagraphStyle::FixedLineSpacing);
4070 subik 250
}
251
 
252
void SampleItem::setTxtShadowX(int txtShadowX)
253
{
5691 avox 254
        tmpStyle.charStyle().setShadowXOffset(txtShadowX);
4070 subik 255
}
256
 
257
void SampleItem::setTxtShadowY(int txtShadowY)
258
{
5691 avox 259
        tmpStyle.charStyle().setShadowYOffset(txtShadowY);
4070 subik 260
}
261
 
262
void SampleItem::setTxtOutline(int txtOutline)
263
{
5691 avox 264
        tmpStyle.charStyle().setOutlineWidth(txtOutline);
4070 subik 265
}
266
 
267
void SampleItem::setTxtUnderPos(int txtUnderPos)
268
{
5691 avox 269
        tmpStyle.charStyle().setUnderlineOffset(txtUnderPos);
4070 subik 270
}
271
 
272
void SampleItem::setTxtUnderWidth(int txtUnderWidth)
273
{
5691 avox 274
        tmpStyle.charStyle().setUnderlineWidth(txtUnderWidth);
4070 subik 275
}
276
 
277
void SampleItem::setTxtStrikePos(int txtStrikePos)
278
{
5691 avox 279
        tmpStyle.charStyle().setStrikethruOffset(txtStrikePos);
4070 subik 280
}
281
 
282
void SampleItem::setTxtStrikeWidth(int txtStrikeWidth)
283
{
5691 avox 284
        tmpStyle.charStyle().setStrikethruWidth(txtStrikeWidth);
4070 subik 285
}
286
 
287
void SampleItem::setScaleH(int scaleH)
288
{
5691 avox 289
        tmpStyle.charStyle().setScaleH(scaleH);
4070 subik 290
}
291
 
292
void SampleItem::setScaleV(int scaleV)
293
{
5691 avox 294
        tmpStyle.charStyle().setScaleV(scaleV);
4070 subik 295
}
296
 
297
void SampleItem::setBaseOff(int baseOff)
298
{
5691 avox 299
        tmpStyle.charStyle().setBaselineOffset(baseOff);
4070 subik 300
}
301
 
302
void SampleItem::setKernVal(int kernVal)
303
{
5691 avox 304
        tmpStyle.charStyle().setTracking(kernVal);
4070 subik 305
}
306
 
307
QPixmap SampleItem::getSample(int width, int height)
308
{
5470 subik 309
        // if it's false => the used font will be removed from used fonts
310
        // after sample creating
311
        bool previouslyUsedFont = false;
312
 
5980 avox 313
        if (tmpStyle.charStyle().font().isNone())
5315 avox 314
                return QPixmap();
5470 subik 315
 
4150 subik 316
        UndoManager::instance()->setUndoEnabled(false); // disable undo
317
 
5781 cbradney 318
        PageItem_TextFrame *previewItem = new PageItem_TextFrame(m_Doc, 0, 0, width, height, 0, "__whiteforpreviewbg__", "__whiteforpreview__");
9319 fschmid 319
        QImage pm(width, height, QImage::Format_ARGB32);
9372 fschmid 320
        ScPainter *painter = new ScPainter(&pm, width, height, 1.0, 0);
4374 subik 321
        double sca = 1.0; // original scale to set back at the end...
5781 cbradney 322
        int userAppMode = m_Doc->appMode; // We need to be in normal when creating/repainting items
323
        m_Doc->appMode = modeNormal;
4070 subik 324
 
5781 cbradney 325
        if (m_Doc->view() != NULL)
4374 subik 326
        {
5781 cbradney 327
                sca = m_Doc->view()->scale();
8877 cbradney 328
                m_Doc->view()->setScale(1.0 * PrefsManager::instance()->appPrefs.DisScale);
4374 subik 329
        }
8877 cbradney 330
        painter->setZoomFactor(m_Doc->view()->scale());
4077 subik 331
 
5980 avox 332
        if (m_Doc->UsedFonts.contains(tmpStyle.charStyle().font().scName()))
5470 subik 333
                previouslyUsedFont = true;
334
 
5980 avox 335
        m_Doc->AddFont(tmpStyle.charStyle().font().scName(), qRound(m_Doc->toolSettings.defSize / 10.0));
6733 avox 336
//      m_Doc->docParagraphStyles.create(tmpStyle);
337
//      int tmpIndex = m_Doc->docParagraphStyles.count() - 1;
4070 subik 338
 
339
        previewItem->FrameType = PageItem::TextFrame;
340
        previewItem->itemText.clear();
5559 avox 341
//      previewItem->setFont(tmpStyle.charStyle().font()->scName());
4070 subik 342
        previewItem->Cols = 1;
5315 avox 343
        text.replace(QChar(10),QChar(13)).replace(QChar(5),QChar(13));
344
        previewItem->itemText.insertChars(0, text);
7349 avox 345
        previewItem->itemText.setDefaultStyle(tmpStyle);
4614 fschmid 346
        previewItem->setFillColor("__whiteforpreviewbg__");
347
        previewItem->setFillShade(bgShade);
348
        previewItem->SetRectFrame();
4603 fschmid 349
        previewItem->Frame = false;
10945 jghali 350
        previewItem->DrawObj(painter, QRect());
4070 subik 351
        painter->end();
352
        delete(painter);
4374 subik 353
        delete previewItem;
354
 
5470 subik 355
        // cleanups and resets
356
        if (!previouslyUsedFont)
12993 jghali 357
        {
358
                QString fontName = tmpStyle.charStyle().font().scName();
359
                (*m_Doc->AllFonts)[fontName].decreaseUsage(); // was increased by AddFont()
360
                m_Doc->UsedFonts.remove(fontName);
361
        }
5781 cbradney 362
        if (m_Doc->view() != NULL)
363
                m_Doc->view()->setScale(sca);
364
        m_Doc->appMode = userAppMode;
6733 avox 365
//      m_Doc->docParagraphStyles.remove(tmpIndex);
4150 subik 366
        UndoManager::instance()->setUndoEnabled(true);
9319 fschmid 367
        return QPixmap::fromImage(pm);
4070 subik 368
}
4467 subik 369
 
370
void SampleItem::cleanupTemporary()
371
{
372
        // clear tmp colors
5781 cbradney 373
        m_Doc->PageColors.remove("__blackforpreview__");
374
        m_Doc->PageColors.remove("__whiteforpreview__");
375
        m_Doc->PageColors.remove("__whiteforpreviewbg__");
4467 subik 376
}