本文整理汇总了C++中KWDocument::setOutputMimeType方法的典型用法代码示例。如果您正苦于以下问题:C++ KWDocument::setOutputMimeType方法的具体用法?C++ KWDocument::setOutputMimeType怎么用?C++ KWDocument::setOutputMimeType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KWDocument
的用法示例。
在下文中一共展示了KWDocument::setOutputMimeType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: convert
KoFilter::ConversionStatus AsciiImport::convert(const QByteArray& from, const QByteArray& to)
{
// check for proper conversion
if (to != "application/vnd.oasis.opendocument.text" || from != "text/plain") {
return KoFilter::NotImplemented;
}
QFile in(m_chain->inputFile());
if (!in.open(QIODevice::ReadOnly)) {
kError(30502) << "Unable to open input file!" << endl;
in.close();
return KoFilter::FileNotFound;
}
#ifdef OUTPUT_AS_ODT_FILE
#else
KoDocument* document = m_chain->outputDocument();
if (!document)
return KoFilter::StupidError;
KWDocument *outputDoc = qobject_cast<KWDocument*>(document);
outputDoc->setOutputMimeType(to);
//outputDoc->setSaveInBatchMode(true);
QPointer<KoUpdater> loadUpdater = outputDoc->progressUpdater()->startSubtask(2, "load");
loadUpdater->setRange(0, in.size());
QPointer<KoUpdater> layoutUpdater = outputDoc->progressUpdater()->startSubtask(3, "layout");
#endif
// try to read 100000 bytes so we can be quite sure the guessed encoding is correct.
// this code is inspired by the kate encoding guessing first try UTF-8
QByteArray data = in.read(100000);
in.seek(0);
QTextCodec *codec = QTextCodec::codecForName("UTF-8");
if (!checkEncoding(codec, data)) {
KEncodingProber prober(KEncodingProber::Universal);
prober.feed(data);
kDebug(30502) << "guessed" << prober.encoding() << prober.confidence();
if (prober.confidence() > 0.5)
codec = QTextCodec::codecForName(prober.encoding());
if (!codec || !checkEncoding(codec, data )) {
codec = QTextCodec::codecForName("ISO 8859-15");
if (!checkEncoding(codec, data))
codec = QTextCodec::codecForName("UTF-8");
}
}
int paragraphStrategy = 0;
if (!m_chain->manager()->getBatchMode()) {
QPointer<AsciiImportDialog> dialog = new AsciiImportDialog(codec->name(), QApplication::activeWindow());
if (!dialog) { in.close(); return KoFilter::StupidError; }
if (!dialog->exec()) { in.close(); return KoFilter::UserCancelled; }
codec = dialog->getCodec();
paragraphStrategy = dialog->getParagraphStrategy();
}
if (!codec) return KoFilter::StupidError;
kDebug(30502) << "Charset used:" << codec->name();
#ifdef OUTPUT_AS_ODT_FILE
KoStore *store = KoStore::createStore(m_chain->outputFile(), KoStore::Write, to, KoStore::Zip);
if (!store || store->bad()) {
kWarning(30502) << "Unable to open output file!";
delete store;
return KoFilter::FileNotFound;
}
store->disallowNameExpansion();
kDebug(30502) << "created store.";
KoOdfWriteStore odfStore(store);
odfStore.manifestWriter(to);
KoXmlWriter* contentWriter = odfStore.contentWriter();
if (!contentWriter) {
delete store;
return KoFilter::CreationError;
}
KoGenStyles mainStyles;
KoXmlWriter *bodyWriter = odfStore.bodyWriter();
bodyWriter->startElement("office:body");
bodyWriter->startElement("office:text");
QString styleName("txt");
KoGenStyle style(KoGenStyle::ParagraphStyle, "paragraph");
style.addAttribute("style:display-name", styleName);
style.addProperty("fo:font-family", "dejavu sans mono", KoGenStyle::TextType);
style.addProperty("fo:font-family-generic", "modern", KoGenStyle::TextType);
style.addProperty("fo:font-size", "10pt", KoGenStyle::TextType);
style.addProperty("fo:font-weight", "normal", KoGenStyle::TextType);
QString name(QString(QUrl::toPercentEncoding(styleName, "", " ")).replace('%', '_'));
name = mainStyles.insert(style, name, KoGenStyles::DontAddNumberToName);
#else
KoStyleManager *styleManager = outputDoc->resourceManager()->resource(KoText::StyleManager).value<KoStyleManager*>();
KoParagraphStyle *p = styleManager->defaultParagraphStyle();
p->setFontFamily("dejavu sans mono");
p->setFontPointSize(10);
p->setFontStyleHint(QFont::TypeWriter);
//.........这里部分代码省略.........