diff options
| author | craig <craig@11d20701-8431-0410-a711-e3c959e3b870> | 2012-01-01 11:40:09 +0000 |
|---|---|---|
| committer | craig <craig@11d20701-8431-0410-a711-e3c959e3b870> | 2012-01-01 11:40:09 +0000 |
| commit | 7ed83b6c6666eb8b6b104c211ae7e52907350372 (patch) | |
| tree | 4430b556abac0ad660a0aacf1887d77f85d8be02 /scribus/plugins/imposition | |
| download | scribus-7ed83b6c6666eb8b6b104c211ae7e52907350372.tar.gz scribus-7ed83b6c6666eb8b6b104c211ae7e52907350372.tar.xz scribus-7ed83b6c6666eb8b6b104c211ae7e52907350372.zip | |
Branch 1.3.5 tree to 1.4.x tree, goodbye 1.3.x
git-svn-id: svn://scribus.net/branches/Version14x/Scribus@17163 11d20701-8431-0410-a711-e3c959e3b870
Diffstat (limited to 'scribus/plugins/imposition')
| -rw-r--r-- | scribus/plugins/imposition/CMakeLists.txt | 37 | ||||
| -rw-r--r-- | scribus/plugins/imposition/imposition.cpp | 1547 | ||||
| -rw-r--r-- | scribus/plugins/imposition/imposition.h | 86 | ||||
| -rw-r--r-- | scribus/plugins/imposition/impositionbase.ui | 730 | ||||
| -rw-r--r-- | scribus/plugins/imposition/impositionplugin.cpp | 101 | ||||
| -rw-r--r-- | scribus/plugins/imposition/impositionplugin.h | 53 |
6 files changed, 2554 insertions, 0 deletions
diff --git a/scribus/plugins/imposition/CMakeLists.txt b/scribus/plugins/imposition/CMakeLists.txt new file mode 100644 index 0000000..00cf2fe --- /dev/null +++ b/scribus/plugins/imposition/CMakeLists.txt @@ -0,0 +1,37 @@ +INCLUDE_DIRECTORIES( +${CMAKE_SOURCE_DIR} +${CMAKE_SOURCE_DIR}/scribus +) + +SET(IMPOSITION_PLUGIN_UI_SRC +impositionbase.ui +) + +SET(IMPOSITION_PLUGIN_MOC_CLASSES +imposition.h +impositionplugin.h +) + +SET(IMPOSITION_PLUGIN_SOURCES +imposition.cpp +impositionplugin.cpp +) + +SET(SCRIBUS_IMPOSITION_PLUGIN "imposition") + +QT4_WRAP_UI(IMPOSITION_PLUGIN_UI_SOURCES ${IMPOSITION_PLUGIN_UI_SRC} ) +QT4_WRAP_CPP(IMPOSITION_PLUGIN_MOC_SOURCES ${IMPOSITION_PLUGIN_MOC_CLASSES}) + +ADD_LIBRARY(${SCRIBUS_IMPOSITION_PLUGIN} MODULE ${IMPOSITION_PLUGIN_SOURCES} ${IMPOSITION_PLUGIN_MOC_SOURCES} ${IMPOSITION_PLUGIN_UI_CPP} ${IMPOSITION_PLUGIN_UI_SOURCES}) + +TARGET_LINK_LIBRARIES(${SCRIBUS_IMPOSITION_PLUGIN} ${PLUGIN_LIBRARIES}) + +INSTALL(TARGETS ${SCRIBUS_IMPOSITION_PLUGIN} + LIBRARY + DESTINATION ${PLUGINDIR} + PERMISSIONS ${PLUGIN_PERMISSIONS} +) + +ADD_DEPENDENCIES(${SCRIBUS_IMPOSITION_PLUGIN} ${EXE_NAME}) + +# SET_TARGET_PROPERTIES(${SCRIBUS_IMPOSITION_PLUGIN} PROPERTIES VERSION "0.0.0") diff --git a/scribus/plugins/imposition/imposition.cpp b/scribus/plugins/imposition/imposition.cpp new file mode 100644 index 0000000..e6aed41 --- /dev/null +++ b/scribus/plugins/imposition/imposition.cpp @@ -0,0 +1,1547 @@ +/* +For general Scribus (>=1.3.2) copyright and licensing information please refer +to the COPYING file provided with the program. Following this notice may exist +a copyright and/or license notice that predates the release of Scribus 1.3.2 +for which a new license (GPL+exception) is in place. +*/ +/*************************************************************************** + begin : Jun 2007 + copyright : (C) 2007 by Mateusz Haligowski + email : halish@kofeina.org + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +#include <iostream> +#include <sstream> +#include <QDebug> + +#include "imposition.h" +#include "scribus.h" +#include "pagesize.h" +#include "pagestructs.h" +#include "units.h" +#include "commonstrings.h" +#include "aligndistribute.h" +#include "guidemanagercore.h" +#include "undomanager.h" +#include "selection.h" +#include "scribusXml.h" +#include "desaxe/saxXML.h" +#include "serializer.h" +#include <QDebug> + +Imposition::Imposition(QWidget* parent, ScribusDoc* doc) : QDialog(parent) +{ + UndoManager::instance()->setUndoEnabled(false); + setupUi(this); + setModal(true); + + languageChange(); + + this->parent = parent; + this->srcDoc = doc; + + //get units + unitIndex = doc->unitIndex(); + unitRatio = unitGetRatioFromIndex(unitIndex); + unitSuffix = unitGetSuffixFromIndex(unitIndex); + + //set units in page settings + pageWidthBox->setSuffix(unitSuffix); + pageHeightBox->setSuffix(unitSuffix); + + //fill Page Size combobox + PageSize ps( tr(doc->m_pageSize.toLocal8Bit().constData())); + pageSizeComboBox->addItems(ps.sizeTRList()); + pageSizeComboBox->addItem( CommonStrings::trCustomPageSize); + + QStringList pageSizes=ps.sizeList(); + int sizeIndex=pageSizes.indexOf(ps.nameTR()); + if (sizeIndex!=-1) + pageSizeComboBox->setCurrentIndex(sizeIndex); + else + pageSizeComboBox->setCurrentIndex(pageSizeComboBox->count()-1); + + pageOrientationComboBox->addItem( tr( "Portrait" ) ); + pageOrientationComboBox->addItem( tr( "Landscape" ) ); + + //put page dimensions to boxes + pageWidthBox->setValue(ps.width() * unitRatio); + pageHeightBox->setValue(ps.height() * unitRatio); + + //fill grid pages boxes with pagelists + for (int i = 1; i <= (int)(doc->Pages->count()); i++) + { + cbFront->addItem(QString::number(i)); + cbBack->addItem(QString::number(i)); + } + + //fill folds pages boxes with pagelists + foldFrontPage->addItem(QString::number(1)); + foldBackPage->addItem(QString::number(1)); + + for (int i = 1; i < (int)(srcDoc->Pages->count()); i++) + { + if (srcDoc->locationOfPage(i) == LeftPage) + { + foldFrontPage->addItem(QString::number(i+1)); + foldBackPage->addItem(QString::number(i+1)); + } + } + + isEdited = true; + isOK = verifyPage(); + btnGo->setEnabled(isOK); + btnPreview->setEnabled(isOK); + + //connect slots and signals + connect(pageSizeComboBox, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(setPageSize(const QString &))); + + connect(pageWidthBox, SIGNAL(valueChanged(double)), this, SLOT(customizeSize())); + connect(pageHeightBox, SIGNAL(valueChanged(double)), this, SLOT(customizeSize())); + connect(chb2Sides, SIGNAL(stateChanged(int)), this, SLOT(change2SidesBox(int))); + connect(foldIsBackSide, SIGNAL(stateChanged(int)), this, SLOT(changeFoldBackPage(int))); + connect(this, SIGNAL(accepted()), this, SLOT(accepted())); + + //document changing slots + connect(impositionTabWidget, SIGNAL(currentChanged(int)), this, SLOT(changeTab(int))); + connect(pageWidthBox, SIGNAL(valueChanged(double)), this, SLOT(verifyPage())); + connect(pageHeightBox, SIGNAL(valueChanged(double)), this, SLOT(verifyPage())); + + connect(cbFront, SIGNAL(currentIndexChanged(QString)), this, SLOT(verifyPage())); + connect(cbBack, SIGNAL(currentIndexChanged(QString)), this, SLOT(verifyPage())); + + connect(cbLayout, SIGNAL(currentIndexChanged(QString)), this, SLOT(verifyPage())); +} + + +Imposition::~Imposition() +{ +// UndoManager::instance()->switchStack(targetDoc->DocName); + + UndoManager::instance()->setUndoEnabled(true); +} + + +void Imposition::languageChange() +{ + +} + +void Imposition::setPageSize(const QString &size) +{ + disconnect(pageWidthBox, SIGNAL(valueChanged(double)), this, SLOT(customizeSize())); + disconnect(pageHeightBox, SIGNAL(valueChanged(double)), this, SLOT(customizeSize())); + + PageSize* ps = new PageSize( tr(size.toLocal8Bit().constData())); + + pageWidthBox->setValue(ps->width() * unitRatio); + pageHeightBox->setValue(ps->height() * unitRatio); + + delete ps; + + isEdited = true; + isOK = verifyPage(); + btnGo->setEnabled(isOK); + btnPreview->setEnabled(isOK); + + connect(pageWidthBox, SIGNAL(valueChanged(double)), this, SLOT(customizeSize())); + connect(pageHeightBox, SIGNAL(valueChanged(double)), this, SLOT(customizeSize())); +} + +void Imposition::changeTab(int dest) +{ + isEdited = true; + isOK = verifyPage(); + btnGo->setEnabled(isOK); + btnPreview->setEnabled(isOK); +} + +void Imposition::changeDocGrid() +{ + //get first copied page + Page* src = srcDoc->Pages->at(cbFront->currentIndex()); + + double realSrcWidth = src->width() + srcDoc->bleeds.Left + srcDoc->bleeds.Right; + double realSrcHeight = src->height() + srcDoc->bleeds.Top + srcDoc->bleeds.Bottom; + + //check whether width fits + if (isOK == true) + { + //count how many rows and cols will be needed + int cols = (int)((targetDoc->pageWidth)/realSrcWidth); // how many columns do we have on page? + int rows = (int)((targetDoc->pageHeight)/realSrcHeight); // how many rows do we have on page? + + //now count how many pages are needed and create them + int countPages=0; + countPages = (int)(boxCopies->value() / (cols * rows)) + 1; + if ((boxCopies->value() % (cols * rows) ) == 0) countPages--; + if (chb2Sides->checkState() == Qt::Checked) countPages = countPages * 2; //double pages! + targetDoc->createNewDocPages(countPages); + + 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 < countPages; i++) + { + Page* p = targetDoc->Pages->at(i); + + //vertical guides + double vertDist = (p->width() - p->Margins.Left - p->Margins.Right - cols*src->width())/cols; + + p->guides.addVertical(p->Margins.Left + 0.5*vertDist, p->guides.Standard); + p->guides.addVertical(p->width() - p->Margins.Right - 0.5*vertDist, p->guides.Standard); + + double left = p->Margins.Left + 0.5*vertDist; + double right = p->width() - p->Margins.Right - 0.5*vertDist; + + for (int j = 0; j < cols; j++) + { + left = left + src->width() + vertDist; + p->guides.addVertical(left, p->guides.Standard); + + right = right - src->width() - vertDist; + p->guides.addVertical(right, p->guides.Standard); + } + + //horizontal guides + double horizDist = (p->height() - p->Margins.Top - p->Margins.Bottom - rows*src->height())/rows; + + p->guides.addHorizontal(p->Margins.Top + 0.5*horizDist, p->guides.Standard); + p->guides.addHorizontal(p->height() - p->Margins.Bottom - 0.5*horizDist, p->guides.Standard); + + double top = p->Margins.Top + 0.5*horizDist; + double bottom = p->height() - p->Margins.Bottom - 0.5*horizDist; + + for (int j = 0; j < rows; j++) + { + top = top + src->height() + horizDist; + p->guides.addHorizontal(top, p->guides.Standard); + + bottom = bottom - src->height() - horizDist; + p->guides.addHorizontal(bottom, p->guides.Standard); + } + } + + + //copy the first page to the clipboard + ScribusMainWindow* scMW = ScCore->primaryMainWindow(); + scMW->view->requestMode(modeNormal); + Selection* s = new Selection(scMW); + + //select items to copy + for (int i = 0; i < srcDoc->Items->count(); i++) + { + if (srcDoc->OnPage(srcDoc->Items->at(i)) == src->pageNr()) + s->addItem(srcDoc->Items->at(i),false); + } + + //Now, as all the relevant items have been copied, move the selection to the clipboard + + // new version: + std::ostringstream xmlString; + SaxXML xmlStream(xmlString); + Serializer::serializeObjects(*s, xmlStream); + std::string xml(xmlString.str()); + QByteArray ba(QByteArray(xml.c_str(), xml.length())); + + int currow = 0; + int curcol = 0; + targetDoc->setCurrentPage(targetDoc->Pages->at(0)); + Page* cur = targetDoc->currentPage(); + + //now, start placing + for (int j = 0; j < boxCopies->value(); j++) + { + + Selection pastedObjects = Serializer(*targetDoc).deserializeObjects(ba); + targetDoc->moveGroup( + cur->guides.vertical(curcol*2, cur->guides.Standard), + cur->guides.horizontal(currow*2, cur->guides.Standard), + true, + &pastedObjects + ); + + if ((curcol + 1) == cols) + { + curcol = 0; + if ((currow + 1) == rows && (j+1 < boxCopies->value())) + { + currow = 0; + if (chb2Sides->checkState() == Qt::Checked) + { + targetDoc->setCurrentPage(targetDoc->Pages->at(cur->pageNr()+2)); + } + else + { + targetDoc->setCurrentPage(targetDoc->Pages->at(cur->pageNr()+1)); + } + cur = targetDoc->currentPage(); + } + else + { + currow++; + } + } + else + { + curcol++; + } + } + delete s; + + if (chb2Sides->checkState() == Qt::Checked) + { + + s = new Selection(scMW); + targetDoc->setCurrentPage(targetDoc->Pages->at(1)); + cur = targetDoc->currentPage(); + src = srcDoc->Pages->at(cbBack->currentIndex()); + + //select items to copy + for (int i = 0; i < srcDoc->Items->count(); i++) + { + if (srcDoc->OnPage(srcDoc->Items->at(i)) == src->pageNr()) + s->addItem(srcDoc->Items->at(i),false); + } + + //Now, as all the relevant items have been copied, move the selection to the clipboard + + // new version: + std::ostringstream xmlString; + SaxXML xmlStream(xmlString); + Serializer::serializeObjects(*s, xmlStream); + std::string xml(xmlString.str()); + QByteArray ba(QByteArray(xml.c_str(), xml.length())); + //start copying from the second page + currow = 0; + curcol = cols-1; + + for ( int j = 0; j < boxCopies->value(); j++ ) + { + Selection pastedObjects = Serializer(*targetDoc).deserializeObjects(ba); + targetDoc->moveGroup( + cur->guides.vertical(curcol*2, cur->guides.Standard), + cur->guides.horizontal(currow*2, cur->guides.Standard), + true, + &pastedObjects + ); + + if ( curcol == 0 ) + { + curcol = cols - 1; + if ( ( currow + 1 ) == rows && ( j+1 < boxCopies->value() ) ) + { + currow = 0; + targetDoc->setCurrentPage ( targetDoc->Pages->at ( cur->pageNr() +2 ) ); + cur = targetDoc->currentPage(); + } + else + { + currow++; + } + } + else + { + curcol--; + } + } + delete s; + } + + view->Deselect(); + srcDoc->view()->Deselect(); + view->DrawNew(); + srcDoc->view()->DrawNew(); + } +} + +QList<int>* Imposition::parsePages(QString pageslist) +{ + QList<int>* li = new QList<int>(); + + QStringList spages = pageslist.split(",", QString::SkipEmptyParts); + for (int i = 0; i < spages.count(); i++) + { + if (spages.at(i).split("-", QString::SkipEmptyParts).count() == 1) + { + li->append(spages.at(i).toInt()); + } + if (spages.at(i).split("-", QString::SkipEmptyParts).count() == 2) + { + QStringList range = spages.at(i).split("-", QString::SkipEmptyParts); + for (int j = range.at(0).toInt(); j <= range.at(1).toInt(); j++) + li->append(j); + + } + } + + return li; +} + +void Imposition::changeDocBooklet() +{ + if (isOK == true) + { + switch (cbLayout->currentText().toInt()) + { + case 4: this->booklet4p(parsePages(inpPages->text())); break; + case 8: this->booklet8p(parsePages(inpPages->text())); break; + case 16: this->booklet16p(parsePages(inpPages->text())); break; + } + } +} + +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::booklet8p(QList<int>* pages) +{ + /* + + 8 page imposition looks like this: + front: back: + -------------------- -------------------- + | | | | | | + | | | | | | + | | | | | | + | 5 | 4 | | 3 | 6 | + | | | | | | + | | | | | | + | | | | | | + |--------------------| |--------------------| + | | | | | | + | | | | | | + | | | | | | + | 8 | 1 | | 2 | 7 | + | | | | | | + | | | | | | + | | | | | | + -------------------- -------------------- + + */ + +} + +void Imposition::booklet16p(QList<int>* pages) +{ + /* + 16 page imposition looks like this: + + front: + ----------------------------------------- + | | | | | + | | | | | + | | | | | + | 5 | 12 | 9 | 8 | + | | | | | + | | | | | + | | | | | + |--------------------|--------------------| + | | | | | + | | | | | + | | | | | + | 4 | 13 | 16 | 1 | + | | | | | + | | | | | + | | | | | + ----------------------------------------- + + back: + ----------------------------------------- + | | | | | + | | | | | + | | | | | + | 7 | 10 | 11 | 6 | + | | | | | + | | | | | + | | | | | + |--------------------|--------------------| + | | | | | + | | | | | + | | | | | + | 2 | 15 | 14 | 3 | + | | | | | + | | | | | + | | | | | + ----------------------------------------- + */ + +} + +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 Imposition::changePage() +{ + //create new ScribusDoc + + PageSize* t_ps = new PageSize(pageWidthBox->value()/unitRatio,pageHeightBox->value()/unitRatio); + + //...name... + QString* t_name = new QString("imposition"); + + //...margins... + MarginStruct* t_margins = new MarginStruct(15,15,15,15); + + //...page setup + DocPagesSetup* t_pagesetup = new DocPagesSetup(0,0,1,0,false,0,0); + + //... et voila! + this->targetDoc = new ScribusDoc(*t_name,unitIndex,*t_ps,*t_margins,*t_pagesetup); + + this->w = new ScribusWin(ScCore->primaryMainWindow()->wsp, targetDoc); + this-> view = new ScribusView(w, ScCore->primaryMainWindow(), targetDoc); + targetDoc->setGUI(true,ScCore->primaryMainWindow(),view); + + //update + switch (impositionTabWidget->currentIndex()) + { + case 0: changeDocGrid(); + break; + case 1: changeDocBooklet(); + break; + case 2: changeDocFold(); + break; + } + +} + +bool Imposition::verifyPage() +{ + bool result = false; + switch (impositionTabWidget->currentIndex()) + { + case 0: + result = verifyGrid(); + break; + case 1: + result = verifyBooklet(); + break; + case 2: + result = verifyFold(); + break; + } + isEdited = true; + btnGo->setEnabled(result); + btnPreview->setEnabled(result); + return result; +} + +bool Imposition::verifyGrid() +{ + bool result = false; + + Page* src = srcDoc->Pages->at(cbFront->currentIndex()); + +// double srcWidth = src->width(); +// double srcHeight = src->height(); + double realSrcWidth = src->width() + srcDoc->bleeds.Left + srcDoc->bleeds.Right; + double realSrcHeight = src->height() + srcDoc->bleeds.Top + srcDoc->bleeds.Bottom; + double width = pageWidthBox->value() / unitRatio; + double height = pageHeightBox->value() / unitRatio; + + if ( (realSrcWidth < width) && + (realSrcHeight < height) ) + { + result = true; + } + + return result; +} + +bool Imposition::verifyBooklet() +{ + return true; +} + +bool Imposition::verifyFold() +{ + if (srcDoc->currentPageLayout == 0) { + return false; + + } + + if (pageWidthBox->value() < (srcDoc->currentPageLayout + 1)*srcDoc->pageWidth || + pageHeightBox->value() < srcDoc->pageHeight) + { + return false; + } + + return true; + +} + +void Imposition::customizeSize() +{ + pageSizeComboBox->setCurrentIndex(pageSizeComboBox->count()-1); +} + +void Imposition::change2SidesBox(int state) +{ + if (state == 0) + cbBack->setEnabled(false); + else + cbBack->setEnabled(true); +} + +void Imposition::changeFoldBackPage(int state) +{ + if (state == 0) + foldBackPage->setEnabled(false); + else + foldBackPage->setEnabled(true); +} + +void Imposition::accepted() +{ + if (isEdited == true) changePage(); + + ScribusMainWindow* scMW = ScCore->primaryMainWindow(); + + w->setMainWindow(scMW); + + w->setView(view); + + scMW->alignDistributePalette->setDoc(targetDoc); + + scMW->ActWin = w; + + targetDoc->WinHan = w; + + scMW->wsp->addWindow(w); + + scMW->HaveDoc++; + scMW->HaveNewDoc(); + targetDoc->reformPages(); + + w->show(); + view->show(); + scMW->newActWin(w); + targetDoc->setCurrentPage(targetDoc->DocPages.at(0)); + view->zoom(); + view->GotoPage(0); + + connect(scMW->wsp, SIGNAL(windowActivated(QWidget *)), scMW, SLOT(newActWin(QWidget *))); + connect(w, SIGNAL(AutoSaved()), scMW, SLOT(slotAutoSaved())); + connect(UndoManager::instance(), SIGNAL(undoRedoDone()), view, SLOT(DrawNew())); + targetDoc->connectDocSignals(); + UndoManager::instance()->setUndoEnabled(true); +} diff --git a/scribus/plugins/imposition/imposition.h b/scribus/plugins/imposition/imposition.h new file mode 100644 index 0000000..3f518ee --- /dev/null +++ b/scribus/plugins/imposition/imposition.h @@ -0,0 +1,86 @@ +/* +For general Scribus (>=1.3.2) copyright and licensing information please refer +to the COPYING file provided with the program. Following this notice may exist +a copyright and/or license notice that predates the release of Scribus 1.3.2 +for which a new license (GPL+exception) is in place. +*/ +/*************************************************************************** + begin : Jun 2007 + copyright : (C) 2007 by Mateusz Haligowski + email : halish@kofeina.org + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +#ifndef IMPOSITION_UI_H +#define IMPOSITION_UI_H + +#include "ui_impositionbase.h" +#include <qtabwidget.h> +#include <qgroupbox.h> +#include <qframe.h> +#include <qlabel.h> +#include <qspinbox.h> + +#include "scribusstructs.h" +#include "scribuscore.h" +#include "scribuswin.h" +#include "scribusapi.h" + + +class ScribusDoc; + +class Imposition : public QDialog,Ui::ImpositionBase +{ + Q_OBJECT + + public: + Imposition(QWidget* parent = 0, ScribusDoc* doc = 0); + virtual ~Imposition(); + + double unitRatio; + QString unitSuffix; + int unitIndex; + + private: + QWidget* parent; + ScribusDoc* srcDoc; + ScribusDoc* targetDoc; + ScribusWin* w; + ScribusView* view; + bool isEdited; + bool isOK; + + bool verifyGrid(); + bool verifyBooklet(); + bool verifyFold(); + QList<int>* parsePages(QString); + + void booklet4p(QList<int>*); + void booklet8p(QList<int>*); + void booklet16p(QList<int>*); + + protected slots: + virtual void languageChange(); + void setPageSize(const QString &); + void customizeSize(); + void change2SidesBox(int); + void changeFoldBackPage(int); + virtual void accepted(); + + void changePage(); + void changeDocGrid(); + void changeDocBooklet(); + void changeDocFold(); + void changeTab(int); + + bool verifyPage(); +}; + +#endif //IMPOSITION_UI_H diff --git a/scribus/plugins/imposition/impositionbase.ui b/scribus/plugins/imposition/impositionbase.ui new file mode 100644 index 0000000..2d7c52e --- /dev/null +++ b/scribus/plugins/imposition/impositionbase.ui @@ -0,0 +1,730 @@ +<ui version="4.0" > + <class>ImpositionBase</class> + <widget class="QDialog" name="ImpositionBase" > + <property name="geometry" > + <rect> + <x>0</x> + <y>0</y> + <width>505</width> + <height>430</height> + </rect> + </property> + <property name="sizePolicy" > + <sizepolicy vsizetype="Minimum" hsizetype="Preferred" > + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="windowTitle" > + <string>Imposition</string> + </property> + <layout class="QGridLayout" > + <item row="0" column="0" > + <layout class="QVBoxLayout" > + <item> + <layout class="QHBoxLayout" > + <item> + <layout class="QVBoxLayout" > + <item> + <widget class="QTabWidget" name="impositionTabWidget" > + <property name="enabled" > + <bool>true</bool> + </property> + <property name="sizePolicy" > + <sizepolicy vsizetype="Expanding" hsizetype="Minimum" > + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="currentIndex" > + <number>0</number> + </property> + <widget class="QWidget" name="grid" > + <attribute name="title" > + <string>Gri&d</string> + </attribute> + <layout class="QGridLayout" > + <property name="leftMargin" > + <number>9</number> + </property> + <property name="topMargin" > + <number>9</number> + </property> + <property name="rightMargin" > + <number>9</number> + </property> + <property name="bottomMargin" > + <number>9</number> + </property> + <property name="horizontalSpacing" > + <number>6</number> + </property> + <property name="verticalSpacing" > + <number>6</number> + </property> + <item row="0" column="0" > + <layout class="QVBoxLayout" > + <property name="spacing" > + <number>5</number> + </property> + <property name="leftMargin" > + <number>0</number> + </property> + <property name="topMargin" > + <number>0</number> + </property> + <property name="rightMargin" > + <number>0</number> + </property> + <property name="bottomMargin" > + <number>0</number> + </property> + <item> + <layout class="QHBoxLayout" > + <property name="spacing" > + <number>6</number> + </property> + <property name="leftMargin" > + <number>0</number> + </property> + <property name="topMargin" > + <number>0</number> + </property> + <property name="rightMargin" > + <number>0</number> + </property> + <property name="bottomMargin" > + <number>0</number> + </property> + <item> + <widget class="QLabel" name="text11" > + <property name="text" > + <string>Copies</string> + </property> + <property name="wordWrap" > + <bool>false</bool> + </property> + </widget> + </item> + <item> + <widget class="QSpinBox" name="boxCopies" > + <property name="alignment" > + <set>Qt::AlignRight</set> + </property> + <property name="minimum" > + <number>1</number> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" > + <property name="spacing" > + <number>6</number> + </property> + <property name="leftMargin" > + <number>0</number> + </property> + <property name="topMargin" > + <number>0</number> + </property> + <property name="rightMargin" > + <number>0</number> + </property> + <property name="bottomMargin" > + <number>0</number> + </property> + <item> + <spacer> + <property name="orientation" > + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeType" > + <enum>QSizePolicy::Expanding</enum> + </property> + <property name="sizeHint" > + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QCheckBox" name="chb2Sides" > + <property name="text" > + <string>Do&uble sided</string> + </property> + <property name="shortcut" > + <string>Alt+U</string> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" > + <property name="spacing" > + <number>6</number> + </property> + <property name="leftMargin" > + <number>0</number> + </property> + <property name="topMargin" > + <number>0</number> + </property> + <property name="rightMargin" > + <number>0</number> + </property> + <property name="bottomMargin" > + <number>0</number> + </property> + <item> + <widget class="QLabel" name="text12" > + <property name="text" > + <string>Front side</string> + </property> + <property name="wordWrap" > + <bool>false</bool> + </property> + </widget> + </item> + <item> + <widget class="QComboBox" name="cbFront" /> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" > + <property name="spacing" > + <number>6</number> + </property> + <property name="leftMargin" > + <number>0</number> + </property> + <property name="topMargin" > + <number>0</number> + </property> + <property name="rightMargin" > + <number>0</number> + </property> + <property name="bottomMargin" > + <number>0</number> + </property> + <item> + <widget class="QLabel" name="text13" > + <property name="text" > + <string>Back side</string> + </property> + <property name="wordWrap" > + <bool>false</bool> + </property> + </widget> + </item> + <item> + <widget class="QComboBox" name="cbBack" > + <property name="enabled" > + <bool>false</bool> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </item> + <item row="1" column="0" > + <spacer> + <property name="orientation" > + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" > + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + </layout> + </widget> + <widget class="QWidget" name="booklet" > + <attribute name="title" > + <string>&Booklet</string> + </attribute> + <widget class="QWidget" name="layoutWidget" > + <property name="geometry" > + <rect> + <x>9</x> + <y>9</y> + <width>211</width> + <height>61</height> + </rect> + </property> + <layout class="QVBoxLayout" > + <item> + <layout class="QHBoxLayout" > + <property name="spacing" > + <number>6</number> + </property> + <property name="leftMargin" > + <number>0</number> + </property> + <property name="topMargin" > + <number>0</number> + </property> + <property name="rightMargin" > + <number>0</number> + </property> + <property name="bottomMargin" > + <number>0</number> + </property> + <item> + <widget class="QLabel" name="textLabel3" > + <property name="text" > + <string>Pages per sheet</string> + </property> + <property name="wordWrap" > + <bool>false</bool> + </property> + </widget> + </item> + <item> + <widget class="QComboBox" name="cbLayout" > + <item> + <property name="text" > + <string>4</string> + </property> + </item> + <item> + <property name="text" > + <string>8</string> + </property> + </item> + <item> + <property name="text" > + <string>16</string> + </property> + </item> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" > + <item> + <widget class="QLabel" name="label_3" > + <property name="text" > + <string>Pages</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="inpPages" > + <property name="toolTip" > + <string><html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Separate pages with a comma, ranges with a hyphen, e.g. 1,4,9-11 to get pages 1,4,9,10,11.</p></body></html></string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + </widget> + <widget class="QWidget" name="fold" > + <attribute name="title" > + <string>Fold</string> + </attribute> + <layout class="QGridLayout" > + <item row="0" column="0" > + <layout class="QVBoxLayout" > + <item> + <layout class="QHBoxLayout" > + <item> + <widget class="QLabel" name="label" > + <property name="text" > + <string>Front page from</string> + </property> + </widget> + </item> + <item> + <widget class="QComboBox" name="foldFrontPage" /> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" > + <item> + <spacer> + <property name="orientation" > + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" > + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QCheckBox" name="foldIsBackSide" > + <property name="text" > + <string>Double sided</string> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" > + <item> + <widget class="QLabel" name="label_2" > + <property name="text" > + <string>Back page from</string> + </property> + </widget> + </item> + <item> + <widget class="QComboBox" name="foldBackPage" > + <property name="enabled" > + <bool>false</bool> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </item> + </layout> + </widget> + </widget> + </item> + <item> + <widget class="QGroupBox" name="pageGroupBox" > + <property name="sizePolicy" > + <sizepolicy vsizetype="Expanding" hsizetype="Minimum" > + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="title" > + <string>Destination page</string> + </property> + <layout class="QVBoxLayout" > + <item> + <layout class="QVBoxLayout" > + <property name="spacing" > + <number>6</number> + </property> + <property name="leftMargin" > + <number>0</number> + </property> + <property name="topMargin" > + <number>0</number> + </property> + <property name="rightMargin" > + <number>0</number> + </property> + <property name="bottomMargin" > + <number>0</number> + </property> + <item> + <layout class="QHBoxLayout" > + <property name="spacing" > + <number>6</number> + </property> + <property name="leftMargin" > + <number>0</number> + </property> + <property name="topMargin" > + <number>0</number> + </property> + <property name="rightMargin" > + <number>0</number> + </property> + <property name="bottomMargin" > + <number>0</number> + </property> + <item> + <widget class="QLabel" name="text01" > + <property name="text" > + <string>Size</string> + </property> + <property name="wordWrap" > + <bool>false</bool> + </property> + </widget> + </item> + <item> + <widget class="QComboBox" name="pageSizeComboBox" /> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" > + <property name="spacing" > + <number>6</number> + </property> + <property name="leftMargin" > + <number>0</number> + </property> + <property name="topMargin" > + <number>0</number> + </property> + <property name="rightMargin" > + <number>0</number> + </property> + <property name="bottomMargin" > + <number>0</number> + </property> + <item> + <widget class="QLabel" name="text02" > + <property name="text" > + <string>Orientation</string> + </property> + <property name="wordWrap" > + <bool>false</bool> + </property> + </widget> + </item> + <item> + <widget class="QComboBox" name="pageOrientationComboBox" /> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" > + <property name="spacing" > + <number>6</number> + </property> + <property name="leftMargin" > + <number>0</number> + </property> + <property name="topMargin" > + <number>0</number> + </property> + <property name="rightMargin" > + <number>0</number> + </property> + <property name="bottomMargin" > + <number>0</number> + </property> + <item> + <widget class="QLabel" name="text03" > + <property name="text" > + <string>Width</string> + </property> + <property name="wordWrap" > + <bool>false</bool> + </property> + </widget> + </item> + <item> + <widget class="QDoubleSpinBox" name="pageWidthBox" > + <property name="alignment" > + <set>Qt::AlignRight</set> + </property> + <property name="decimals" > + <number>4</number> + </property> + <property name="minimum" > + <double>0.000100000000000</double> + </property> + <property name="maximum" > + <double>10000.000000000000000</double> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" > + <property name="spacing" > + <number>6</number> + </property> + <property name="leftMargin" > + <number>0</number> + </property> + <property name="topMargin" > + <number>0</number> + </property> + <property name="rightMargin" > + <number>0</number> + </property> + <property name="bottomMargin" > + <number>0</number> + </property> + <item> + <widget class="QLabel" name="text04" > + <property name="text" > + <string>Height</string> + </property> + <property name="wordWrap" > + <bool>false</bool> + </property> + </widget> + </item> + <item> + <widget class="QDoubleSpinBox" name="pageHeightBox" > + <property name="alignment" > + <set>Qt::AlignRight</set> + </property> + <property name="decimals" > + <number>4</number> + </property> + <property name="minimum" > + <double>0.000100000000000</double> + </property> + <property name="maximum" > + <double>10000.000000000000000</double> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </item> + <item> + <spacer> + <property name="orientation" > + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" > + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + </layout> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QVBoxLayout" > + <item> + <widget class="QGroupBox" name="previewGroupBox" > + <property name="sizePolicy" > + <sizepolicy vsizetype="Preferred" hsizetype="Preferred" > + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="title" > + <string>Preview</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="btnPreview" > + <property name="text" > + <string>Refresh preview</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" > + <property name="spacing" > + <number>6</number> + </property> + <property name="leftMargin" > + <number>0</number> + </property> + <property name="topMargin" > + <number>0</number> + </property> + <property name="rightMargin" > + <number>0</number> + </property> + <property name="bottomMargin" > + <number>0</number> + </property> + <item> + <spacer> + <property name="orientation" > + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeType" > + <enum>QSizePolicy::Expanding</enum> + </property> + <property name="sizeHint" > + <size> + <width>160</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QPushButton" name="btnGo" > + <property name="text" > + <string>&OK</string> + </property> + <property name="shortcut" > + <string>Alt+G</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="btnCancel" > + <property name="text" > + <string>&Cancel</string> + </property> + <property name="shortcut" > + <string>Alt+C</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </item> + </layout> + </widget> + <layoutdefault spacing="6" margin="11" /> + <resources/> + <connections> + <connection> + <sender>btnGo</sender> + <signal>clicked()</signal> + <receiver>ImpositionBase</receiver> + <slot>accept()</slot> + <hints> + <hint type="sourcelabel" > + <x>407</x> + <y>392</y> + </hint> + <hint type="destinationlabel" > + <x>20</x> + <y>20</y> + </hint> + </hints> + </connection> + <connection> + <sender>btnCancel</sender> + <signal>clicked()</signal> + <receiver>ImpositionBase</receiver> + <slot>reject()</slot> + <hints> + <hint type="sourcelabel" > + <x>488</x> + <y>392</y> + </hint> + <hint type="destinationlabel" > + <x>20</x> + <y>20</y> + </hint> + </hints> + </connection> + </connections> +</ui> diff --git a/scribus/plugins/imposition/impositionplugin.cpp b/scribus/plugins/imposition/impositionplugin.cpp new file mode 100644 index 0000000..645986f --- /dev/null +++ b/scribus/plugins/imposition/impositionplugin.cpp @@ -0,0 +1,101 @@ +/* +For general Scribus (>=1.3.2) copyright and licensing information please refer +to the COPYING file provided with the program. Following this notice may exist +a copyright and/or license notice that predates the release of Scribus 1.3.2 +for which a new license (GPL+exception) is in place. +*/ +/*************************************************************************** + begin : Jun 2007 + copyright : (C) 2007 by Mateusz Haligowski + email : halish@kofeina.org +***************************************************************************/ + +/*************************************************************************** +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +***************************************************************************/ +#include "impositionplugin.h" +//#include "impositionplugin.moc" +#include "imposition.h" +#include "scribuscore.h" +#include "scribusdoc.h" + +ImpositionPlugin::ImpositionPlugin() : ScActionPlugin() +{ + languageChange(); +} + +ImpositionPlugin::~ImpositionPlugin() {}; + +void ImpositionPlugin::languageChange() +{ + m_actionInfo.name = "Imposition"; + m_actionInfo.text = tr("&Imposition..."); + m_actionInfo.menu = "Extras"; + m_actionInfo.enabledOnStartup = false; + m_actionInfo.needsNumObjects = -1; +} + +bool ImpositionPlugin::run(QWidget* parent, ScribusDoc* doc, QString target) +{ + if (doc==NULL) + return false; + Imposition *imp = new Imposition(parent,doc); + imp->exec(); + + return true; +} + +bool ImpositionPlugin::run(ScribusDoc* doc, QString target) +{ + ScribusMainWindow* scmw=(doc==0)?ScCore->primaryMainWindow():doc->scMW(); + return run(scmw, doc, target); +} + +const QString ImpositionPlugin::fullTrName() const +{ + return QObject::tr("Imposition"); +} + +const ScActionPlugin::AboutData* ImpositionPlugin::getAboutData() const +{ + AboutData* about = new AboutData; + Q_CHECK_PTR(about); + about->authors = QString::fromUtf8("Mateusz Haligowski <halish@kofeina.org>"); + about->shortDescription = tr("Imposition dialog"); + about->description = tr("Imposition on grids, booklets and folds"); + // about->version + // about->releaseDate + // about->copyright + about->license = "GPL"; + return about; +} + +void ImpositionPlugin::deleteAboutData(const AboutData* about) const +{ + Q_ASSERT(about); + delete about; +} + +int imposition_getPluginAPIVersion() +{ + return PLUGIN_API_VERSION; +} + +ScPlugin* imposition_getPlugin() +{ + ImpositionPlugin* plug = new ImpositionPlugin(); + Q_CHECK_PTR(plug); + return plug; +} + +void imposition_freePlugin(ScPlugin* plugin) +{ + ImpositionPlugin* plug = dynamic_cast<ImpositionPlugin*>(plugin); + Q_ASSERT(plug); + delete plug; +} diff --git a/scribus/plugins/imposition/impositionplugin.h b/scribus/plugins/imposition/impositionplugin.h new file mode 100644 index 0000000..441e9f7 --- /dev/null +++ b/scribus/plugins/imposition/impositionplugin.h @@ -0,0 +1,53 @@ +/* +For general Scribus (>=1.3.2) copyright and licensing information please refer +to the COPYING file provided with the program. Following this notice may exist +a copyright and/or license notice that predates the release of Scribus 1.3.2 +for which a new license (GPL+exception) is in place. +*/ +/*************************************************************************** + begin : Jun 2007 + copyright : (C) 2007 by Mateusz Haligowski + email : halish@kofeina.org + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +#ifndef IMPOSITION_H +#define IMPOSITION_H + +#include "pluginapi.h" +#include "scplugin.h" + +class ScribusDoc; + +class PLUGIN_API ImpositionPlugin : public ScActionPlugin +{ + Q_OBJECT + + public: + ImpositionPlugin(); + virtual ~ImpositionPlugin(); + + virtual bool run(QWidget* parent, ScribusDoc* doc, QString target = QString::null); + virtual bool run(ScribusDoc* doc, QString target = QString::null); + virtual void languageChange(); + virtual const QString fullTrName() const; + virtual const AboutData* getAboutData() const; + virtual void deleteAboutData(const AboutData* about) const; + virtual void addToMainWindowMenu(ScribusMainWindow *) {}; +}; + +extern "C" PLUGIN_API int imposition_getPluginAPIVersion(); +extern "C" PLUGIN_API ScPlugin* imposition_getPlugin(); +extern "C" PLUGIN_API void imposition_freePlugin(ScPlugin* plugin); + + + +#endif + |
