/** * Scripter.activeDocument.selection * Property * List of selected Item objects on active document */ QList<QVariant> DocumentAPI::selection() { QList<QVariant> l; Selection *sel = ScCore->primaryMainWindow()->doc->m_Selection; for (int i=0; i < sel->count(); i++) { /** * Checking whether it is a textframe. If yes, we are trying to cast * it onto TextWrapper class, which can effectively perform all * the text operations */ PageItem *item = sel->itemAt(i); if (item->asTextFrame()) { TextAPI *textItem = new TextAPI(item->asTextFrame()); l.append(qVariantFromValue((QObject *)(textItem))); } else if(item->asImageFrame()) { ImageAPI *imageItem = new ImageAPI(item->asImageFrame()); l.append(qVariantFromValue((QObject *)(imageItem))); } else { ItemAPI *otherItem = new ItemAPI(item); l.append(qVariantFromValue( (QObject *)(otherItem) )); } } return l; }
/** * Scripter.activeDocument.selection * Property * List of selected Item objects on active document */ QList<QVariant> DocumentAPI::selection() { QList<QVariant> l; Selection *sel = ScCore->primaryMainWindow()->doc->m_Selection; for (int i=0; i < sel->count(); i++) l.append(qVariantFromValue( (QObject *)sel->itemAt(i))); return l; }
void Imposition::booklet4p(QList<int>* pages) { /* 4 page imposition looks like this: front: back: -------------------- -------------------- | | | | | | | | | | | | | | | | | | | 4 | 1 | | 2 | 3 | | | | | | | | | | | | | | | | | | | -------------------- -------------------- */ //fill the pages, so that it could be divided by for while ( (pages->count() % 4) != 0) { pages->append(0); } //create pages int targetSheets = (int)ceil(pages->count() / 4.0); //how many sheets do we have int targetPages = targetSheets * 2; //how many pages do we have targetDoc->createNewDocPages(targetPages); targetDoc->changeLayerName(0,srcDoc->layerName(0)); for (int i = 1; i < srcDoc->layerCount(); i++) { targetDoc->addLayer(srcDoc->layerName(i)); } //make guides for (int i = 0; i < targetDoc->Pages->count(); i++) { Page* p = targetDoc->Pages->at(i); //count the left guide: double guide_x = (p->width() - 2 * srcDoc->pageWidth)/2; p->guides.addVertical(guide_x, p->guides.Standard); //middle guide: guide_x += srcDoc->pageWidth; p->guides.addVertical(guide_x, p->guides.Standard); //and the right one: guide_x += srcDoc->pageWidth; p->guides.addVertical(guide_x, p->guides.Standard); //now, the top guide: double guide_y = (p->height() - srcDoc->pageHeight)/2; p->guides.addHorizontal(guide_y, p->guides.Standard); //and the bottom one: guide_y += srcDoc->pageHeight; p->guides.addHorizontal(guide_y, p->guides.Standard); } //start copying ScribusMainWindow* scMW = ScCore->primaryMainWindow(); scMW->slotSelect(); Selection* s = new Selection(scMW); //first, do the frontsides for (int i = 0; i < targetDoc->Pages->count(); i = i + 2) { targetDoc->setCurrentPage(targetDoc->Pages->at(i)); //copy the page to the clipboard //right side //make selections for (int j = 0; j < srcDoc->Items->count(); j++) { if (srcDoc->OnPage(srcDoc->Items->at(j)) == (pages->at(i)-1)) { s->addItem(srcDoc->Items->at(j),false); } } if (s->count() > 0) { std::ostringstream xmlString; SaxXML xmlStream(xmlString); Serializer::serializeObjects(*s, xmlStream); std::string xml(xmlString.str()); QByteArray ba(QByteArray(xml.c_str(), xml.length())); //paste page from clipboard Selection pastedObjects = Serializer(*targetDoc).deserializeObjects(ba); targetDoc->moveGroup( targetDoc->Pages->at(i)->guides.vertical(1, targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(i)->guides.horizontal(0, targetDoc->Pages->at(i)->guides.Standard), false, &pastedObjects ); s->clear(); for (int j = 0; j < targetDoc->layerCount(); j++) { //create group out of all the items in the layer Selection* gs = new Selection(scMW); for (int k = 0; k < pastedObjects.count(); k++) { if (pastedObjects.itemAt(k)->LayerNr == j) gs->addItem(pastedObjects.itemAt(k)); } if (gs->count() > 0) { //create group targetDoc->itemSelection_GroupObjects(false, false, gs); //get group control signed int groupid = gs->itemAt(0)->Groups.at(0); PageItem* groupcontrol = NULL; for (int k = 0; k < targetDoc->Items->count(); k++) { if ( targetDoc->Items->at(k)->Groups.count() > 0 && targetDoc->Items->at(k)->Groups.at(0) == groupid && targetDoc->Items->at(k)->isGroupControl ) { groupcontrol = targetDoc->Items->at(k); break; } } groupcontrol->SetRectFrame(); double points[32] = { //left upper corner - left lower corner targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard), //left lower corner - right lower corner targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard), 100, 100, 100, 100, //right lower corner - right upper corner 100, 100, 100, 100, 0, 100, 0, 100, //right upper corner - left upper corner 0, 100, 0, 100, targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard), }; double groupX = groupcontrol->xPos(); double groupY = groupcontrol->yPos() - targetDoc->Pages->at(i)->yOffset(); double groupWidth = groupcontrol->width(); double groupHeight = groupcontrol->height(); qDebug() << groupX << groupY << groupWidth << groupHeight; for (int k = 0; k < 12; k += 2) { if (points[k] < groupX) { points[k] = 0; } else if (points[k] - groupX > 100) { points[k] = 100; } else { points[k] = 100* (points[k] - groupX) / groupWidth; } if (points[k+1] < groupY) { points[k+1] = 0; } else if (points[k+1] - groupY > 100) { points[k+1] = 100; } else { points[k+1] = 100* (points[k+1] - groupY) / groupHeight; } qDebug() << "IMPOSITION: points[" << k << "] " << points[i] << "\n"; qDebug() << "IMPOSITION: points[" << k+1 << "] " << points[i+1] << "\n"; } for (int k = 28; k < 32; k += 2) { if (points[k] < groupX) { points[k] = 0; } else if (points[k] - groupX > 100) { points[k] = 100; } else { points[k] = 100* (points[k] - groupX) / groupWidth; } if (points[k+1] < groupY) { points[k+1] = 0; } else if (points[k+1] - groupY > 100) { points[k+1] = 100; } else { points[k+1] = 100* (points[k+1] - groupY) / groupHeight; } qDebug() << "IMPOSITION: points[" << k << "] " << points[i] << "\n"; qDebug() << "IMPOSITION: points[" << k+1 << "] " << points[i+1] << "\n"; } groupcontrol->SetFrameShape(32,points); } } } //left side for (int j = 0; j < srcDoc->Items->count(); j++) { if (srcDoc->OnPage(srcDoc->Items->at(j)) == (pages->at(pages->count()-i-1)-1)) { s->addItem(srcDoc->Items->at(j),false); } } if (s->count() > 0) { std::ostringstream xmlString; SaxXML xmlStream(xmlString); Serializer::serializeObjects(*s, xmlStream); std::string xml(xmlString.str()); QByteArray ba(QByteArray(xml.c_str(), xml.length())); //paste page from clipboard Selection pastedObjects = Serializer(*targetDoc).deserializeObjects(ba); targetDoc->moveGroup( targetDoc->Pages->at(i)->guides.vertical(0, targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(i)->guides.horizontal(0, targetDoc->Pages->at(i)->guides.Standard), false, &pastedObjects ); s->clear(); //clipping layerwise for (int j = 0; j < targetDoc->layerCount(); j++) { //create group out of all the items in the layer Selection* gs = new Selection(scMW); for (int k = 0; k < pastedObjects.count(); k++) { if (pastedObjects.itemAt(k)->LayerNr == j) gs->addItem(pastedObjects.itemAt(k)); } if (gs->count() > 0) { //create group targetDoc->itemSelection_GroupObjects(false, false, gs); //get group control signed int groupid = gs->itemAt(0)->Groups.at(0); PageItem* groupcontrol = NULL; for (int k = 0; k < targetDoc->Items->count(); k++) { if ( targetDoc->Items->at(k)->Groups.count() > 0 && targetDoc->Items->at(k)->Groups.at(0) == groupid && targetDoc->Items->at(k)->isGroupControl ) { groupcontrol = targetDoc->Items->at(k); break; } } groupcontrol->SetRectFrame(); double points[32] = { //left upper corner - left lower corner 0, 0, 0, 0, 0, 100, 0, 100, //left lower corner - right lower corner 0, 100, 0, 100, targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard), //right lower corner - right upper corner targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard), //right upper corner - left upper corner targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard), 0, 0, 0, 0 }; double groupX = groupcontrol->xPos(); double groupY = groupcontrol->yPos() - targetDoc->Pages->at(i)->yOffset(); double groupWidth = groupcontrol->width(); double groupHeight = groupcontrol->height(); qDebug() << groupX << groupY << groupWidth << groupHeight; for (int k = 13; k < 28; k += 2) { if (points[k] < groupX) { points[k] = 0; } else if (points[k] - groupX > 100) { points[k] = 100; } else { points[k] = 100* (points[k] - groupX) / groupWidth; } if (points[k+1] < groupY) { points[k+1] = 0; } else if (points[k+1] - groupY > 100) { points[k+1] = 100; } else { points[k+1] = 100* (points[k+1] - groupY) / groupHeight; } qDebug() << "IMPOSITION: points[" << k << "] " << points[i] << "\n"; qDebug() << "IMPOSITION: points[" << k+1 << "] " << points[i+1] << "\n"; } groupcontrol->SetFrameShape(32,points); } } } } //backsides for (int i = 1; i < targetDoc->Pages->count(); i = i + 2) { targetDoc->setCurrentPage(targetDoc->Pages->at(i)); //copy the page to the clipboard //left side //make selections for (int j = 0; j < srcDoc->Items->count(); j++) { if (srcDoc->OnPage(srcDoc->Items->at(j)) == (pages->at(i)-1)) { s->addItem(srcDoc->Items->at(j),false); } } if (s->count() > 0) { std::ostringstream xmlString; SaxXML xmlStream(xmlString); Serializer::serializeObjects(*s, xmlStream); std::string xml(xmlString.str()); QByteArray ba(QByteArray(xml.c_str(), xml.length())); //paste page from clipboard Selection pastedObjects = Serializer(*targetDoc).deserializeObjects(ba); targetDoc->moveGroup( targetDoc->Pages->at(i)->guides.vertical(0, targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(i)->guides.horizontal(0, targetDoc->Pages->at(i)->guides.Standard), false, &pastedObjects ); s->clear(); //clipping layerwise for (int j = 0; j < targetDoc->layerCount(); j++) { //create group out of all the items in the layer Selection* gs = new Selection(scMW); for (int k = 0; k < pastedObjects.count(); k++) { if (pastedObjects.itemAt(k)->LayerNr == j) gs->addItem(pastedObjects.itemAt(k)); } if (gs->count() > 0) { //create group targetDoc->itemSelection_GroupObjects(false, false, gs); //get group control signed int groupid = gs->itemAt(0)->Groups.at(0); PageItem* groupcontrol = NULL; for (int k = 0; k < targetDoc->Items->count(); k++) { if ( targetDoc->Items->at(k)->Groups.count() > 0 && targetDoc->Items->at(k)->Groups.at(0) == groupid && targetDoc->Items->at(k)->isGroupControl ) { groupcontrol = targetDoc->Items->at(k); break; } } groupcontrol->SetRectFrame(); double points[32] = { //left upper corner - left lower corner 0, 0, 0, 0, 0, 100, 0, 100, //left lower corner - right lower corner 0, 100, 0, 100, targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard), //right lower corner - right upper corner targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard), //right upper corner - left upper corner targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard), 0, 0, 0, 0 }; double groupX = groupcontrol->xPos(); double groupY = groupcontrol->yPos() - targetDoc->Pages->at(i)->yOffset(); double groupWidth = groupcontrol->width(); double groupHeight = groupcontrol->height(); qDebug() << groupX << groupY << groupWidth << groupHeight; for (int k = 13; k < 28; k += 2) { if (points[k] < groupX) { points[k] = 0; } else if (points[k] - groupX > 100) { points[k] = 100; } else { points[k] = 100* (points[k] - groupX) / groupWidth; } if (points[k+1] < groupY) { points[k+1] = 0; } else if (points[k+1] - groupY > 100) { points[k+1] = 100; } else { points[k+1] = 100* (points[k+1] - groupY) / groupHeight; } qDebug() << "IMPOSITION: points[" << k << "] " << points[i] << "\n"; qDebug() << "IMPOSITION: points[" << k+1 << "] " << points[i+1] << "\n"; } groupcontrol->SetFrameShape(32,points); } } } //right side for (int j = 0; j < srcDoc->Items->count(); j++) { if (srcDoc->OnPage(srcDoc->Items->at(j)) == (pages->at(pages->count()-i-1)-1)) { s->addItem(srcDoc->Items->at(j),false); } } if (s->count() > 0) { std::ostringstream xmlString; SaxXML xmlStream(xmlString); Serializer::serializeObjects(*s, xmlStream); std::string xml(xmlString.str()); QByteArray ba(QByteArray(xml.c_str(), xml.length())); //paste page from clipboard Selection pastedObjects = Serializer(*targetDoc).deserializeObjects(ba); targetDoc->moveGroup( targetDoc->Pages->at(i)->guides.vertical(1, targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(i)->guides.horizontal(0, targetDoc->Pages->at(i)->guides.Standard), false, &pastedObjects ); s->clear(); for (int j = 0; j < targetDoc->layerCount(); j++) { //create group out of all the items in the layer Selection* gs = new Selection(scMW); for (int k = 0; k < pastedObjects.count(); k++) { if (pastedObjects.itemAt(k)->LayerNr == j) gs->addItem(pastedObjects.itemAt(k)); } if (gs->count() > 0) { //create group targetDoc->itemSelection_GroupObjects(false, false, gs); //get group control signed int groupid = gs->itemAt(0)->Groups.at(0); PageItem* groupcontrol = NULL; for (int k = 0; k < targetDoc->Items->count(); k++) { if ( targetDoc->Items->at(k)->Groups.count() > 0 && targetDoc->Items->at(k)->Groups.at(0) == groupid && targetDoc->Items->at(k)->isGroupControl ) { groupcontrol = targetDoc->Items->at(k); break; } } groupcontrol->SetRectFrame(); double points[32] = { //left upper corner - left lower corner targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard), //left lower corner - right lower corner targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard), 100, 100, 100, 100, //right lower corner - right upper corner 100, 100, 100, 100, 0, 100, 0, 100, //right upper corner - left upper corner 0, 100, 0, 100, targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard), }; double groupX = groupcontrol->xPos(); double groupY = groupcontrol->yPos() - targetDoc->Pages->at(i)->yOffset(); double groupWidth = groupcontrol->width(); double groupHeight = groupcontrol->height(); qDebug() << groupX << groupY << groupWidth << groupHeight; for (int k = 0; k < 12; k += 2) { if (points[k] < groupX) { points[k] = 0; } else if (points[k] - groupX > 100) { points[k] = 100; } else { points[k] = 100* (points[k] - groupX) / groupWidth; } if (points[k+1] < groupY) { points[k+1] = 0; } else if (points[k+1] - groupY > 100) { points[k+1] = 100; } else { points[k+1] = 100* (points[k+1] - groupY) / groupHeight; } qDebug() << "IMPOSITION: points[" << k << "] " << points[i] << "\n"; qDebug() << "IMPOSITION: points[" << k+1 << "] " << points[i+1] << "\n"; } for (int k = 28; k < 32; k += 2) { if (points[k] < groupX) { points[k] = 0; } else if (points[k] - groupX > 100) { points[k] = 100; } else { points[k] = 100* (points[k] - groupX) / groupWidth; } if (points[k+1] < groupY) { points[k+1] = 0; } else if (points[k+1] - groupY > 100) { points[k+1] = 100; } else { points[k+1] = 100* (points[k+1] - groupY) / groupHeight; } qDebug() << "IMPOSITION: points[" << k << "] " << points[i] << "\n"; qDebug() << "IMPOSITION: points[" << k+1 << "] " << points[i+1] << "\n"; } groupcontrol->SetFrameShape(32,points); } } } } }
void Imposition::changeDocFold() { if (isOK == true) { //create page if (foldIsBackSide->checkState() == Qt::Checked) targetDoc->createNewDocPages(2); else targetDoc->createNewDocPages(1); //copy layers for (int i = 1; i < srcDoc->layerCount(); i++) { targetDoc->addLayer(srcDoc->layerName(i)); } targetDoc->setCurrentPage(targetDoc->Pages->at(0)); Page* p = targetDoc->currentPage(); int firstPage = foldFrontPage->currentText().toInt() - 1; int lastPage = 0; if (foldFrontPage->currentIndex() < (foldFrontPage->count()-1)) { lastPage = foldFrontPage->itemText(foldFrontPage->currentIndex()+1).toInt() - 2; } else { lastPage = firstPage + srcDoc->currentPageLayout; } //make guides double allWidth = srcDoc->pageWidth * (srcDoc->currentPageLayout+1); double allHeight = srcDoc->pageHeight; double guide_x = (p->width() - allWidth)/2; //initial (left) guide p->guides.addVertical(guide_x, p->guides.Standard); for (int i = firstPage; i <= lastPage; i++) { guide_x += srcDoc->Pages->at(i)->width(); p->guides.addVertical(guide_x,p->guides.Standard); } double guide_y = (p->height() - allHeight)/2; p->guides.addHorizontal(guide_y, p->guides.Standard); guide_y += allHeight; p->guides.addHorizontal(guide_y, p->guides.Standard); //do the copying ScribusMainWindow* scMW = ScCore->primaryMainWindow(); scMW->view->requestMode(modeNormal); Selection* s = new Selection(scMW); //select items to copy for the first page for (int i = 0; i < srcDoc->Items->count(); i++) { if ( (srcDoc->OnPage(srcDoc->Items->at(i)) >= firstPage) && (srcDoc->OnPage(srcDoc->Items->at(i)) <= lastPage) ) s->addItem(srcDoc->Items->at(i),false); } if (s->count() > 0) { //move the selection to the clipboard std::ostringstream xmlString; SaxXML xmlStream(xmlString); Serializer::serializeObjects(*s, xmlStream); std::string xml(xmlString.str()); QByteArray ba(QByteArray(xml.c_str(), xml.length())); //paste Selection pastedObjects = Serializer(*targetDoc).deserializeObjects(ba); targetDoc->moveGroup( p->guides.vertical(0, p->guides.Standard), p->guides.horizontal(0, p->guides.Standard), true, &pastedObjects ); } if (foldIsBackSide->checkState() != Qt::Checked) return; //do the second page s->clear(); firstPage = foldBackPage->currentText().toInt() - 1; if (foldBackPage->currentIndex() < (foldBackPage->count()-1)) { lastPage = foldBackPage->itemText(foldBackPage->currentIndex()+1).toInt() - 2; } else { lastPage = firstPage + srcDoc->currentPageLayout; } targetDoc->setCurrentPage(targetDoc->Pages->at(1)); p = targetDoc->currentPage(); guide_x = (p->width() - allWidth)/2; //initial (left) guide p->guides.addVertical(guide_x, p->guides.Standard); for (int i = firstPage; i <= lastPage; i++) { guide_x += srcDoc->Pages->at(i)->width(); p->guides.addVertical(guide_x,p->guides.Standard); } guide_y = (p->height() - allHeight)/2; p->guides.addHorizontal(guide_y, p->guides.Standard); guide_y += allHeight; p->guides.addHorizontal(guide_y, p->guides.Standard); for (int i = 0; i < srcDoc->Items->count(); i++) { if ( (srcDoc->OnPage(srcDoc->Items->at(i)) >= firstPage) && (srcDoc->OnPage(srcDoc->Items->at(i)) <= lastPage) ) s->addItem(srcDoc->Items->at(i),false); } if (s->count() > 0) { //move the selection to the clipboard std::ostringstream xmlString; SaxXML xmlStream(xmlString); Serializer::serializeObjects(*s, xmlStream); std::string xml(xmlString.str()); QByteArray ba(QByteArray(xml.c_str(), xml.length())); //paste Selection pastedObjects = Serializer(*targetDoc).deserializeObjects(ba); targetDoc->moveGroup( p->guides.vertical(0, p->guides.Standard), p->guides.horizontal(0, p->guides.Standard), true, &pastedObjects ); } } }
void DialogShiftTimes::Process(wxCommandEvent &) { int mode = selection_mode->GetSelection(); int type = time_fields->GetSelection(); bool reverse = shift_backward->GetValue(); bool by_time = shift_by_time->GetValue(); bool start = type != 2; bool end = type != 1; Selection sel = context->selectionController->GetSelectedSet(); long shift; if (by_time) { shift = shift_time->GetTime(); if (shift == 0) { Close(); return; } } else shift_frames->GetValue().ToLong(&shift); if (reverse) shift = -shift; // Track which rows were shifted for the log int row_number = 0; int block_start = 0; json::Array shifted_blocks; for (entryIter it = context->ass->Line.begin(); it != context->ass->Line.end(); ++it) { AssDialogue *line = dynamic_cast<AssDialogue*>(*it); if (!line) continue; ++row_number; if (!sel.count(line)) { if (block_start) { json::Object block; block["start"] = block_start; block["end"] = row_number - 1; shifted_blocks.push_back(block); block_start = 0; } if (mode == 1) continue; if (mode == 2 && shifted_blocks.empty()) continue; } else if (!block_start) block_start = row_number; if (start) line->Start = Shift(line->Start, shift, by_time, agi::vfr::START); if (end) line->End = Shift(line->End, shift, by_time, agi::vfr::END); } context->ass->Commit(_("shifting"), AssFile::COMMIT_DIAG_TIME); if (block_start) { json::Object block; block["start"] = block_start; block["end"] = row_number - 1; shifted_blocks.push_back(block); } SaveHistory(shifted_blocks); Close(); }
/// @brief Recombine void SubtitlesGrid::RecombineLines() { using namespace std; Selection selectedSet = GetSelectedSet(); if (selectedSet.size() < 2) return; AssDialogue *activeLine = GetActiveLine(); vector<AssDialogue*> sel; sel.reserve(selectedSet.size()); copy(selectedSet.begin(), selectedSet.end(), back_inserter(sel)); for_each(sel.begin(), sel.end(), trim_text); sort(sel.begin(), sel.end(), &AssFile::CompStart); typedef vector<AssDialogue*>::iterator diag_iter; diag_iter end = sel.end() - 1; for (diag_iter cur = sel.begin(); cur != end; ++cur) { AssDialogue *d1 = *cur; diag_iter d2 = cur + 1; // 1, 1+2 (or 2+1), 2 gets turned into 1, 2, 2 so kill the duplicate if (d1->Text == (*d2)->Text) { expand_times(d1, *d2); delete d1; context->ass->Line.remove(d1); continue; } // 1, 1+2, 1 turns into 1, 2, [empty] if (d1->Text.empty()) { delete d1; context->ass->Line.remove(d1); continue; } // If d2 is the last line in the selection it'll never hit the above test if (d2 == end && (*d2)->Text.empty()) { delete *d2; context->ass->Line.remove(*d2); continue; } // 1, 1+2 while (d2 <= end && (*d2)->Text.StartsWith(d1->Text, &(*d2)->Text)) { expand_times(*d2, d1); trim_text(*d2); ++d2; } // 1, 2+1 while (d2 <= end && (*d2)->Text.EndsWith(d1->Text, &(*d2)->Text)) { expand_times(*d2, d1); trim_text(*d2); ++d2; } // 1+2, 2 while (d2 <= end && d1->Text.EndsWith((*d2)->Text, &d1->Text)) { expand_times(d1, *d2); trim_text(d1); ++d2; } // 2+1, 2 while (d2 <= end && d1->Text.StartsWith((*d2)->Text, &d1->Text)) { expand_times(d1, *d2); trim_text(d1); ++d2; } } // Remove now non-existent lines from the selection Selection lines; transform(context->ass->Line.begin(), context->ass->Line.end(), inserter(lines, lines.begin()), cast<AssDialogue*>()); Selection newSel; set_intersection(lines.begin(), lines.end(), selectedSet.begin(), selectedSet.end(), inserter(newSel, newSel.begin())); if (newSel.empty()) newSel.insert(*lines.begin()); // Restore selection if (!newSel.count(activeLine)) activeLine = *newSel.begin(); SetSelectionAndActive(newSel, activeLine); context->ass->Commit(_("combining"), AssFile::COMMIT_DIAG_ADDREM | AssFile::COMMIT_DIAG_FULL); }