void BarcodeGenerator::okButton_pressed() { QString psFile = QDir::toNativeSeparators(ScPaths::tempFileDir() + "bcode.ps"); // no need to call paintBarcode(pngFile, 300); because // it's created by previous run... hide(); const FileFormat * fmt = LoadSavePlugin::getFormatByExt("ps"); UndoTransaction tran; if (UndoManager::undoEnabled()) { tran = UndoManager::instance()->beginTransaction( ScCore->primaryMainWindow()->doc->currentPage()->getUName(), Um::IImageFrame, Um::ImportBarcode, ui.bcCombo->currentText() + " (" + ui.codeEdit->text() + ")", Um::IEPS); } if (fmt) { fmt->loadFile(psFile, LoadSavePlugin::lfUseCurrentPage|LoadSavePlugin::lfInteractive); if (tran) tran.commit(); } accept(); }
bool WMFImportPlugin::import(QString filename, int flags) { if (!checkFlags(flags)) return false; if (m_Doc == nullptr) m_Doc = ScCore->primaryMainWindow()->doc; ScribusMainWindow* mw=(m_Doc==nullptr) ? ScCore->primaryMainWindow() : m_Doc->scMW(); if (filename.isEmpty()) { flags |= lfInteractive; PrefsContext* prefs = PrefsManager::instance()->prefsFile->getPluginContext("WMFPlugin"); QString wdir = prefs->get("wdir", "."); CustomFDialog diaf(mw, wdir, QObject::tr("Open"), FormatsManager::instance()->fileDialogFormatList(FormatsManager::WMF)); if (diaf.exec()) { filename = diaf.selectedFile(); prefs->set("wdir", filename.left(filename.lastIndexOf("/"))); } else return true; } bool hasCurrentPage = (m_Doc && m_Doc->currentPage()); TransactionSettings trSettings; trSettings.targetName = hasCurrentPage ? m_Doc->currentPage()->getUName() : ""; trSettings.targetPixmap = Um::IImageFrame; trSettings.actionName = Um::ImportWMF; trSettings.description = filename; trSettings.actionPixmap = Um::IWMF; UndoTransaction activeTransaction; if ((m_Doc == nullptr) || !(flags & lfInteractive) || !(flags & lfScripted)) UndoManager::instance()->setUndoEnabled(false); if (UndoManager::undoEnabled()) activeTransaction = UndoManager::instance()->beginTransaction(trSettings); WMFImport *dia = new WMFImport(m_Doc, flags); dia->import(filename, trSettings, flags); Q_CHECK_PTR(dia); if (activeTransaction) activeTransaction.commit(); if ((m_Doc == nullptr) || !(flags & lfInteractive) || !(flags & lfScripted)) UndoManager::instance()->setUndoEnabled(true); if (dia->importCanceled) { if (dia->importFailed) ScMessageBox::warning(mw, CommonStrings::trWarning, tr("The file could not be imported")); else if (dia->unsupported) ScMessageBox::warning(mw, CommonStrings::trWarning, tr("WMF file contains some unsupported features")); } bool success = !dia->importFailed; delete dia; return success; }
void CanvasMode_ObjImport::mousePressEvent(QMouseEvent *m) { // const double mouseX = m->globalX(); // const double mouseY = m->globalY(); const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos()); double Rxp = 0, Ryp = 0; m_canvas->PaintSizeRect(QRect()); m_canvas->m_viewMode.m_MouseButtonPressed = true; m_canvas->m_viewMode.operItemMoving = false; m_view->HaveSelRect = false; m_doc->DragP = false; m_doc->leaveDrag = false; // oldClip = 0; m->accept(); m_view->registerMousePress(m->globalPos()); Mxp = mousePointDoc.x(); Myp = mousePointDoc.y(); Rxp = m_doc->ApplyGridF(FPoint(Mxp, Myp)).x(); Mxp = qRound(Rxp); Ryp = m_doc->ApplyGridF(FPoint(Mxp, Myp)).y(); Myp = qRound(Ryp); if (m->button() == Qt::MidButton) { m_view->MidButt = true; if (m->modifiers() & Qt::ControlModifier) m_view->DrawNew(); return; } if ((m->button() == Qt::LeftButton) && m_mimeData) { UndoTransaction* undoTransaction = NULL; if (m_trSettings && UndoManager::undoEnabled()) { undoTransaction = new UndoTransaction(UndoManager::instance()->beginTransaction(*m_trSettings)); } // Creating QDragEnterEvent outside of Qt is not recommended per docs :S QPoint dropPos = m_view->widget()->mapFromGlobal(m->globalPos()); QDropEvent dropEvent(dropPos, Qt::CopyAction|Qt::MoveAction, m_mimeData, m->buttons(), m->modifiers()); m_view->contentsDropEvent(&dropEvent); // Commit undo transaction if necessary if (undoTransaction) { undoTransaction->commit(); delete undoTransaction; undoTransaction = NULL; } // Return to normal mode m_view->requestMode(modeNormal); } }
void gtAction::writeUnstyled(const QString& text) { UndoTransaction* activeTransaction = NULL; if (isFirstWrite) { if (!doAppend) { if (UndoManager::undoEnabled()) activeTransaction = new UndoTransaction(undoManager->beginTransaction(Um::Selection, Um::IGroup, Um::ImportText, "", Um::IDelete)); if (it->nextInChain() != 0) { PageItem *nextItem = it->nextInChain(); while (nextItem != 0) { nextItem->itemText.selectAll(); nextItem->asTextFrame()->deleteSelectedTextFromFrame(); nextItem = nextItem->nextInChain(); } } it->itemText.selectAll(); it->asTextFrame()->deleteSelectedTextFromFrame(); } } QChar ch0(0), ch5(5), ch10(10), ch13(13); QString textStr = text; textStr.remove(ch0); textStr.remove(ch13); textStr.replace(ch10,ch13); textStr.replace(ch5,ch13); textStr.replace(QString(0x2028),SpecialChars::LINEBREAK); textStr.replace(QString(0x2029),SpecialChars::PARSEP); int pos = it->itemText.length(); if (UndoManager::undoEnabled()) { SimpleState *ss = new SimpleState(Um::AppendText,"",Um::ICreate); ss->set("INSERT_FRAMETEXT", "insert_frametext"); ss->set("TEXT_STR",textStr); ss->set("START", pos); undoManager->action(it, ss); } it->itemText.insertChars(pos, textStr); lastCharWasLineChange = text.right(1) == "\n"; isFirstWrite = false; if (activeTransaction) { activeTransaction->commit(); delete activeTransaction; activeTransaction = NULL; } }
bool ImportXfigPlugin::import(QString fileName, int flags) { if (!checkFlags(flags)) return false; if( fileName.isEmpty() ) { flags |= lfInteractive; PrefsContext* prefs = PrefsManager::instance()->prefsFile->getPluginContext("importxfig"); QString wdir = prefs->get("wdir", "."); CustomFDialog diaf(ScCore->primaryMainWindow(), wdir, QObject::tr("Open"), tr("All Supported Formats")+" (*.fig *.FIG);;All Files (*)"); if (diaf.exec()) { fileName = diaf.selectedFile(); prefs->set("wdir", fileName.left(fileName.lastIndexOf("/"))); } else return true; } m_Doc=ScCore->primaryMainWindow()->doc; UndoTransaction* activeTransaction = NULL; bool emptyDoc = (m_Doc == NULL); bool hasCurrentPage = (m_Doc && m_Doc->currentPage()); TransactionSettings trSettings; trSettings.targetName = hasCurrentPage ? m_Doc->currentPage()->getUName() : ""; trSettings.targetPixmap = Um::IImageFrame; trSettings.actionName = Um::ImportXfig; trSettings.description = fileName; trSettings.actionPixmap = Um::IXFIG; if (emptyDoc || !(flags & lfInteractive) || !(flags & lfScripted)) UndoManager::instance()->setUndoEnabled(false); if (UndoManager::undoEnabled()) activeTransaction = new UndoTransaction(UndoManager::instance()->beginTransaction(trSettings)); XfigPlug *dia = new XfigPlug(m_Doc, flags); Q_CHECK_PTR(dia); dia->import(fileName, trSettings, flags); if (activeTransaction) { activeTransaction->commit(); delete activeTransaction; activeTransaction = NULL; } if (emptyDoc || !(flags & lfInteractive) || !(flags & lfScripted)) UndoManager::instance()->setUndoEnabled(true); delete dia; return true; }
void CanvasMode_ObjImport::mouseReleaseEvent(QMouseEvent *m) { m_canvas->m_viewMode.m_MouseButtonPressed = false; m_canvas->resetRenderMode(); m->accept(); if ((m->button() == Qt::LeftButton) && m_mimeData) { UndoTransaction* undoTransaction = NULL; if (m_trSettings && UndoManager::undoEnabled()) { undoTransaction = new UndoTransaction(UndoManager::instance()->beginTransaction(*m_trSettings)); } // Creating QDragEnterEvent outside of Qt is not recommended per docs :S QPoint dropPos = m_view->widget()->mapFromGlobal(m->globalPos()); const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos()); QDropEvent dropEvent(dropPos, Qt::CopyAction|Qt::MoveAction, m_mimeData, m->buttons(), m->modifiers()); m_view->contentsDropEvent(&dropEvent); if (m_doc->m_Selection->count() > 0) { double gx, gy, gh, gw; m_doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh); m_doc->moveGroup(mousePointDoc.x() - gx, mousePointDoc.y() -gy); } // Commit undo transaction if necessary if (undoTransaction) { undoTransaction->commit(); delete undoTransaction; undoTransaction = NULL; } // Return to normal mode m_view->requestMode(modeNormal); } // m_view->stopDragTimer(); m_canvas->setRenderModeUseBuffer(false); m_doc->DragP = false; m_doc->leaveDrag = false; m_canvas->m_viewMode.operItemMoving = false; m_canvas->m_viewMode.operItemResizing = false; m_view->MidButt = false; //Make sure the Zoom spinbox and page selector dont have focus if we click on the canvas m_view->m_ScMW->zoomSpinBox->clearFocus(); m_view->m_ScMW->pageSelector->clearFocus(); }
bool ImportPSPlugin::import(QString fileName, int flags) { if (!checkFlags(flags)) return false; if( fileName.isEmpty() ) { flags |= lfInteractive; PrefsContext* prefs = PrefsManager::instance()->prefsFile->getPluginContext("importps"); QString wdir = prefs->get("wdir", "."); CustomFDialog diaf(ScCore->primaryMainWindow(), wdir, QObject::tr("Open"), FormatsManager::instance()->fileDialogFormatList(FormatsManager::EPS|FormatsManager::PS)); if (diaf.exec()) { fileName = diaf.selectedFile(); prefs->set("wdir", fileName.left(fileName.lastIndexOf("/"))); } else return true; } m_Doc=ScCore->primaryMainWindow()->doc; UndoTransaction activeTransaction; bool emptyDoc = (m_Doc == nullptr); bool hasCurrentPage = (m_Doc && m_Doc->currentPage()); TransactionSettings trSettings; trSettings.targetName = hasCurrentPage ? m_Doc->currentPage()->getUName() : ""; trSettings.targetPixmap = Um::IImageFrame; trSettings.actionName = Um::ImportEPS; trSettings.description = fileName; trSettings.actionPixmap = Um::IEPS; if (emptyDoc || !(flags & lfInteractive) || !(flags & lfScripted)) UndoManager::instance()->setUndoEnabled(false); if (UndoManager::undoEnabled()) activeTransaction = UndoManager::instance()->beginTransaction(trSettings); EPSPlug *dia = new EPSPlug(m_Doc, flags); Q_CHECK_PTR(dia); dia->import(fileName, trSettings, flags); if (activeTransaction) activeTransaction.commit(); if (emptyDoc || !(flags & lfInteractive) || !(flags & lfScripted)) UndoManager::instance()->setUndoEnabled(true); delete dia; return true; }
bool PathConnectPlugin::run(ScribusDoc* doc, QString) { m_doc = doc; firstUpdate = true; if (m_doc == 0) m_doc = ScCore->primaryMainWindow()->doc; if (m_doc->m_Selection->count() > 1) { m_item1 = m_doc->m_Selection->itemAt(0); m_item2 = m_doc->m_Selection->itemAt(1); originalPath1 = m_item1->PoLine.copy(); originalPath2 = m_item2->PoLine.copy(); originalXPos = m_item1->xPos(); originalYPos = m_item1->yPos(); PathConnectDialog *dia = new PathConnectDialog(m_doc->scMW()); connect(dia, SIGNAL(updateValues(int, int, int, int)), this, SLOT(updateEffect(int, int, int, int))); if (dia->exec()) { int pointOne = dia->getFirstLinePoint(); int pointTwo = dia->getSecondLinePoint(); int mode = dia->getMode(); UndoTransaction *trans = NULL; if(UndoManager::undoEnabled()) trans = new UndoTransaction(UndoManager::instance()->beginTransaction(Um::BezierCurve,Um::ILine,Um::ConnectPath,"",Um::ILine)); m_item1->PoLine = computePath(pointOne, pointTwo, mode, originalPath1, originalPath2); m_item1->ClipEdited = true; m_item1->FrameType = 3; m_doc->AdjustItemSize(m_item1); m_item1->OldB2 = m_item1->width(); m_item1->OldH2 = m_item1->height(); if(UndoManager::undoEnabled()) { ScItemState<QPair<FPointArray,FPointArray> > *is = new ScItemState<QPair<FPointArray,FPointArray> >(Um::ConnectPath); is->set("CONNECT_PATH","connect_path"); is->set("OLDX", originalXPos); is->set("OLDY", originalYPos); is->set("NEWX", m_item1->xPos()); is->set("NEWY", m_item1->yPos()); is->setItem(qMakePair(originalPath1, m_item1->PoLine)); UndoManager::instance()->action(m_item1, is); } m_item1->updateClip(); m_item1->ContourLine = m_item1->PoLine.copy(); m_doc->m_Selection->removeItem(m_item1); m_doc->itemSelection_DeleteItem(); m_doc->changed(); if (trans) { trans->commit(); delete trans; trans = NULL; } } else { m_item1->PoLine = originalPath1.copy(); m_item1->ClipEdited = true; m_item1->FrameType = 3; m_item1->setXYPos(originalXPos, originalYPos); m_doc->AdjustItemSize(m_item1); m_item1->OldB2 = m_item1->width(); m_item1->OldH2 = m_item1->height(); m_item1->updateClip(); m_item1->ContourLine = m_item1->PoLine.copy(); } m_doc->view()->DrawNew(); delete dia; }
void gtAction::writeUnstyled(const QString& text, bool isNote) { UndoTransaction activeTransaction; if (isFirstWrite && it->itemText.length() > 0) { if (!doAppend) { if (UndoManager::undoEnabled()) activeTransaction = undoManager->beginTransaction(Um::Selection, Um::IGroup, Um::ImportText, "", Um::IDelete); if (it->nextInChain() != 0) { PageItem *nextItem = it->nextInChain(); while (nextItem != 0) { nextItem->itemText.selectAll(); nextItem->asTextFrame()->deleteSelectedTextFromFrame(); nextItem = nextItem->nextInChain(); } } it->itemText.selectAll(); it->asTextFrame()->deleteSelectedTextFromFrame(); } } QChar ch0(0), ch5(5), ch10(10), ch13(13); QString textStr = text; textStr.remove(ch0); textStr.remove(ch13); textStr.replace(ch10,ch13); textStr.replace(ch5,ch13); textStr.replace(QString(0x2028),SpecialChars::LINEBREAK); textStr.replace(QString(0x2029),SpecialChars::PARSEP); if (isNote) { if (note == NULL) { note = it->m_Doc->newNote(it->m_Doc->m_docNotesStylesList.at(0)); Q_ASSERT(noteStory == NULL); noteStory = new StoryText(it->m_Doc); } if (textStr == SpecialChars::OBJECT) { NotesStyle* nStyle = note->notesStyle(); QString label = "NoteMark_" + nStyle->name(); if (nStyle->range() == NSRsection) label += " in section " + it->m_Doc->getSectionNameForPageIndex(it->OwnPage) + " page " + QString::number(it->OwnPage +1); else if (nStyle->range() == NSRpage) label += " on page " + QString::number(it->OwnPage +1); else if (nStyle->range() == NSRstory) label += " in " + it->firstInChain()->itemName(); else if (nStyle->range() == NSRframe) label += " in frame" + it->itemName(); if (it->m_Doc->getMark(label + "_1", MARKNoteMasterType) != NULL) getUniqueName(label,it->m_Doc->marksLabelsList(MARKNoteMasterType), "_"); //FIX ME here user should be warned that inserted mark`s label was changed else label = label + "_1"; Mark* mrk = it->m_Doc->newMark(); mrk->label = label; mrk->setType(MARKNoteMasterType); mrk->setNotePtr(note); note->setMasterMark(mrk); if (noteStory->text(noteStory->length() -1) == SpecialChars::PARSEP) noteStory->removeChars(noteStory->length() -1, 1); note->setSaxedText(saxedText(noteStory)); mrk->setString(""); mrk->OwnPage = it->OwnPage; it->itemText.insertMark(mrk); if (UndoManager::undoEnabled()) { ScItemsState* is = new ScItemsState(UndoManager::InsertNote); is->set("ETEA", mrk->label); is->set("MARK", QString("new")); is->set("label", mrk->label); is->set("type", (int) MARKNoteMasterType); is->set("strtxt", QString("")); is->set("nStyle", nStyle->name()); is->set("at", it->itemText.cursorPosition() -1); is->insertItem("inItem", it); undoManager->action(it->m_Doc, is); } note = NULL; delete noteStory; } else noteStory->insertChars(noteStory->length(), textStr); } else { int pos = it->itemText.length(); if (UndoManager::undoEnabled()) { SimpleState *ss = new SimpleState(Um::AppendText,"",Um::ICreate); ss->set("INSERT_FRAMETEXT", "insert_frametext"); ss->set("TEXT_STR",textStr); ss->set("START", pos); undoManager->action(it, ss); } it->itemText.insertChars(pos, textStr); } lastCharWasLineChange = text.right(1) == "\n"; isFirstWrite = false; if (activeTransaction) { activeTransaction.commit(); } }
void CalligraphicMode::mouseReleaseEvent(QMouseEvent *m) { undoManager->setUndoEnabled(true); PageItem *currItem; m_MouseButtonPressed = false; m_canvas->resetRenderMode(); m->accept(); if (m_doc->appMode == modeDrawCalligraphicLine) { if (RecordP.size() > 1) { UndoTransaction createTransaction; if (UndoManager::undoEnabled()) createTransaction = UndoManager::instance()->beginTransaction(); uint z = m_doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, Mxp, Myp, 1, 1, m_doc->itemToolPrefs().calligraphicPenLineWidth, m_doc->itemToolPrefs().calligraphicPenFillColor, m_doc->itemToolPrefs().calligraphicPenLineColor); currItem = m_doc->Items->at(z); currItem->PoLine.resize(0); QList<QPointF> clipU; QList<QPointF> clipL; double mx = sin(m_doc->itemToolPrefs().calligraphicPenAngle / 180.0 * M_PI) * (m_doc->itemToolPrefs().calligraphicPenWidth / 2.0); double my = cos(m_doc->itemToolPrefs().calligraphicPenAngle / 180.0 * M_PI) * (m_doc->itemToolPrefs().calligraphicPenWidth / 2.0); for (int px = 0; px < RecordP.size()-1; ++px) { FPoint clp = RecordP.point(px); clipU.append(QPointF(clp.x() - mx, clp.y() - my)); clipL.prepend(QPointF(clp.x() + mx, clp.y() + my)); } QPainterPath ppU = bezierFit(clipU, 5.0); QPainterPath ppL = bezierFit(clipL, 5.0); QPainterPath pp; pp.addPath(ppU); pp.connectPath(ppL); pp.closeSubpath(); currItem->PoLine.fromQPainterPath(pp); FPoint tp2(getMinClipF(&currItem->PoLine)); currItem->setXYPos(tp2.x(), tp2.y(), true); currItem->PoLine.translate(-tp2.x(), -tp2.y()); FPoint tp(getMaxClipF(&currItem->PoLine)); m_doc->sizeItem(tp.x(), tp.y(), currItem, false, false, false); m_doc->adjustItemSize(currItem); m_doc->m_Selection->clear(); m_doc->m_Selection->addItem(currItem); currItem->ClipEdited = true; currItem->FrameType = 3; currItem->OwnPage = m_doc->OnPage(currItem); currItem->PLineArt = Qt::PenStyle(m_doc->itemToolPrefs().calligraphicPenStyle); currItem->setFillShade(m_doc->itemToolPrefs().calligraphicPenFillColorShade); currItem->setLineShade(m_doc->itemToolPrefs().calligraphicPenLineColorShade); currItem->setFillEvenOdd(true); m_view->resetMousePressed(); currItem->checkChanges(); QString targetName = Um::ScratchSpace; if (currItem->OwnPage > -1) targetName = m_doc->Pages->at(currItem->OwnPage)->getUName(); if (createTransaction) createTransaction.commit(targetName, currItem->getUPixmap(), Um::Create + " " + currItem->getUName(), "", Um::ICreate); //FIXME m_canvas->m_viewMode.operItemResizing = false; m_doc->changed(); } if (!PrefsManager::instance()->appPrefs.uiPrefs.stickyTools) { m_view->requestMode(modeNormal); } else m_view->requestMode(m_doc->appMode); return; } m_canvas->setRenderModeUseBuffer(false); m_doc->DragP = false; m_doc->leaveDrag = false; m_view->MidButt = false; if (m_view->groupTransactionStarted()) { for (int i = 0; i < m_doc->m_Selection->count(); ++i) m_doc->m_Selection->itemAt(i)->checkChanges(true); m_view->endGroupTransaction(); } for (int i = 0; i < m_doc->m_Selection->count(); ++i) m_doc->m_Selection->itemAt(i)->checkChanges(true); //Commit drag created items to undo manager. if (m_doc->m_Selection->itemAt(0)!=NULL) { m_doc->itemAddCommit(m_doc->m_Selection->itemAt(0)); } //Make sure the Zoom spinbox and page selector don't have focus if we click on the canvas m_view->m_ScMW->zoomSpinBox->clearFocus(); m_view->m_ScMW->pageSelector->clearFocus(); if (m_doc->m_Selection->itemAt(0) != 0) // is there the old clip stored for the undo action { currItem = m_doc->m_Selection->itemAt(0); m_doc->nodeEdit.finishTransaction(currItem); } }
bool PathFinderPlugin::run(ScribusDoc* doc, QString) { ScribusDoc* currDoc = doc; if (currDoc == 0) currDoc = ScCore->primaryMainWindow()->doc; if (currDoc->m_Selection->count() <= 1) return true; //<<#9046 UndoTransaction* activeTransaction = NULL; UndoManager* undoManager = UndoManager::instance(); if (UndoManager::undoEnabled()) activeTransaction = new UndoTransaction(undoManager->beginTransaction(Um::SelectionGroup, Um::IDocument, Um::PathOperation, "", Um::IPolygon)); //>>#9046 PageItem *Item1 = currDoc->m_Selection->itemAt(0); PageItem *Item2 = currDoc->m_Selection->itemAt(1); PathFinderDialog *dia = new PathFinderDialog(currDoc->scMW(), currDoc, Item1, Item2); if (dia->exec()) { int opMode=dia->opMode; if (dia->keepItem1) { PageItem *newItem; if (dia->swapped) { newItem = new PageItem_Polygon(*Item2); newItem->setSelected(false); currDoc->Items->insert(currDoc->Items->indexOf(Item2), newItem); } else { newItem = new PageItem_Polygon(*Item1); newItem->setSelected(false); currDoc->Items->insert(currDoc->Items->indexOf(Item1), newItem); } if (UndoManager::undoEnabled()) { ScItemState<PageItem*> *is = new ScItemState<PageItem*>("Create PageItem"); is->set("CREATE_ITEM", "create_item"); is->setItem(newItem); UndoObject *target = currDoc->Pages->at(Item1->OwnPage); undoManager->action(target, is); } } if (dia->keepItem2) { PageItem *newItem; if (dia->swapped) { newItem = new PageItem_Polygon(*Item1); newItem->setSelected(false); currDoc->Items->insert(currDoc->Items->indexOf(Item1), newItem); } else { newItem = new PageItem_Polygon(*Item2); newItem->setSelected(false); currDoc->Items->insert(currDoc->Items->indexOf(Item2), newItem); } if (UndoManager::undoEnabled()) { ScItemState<PageItem*> *is = new ScItemState<PageItem*>("Create PageItem"); is->set("CREATE_ITEM", "create_item"); is->setItem(newItem); UndoObject *target = currDoc->Pages->at(Item1->OwnPage); undoManager->action(target, is); } } if (opMode != 4) { PageItem *currItem; QPainterPath path; FPointArray points; if (dia->targetColor == 0) { currItem = Item1; if (dia->swapped) { currItem = Item2; currItem->setXYPos(Item1->xPos(), Item1->yPos()); currItem->setRotation(0.0); } } else { if (dia->swapped) currItem = Item1; else { currItem = Item2; currItem->setXYPos(Item1->xPos(), Item1->yPos()); currItem->setRotation(0.0); } } path = dia->result; points.fromQPainterPath(path); //<<#9046 FPointArray oldPOLine=currItem->PoLine; FPointArray oldContourLine=currItem->ContourLine; ScItemState<QPair<QPair<FPointArray, FPointArray>, QPair<FPointArray, FPointArray> > >* state = NULL; if (UndoManager::undoEnabled()) { state = new ScItemState<QPair<QPair<FPointArray, FPointArray>, QPair<FPointArray, FPointArray> > >(Um::PathOperation); state->set("PATH_OPERATION", "path_operation"); state->set("PATH_OP_OLD_FRAME", currItem->Frame); state->set("PATH_OP_OLD_CLIPEDITED", currItem->ClipEdited); state->set("PATH_OP_OLD_FRAMETYPE", currItem->FrameType); state->set("PATH_OP_OLD_OLDB2", currItem->OldB2); state->set("PATH_OP_OLD_OLDH2", currItem->OldH2); state->set("PATH_OP_NEW_FRAME", false); state->set("PATH_OP_NEW_CLIPEDITED", true); state->set("PATH_OP_NEW_FRAMETYPE", 3); } //>>#9046 currItem->PoLine = points; currItem->Frame = false; currItem->ClipEdited = true; currItem->FrameType = 3; currDoc->AdjustItemSize(currItem); currItem->OldB2 = currItem->width(); currItem->OldH2 = currItem->height(); currItem->updateClip(); currItem->ContourLine = currItem->PoLine.copy(); //<<#9046 if (UndoManager::undoEnabled()) { state->set("PATH_OP_NEW_OLDB2", currItem->OldB2); state->set("PATH_OP_NEW_OLDH2", currItem->OldH2); state->setItem(QPair<QPair<FPointArray, FPointArray>, QPair<FPointArray, FPointArray> >(QPair<FPointArray, FPointArray>(oldPOLine, oldContourLine), QPair<FPointArray, FPointArray>(points, currItem->ContourLine))); undoManager->action(currItem, state); } //>>#9046 currDoc->m_Selection->removeItem(currItem); currDoc->itemSelection_DeleteItem(); } else { QPainterPath path; FPointArray points; PageItem *newItem; double i1x = Item1->xPos(); double i1y = Item1->yPos(); path = dia->result; if (!path.isEmpty()) { points.fromQPainterPath(path); //<<#9046 FPointArray oldPOLine=Item1->PoLine; FPointArray oldContourLine=Item1->ContourLine; ScItemState<QPair<QPair<FPointArray, FPointArray>, QPair<FPointArray, FPointArray> > >* state = NULL; if (UndoManager::undoEnabled()) { state = new ScItemState<QPair<QPair<FPointArray, FPointArray>, QPair<FPointArray, FPointArray> > >(Um::PathOperation); state->set("PATH_OPERATION", "path_operation"); state->set("PATH_OP_OLD_FRAME", Item1->Frame); state->set("PATH_OP_OLD_CLIPEDITED", Item1->ClipEdited); state->set("PATH_OP_OLD_FRAMETYPE", Item1->FrameType); state->set("PATH_OP_OLD_OLDB2", Item1->OldB2); state->set("PATH_OP_OLD_OLDH2", Item1->OldH2); state->set("PATH_OP_NEW_FRAME", false); state->set("PATH_OP_NEW_CLIPEDITED", true); state->set("PATH_OP_NEW_FRAMETYPE", 3); } //>>#9046 Item1->PoLine = points; Item1->Frame = false; Item1->ClipEdited = true; Item1->FrameType = 3; currDoc->AdjustItemSize(Item1); Item1->OldB2 = Item1->width(); Item1->OldH2 = Item1->height(); Item1->updateClip(); Item1->ContourLine = Item1->PoLine.copy(); //<<#9046 if (UndoManager::undoEnabled()) { state->set("PATH_OP_NEW_OLDB2", Item1->OldB2); state->set("PATH_OP_NEW_OLDH2", Item1->OldH2); state->setItem(QPair<QPair<FPointArray, FPointArray>, QPair<FPointArray, FPointArray> >(QPair<FPointArray, FPointArray>(oldPOLine, oldContourLine), QPair<FPointArray, FPointArray>(Item1->PoLine, Item1->ContourLine))); undoManager->action(Item1, state); } //>>#9046 } path = QPainterPath(); path = dia->result1; if (!path.isEmpty()) { points.fromQPainterPath(path); //<<#9046 FPointArray oldPOLine=Item2->PoLine; FPointArray oldContourLine=Item2->ContourLine; ScItemState<QPair<QPair<FPointArray, FPointArray>, QPair<FPointArray, FPointArray> > >* state = NULL; if (UndoManager::undoEnabled()) { state = new ScItemState<QPair<QPair<FPointArray, FPointArray>, QPair<FPointArray, FPointArray> > >(Um::PathOperation); state->set("PATH_OPERATION", "path_operation"); state->set("PATH_OP_OLD_FRAME", Item2->Frame); state->set("PATH_OP_OLD_CLIPEDITED", Item2->ClipEdited); state->set("PATH_OP_OLD_FRAMETYPE", Item2->FrameType); state->set("PATH_OP_OLD_OLDB2", Item2->OldB2); state->set("PATH_OP_OLD_OLDH2", Item2->OldH2); state->set("PATH_OP_NEW_FRAME", false); state->set("PATH_OP_NEW_CLIPEDITED", true); state->set("PATH_OP_NEW_FRAMETYPE", 3); } //>>#9046 Item2->setXYPos(i1x, i1y); Item2->setRotation(0.0); Item2->PoLine = points; Item2->Frame = false; Item2->ClipEdited = true; Item2->FrameType = 3; currDoc->AdjustItemSize(Item2); Item2->OldB2 = Item2->width(); Item2->OldH2 = Item2->height(); Item2->updateClip(); Item2->ContourLine = Item2->PoLine.copy(); //<<#9046 if (UndoManager::undoEnabled()) { state->set("PATH_OP_NEW_OLDB2", Item2->OldB2); state->set("PATH_OP_NEW_OLDH2", Item2->OldH2); state->setItem(QPair<QPair<FPointArray, FPointArray>, QPair<FPointArray, FPointArray> >(QPair<FPointArray, FPointArray>(oldPOLine, oldContourLine), QPair<FPointArray, FPointArray>(Item2->PoLine, Item2->ContourLine))); undoManager->action(Item2, state); } //>>#9046 } path = QPainterPath(); path = dia->result2; if (!path.isEmpty()) { if (dia->targetColor == 0) { newItem = new PageItem_Polygon(*Item1); newItem->setXYPos(i1x, i1y); } else { newItem = new PageItem_Polygon(*Item2); newItem->setXYPos(i1x, i1y); newItem->setRotation(0.0); } currDoc->Items->append(newItem); newItem->setSelected(false); points.fromQPainterPath(path); newItem->PoLine = points; newItem->Frame = false; newItem->ClipEdited = true; newItem->FrameType = 3; currDoc->AdjustItemSize(newItem); newItem->OldB2 = newItem->width(); newItem->OldH2 = newItem->height(); newItem->updateClip(); newItem->ContourLine = newItem->PoLine.copy(); if (dia->targetColor == 2) { QString fill = dia->getOtherFillColor(); if (fill == CommonStrings::tr_NoneColor) fill = CommonStrings::None; newItem->setFillColor(fill); QString stroke = dia->getOtherLineColor(); if (stroke == CommonStrings::tr_NoneColor) stroke = CommonStrings::None; newItem->setLineColor(stroke); } } currDoc->m_Selection->clear(); currDoc->view()->Deselect(true); } currDoc->changed(); currDoc->view()->DrawNew(); } delete dia; //<<#9046 if (activeTransaction) { activeTransaction->commit(); delete activeTransaction; activeTransaction = NULL; } //>>#9046 return true; }
bool ImportPdfPlugin::import(QString fileName, int flags) { if (!checkFlags(flags)) return false; if( fileName.isEmpty() ) { flags |= lfInteractive; PrefsContext* prefs = PrefsManager::instance()->prefsFile->getPluginContext("importpdf"); QString wdir = prefs->get("wdir", "."); CustomFDialog diaf(ScCore->primaryMainWindow(), wdir, QObject::tr("Open"), tr("All Supported Formats")+" (*.pdf *.PDF);;All Files (*)"); if (diaf.exec()) { fileName = diaf.selectedFile(); prefs->set("wdir", fileName.left(fileName.lastIndexOf("/"))); } else return true; } m_Doc=ScCore->primaryMainWindow()->doc; UndoTransaction* activeTransaction = NULL; bool emptyDoc = (m_Doc == NULL); bool hasCurrentPage = (m_Doc && m_Doc->currentPage()); TransactionSettings trSettings; trSettings.targetName = hasCurrentPage ? m_Doc->currentPage()->getUName() : ""; trSettings.targetPixmap = Um::IImageFrame; trSettings.actionName = Um::ImportXfig; trSettings.description = fileName; trSettings.actionPixmap = Um::IXFIG; if (emptyDoc || !(flags & lfInteractive) || !(flags & lfScripted)) UndoManager::instance()->setUndoEnabled(false); if (UndoManager::undoEnabled()) activeTransaction = new UndoTransaction(UndoManager::instance()->beginTransaction(trSettings)); bool isCleanedFile = false; QString cleanFile = ""; QFileInfo fi(fileName); QStringList exts = QStringList() << "eps" << "epsf" << "epsi" << "eps2" << "eps3" << "epi" << "ept" << "ps"; if (exts.contains(fi.suffix().toLower())) { if (ScCore->haveGS()) { // Destill the eps/ps with ghostscript to get a clean pdf file bool cancel = false; QString errFile = getShortPathName(ScPaths::getTempFileDir())+ "/ps.err"; cleanFile = getShortPathName(ScPaths::getTempFileDir())+ "/clean.pdf"; QStringList args; args.append( "-q" ); args.append( "-dNOPAUSE" ); args.append( "-sDEVICE=pdfwrite" ); args.append( "-dBATCH" ); args.append( "-dSAFER" ); if (extensionIndicatesEPS(fi.suffix().toLower())) args.append("-dEPSCrop"); args.append("-dCompatibilityLevel=1.4"); args.append( QString("-sOutputFile=%1").arg(QDir::toNativeSeparators(cleanFile)) ); args.append( QDir::toNativeSeparators(fileName) ); System(getShortPathName(PrefsManager::instance()->ghostscriptExecutable()), args, errFile, errFile, &cancel); args.clear(); isCleanedFile = true; } else { qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor)); QMessageBox::warning(ScCore->primaryMainWindow(), CommonStrings::trWarning, tr("The Import plugin cannot handle Postscript files"), 1, 0, 0); qApp->changeOverrideCursor(QCursor(Qt::WaitCursor)); return false; } } PdfPlug *dia = new PdfPlug(m_Doc, flags); Q_CHECK_PTR(dia); if (isCleanedFile) dia->import(cleanFile, trSettings, flags); else dia->import(fileName, trSettings, flags); if (activeTransaction) { activeTransaction->commit(); delete activeTransaction; activeTransaction = NULL; } if (emptyDoc || !(flags & lfInteractive) || !(flags & lfScripted)) UndoManager::instance()->setUndoEnabled(true); delete dia; if (isCleanedFile) QFile::remove(cleanFile); return true; }