void SimpleStyleWidget::fillListsCombobox() { if (widget.listType->count() > 0 && (m_comboboxHasBidiItems || !m_tool->isBidiDocument())) return; widget.listType->clear(); KoZoomHandler zoomHandler; zoomHandler.setZoomAndResolution(100, 72, 72); TextShape textShape; textShape.setSize(QSizeF(300, 100)); KTextDocumentLayout *layouter = qobject_cast<KTextDocumentLayout*> (textShape.textShapeData()->document()->documentLayout()); Q_ASSERT(layouter); KParagraphStyle ps; ps.characterStyle()->setFontPointSize(12); ps.applyStyle(textShape.textShapeData()->document()->begin()); foreach(const Lists::ListStyleItem &item, Lists::genericListStyleItems()) { if (item.style == KListStyle::None) { widget.listType->addItem(item.name, static_cast<int>(item.style)); continue; } QPixmap pixmap(16, 16); // can we get the actual size from the style? pixmap.fill(Qt::transparent); QPainter p(&pixmap); KListStyle listStyle; KListLevelProperties llp = listStyle.levelProperties(1); llp.setStyle(item.style); if (KListStyle::isNumberingStyle(item.style)) { llp.setStartValue(1); } else { p.setRenderHint(QPainter::Antialiasing); } listStyle.setLevelProperties(llp); listStyle.applyStyle(textShape.textShapeData()->document()->begin(), 1); layouter->layout(); textShape.paintComponent(p, zoomHandler); p.end(); widget.listType->addItem(QIcon(pixmap), item.name, static_cast<int>(item.style)); if (item.style == m_quickApplyListStyle) { widget.listStyleAgain->setIcon(QIcon(pixmap)); } } if (m_tool->isBidiDocument()) { foreach(const Lists::ListStyleItem &item, Lists::otherListStyleItems()) widget.listType->addItem(item.name, static_cast<int>(item.style)); m_comboboxHasBidiItems = true; }
void MusicShape::saveOdf( KoShapeSavingContext & context ) const { KoXmlWriter& writer = context.xmlWriter(); writer.startElement("draw:frame"); saveOdfAttributes(context, OdfAllAttributes); writer.startElement("music:shape"); writer.addAttribute("xmlns:music", "http://www.koffice.org/music"); MusicXmlWriter().writeSheet(writer, m_sheet, false); writer.endElement(); // music:shape // Save a preview image qreal previewDPI = 150; QSizeF imgSize = size(); // in points imgSize *= previewDPI / 72; QImage img(imgSize.toSize(), QImage::Format_ARGB32); QPainter painter(&img); painter.setRenderHint(QPainter::Antialiasing); painter.setRenderHint(QPainter::TextAntialiasing); KoZoomHandler converter; converter.setZoomAndResolution(100, previewDPI, previewDPI); constPaint(painter, converter); writer.startElement("draw:image"); // In the spec, only the xlink:href attribute is marked as mandatory, cool :) QString name = context.imageHref(img); writer.addAttribute("xlink:type", "simple" ); writer.addAttribute("xlink:show", "embed" ); writer.addAttribute("xlink:actuate", "onLoad"); writer.addAttribute("xlink:href", name); writer.endElement(); // draw:image // TODO: Save a preview svg saveOdfCommonChildElements(context); writer.endElement(); // draw:frame }
KoFilter::ConversionStatus ImageExport::convert(const QByteArray& from, const QByteArray& to) { if(from != "application/x-kivio") { return KoFilter::BadMimeType; } QString format; if(to == "image/png") { format = "PNG"; } else if(to == "image/jpeg") { format = "JPEG"; } else if(to == "image/bmp") { format = "BMP"; } else if(to == "image/x-eps") { format = "EPS"; } else if(to == "image/x-portable-bitmap") { format = "PBM"; } else if(to == "image/x-pcx") { format = "PCX"; } else if(to == "image/x-portable-pixmap") { format = "PPM"; } else if(to == "image/x-rgb") { format = "RGB"; } else if(to == "image/x-xpixmap") { format = "XPM"; } else if(to == "image/jpeg2000") { format = "JP2"; } else { return KoFilter::BadMimeType; } KoStoreDevice* storeIn = m_chain->storageFile("root", KoStore::Read); if (!storeIn) { KMessageBox::error(0, i18n("Failed to read data."), i18n( "Export Error" )); return KoFilter::FileNotFound; } // Get the XML tree. QDomDocument domIn; domIn.setContent(storeIn); KivioDoc doc; if(!doc.loadXML(0, domIn)) { KMessageBox::error(0, i18n("Malformed XML data."), i18n("Export Error")); return KoFilter::WrongFormat; } ImageExportDialog dlg; QStringList pageNames; Q3PtrList<KivioPage> pageList = doc.map()->pageList(); Q3PtrListIterator<KivioPage> it(pageList); for(; it.current() != 0; ++it) { pageNames.append(it.current()->pageName()); } KoZoomHandler zoom; dlg.setPageList(pageNames); KivioPage* page = doc.map()->firstPage(); QSize size = QSize(zoom.zoomItX(page->paperLayout().ptWidth), zoom.zoomItY(page->paperLayout().ptHeight)); dlg.setInitialCustomSize(size); if(dlg.exec() != QDialog::Accepted) { return KoFilter::UserCancelled; } page = doc.map()->findPage(dlg.selectedPage()); if(!page) { kDebug() <<"The page named" << dlg.selectedPage() <<" wasn't found!!"; return KoFilter::InternalError; } if(dlg.usePageBorders()) { size = QSize(zoom.zoomItX(page->paperLayout().ptWidth), zoom.zoomItY(page->paperLayout().ptHeight)); } else { size = zoom.zoomSize(page->getRectForAllStencils().size()); } if(dlg.useCustomSize()) { QSize customSize = dlg.customSize(); float zw = (float)customSize.width() / (float)size.width(); float zh = (float)customSize.height() / (float)size.height(); float z = qMin(zw, zh); zoom.setZoomAndResolution(qRound(z * 100), KoGlobal::dpiX(), KoGlobal::dpiY()); size = customSize; } int border = dlg.margin(); size.setWidth(size.width() + (border * 2)); size.setHeight(size.height() + (border * 2)); QPixmap pixmap = QPixmap(size); pixmap.fill(Qt::white); KivioScreenPainter kpainter; kpainter.start(&pixmap); int translationX = border; int translationY = border; if(!dlg.usePageBorders()) { QPoint point = zoom.zoomPoint(page->getRectForAllStencils().topLeft()); translationX += point.x(); translationY += point.y(); } kpainter.setTranslation(-translationX, -translationY); page->printContent(kpainter, &zoom); if(!pixmap.save(m_chain->outputFile(), format.local8Bit())) { return KoFilter::CreationError; } return KoFilter::OK; }