LensDialog::LensDialog(QWidget* parent, ScribusDoc *doc) : QDialog(parent) { setupUi(this); buttonRemove->setEnabled(false); setModal(true); buttonZoomOut->setIcon(QIcon(loadIcon("16/zoom-out.png"))); buttonZoomI->setIcon(QIcon(loadIcon("16/zoom-in.png"))); PageItem *currItem; double gx, gy, gh, gw; doc->m_Selection->setGroupRect(); doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh); uint selectedItemCount = doc->m_Selection->count(); QStack<PageItem*> groupStack; QStack<QGraphicsPathItem*> groupStack2; QStack<PageItem*> groupStack3; groupStack2.push(0); for (uint i = 0; i < selectedItemCount; ++i) { currItem = doc->m_Selection->itemAt(i); FPointArray path = currItem->PoLine; QPainterPath pp; if (currItem->itemType() == PageItem::PolyLine) pp = path.toQPainterPath(false); else pp = path.toQPainterPath(true); origPath.append(pp); QGraphicsPathItem* pItem = new QGraphicsPathItem(pp, groupStack2.top()); if (groupStack2.top() == 0) { scene.addItem(pItem); pItem->setPos(currItem->xPos() - gx, currItem->yPos() - gy); pItem->rotate(currItem->rotation()); } else { PageItem* parent = groupStack3.top(); QMatrix mm; mm.rotate(-parent->rotation()); mm.translate(-parent->xPos(), -parent->yPos()); pItem->setPos(mm.map(QPointF(currItem->xPos(), currItem->yPos()))); } pItem->setZValue(i); origPathItem.append(pItem); if (((currItem->fillColor() == CommonStrings::None) && (currItem->GrType == 0)) || (currItem->controlsGroup())) pItem->setBrush(Qt::NoBrush); else { if (currItem->GrType != 0) { if (currItem->GrType != 8) { QGradient pat; double x1 = currItem->GrStartX; double y1 = currItem->GrStartY; double x2 = currItem->GrEndX; double y2 = currItem->GrEndY; switch (currItem->GrType) { case 1: case 2: case 3: case 4: case 6: pat = QLinearGradient(x1, y1, x2, y2); break; case 5: case 7: pat = QRadialGradient(x1, y1, sqrt(pow(x2 - x1, 2) + pow(y2 - y1,2)), x1, y1); break; } QList<VColorStop*> colorStops = currItem->fill_gradient.colorStops(); QColor qStopColor; for( int offset = 0 ; offset < colorStops.count() ; offset++ ) { qStopColor = colorStops[ offset ]->color; int h, s, v, sneu, vneu; int shad = colorStops[offset]->shade; qStopColor.getHsv(&h, &s, &v); sneu = s * shad / 100; vneu = 255 - ((255 - v) * shad / 100); qStopColor.setHsv(h, sneu, vneu); qStopColor.setAlphaF(colorStops[offset]->opacity); pat.setColorAt(colorStops[ offset ]->rampPoint, qStopColor); } pItem->setBrush(pat); } else if ((currItem->GrType == 8) && (!currItem->pattern().isEmpty()) && (doc->docPatterns.contains(currItem->pattern()))) { double patternScaleX, patternScaleY, patternOffsetX, patternOffsetY, patternRotation; currItem->patternTransform(patternScaleX, patternScaleY, patternOffsetX, patternOffsetY, patternRotation); QMatrix qmatrix; qmatrix.translate(patternOffsetX, patternOffsetY); qmatrix.rotate(patternRotation); qmatrix.scale(patternScaleX / 100.0, patternScaleY / 100.0); QImage pat = *doc->docPatterns[currItem->pattern()].getPattern(); QBrush brush = QBrush(pat); brush.setMatrix(qmatrix); pItem->setBrush(brush); } } else { QColor paint = ScColorEngine::getShadeColorProof(doc->PageColors[currItem->fillColor()], doc, currItem->fillShade()); paint.setAlphaF(1.0 - currItem->fillTransparency()); pItem->setBrush(paint); } } if ((currItem->lineColor() == CommonStrings::None) || (currItem->controlsGroup())) pItem->setPen(Qt::NoPen); else { QColor paint = ScColorEngine::getShadeColorProof(doc->PageColors[currItem->lineColor()], doc, currItem->lineShade()); paint.setAlphaF(1.0 - currItem->lineTransparency()); pItem->setPen(QPen(paint, currItem->lineWidth(), currItem->lineStyle(), currItem->lineEnd(), currItem->lineJoin())); } if (currItem->controlsGroup()) { groupStack.push(currItem->groupsLastItem); groupStack2.push(pItem); groupStack3.push(currItem); pItem->setFlags(QGraphicsItem::ItemClipsChildrenToShape); } if (groupStack.count() != 0) { while (currItem == groupStack.top()) { groupStack3.pop(); groupStack2.pop(); groupStack.pop(); if (groupStack.count() == 0) break; } } } previewWidget->setRenderHint(QPainter::Antialiasing); previewWidget->setScene(&scene); isFirst = true; addLens(); connect(spinXPos, SIGNAL(valueChanged(double)), this, SLOT(setNewLensX(double))); connect(spinYPos, SIGNAL(valueChanged(double)), this, SLOT(setNewLensY(double))); connect(spinRadius, SIGNAL(valueChanged(double)), this, SLOT(setNewLensRadius(double))); connect(spinStrength, SIGNAL(valueChanged(double)), this, SLOT(setNewLensStrength(double))); connect(buttonAdd, SIGNAL(clicked()), this, SLOT(addLens())); connect(buttonRemove, SIGNAL(clicked()), this, SLOT(removeLens())); connect(buttonMagnify, SIGNAL(toggled(bool)), this, SLOT(changeLens())); connect(buttonZoomI, SIGNAL(clicked()), this, SLOT(doZoomIn())); connect(buttonZoomOut, SIGNAL(clicked()), this, SLOT(doZoomOut())); connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); connect(&scene, SIGNAL(selectionChanged()), this, SLOT(selectionHasChanged())); }
/*! ** @brief Load configuration from a file ** ** @param[In] filename Filename to load from ** ** @return True/False */ bool ClassicPrint::load(QString filename) { QDomDocument doc("ClassicPrint"); QFile file(filename); if (!file.open(QIODevice::ReadOnly)) { return false; } if (!doc.setContent(&file)) { return false; } // Get the root element QDomElement root = doc.documentElement(); if (root.tagName() != "ClassicPrint") { return false; } // Iterate through all elements QDomNode n = root.firstChild(); while (!n.isNull()) { // Try to convert the node to an element. QDomElement e = n.toElement(); if(!e.isNull()) { if (e.tagName() == "LastPhotoFolder") { m_photo_folder = e.text(); } else if (e.tagName() == "LastSaveFolder") { m_save_folder = e.text(); } else if (e.tagName() == "LastSaveWidth") { m_save_width = e.text().toInt(); } else if (e.tagName() == "LastSaveHeight") { m_save_height = e.text().toInt(); } else if (e.tagName() == "Lenses") { QDomNode child = e.firstChild(); while (!child.isNull()) { // Try to convert the node to an element. QDomElement child_elem = child.toElement(); if(!child_elem.isNull()) { ClassicPrintLens* lens = new ClassicPrintLens(); if (lens->load_node(doc, child_elem)) { addLens(lens); } } child = child.nextSibling(); } } else if (e.tagName() == "Films") { QDomNode child = e.firstChild(); while (!child.isNull()) { // Try to convert the node to an element. QDomElement child_elem = child.toElement(); if(!child_elem.isNull()) { ClassicPrintFilm* film = new ClassicPrintFilm(); if (film->load_node(doc, child_elem)) { addFilm(film); } } child = child.nextSibling(); } } else if (e.tagName() == "Processes") { QDomNode child = e.firstChild(); while (!child.isNull()) { // Try to convert the node to an element. QDomElement child_elem = child.toElement(); if(!child_elem.isNull()) { ClassicPrintProcessing* proc = new ClassicPrintProcessing(this); if (proc->load_node(doc, child_elem)) { addProcessing(proc); } } child = child.nextSibling(); } } else if (e.tagName() == "CurrentLens") { delete m_current_lens; m_current_lens = new ClassicPrintLens(); if (!m_current_lens->load_node(doc, e)) { delete m_current_lens; m_current_lens = NULL; } } else if (e.tagName() == "CurrentFilm") { delete m_current_film; m_current_film = new ClassicPrintFilm(); if (!m_current_film->load_node(doc, e)) { delete m_current_film; m_current_film = NULL; } } else if (e.tagName() == "CurrentProcessing") { delete m_current_processing; m_current_processing = new ClassicPrintProcessing(this); if (!m_current_processing->load_node(doc, e)) { delete m_current_processing; m_current_processing = NULL; } } } n = n.nextSibling(); } // If any of the current settings are missing then pick the first saved setting if (!m_current_lens && (m_lenses.size() > 0)) { setCurrentLens(m_lenses.begin().value()->name()); } if (!m_current_film && (m_films.size() > 0)) { setCurrentFilm(m_films.begin().value()->name()); } if (!m_current_processing && (m_processes.size() > 0)) { setCurrentProcessing(m_processes.begin().value()->name()); } return true; }