void KWPageStylePrivate::clear() { // defaults footNoteSeparatorLineLength = 20; // 20%, i.e. 1/5th footNoteSeparatorLineWidth = 0.5; // like in OOo footNoteSeparatorLineType = Qt::SolidLine; mainFrame = true; headerMargin.bottom = MM_TO_POINT(5); footerMargin.top = MM_TO_POINT(5); headerMinimumHeight = MM_TO_POINT(10); footerMinimumHeight = MM_TO_POINT(10); footNoteDistance = 10; endNoteDistance = 10; headers = KWord::HFTypeNone; footers = KWord::HFTypeNone; columns.columns = 1; columns.columnSpacing = MM_TO_POINT(6); direction = KOdfText::AutoDirection; if (fullPageBackground && !fullPageBackground->deref()) { delete fullPageBackground; } fullPageBackground = 0; nextStyleName.clear(); fixedHeaderSize = false; fixedFooterSize = false; }
void KCPrintSettings::Private::calculatePageDimensions() { if (pageLayout.format != KOdfPageFormat::CustomSize) { pageLayout.width = MM_TO_POINT(KOdfPageFormat::width(pageLayout.format, pageLayout.orientation)); pageLayout.height = MM_TO_POINT(KOdfPageFormat::height(pageLayout.format, pageLayout.orientation)); } }
M_PageSize::M_PageSize() { landscape = false; body = FoRegion(); coolspace = 0; modus = 0; name = "A4 (210 x 297 mm)"; P_rect = QPrinter::A4; G_regt = QRectF(0,0,MM_TO_POINT(210),MM_TO_POINT(297)); RealSize = G_regt.size(); AllowHeaderFooter = true; FoRegion topR; FoRegion bottomR; FoRegion leftR; FoRegion rightR; area[0] = topR; area[1] = bottomR; area[2] = leftR; area[3] = rightR; /* FoRegion region_before() const { return area[0]; } FoRegion region_after() const { return area[1]; } FoRegion region_start() const { return area[2]; } FoRegion region_end() const { return area[3]; } */ area[0].margin_top = CM_TO_POINT(0.4); area[0].margin_bottom = CM_TO_POINT(0.4); area[0].margin_left = CM_TO_POINT(0); area[0].margin_right = CM_TO_POINT(0); area[1].margin_top = CM_TO_POINT(0.4); area[1].margin_bottom = CM_TO_POINT(0.4); area[1].margin_left = CM_TO_POINT(0); area[1].margin_right = CM_TO_POINT(0); area[2].margin_top = CM_TO_POINT(0); area[2].margin_bottom = CM_TO_POINT(0); area[2].margin_left = CM_TO_POINT(0); area[2].margin_right = CM_TO_POINT(0); area[3].margin_top = CM_TO_POINT(0); area[3].margin_bottom = CM_TO_POINT(0); area[3].margin_left = CM_TO_POINT(0); area[3].margin_right = CM_TO_POINT(0); area[0].enable = false; area[1].enable = false; area[2].enable = false; area[3].enable = false; }
void parseHelpLine(const QString &text) { //<config:config-item config:name="SnapLinesDrawing" config:type="string">V7939H1139</config:config-item> QString str; int newPos = text.length() - 1; //start to element = 1 for (int pos = text.length() - 1; pos >= 0;--pos) { if (text[pos] == 'P') { //point element str = text.mid(pos + 1, (newPos - pos)); /* QStringList listVal = QStringList::split(",", str); int posX = (listVal[0].toInt()/100); int posY = (listVal[1].toInt()/100); point.setAttribute("posX", MM_TO_POINT(posX)); point.setAttribute("posY", MM_TO_POINT(posY)); */ newPos = pos - 1; } else if (text[pos] == 'V') { //vertical element str = text.mid(pos + 1, (newPos - pos)); //debugFlake<<" vertical :"<< str; qreal posX = str.toDouble() / 100.0; vertGuideLines.append(MM_TO_POINT(posX)); newPos = (pos - 1); } else if (text[pos] == 'H') { //horizontal element str = text.mid(pos + 1, (newPos - pos)); qreal posY = str.toDouble() / 100.0; horzGuideLines.append(MM_TO_POINT(posY)); newPos = pos - 1; } } }
Private() : snapToGrid(false), showGrid(false), paintGridInBackground(false), gridX(MM_TO_POINT(DEFAULT_GRID_SIZE_MM)), gridY(MM_TO_POINT(DEFAULT_GRID_SIZE_MM)), gridColor(Qt::lightGray), toggleGridAction(0) { }
QMap<QString,QPen> FoRegion::penstyle() { QMap<QString,QPen> plist; plist.insert( QString("0.0mm empty border") ,QPen(Qt::NoPen)); plist.insert( QString("0.5mm solid") ,QPen(Qt::black,MM_TO_POINT(0.5),Qt::SolidLine)); plist.insert( QString("0.5mm dotline") ,QPen(Qt::black,MM_TO_POINT(0.5),Qt::DotLine)); for (int i = 1; i < 9; ++i) { plist.insert( QString("%1mm solid").arg(i) ,QPen(Qt::black,MM_TO_POINT(i),Qt::SolidLine)); plist.insert( QString("%1mm dotline").arg(i) ,QPen(Qt::black,MM_TO_POINT(i),Qt::DotLine)); plist.insert( QString("%1mm dashline").arg(i) ,QPen(Qt::black,MM_TO_POINT(i),Qt::DashLine)); } return plist; }
M_PageSize::M_PageSize() { landscape = false; coolspace = 0; modus = 0; name = "A4 (210 x 297 mm, 8.26 x 11.7 inches)"; //////// G_regt.size() P_rect = QPrinter::A4; G_regt = QRectF(0,0,MM_TO_POINT(210),MM_TO_POINT(297)); RealSize = G_regt.size(); const qreal mr = MM_TO_POINT(10); P_margin = QRectF(mr,mr,mr,MM_TO_POINT(30)); //////P_margin = QRectF(0,0,0,0); ////// css like QRectF(xTopMargin,xRightMargin,xBottomMargin,xLeftMargin); AllowHeaderFooter = true; }
qreal ToPoint( qreal unit , const QString unita ) { qreal ri = 0; if (unita == "cm") { ri = CM_TO_POINT( unit ); } else if (unita == "pt" || unita == "px" ) { ri = unit; return ri; } else if (unita == "mm") { ri = MM_TO_POINT( unit ); } else if (unita == "dm") { ri = DM_TO_POINT( unit ); } else if (unita == "inch") { ri = INCH_TO_POINT( unit ); } else if (unita == "pi") { ri = PI_TO_POINT( unit ); } else if (unita == "dd") { ri = DD_TO_POINT( unit ); } else if (unita == "cc") { ri = CC_TO_POINT( unit ); } else { ri = 10; } return ri; }
void KWFrameRunaroundProperties::open(KoShape *shape) { m_state->addUser(); m_shape = shape; widget.runAround->setChecked(true); widget.longest->setChecked(true); widget.distance->changeValue(MM_TO_POINT(3)); }
qreal FopInt( const QString datain ) { QString ctmp = datain; const QString data = ctmp.replace(" ","").trimmed(); //////////qDebug() << "### request unit data->" << datain << " size->" << datain.size(); qreal points = 0; if (data.size() < 1) { return points; } if ( data.endsWith( "%" )) { return 12.5; } if (datain == "0") { return points; } if ( data.endsWith( "pt" ) || data.endsWith( "px" ) ) { points = data.left( data.length() - 2 ).toDouble(); return points; } else if ( data.endsWith( "cm" ) ) { double value = data.left( data.length() - 2 ).toDouble(); points = CM_TO_POINT( value ); } else if ( data.endsWith( "em" ) ) { points = data.left( data.length() - 2 ).toDouble(); } else if ( data.endsWith( "mm" ) ) { double value = data.left( data.length() - 2 ).toDouble(); points = MM_TO_POINT( value ); } else if ( data.endsWith( "dm" ) ) { double value = data.left( data.length() - 2 ).toDouble(); points = DM_TO_POINT( value ); } else if ( data.endsWith( "in" ) ) { double value = data.left( data.length() - 2 ).toDouble(); points = INCH_TO_POINT( value ); } else if ( data.endsWith( "inch" ) ) { double value = data.left( data.length() - 4 ).toDouble(); points = INCH_TO_POINT( value ); } else if ( data.endsWith( "pi" ) ) { double value = data.left( data.length() - 4 ).toDouble(); points = PI_TO_POINT( value ); } else if ( data.endsWith( "dd" ) ) { double value = data.left( data.length() - 4 ).toDouble(); points = DD_TO_POINT( value ); } else if ( data.endsWith( "cc" ) ) { double value = data.left( data.length() - 4 ).toDouble(); points = CC_TO_POINT( value ); } else { points = 0; } return points; }
KarbonPart::KarbonPart(QWidget* parentWidget, const char* widgetName, QObject* parent, const char* name, bool singleViewMode) : KoDocument(parentWidget, parent, singleViewMode), d(new Private()) { Q_UNUSED(widgetName); d->document.setResourceManager(resourceManager()); setObjectName(name); setComponentData(KarbonFactory::componentData(), false); setTemplateType("karbon_template"); resourceManager()->setUndoStack(undoStack()); initConfig(); // set as default paper KoPageLayout pl = pageLayout(); pl.format = KoPageFormat::defaultFormat(); pl.orientation = KoPageFormat::Portrait; pl.width = MM_TO_POINT(KoPageFormat::width(pl.format, pl.orientation)); pl.height = MM_TO_POINT(KoPageFormat::height(pl.format, pl.orientation)); setPageLayout(pl); }
KWStartupWidget::KWStartupWidget(QWidget *parent, KWDocument *doc, const KoColumns &columns) : QWidget(parent), m_unit(doc->unit()) { widget.setupUi(this); m_columns = columns; m_layout.leftMargin = MM_TO_POINT(30); m_layout.rightMargin = MM_TO_POINT(30); m_layout.topMargin = MM_TO_POINT(25); m_layout.bottomMargin = MM_TO_POINT(25); m_doc = doc; setFocusProxy(widget.createButton); QVBoxLayout *lay = new QVBoxLayout(widget.sizeTab); m_sizeWidget = new KoPageLayoutWidget(widget.sizeTab, m_layout); m_sizeWidget->showPageSpread(true); m_sizeWidget->setUnit(m_unit); lay->addWidget(m_sizeWidget); lay = new QVBoxLayout(widget.columnsTab); m_columnsWidget = new KWDocumentColumns(widget.columnsTab, m_columns); m_columnsWidget->setUnit(m_unit); m_columnsWidget->setShowPreview(false); lay->addWidget(m_columnsWidget); lay = new QVBoxLayout(widget.previewPane); widget.previewPane->setLayout(lay); KoPagePreviewWidget *prev = new KoPagePreviewWidget(widget.previewPane); lay->addWidget(prev); prev->setColumns(columns); prev->setPageLayout(m_layout); connect(m_sizeWidget, SIGNAL(layoutChanged(KoPageLayout)), this, SLOT(sizeUpdated(KoPageLayout))); connect(widget.createButton, SIGNAL(clicked()), this, SLOT(buttonClicked())); connect(m_sizeWidget, SIGNAL(unitChanged(KoUnit)), this, SLOT(unitChanged(KoUnit))); connect(m_columnsWidget, SIGNAL(columnsChanged(KoColumns)), prev, SLOT(setColumns(KoColumns))); connect(m_columnsWidget, SIGNAL(columnsChanged(KoColumns)), this, SLOT(columnsUpdated(KoColumns))); connect(m_sizeWidget, SIGNAL(layoutChanged(KoPageLayout)), prev, SLOT(setPageLayout(KoPageLayout))); }
qreal KoUnit::convertFromUnitToUnit(const qreal value, const KoUnit &fromUnit, const KoUnit &toUnit, qreal factor) { qreal pt; switch (fromUnit.type()) { case Millimeter: pt = MM_TO_POINT(value); break; case Centimeter: pt = CM_TO_POINT(value); break; case Decimeter: pt = DM_TO_POINT(value); break; case Inch: pt = INCH_TO_POINT(value); break; case Pica: pt = PI_TO_POINT(value); break; case Cicero: pt = CC_TO_POINT(value); break; case Pixel: pt = value / factor; break; case Point: default: pt = value; } switch (toUnit.type()) { case Millimeter: return POINT_TO_MM(pt); case Centimeter: return POINT_TO_CM(pt); case Decimeter: return POINT_TO_DM(pt); case Inch: return POINT_TO_INCH(pt); case Pica: return POINT_TO_PI(pt); case Cicero: return POINT_TO_CC(pt); case Pixel: return pt * factor; case Point: default: return pt; } }
void KoPageLayoutWidget::sizeChanged(int row) { if (row < 0) return; if (! d->allowSignals) return; d->allowSignals = false; d->pageLayout.format = static_cast<KOdfPageFormat::Format> (row); bool custom = d->pageLayout.format == KOdfPageFormat::CustomSize; d->widget.width->setEnabled( custom ); d->widget.height->setEnabled( custom ); if ( !custom ) { d->pageLayout.width = MM_TO_POINT( KOdfPageFormat::width( d->pageLayout.format, d->pageLayout.orientation ) ); d->pageLayout.height = MM_TO_POINT( KOdfPageFormat::height( d->pageLayout.format, d->pageLayout.orientation ) ); if (d->widget.facingPages->isChecked()) // is pagespread d->pageLayout.width *= 2; } d->widget.width->changeValue( d->pageLayout.width ); d->widget.height->changeValue( d->pageLayout.height ); emit layoutChanged(d->pageLayout); d->allowSignals = true; }
void KWFrameGeometry::open(KShape *shape) { KWPage page = m_state->document()->pageManager()->page(shape); m_topOfPage = page.offsetInDocument(); m_originalPosition = shape->position(); m_originalSize = shape->size(); QPointF position = shape->absolutePosition(widget.positionSelector->position()); widget.xPos->changeValue(position.x()); widget.yPos->changeValue(position.y() - m_topOfPage); widget.width->changeValue(m_originalSize.width()); widget.height->changeValue(m_originalSize.height()); if (m_frame == 0) { // default values for new frames widget.leftMargin->changeValue(MM_TO_POINT(3)); widget.rightMargin->changeValue(MM_TO_POINT(3)); widget.topMargin->changeValue(MM_TO_POINT(3)); widget.bottomMargin->changeValue(MM_TO_POINT(3)); } connect(widget.protectSize, SIGNAL(stateChanged(int)), this, SLOT(protectSizeChanged(int))); m_originalGeometryLock = shape->isGeometryProtected(); if (m_originalGeometryLock) { widget.protectSize->setCheckState(Qt::Checked); KWTextFrame *tf = dynamic_cast<KWTextFrame*>(shape->applicationData()); if (tf && static_cast<KWTextFrameSet*>(tf->frameSet())->textFrameSetType() != KWord::OtherTextFrameSet) widget.protectSize->setEnabled(false); // auto-generated frame, can't edit } connect(widget.xPos, SIGNAL(valueChanged(double)), this, SLOT(updateShape())); connect(widget.yPos, SIGNAL(valueChanged(double)), this, SLOT(updateShape())); connect(widget.width, SIGNAL(valueChanged(double)), this, SLOT(updateShape())); connect(widget.height, SIGNAL(valueChanged(double)), this, SLOT(updateShape())); }
void dController::printOverSide(int RowId) { //TODO это должно быть в отдельном классе !!! QGraphicsScene *scene = new QGraphicsScene(); bool page_orient= false; int margin_top = MM_TO_POINT(15); int margin_bottom=MM_TO_POINT(15); int margin_left=MM_TO_POINT(35); int margin_right=MM_TO_POINT(15); int page_width=210; int page_height=297; scene->clear(); scene->setSceneRect(0, 0, MM_TO_POINT(page_width),MM_TO_POINT(page_height)); QGraphicsRectItem *border_rect = new QGraphicsRectItem (QRectF(margin_left, margin_top, MM_TO_POINT(page_width)-margin_left-margin_right,MM_TO_POINT(page_height)-margin_top-margin_bottom)); qDebug() <<"margin_rect"<< margin_left << margin_top << margin_left<<margin_right; border_rect->setPen(QPen(Qt::black,2,Qt::DotLine)); border_rect->setBrush(QBrush(Qt::white)); border_rect->setOpacity(0.5); border_rect->setZValue(0); //border_rect->setData(ObjectName, "Border"); scene->addItem(border_rect); SimpleItem* MBitem = new SimpleItem; MBitem->setPos(MM_TO_POINT(5), MM_TO_POINT(280)); MBitem->setPrintFrame(false); MBitem->setText(QStringList()<<QString("МБ №-%1")); MBitem->setFlag(QGraphicsItem::ItemIsMovable); MBitem->setParentItem(border_rect); //scene->addItem(MBtem); scene->update(); QPrinter printer; printer.setPrinterName(curPrinter); //Печать на реальный принтер //printer.setOutputFormat(QPrinter::PdfFormat); //printer.setOutputFileName("overside.pdf"); //printer.setPageSize(QPrinter::A4); QPainter painter(&printer); scene->render(&painter); //emit sayMeGood(); }
KWApplicationConfig::KWApplicationConfig() : m_viewFrameBorders(true), m_viewRulers(false), m_showFormattingChars(false), m_showTableBorders(true), m_createBackupFile(true), m_statusBarShowPage(true), m_statusBarShowPageStyle(true), m_statusBarShowPageSize(false), m_statusBarShowLineNumber(true), m_statusBarShowModified(true), m_statusBarShowMouse(false), m_statusBarShowZoom(true), m_statusBarShowWordCount(false), m_showInlineObjectVisualization(true), m_zoom(100), m_zoomMode(KoZoomMode::ZOOM_WIDTH), m_autoSaveSeconds(KoDocument::defaultAutoSave()), m_defaultColumnSpacing(MM_TO_POINT(6)) { }
KgvPageLayout KgvPageLayout::standardLayout() { KgvPageLayout layout; layout.format = KgvPageFormat::defaultFormat(); layout.orientation = PG_PORTRAIT; layout.ptWidth = MM_TO_POINT( KgvPageFormat::width( layout.format, layout.orientation ) ); layout.ptHeight = MM_TO_POINT( KgvPageFormat::height( layout.format, layout.orientation ) ); layout.ptLeft = MM_TO_POINT( 20.0 ); layout.ptRight = MM_TO_POINT( 20.0 ); layout.ptTop = MM_TO_POINT( 20.0 ); layout.ptBottom = MM_TO_POINT( 20.0 ); layout.ptPageEdge = -1; layout.ptBindingSide = -1; kDebug() << "Returning standardLayout"; return layout; }
qreal KoUnit::fromUserValue(qreal value) const { switch (m_type) { case Millimeter: return MM_TO_POINT(value); case Centimeter: return CM_TO_POINT(value); case Decimeter: return DM_TO_POINT(value); case Inch: return INCH_TO_POINT(value); case Pica: return PI_TO_POINT(value); case Cicero: return CC_TO_POINT(value); case Pixel: return value / m_pixelConversion; case Point: default: return value; } }
KoPageLayout::KoPageLayout() : format(KoPageFormat::defaultFormat()) , orientation(KoPageFormat::Portrait) , width(MM_TO_POINT(KoPageFormat::width(format, orientation))) , height(MM_TO_POINT(KoPageFormat::height(format, orientation))) , leftMargin(MM_TO_POINT(20.0)) , rightMargin(MM_TO_POINT(20.0)) , topMargin(MM_TO_POINT(20.0)) , bottomMargin(MM_TO_POINT(20.0)) , pageEdge(-1) , bindingSide(-1) , leftPadding(0) , rightPadding(0) , topPadding(0) , bottomPadding(0) , border() { }
#include <ktoggleaction.h> #include <klocalizedstring.h> #include <QPainter> #include <QRectF> #include <FlakeDebug.h> #define DEFAULT_GRID_SIZE_MM 5.0 class Q_DECL_HIDDEN KoGridData::Private { public: bool snapToGrid{false}; bool showGrid{false}; bool paintGridInBackground{false}; qreal gridX{MM_TO_POINT(DEFAULT_GRID_SIZE_MM)}; qreal gridY{MM_TO_POINT(DEFAULT_GRID_SIZE_MM)}; QColor gridColor{Qt::lightGray}; QScopedPointer<KToggleAction> toggleGridAction; }; KoGridData::KoGridData() : d(new Private()) { } KoGridData::~KoGridData() { delete d; }
//1.6: KWDocument::loadOasis bool KWOdfLoader::load(KoOdfReadStore & odfStore) { emit sigProgress(0); //kDebug(32001) << "========================> KWOdfLoader::load START"; KoXmlElement content = odfStore.contentDoc().documentElement(); KoXmlElement realBody(KoXml::namedItemNS(content, KoXmlNS::office, "body")); if (realBody.isNull()) { kError(32001) << "No office:body found!" << endl; m_document->setErrorMessage(i18n("Invalid OASIS OpenDocument file. No office:body tag found.")); return false; } KoXmlElement body = KoXml::namedItemNS(realBody, KoXmlNS::office, "text"); if (body.isNull()) { kError(32001) << "No office:text found!" << endl; KoXmlElement childElem; QString localName; forEachElement(childElem, realBody) localName = childElem.localName(); if (localName.isEmpty()) m_document->setErrorMessage(i18n("Invalid OASIS OpenDocument file. No tag found inside office:body.")); else m_document->setErrorMessage(i18n("This is not a word processing document, but %1. Please try opening it with the appropriate application.", KoDocument::tagNameToDocumentType(localName))); return false; } // TODO check versions and mimetypes etc. bool hasMainText = false; KoXmlElement childElem; forEachElement(childElem, body) { if (childElem.namespaceURI() == KoXmlNS::text) { hasMainText = true; break; } } KoOdfLoadingContext odfContext(odfStore.styles(), odfStore.store(), m_document->componentData()); KoShapeLoadingContext sc(odfContext, m_document->dataCenterMap()); // Load all styles before the corresponding paragraphs try to use them! KWOdfSharedLoadingData * sharedData = new KWOdfSharedLoadingData(this); KoStyleManager *styleManager = dynamic_cast<KoStyleManager *>(m_document->dataCenterMap()["StyleManager"]); Q_ASSERT(styleManager); sharedData->loadOdfStyles(odfContext, styleManager); sc.addSharedData(KOTEXT_SHARED_LOADING_ID, sharedData); KoTextLoader * loader = new KoTextLoader(sc); Q_UNUSED(loader); KoOdfLoadingContext context(odfStore.styles(), odfStore.store(), m_document->componentData()); loadMasterPageStyles(context, hasMainText); #if 0 //1.6: KWOasisLoader oasisLoader(this); // <text:page-sequence> oasis extension for DTP (2003-10-27 post by Daniel) m_processingType = (!KoXml::namedItemNS(body, KoXmlNS::text, "page-sequence").isNull()) ? DTP : WP; m_hasTOC = false; m_tabStop = MM_TO_POINT(15); const KoXmlElement* defaultParagStyle = styles.defaultStyle("paragraph"); if (defaultParagStyle) { KoStyleStack stack; stack.push(*defaultParagStyle); stack.setTypeProperties("paragraph"); QString tabStopVal = stack.property(KoXmlNS::style, "tab-stop-distance"); if (!tabStopVal.isEmpty()) m_tabStop = KoUnit::parseValue(tabStopVal); } m_initialEditing = 0; // TODO MAILMERGE // Variable settings // By default display real variable value if (!isReadWrite()) m_varColl->variableSetting()->setDisplayFieldCode(false); #endif // Load all styles before the corresponding paragraphs try to use them! #if 0 //1.6: if (m_frameStyleColl->loadOasisStyles(context) == 0) { // no styles loaded -> load default styles loadDefaultFrameStyleTemplates(); } if (m_tableStyleColl->loadOasisStyles(context, *m_styleColl, *m_frameStyleColl) == 0) { // no styles loaded -> load default styles loadDefaultTableStyleTemplates(); } static_cast<KWVariableSettings *>(m_varColl->variableSetting())->loadNoteConfiguration(styles.officeStyle()); loadDefaultTableTemplates(); //#else /* // We always needs at least one valid default paragraph style KoParagraphStyle *defaultParagraphStyle = m_document->styleManager()->defaultParagraphStyle(); //const KoXmlElement* defaultParagraphStyle = context.stylesReader().defaultStyle("paragraph"); //if( ! defaultParagraphStyle ) { KoParagraphStyle *parastyle = new KoParagraphStyle(); parastyle->setName("Standard"); m_document->styleManager()->add(parastyle); context.styleStack().setTypeProperties( "paragraph" ); // load all style attributes from "style:paragraph-properties" parastyle->loadOasis(context.styleStack()); // load the KoParagraphStyle from the stylestack KoCharacterStyle *charstyle = parastyle->characterStyle(); context.styleStack().setTypeProperties( "text" ); // load all style attributes from "style:text-properties" charstyle->loadOasis(context.styleStack()); // load the KoCharacterStyle from the stylestack //} */ #endif // load text:page-sequence KoXmlElement pageSequence = KoXml::namedItemNS(body, KoXmlNS::text, "page-sequence"); if (! pageSequence.isNull()) { KWPageManager *pageManager = m_document->pageManager(); KoXmlElement page; forEachElement(page, pageSequence) { if (page.namespaceURI() == KoXmlNS::text && page.localName() == "page") { QString master = page.attributeNS(KoXmlNS::text, "master-page-name", QString()); pageManager->appendPage(pageManager->pageStyle(master)); } } }
void KoPageLayout::loadOdf(const KoXmlElement &style) { KoXmlElement properties(KoXml::namedItemNS(style, KoXmlNS::style, "page-layout-properties")); if (!properties.isNull()) { KoPageLayout standard; // Page dimension -- width / height width = KoUnit::parseValue(properties.attributeNS(KoXmlNS::fo, "page-width"), standard.width); height = KoUnit::parseValue(properties.attributeNS(KoXmlNS::fo, "page-height"), standard.height); // Page orientation if (properties.attributeNS(KoXmlNS::style, "print-orientation", QString()) == "portrait") orientation = KoPageFormat::Portrait; else orientation = KoPageFormat::Landscape; // Margins. Check if there is one "margin" attribute and use it for all // margins if there is. Otherwise load the individual margins. if (properties.hasAttributeNS(KoXmlNS::fo, "margin")) { leftMargin = KoUnit::parseValue(properties.attributeNS(KoXmlNS::fo, "margin")); topMargin = leftMargin; rightMargin = leftMargin; bottomMargin = leftMargin; } else { /* If one of the individual margins is specified then the default for the others is zero. Otherwise all of them are set to 20mm. */ qreal defaultValue = 0; if (!(properties.hasAttributeNS(KoXmlNS::fo, "margin-left") || properties.hasAttributeNS(KoXmlNS::fo, "margin-top") || properties.hasAttributeNS(KoXmlNS::fo, "margin-right") || properties.hasAttributeNS(KoXmlNS::fo, "margin-bottom"))) defaultValue = MM_TO_POINT(20.0); // no margin specified at all, lets make it 20mm leftMargin = KoUnit::parseValue(properties.attributeNS(KoXmlNS::fo, "margin-left"), defaultValue); topMargin = KoUnit::parseValue(properties.attributeNS(KoXmlNS::fo, "margin-top"), defaultValue); rightMargin = KoUnit::parseValue(properties.attributeNS(KoXmlNS::fo, "margin-right"), defaultValue); bottomMargin = KoUnit::parseValue(properties.attributeNS(KoXmlNS::fo, "margin-bottom"), defaultValue); } // Padding. Same reasoning as for margins if (properties.hasAttributeNS(KoXmlNS::fo, "padding")) { leftPadding = KoUnit::parseValue(properties.attributeNS(KoXmlNS::fo, "padding")); topPadding = leftPadding; rightPadding = leftPadding; bottomPadding = leftPadding; } else { leftPadding = KoUnit::parseValue(properties.attributeNS(KoXmlNS::fo, "padding-left")); topPadding = KoUnit::parseValue(properties.attributeNS(KoXmlNS::fo, "padding-top")); rightPadding = KoUnit::parseValue(properties.attributeNS(KoXmlNS::fo, "padding-right")); bottomPadding = KoUnit::parseValue(properties.attributeNS(KoXmlNS::fo, "padding-bottom")); } // Parse border properties if there are any. border.loadOdf(properties); // guessFormat takes millimeters if (orientation == KoPageFormat::Landscape) format = KoPageFormat::guessFormat(POINT_TO_MM(height), POINT_TO_MM(width)); else format = KoPageFormat::guessFormat(POINT_TO_MM(width), POINT_TO_MM(height)); } }
//1.6: KWDocument::loadOasis bool KWOdfLoader::load(KoOdfReadStore &odfStore) { //debugWords << "========================> KWOdfLoader::load START"; QPointer<KoUpdater> updater; QPointer<KoUpdater> loadUpdater; if (m_document->progressUpdater()) { updater = m_document->progressUpdater()->startSubtask(1, "KWOdfLoader::load"); loadUpdater = m_document->progressUpdater()->startSubtask(5, "KWOdfLoader::loadOdf"); updater->setProgress(0); loadUpdater->setProgress(0); } KoXmlElement content = odfStore.contentDoc().documentElement(); KoXmlElement realBody(KoXml::namedItemNS(content, KoXmlNS::office, "body")); if (realBody.isNull()) { errorWords << "No office:body found!" << endl; m_document->setErrorMessage(i18n("Invalid OASIS OpenDocument file. No office:body tag found.")); return false; } KoXmlElement body = KoXml::namedItemNS(realBody, KoXmlNS::office, "text"); if (body.isNull()) { errorWords << "No office:text found!" << endl; KoXmlElement childElem; QString localName; forEachElement(childElem, realBody) localName = childElem.localName(); if (localName.isEmpty()) m_document->setErrorMessage(i18n("Invalid OASIS OpenDocument file. No tag found inside office:body.")); else m_document->setErrorMessage(i18n("This is not a word processing document, but %1. Please try opening it with the appropriate application.", KoDocument::tagNameToDocumentType(localName))); return false; } // Load attributes from the office:text. These are text:global and text:use-soft-page-breaks. QString textGlobal = body.attributeNS(KoXmlNS::text, "global"); bool isTextGlobal = (textGlobal == "true"); if (isTextGlobal) { m_document->setIsMasterDocument(true); } // FIXME: text:use-soft-page-breaks if (updater) updater->setProgress(20); KoOdfLoadingContext odfContext(odfStore.styles(), odfStore.store(), QLatin1String("calligrawords/styles/")); KoShapeLoadingContext sc(odfContext, m_document->resourceManager()); sc.setDocumentRdf(m_document->documentRdf()); // Load user defined variable declarations if (KoVariableManager *variableManager = m_document->inlineTextObjectManager()->variableManager()) { variableManager->loadOdf(body); } // Load all styles before the corresponding paragraphs try to use them! KWOdfSharedLoadingData *sharedData = new KWOdfSharedLoadingData(this); sc.addSharedData(KOTEXT_SHARED_LOADING_ID, sharedData); KoStyleManager *styleManager = m_document->resourceManager()->resource(KoText::StyleManager).value<KoStyleManager*>(); Q_ASSERT(styleManager); sharedData->loadOdfStyles(sc, styleManager); if (updater) updater->setProgress(40); loadMasterPageStyles(sc); // add page background frame set KWFrameSet *pageBackgroundFrameSet = new KWFrameSet(Words::BackgroundFrameSet); m_document->addFrameSet(pageBackgroundFrameSet); #if 0 //1.6: KWOasisLoader oasisLoader(this); // <text:page-sequence> oasis extension for DTP (2003-10-27 post by Daniel) m_processingType = (!KoXml::namedItemNS(body, KoXmlNS::text, "page-sequence").isNull()) ? DTP : WP; m_hasTOC = false; m_tabStop = MM_TO_POINT(15); const KoXmlElement *defaultParagStyle = styles.defaultStyle("paragraph"); if (defaultParagStyle) { KoStyleStack stack; stack.push(*defaultParagStyle); stack.setTypeProperties("paragraph"); QString tabStopVal = stack.property(KoXmlNS::style, "tab-stop-distance"); if (!tabStopVal.isEmpty()) m_tabStop = KoUnit::parseValue(tabStopVal); } m_initialEditing = 0; // TODO MAILMERGE // Variable settings // By default display real variable value if (!isReadWrite()) m_varColl->variableSetting()->setDisplayFieldCode(false); #endif // Load all styles before the corresponding paragraphs try to use them! #if 0 //1.6: if (m_frameStyleColl->loadOasisStyles(context) == 0) { // no styles loaded -> load default styles loadDefaultFrameStyleTemplates(); } if (m_tableStyleColl->loadOasisStyles(context, *m_styleColl, *m_frameStyleColl) == 0) { // no styles loaded -> load default styles loadDefaultTableStyleTemplates(); } static_cast<KWVariableSettings *>(m_varColl->variableSetting())->loadNoteConfiguration(styles.officeStyle()); loadDefaultTableTemplates(); //#else /* // We always needs at least one valid default paragraph style KoParagraphStyle *defaultParagraphStyle = m_document->styleManager()->defaultParagraphStyle(); //const KoXmlElement *defaultParagraphStyle = context.stylesReader().defaultStyle("paragraph"); //if(! defaultParagraphStyle) { KoParagraphStyle *parastyle = new KoParagraphStyle(); parastyle->setName("Standard"); m_document->styleManager()->add(parastyle); context.styleStack().setTypeProperties("paragraph"); // load all style attributes from "style:paragraph-properties" parastyle->loadOasis(context.styleStack()); // load the KoParagraphStyle from the stylestack KoCharacterStyle *charstyle = parastyle->characterStyle(); context.styleStack().setTypeProperties("text"); // load all style attributes from "style:text-properties" charstyle->loadOasis(context.styleStack()); // load the KoCharacterStyle from the stylestack //} */ #endif // load text:page-sequence KoXmlElement pageSequence = KoXml::namedItemNS(body, KoXmlNS::text, "page-sequence"); if (! pageSequence.isNull()) { KWPageManager *pageManager = m_document->pageManager(); KoXmlElement page; forEachElement(page, pageSequence) { if (page.namespaceURI() == KoXmlNS::text && page.localName() == "page") { QString master = page.attributeNS(KoXmlNS::text, "master-page-name", QString()); pageManager->appendPage(pageManager->pageStyle(master)); } } }
void dController::printWithTemplate (int RowId) { qDebug()<<Q_FUNC_INFO; //TODO это должно быть в отдельном классе !!! QGraphicsScene * scene = new QGraphicsScene(); bool page_orient= false; int margin_top = MM_TO_POINT(15); int margin_bottom=MM_TO_POINT(15); int margin_left=MM_TO_POINT(35); int margin_right=MM_TO_POINT(15); int page_width=210; int page_height=297; scene->clear(); scene->setSceneRect(0, 0, MM_TO_POINT(page_width),MM_TO_POINT(page_height)); QGraphicsRectItem *border_rect = new QGraphicsRectItem (QRectF(margin_left, margin_top, MM_TO_POINT(page_width)-margin_left-margin_right,MM_TO_POINT(page_height)-margin_top-margin_bottom)); qDebug() <<"margin_rect"<< margin_left << margin_top << margin_left<<margin_right; border_rect->setPen(QPen(Qt::black,2,Qt::DotLine)); border_rect->setBrush(QBrush(Qt::white)); border_rect->setOpacity(0.5); border_rect->setZValue(0); //border_rect->setData(ObjectName, "Border"); scene->addItem(border_rect); SimpleItem* Gritem = new SimpleItem; Gritem->setPos(MM_TO_POINT(180), MM_TO_POINT(0)); Gritem->setPrintFrame(false); Gritem->setText(QStringList()<<QString("Секретно")<<QString("Пункт 12")); Gritem->setFlag(QGraphicsItem::ItemIsMovable); Gritem->setParentItem(border_rect); SimpleItem* MBitem = new SimpleItem; MBitem->setPos(MM_TO_POINT(5), MM_TO_POINT(280)); MBitem->setPrintFrame(false); MBitem->setText(QStringList()<<QString("МБ №-%1"));//.arg(templ)); MBitem->setFlag(QGraphicsItem::ItemIsMovable); scene->addItem(MBitem);//->setParentItem(border_rect); scene->update(); QPrinter printer; QString with_t; with_t.append(spoolDIR).append("compl_teml2.pdf"); printer.setOutputFormat(QPrinter::PdfFormat); printer.setOutputFileName(with_t); printer.setPageSize(QPrinter::A4); QPainter painter(&printer); scene->render(&painter); //QString in_file =mainPDF; //in_file.arg(QString(SID)); qDebug() <<Q_FUNC_INFO<< mainPDF << outPDF; this->mergeTwoPDF(mainPDF,with_t,outPDF); // Рисуем последнюю страничку scene->clear(); border_rect = new QGraphicsRectItem (QRectF(margin_left, margin_top, MM_TO_POINT(page_width)-margin_left-margin_right,MM_TO_POINT(page_height)-margin_top-margin_bottom)); qDebug() <<"margin_rect"<< margin_left << margin_top << margin_left<<margin_right; border_rect->setPen(QPen(Qt::black,2,Qt::DotLine)); border_rect->setBrush(QBrush(Qt::white)); border_rect->setOpacity(0.5); border_rect->setZValue(0); //border_rect->setData(ObjectName, "Border"); scene->addItem(border_rect); SimpleItem* Lastitem = new SimpleItem; Lastitem->setPos(MM_TO_POINT(40), MM_TO_POINT(200)); Lastitem->setPrintFrame(true); Lastitem->setText(QStringList()<<QString("Секретно") <<QString("Пункт 12") <<QString("Исполнитель:ФИО исполнителя") <<QString("Отпечатал:ФИО кто печатал") <<QString("Телефон:2-63-15") <<QString("Инв.№ 12/13") <<QString("Дата: 09.09.09'") <<QString("МБ №-%1"));//.arg(templ) //); Lastitem->setFlag(QGraphicsItem::ItemIsMovable); scene->addItem(Lastitem);//->setParentItem(border_rect); QPrinter printer2; printer2.setOutputFormat(QPrinter::PdfFormat); QString last_p; last_p.append(spoolDIR).append("last_page.pdf"); printer2.setOutputFileName(last_p); printer2.setPageSize(QPrinter::A4); QPainter painter2(&printer2); scene->render(&painter2); // emit sayMeGood(); }