Subversion Repositories Scribus

Compare Revisions

Ignore whitespace Rev 6372 → Rev 6369

/branches/Version13x/Scribus/scribus/patterndialog.cpp
30,15 → 30,12
#include "prefsmanager.h"
#include "prefsfile.h"
#include "util.h"
#include "stencilreader.h"
#include "scconfig.h"
#include <qpixmap.h>
#include <qimage.h>
 
PatternDialog::PatternDialog(QWidget* parent, QMap<QString, ScPattern> *docPatterns, ScribusDoc *doc, ScribusMainWindow *scMW) : patternDialogBase(parent)
PatternDialog::PatternDialog(QWidget* parent, QMap<QString, ScPattern> *docPatterns, ScribusDoc *doc) : patternDialogBase(parent)
{
m_doc = doc;
mainWin = scMW;
patternView->clear();
for (QMap<QString, ScPattern>::Iterator it = docPatterns->begin(); it != docPatterns->end(); ++it)
{
70,37 → 67,10
void PatternDialog::loadPattern()
{
QString fileName;
QString formats = "";
QString form1 = "";
QString form2 = "";
for ( uint i = 0; i < QImageIO::inputFormats().count(); ++i )
{
form1 = QString(QImageIO::inputFormats().at(i)).lower();
form2 = QString(QImageIO::inputFormats().at(i)).upper();
if (form1 == "jpeg")
{
form1 = "jpg";
form2 = "JPG";
}
if ((form1 == "png") || (form1 == "xpm") || (form1 == "gif"))
{
formats += form2 + " (*."+form1+" *."+form2+");;";
}
else if (form1 == "jpg")
{
// JPEG is a special case because both .jpg and .jpeg
// are acceptable extensions.
formats += "JPEG (*.jpg *.jpeg *.JPG *.JPEG);;";
}
}
#ifdef HAVE_TIFF
formats += "TIFF (*.tif *.tiff *.TIF *.TIFF);;";
#endif
formats += "PSD (*.psd *.PSD);;";
formats += "EPS (*.eps *.EPS);;PDF (*.pdf *.PDF);;Dia Shapes (*.shape *.SHAPE);;Kivio Stencils (*.sml *.SML);;Scribus Objects (*.sce *.SCE);;" + tr("All Files (*)");
QString formatD(setupImageFormats());
PrefsContext* dirs = PrefsManager::instance()->prefsFile->getContext("dirs");
QString wdir = dirs->get("patterns", ".");
CustomFDialog dia(this, wdir, tr("Open"), formats, fdExistingFiles);
CustomFDialog dia(this, wdir, tr("Open"), formatD, fdShowPreview | fdExistingFiles);
if (dia.exec() == QDialog::Accepted)
fileName = dia.selectedFile();
else
109,73 → 79,18
{
PrefsManager::instance()->prefsFile->getContext("dirs")->set("patterns", fileName.left(fileName.findRev("/")));
QFileInfo fi(fileName);
if ((fi.extension(true).lower() == "sml") || (fi.extension(true).lower() == "shape") || (fi.extension(true).lower() == "sce"))
loadVectors(fileName);
else
QString patNam = fi.baseName().stripWhiteSpace().simplifyWhiteSpace().replace(" ", "_");
ScPattern pat = ScPattern();
pat.setDoc(m_doc);
pat.setPattern(fileName);
if (!dialogPatterns.contains(patNam))
{
QString patNam = fi.baseName().stripWhiteSpace().simplifyWhiteSpace().replace(" ", "_");
ScPattern pat = ScPattern();
pat.setDoc(m_doc);
pat.setPattern(fileName);
if (!dialogPatterns.contains(patNam))
{
dialogPatterns.insert(patNam, pat);
updatePatternList();
}
dialogPatterns.insert(patNam, pat);
updatePatternList();
}
}
}
 
void PatternDialog::loadVectors(QString data)
{
QFileInfo fi(data);
QString patNam = fi.baseName().stripWhiteSpace().simplifyWhiteSpace().replace(" ", "_");
if (fi.extension(true).lower() == "sml")
{
QString f = "";
loadText(data, &f);
StencilReader *pre = new StencilReader();
data = pre->createObjects(f);
delete pre;
}
else if (fi.extension(true).lower() == "shape")
{
QString f = "";
loadText(data, &f);
StencilReader *pre = new StencilReader();
data = pre->createShape(f);
delete pre;
}
else if (fi.extension(true).lower() == "sce")
{
QString f = "";
loadText(data, &f);
data = f;
}
uint ac = m_doc->Items->count();
bool savedAlignGrid = m_doc->useRaster;
bool savedAlignGuides = m_doc->SnapGuides;
m_doc->useRaster = false;
m_doc->SnapGuides = false;
mainWin->slotElemRead(data, m_doc->currentPage()->xOffset(), m_doc->currentPage()->yOffset(), false, true, m_doc, m_doc->view());
m_doc->useRaster = savedAlignGrid;
m_doc->SnapGuides = savedAlignGuides;
uint ae = m_doc->Items->count();
ScPattern pat = ScPattern();
pat.setDoc(m_doc);
PageItem* currItem = m_doc->Items->at(ac);
pat.pattern = currItem->DrawObj_toImage();
for (uint as = ac; as < ae; ++as)
{
pat.items.append(m_doc->Items->take(ac));
}
if (!dialogPatterns.contains(patNam))
{
dialogPatterns.insert(patNam, pat);
updatePatternList();
}
}
 
void PatternDialog::patternSelected(QIconViewItem* it)
{
if (it)