void FontExportSerializer::serialization(pugi::xml_document& _doc) { pugi::xml_node root = _doc.append_child("MyGUI"); root.append_attribute("type").set_value("Resource"); root.append_attribute("version").set_value("1.1"); DataPtr data = DataManager::getInstance().getRoot(); for (Data::VectorData::const_iterator child = data->getChilds().begin(); child != data->getChilds().end(); child ++) writeFont(root, (*child)); }
bool RC2UI::makeDialog() { line = in->readLine(); do { QFile fileOut; QString buffer; int count; QCString className; uint x, y, w, h; uint endDesc; bool space = FALSE; for ( endDesc = 0; endDesc < line.length() ; endDesc++ ) { char c = (QChar)line.at(endDesc); if ( space && (c >= '0') && (c <= '9') ) break; space = c==' '; } QString desc = line.left(endDesc-1); line = line.right( line.length() - endDesc ); className = parseNext( desc, ' ' ); count = sscanf( line, "%d, %d, %d, %d", &x, &y, &w, &h ); if ( !count && count == EOF ) return FALSE; char property[256]; QStringList styles; QStringList extendedStyles; QString caption = ""; QString baseClass = ""; QString widgetType; QString widgetName; QString arguments; int pointsize; QString fontname; do { if ( in->eof() ) return TRUE; line = ""; do { line += in->readLine(); } while ( line[(int)line.length()-1] == '|' || line[(int)line.length()-1] == ',' ); count = sscanf( line, "%s", property ); line = line.right( line.length() - line.find(" ") -1 ); if ( QString(property) == "STYLE" ) { styles = splitStyles(line); if ( styles.contains( "WS_CAPTION" ) ) baseClass = "QDialog"; else baseClass = "QWidget"; } else if ( QString(property) == "CAPTION" ) { caption = stripQM( line ); } else if ( QString(property) == "FONT" ) { QString pt = line.left( line.find(",") ); pointsize = pt.toInt(); fontname = stripQM(line.right( line.length() - line.find(",") - 2 )); } } while ( line != "BEGIN" ); if ( writeToFile ) { QString outputFile = QString(className) + ".ui"; fileOut.setName( outputFile ); if (!fileOut.open( IO_WriteOnly ) ) qFatal( "rc2ui: Could not open output file '%s'", outputFile.latin1() ); out = new QTextStream( &fileOut ); } else { out = new QTextStream( &buffer, IO_WriteOnly ); } *out << "<!DOCTYPE UI><UI>" << endl; writeClass( className ); wi(); *out << "<widget>"<< endl; indent(); writeClass( baseClass ); writeCString( "name", className ); writeRect( "geometry", x, y, w, h ); writeString( "caption", caption ); writeFont( fontname, pointsize ); do { line = in->readLine().stripWhiteSpace(); if ( line == "END" ) continue; widgetType = parseNext(line, ' '); arguments = line.stripWhiteSpace(); while ( arguments[(int)arguments.length()-1] == ',' || arguments[(int)arguments.length()-1] == '|' ) arguments += " "+in->readLine().stripWhiteSpace(); wi(); *out << "<widget>" << endl; indent(); WidgetType ID = IDUnknown; QString controlType; QString widgetID; QString widgetText; bool hasText = FALSE; bool isControl = FALSE; bool isFrame = FALSE; if ( widgetType == "PUSHBUTTON" ) { ID = IDPushButton; hasText = TRUE; } else if ( widgetType == "DEFPUSHBUTTON" ) { ID = IDPushButton; hasText = TRUE; } else if ( widgetType == "LTEXT" ) { ID = IDLabel; hasText = TRUE; } else if ( widgetType == "CTEXT" ) { ID = IDLabel; hasText = TRUE; } else if ( widgetType == "RTEXT" ) { ID = IDLabel; hasText = TRUE; } else if ( widgetType == "EDITTEXT" ) { ID = IDLineEdit; } else if ( widgetType == "GROUPBOX" ) { ID = IDGroupBox; hasText = TRUE; } else if ( widgetType == "COMBOBOX" ) { ID = IDComboBox; } else if ( widgetType == "LISTBOX" ) { ID = IDListBox; } else if ( widgetType == "SCROLLBAR" ) { ID = IDScrollBar; } else if ( widgetType == "CHECKBOX" ) { ID = IDCheckBox; hasText = TRUE; } else if ( widgetType == "RADIOBUTTON" ) { ID = IDRadioButton; hasText = TRUE; } else if ( widgetType == "CONTROL" ) { isControl = TRUE; widgetText = stripQM(parseNext( arguments )); widgetID = parseNext( arguments ); controlType = stripQM(parseNext( arguments )); styles = splitStyles(parseNext( arguments )); if ( controlType == "Static" ) { ID = IDLabel; } else if ( controlType == "Button" ) { if ( styles.contains("BS_AUTOCHECKBOX") || styles.contains("BS_3STATE") ) ID = IDCheckBox; else if ( styles.contains("BS_AUTORADIOBUTTON") ) ID = IDRadioButton; } else if ( controlType == "msctls_updown32" ) { ID = IDSpinBox; } else if ( controlType == "msctls_progress32" ) { ID = IDProgressBar; } else if ( controlType == "msctls_trackbar32" ) { ID = IDSlider; } else if ( controlType == "SysListView32" ) { ID = IDIconView; } else if ( controlType == "SysTreeView32" ) { ID = IDListView; } else if ( controlType == "SysTabControl32" ) { ID = IDTabWidget; } else if ( controlType == "SysAnimate32" ) { ID = IDLabel; } else if ( controlType == "RICHEDIT" ) { ID = IDMultiLineEdit; } else if ( controlType == "ComboBoxEx32" ) { ID = IDComboBox; } else if ( controlType == "" ) { ID = IDCustom; } else { ID = IDUnknown; } } else ID = IDUnknown; if ( hasText ) widgetText = stripQM(parseNext( arguments )); if ( isControl ) { x = parseNext( arguments ).toInt(); y = parseNext( arguments ).toInt(); w = parseNext( arguments ).toInt(); h = parseNext( arguments ).toInt(); } else { widgetID = parseNext( arguments ); x = parseNext( arguments ).toInt(); y = parseNext( arguments ).toInt(); w = parseNext( arguments ).toInt(); h = parseNext( arguments ).toInt(); styles.clear(); } do { extendedStyles = splitStyles(parseNext( arguments )); for ( uint i = 0; i < extendedStyles.count(); i++ ) styles << (*extendedStyles.at(i)); } while ( arguments.find(',') > -1 ); switch ( ID ) { case IDWidget: break; case IDPushButton: { writeClass("QPushButton"); writeCString( "name", useName("PushButton_"+widgetID) ); writeRect( "geometry", x, y, w, h ); writeString( "text", widgetText ); if ( widgetType == "DEFPUSHBUTTON" ) writeBool( "default", TRUE ); } break; case IDLabel: { isFrame = TRUE, writeClass("QLabel"); writeCString( "name", useName("Label_"+widgetID) ); writeRect( "geometry", x,y,w,h ); writeString( "text", widgetText ); QString align; if ( !styles.contains("SS_CENTERIMAGE") ) align += "|AlignTop"; else align += "|AlignVCenter"; if ( widgetType == "LTEXT" ) { align += "|AlignLeft"; } else if ( widgetType == "CTEXT") { align += "|AlignHCenter"; } else if ( widgetType == "RTEXT") { align += "|AlignRight"; } writeSet("alignment", align ); } break; case IDCheckBox: { writeClass("QCheckBox"); writeCString("name", useName("CheckBox_"+widgetID) ); writeRect("geometry", x,y,w,h); writeString("text", widgetText ); if ( styles.contains( "BS_3STATE" ) ) writeBool( "tristate", TRUE ); } break; case IDRadioButton: { writeClass("QRadioButton"); writeCString("name", useName("RadioButton_"+widgetID) ); writeRect("geometry", x,y,w,h); writeString("text", widgetText ); } break; case IDGroupBox: { isFrame = TRUE; writeClass("QGroupBox"); writeCString( "name", useName("GroupBox_"+widgetID) ); writeRect( "geometry", x,y,w,h ); writeString( "title", widgetText ); if ( !styles.contains( "WS_BORDER" ) ) styles.append( "WS_BORDER" ); } break; case IDLineEdit: { if ( !styles.contains("ES_MULTILINE") ) { writeClass("QLineEdit"); writeCString( "name", useName("LineEdit_"+widgetID) ); } else { writeClass("QMultiLineEdit"); writeCString( "name", useName("MultiLineEdit_"+widgetID) ); } writeRect( "geometry", x,y,w,h ); QString align = "AlignTop"; if ( styles.contains("ES_CENTER") ) align+="|AlignHCenter"; else if ( styles.contains("ES_RIGHT") ) align+="|AlignRight"; else align+="|AlignLeft"; writeSet("alignment", align); } break; case IDMultiLineEdit: { writeClass("QMultiLineEdit"); writeCString("name", useName("MultiLineEdit_"+widgetID) ); writeRect("geometry", x,y,w,h ); } break; case IDIconView: { isFrame = TRUE; writeClass("QIconView"); writeCString("name", useName("IconView_"+widgetID) ); writeRect("geometry", x,y,w,h ); if ( !styles.contains( "LVS_SINGLESEL" ) ) writeEnum( "selectionMode", "Extended" ); if ( styles.contains( "LVS_NOLABELWRAP" ) ) writeBool("wordWrapIconText", FALSE ); } break; case IDListView: { isFrame = TRUE; writeClass("QListView"); writeCString("name", useName("ListView_"+widgetID) ); writeRect("geometry", x,y,w,h ); if ( styles.contains( "TVS_LINESATROOT" ) ) writeBool( "rootIsDecorated", TRUE ); if ( styles.contains( "TVS_FULLROWSELECT" ) ) writeBool( "allColumnsShowFocus", TRUE ); } break; case IDProgressBar: { isFrame = TRUE; writeClass("QProgressBar"); writeCString("name", useName("ProgressBar_"+widgetID) ); writeRect("geometry", x,y,w,h ); if ( styles.contains("TBS_VERT") ) writeEnum("orientation", "Vertical"); else writeEnum("orientation", "Horizontal"); } break; case IDTabWidget: { writeClass("QTabWidget"); writeCString("name", useName("TabWidget_"+widgetID) ); writeRect("geometry", x,y,w,h ); wi(); *out << "<widget>" << endl; indent(); writeClass("QWidget"); wi(); *out << "<attribute>" << endl; indent(); wi(); *out << "<name>title</name>" << endl; wi(); *out << "<string>Tab1</string>" << endl; undent(); wi(); *out << "</attribute>" << endl; undent(); wi(); *out << "</widget>" << endl; } break; case IDSpinBox: { isFrame = TRUE; writeClass("QSpinBox"); writeCString("name", useName("SpinBox_"+widgetID) ); writeRect("geometry", x,y,w,h); } break; case IDSlider: { writeClass("QSlider"); writeCString("name", useName("Slider_"+widgetID) ); writeRect("geometry", x,y,w,h ); if ( styles.contains("TBS_VERT") ) writeEnum("orientation", "Vertical"); else writeEnum("orientation", "Horizontal"); if ( !styles.contains("TBS_NOTICKS") ) writeEnum("tickmarks", "Left" ); } break; case IDComboBox: { writeClass("QComboBox"); writeCString("name", useName("ComboBox_"+widgetID) ); if ( isControl ) writeRect( "geometry", x,y,w,14 ); else writeRect( "geometry", x,y,w,h ); } break; case IDListBox: { isFrame = TRUE; writeClass("QListBox"); writeCString("name", useName("ListBox_"+widgetID) ); writeRect( "geometry", x,y,w,h ); if ( styles.contains("WS_HSCROLL") ) writeEnum("hScrollBarMode", "Auto"); else writeEnum("hScrollBarMode", "AlwaysOff"); if ( styles.contains("WS_VSCROLL") ) writeEnum("vScrollBarMode", "Auto"); else writeEnum("vScrollBarMode", "AlwaysOff"); if ( styles.contains("LBS_EXTENDEDSEL") ) writeEnum("selectionMode", "Extended"); else if ( styles.contains("LBS_MULTIPLESEL") ) writeEnum("selectionMode", "Multi"); else if ( styles.contains("LBS_NOSEL") ) writeEnum("selectionMode", "NoSelection"); else writeEnum("selectionMode", "Single"); if ( !styles.contains( "NO WS_BORDER" ) ) styles.append( "WS_BORDER" ); } break; case IDScrollBar: { writeClass("QScrollBar"); writeCString("name", useName("ScrollBar_"+widgetID) ); writeRect("geometry", x,y,w,h ); if ( styles.contains("SBS_VERT") ) writeEnum("orientation", "Vertical"); else writeEnum("orientation", "Horizontal"); } break; case IDCustom: { writeClass("QLabel"); writeCString("name", useName("Custom_"+widgetID) ); writeRect("geometry", x,y,w,h ); writeString("text", "Create a custom widget and place it here." ); } default: { writeClass("QLabel"); writeCString("name", useName("Unknown_"+widgetID) ); writeRect("geometry", x,y,w,h ); writeString("text", QString("No support for %1.").arg(controlType) ); } break; } writeStyles( styles, isFrame ); styles.clear(); undent(); wi(); *out << "</widget>" << endl; } while ( line != "END" ); undent(); wi(); *out << "</widget>" << endl; *out << "</UI>" << endl; do { line = in->readLine(); } while ( line.isEmpty() ); if ( !writeToFile ) target.append( buffer.copy() ); if (out) { delete out; out = 0; } fileOut.close(); if ( writeToFile ) printf( QDir::currentDirPath() + "/" + fileOut.name() + '\n' ); } while ( line != blockStart1 ); return TRUE; }
bool QTableModelWordMLWriter::write(QAbstractItemModel* model, QItemSelectionModel* selectionModel, QHeaderView* headerView, bool all) { if (!m_device->isWritable() && ! m_device->open(QIODevice::WriteOnly)) { qWarning() << "QTableModelXmlWriter::writeAll: the device can not be opened for writing"; return false; } QXmlStreamWriter stream(m_device); stream.setAutoFormatting(true); stream.setAutoFormattingIndent(2); stream.writeStartDocument("1.0", true); stream.writeProcessingInstruction("mso-application progid=\"Word.Document\""); stream.writeStartElement("w:wordDocument"); // stream.writeAttribute("xmlns:w", "http://schemas.microsoft.com/office/word/2003/wordml"); stream.writeAttribute("xmlns:v", "urn:schemas-microsoft-com:vml"); //stream.writeAttribute("xmlns:w10", "urn:schemas-microsoft-com:office:word"); //stream.writeAttribute("xmlns:sl", "http://schemas.microsoft.com/schemaLibrary/2003/core"); //stream.writeAttribute("xmlns:aml", "http://schemas.microsoft.com/aml/2001/core"); stream.writeAttribute("xmlns:wx", "http://schemas.microsoft.com/office/word/2003/auxHint"); stream.writeAttribute("xmlns:o", "urn:schemas-microsoft-com:office:office"); //stream.writeAttribute("xmlns:dt", "uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"); //stream.writeAttribute("w:macrosPresent", "no"); //stream.writeAttribute("w:embeddedObjPresent", "no"); //stream.writeAttribute("w:ocxPresent", "no"); //stream.writeAttribute("xml:space","preserve"); //stream.writeEmptyElement("w:ignoreSubtree"); //stream.writeAttribute("w:val", "http://schemas.microsoft.com/office/word/2003/wordml/sp2"); // document properties stream.writeStartElement("o:DocumentProperties"); stream.writeTextElement("o:Author", "qaiv"); stream.writeTextElement("o:LastAuthor", "qaiv"); //<o:Revision>2</o:Revision> //<o:TotalTime>0</o:TotalTime> //<o:Created>2013-08-23T16:21:00Z</o:Created> //<o:LastSaved>2013-08-23T16:21:00Z</o:LastSaved> //stream.writeTextElement("o:Pages", "1"); //<o:Words>1</o:Words> //<o:Characters>12</o:Characters> //<o:Lines>1</o:Lines> //<o:Paragraphs>1</o:Paragraphs> //<o:CharactersWithSpaces>12</o:CharactersWithSpaces> stream.writeTextElement("o:Version", "14"); stream.writeEndElement(); //// fonts //stream.writeStartElement("w:fonts"); //stream.writeStartElement("w:defaultFonts"); // stream.writeAttribute("w:ascii", "Times New Roman"); // stream.writeAttribute("w:fareast", "Times New Roman"); // stream.writeAttribute("w:h-ansi", "Times New Roman"); // stream.writeAttribute("w:cs", "Times New Roman"); //stream.writeEndElement(); //stream.writeEndElement(); //// lists //stream.writeStartElement("lists"); //stream.writeEndElement(); //// styles //stream.writeStartElement("styles"); //stream.writeEndElement(); // start body stream.writeStartElement("w:body"); stream.writeStartElement("w:tbl"); stream.writeStartElement("w:tblPr"); // define table borders stream.writeStartElement("w:tblBorders"); stream.writeEmptyElement("w:top"); stream.writeAttribute("w:val", "single"); stream.writeAttribute("w:sz", "4"); stream.writeAttribute("wx:bdrwidth", "10"); stream.writeAttribute("w:space", "0"); stream.writeAttribute("w:color", "auto"); stream.writeEmptyElement("w:left"); stream.writeAttribute("w:val", "single"); stream.writeAttribute("w:sz", "4"); stream.writeAttribute("wx:bdrwidth", "10"); stream.writeAttribute("w:space", "0"); stream.writeAttribute("w:color", "auto"); stream.writeEmptyElement("w:bottom"); stream.writeAttribute("w:val", "single"); stream.writeAttribute("w:sz", "4"); stream.writeAttribute("wx:bdrwidth", "10"); stream.writeAttribute("w:space", "0"); stream.writeAttribute("w:color", "auto"); stream.writeEmptyElement("w:right"); stream.writeAttribute("w:val", "single"); stream.writeAttribute("w:sz", "4"); stream.writeAttribute("wx:bdrwidth", "10"); stream.writeAttribute("w:space", "0"); stream.writeAttribute("w:color", "auto"); stream.writeEmptyElement("w:insideH"); stream.writeAttribute("w:val", "single"); stream.writeAttribute("w:sz", "4"); stream.writeAttribute("wx:bdrwidth", "10"); stream.writeAttribute("w:space", "0"); stream.writeAttribute("w:color", "auto"); stream.writeEmptyElement("w:insideV"); stream.writeAttribute("w:val", "single"); stream.writeAttribute("w:sz", "4"); stream.writeAttribute("wx:bdrwidth", "10"); stream.writeAttribute("w:space", "0"); stream.writeAttribute("w:color", "auto"); stream.writeEndElement(); // stream.writeEmptyElement("w:tblStyle"); stream.writeAttribute("w:val", "TableGrid"); stream.writeEmptyElement("w:tblW"); stream.writeAttribute("w:w", "0"); stream.writeAttribute("w:type", "auto"); stream.writeEmptyElement("w:tblLook"); stream.writeAttribute("w:val", "01E0"); stream.writeEndElement(); // get selection range QPair<QModelIndex, QModelIndex> e; if (!all){ e = selectionEdges(selectionModel->selection()); } else { e.first = model->index(0, 0); e.second = model->index(model->rowCount() - 1, model->columnCount() - 1); } QMap<int,int> width; stream.writeStartElement("w:tblGrid"); for (int c = e.first.column(); c <= e.second.column(); c++){ if (all || !headerView->isSectionHidden(c)){ int w = 1440 / headerView->logicalDpiX() * headerView->sectionSize(c); stream.writeEmptyElement("w:gridCol"); stream.writeAttribute("w:w", QString("%1").arg(w)); width[c] = w; } } stream.writeEndElement(); // write column header stream.writeStartElement("w:tr"); // write column header for (int c = e.first.column(); c <= e.second.column(); c++){ if (all || !headerView->isSectionHidden(c)){ stream.writeStartElement("w:trPr"); stream.writeEmptyElement("w:tblHeader"); stream.writeEndElement(); stream.writeStartElement("w:tc"); stream.writeStartElement("w:tcPr"); stream.writeEmptyElement("w:tcW"); stream.writeAttribute("w:w", QString("%1").arg(width.value(c))); stream.writeAttribute("w:type", "dxa"); stream.writeEmptyElement("w:shd"); stream.writeAttribute("w:val", "clear"); stream.writeAttribute("w:color", "auto"); writeBackgroundColor(stream, qvariant_cast<QBrush>(model->headerData(headerView->visualIndex(c), Qt::Horizontal, Qt::BackgroundRole))); // end tag <w:tcPr> stream.writeEndElement(); stream.writeStartElement("w:p"); stream.writeStartElement("w:r"); stream.writeStartElement("w:rPr"); writeFont(stream, qvariant_cast<QFont>(model->headerData(headerView->visualIndex(c), Qt::Horizontal, Qt::FontRole))); // end tag <w:rPr> stream.writeEndElement(); stream.writeTextElement("w:t", model->headerData(headerView->visualIndex(c), Qt::Horizontal, Qt::DisplayRole).toString()); // end tag <w:r> stream.writeEndElement(); // end tag <w:p> stream.writeEndElement(); // end tag <tc> stream.writeEndElement(); } } // end tag <w:tr> stream.writeEndElement(); // write table content for (int r = e.first.row(); r <= e.second.row(); r++){ stream.writeStartElement("w:tr"); for (int c = e.first.column(); c <= e.second.column(); c++){ if (all || !headerView->isSectionHidden(c)){ stream.writeStartElement("w:tc"); stream.writeStartElement("w:tcPr"); stream.writeEmptyElement("w:tcW"); stream.writeAttribute("w:w", QString("%1").arg(width.value(c))); stream.writeAttribute("w:type", "dxa"); stream.writeEmptyElement("w:shd"); stream.writeAttribute("w:val", "clear"); stream.writeAttribute("w:color", "auto"); //stream.writeAttribute("w:fill", "auto"); if (m_filterProxy){ writeBackgroundColor(stream, qvariant_cast<QBrush>(m_filterProxy->index(r, headerView->visualIndex(c)).data(Qt::BackgroundRole))); } else { writeBackgroundColor(stream, qvariant_cast<QBrush>(model->index(r, headerView->visualIndex(c)).data(Qt::BackgroundRole))); } // end tag <w:tcPr> stream.writeEndElement(); stream.writeStartElement("w:p"); stream.writeStartElement("w:r"); stream.writeStartElement("w:rPr"); if (m_filterProxy){ writeFont(stream, qvariant_cast<QFont>(m_filterProxy->index(r, headerView->visualIndex(c)).data(Qt::FontRole))); } else { writeFont(stream, qvariant_cast<QFont>(model->index(r, headerView->visualIndex(c)).data(Qt::FontRole))); } // end tag <w:rPr> stream.writeEndElement(); writeDecoration(stream, model->index(r, headerView->visualIndex(c)).data(Qt::DecorationRole)); // write cell content stream.writeTextElement("w:t", model->index(r, headerView->visualIndex(c)).data(Qt::DisplayRole).toString()); //writeAlignment(stream, static_cast<Qt::AlignmentFlag>(view->model()->index(r, view->horizontalHeader()->visualIndex(c)).data(Qt::TextAlignmentRole).toInt())); //writeBorderStyle(stream, view->gridStyle()); //writeBackgroundColor(stream, qvariant_cast<QBrush>(view->filterProxyModel()->index(r, view->horizontalHeader()->visualIndex(c)).data(Qt::BackgroundRole))); //writeDecoration(stream, view->model()->index(r, view->horizontalHeader()->visualIndex(c)).data(Qt::DecorationRole)); //stream.writeStartElement("font"); //writeFontAttributes(stream, qvariant_cast<QFont>(view->model()->index(r, view->horizontalHeader()->visualIndex(c)).data(Qt::FontRole))); //writeCharacters(stream, view->model()->index(r, view->horizontalHeader()->visualIndex(c)).data(Qt::DisplayRole).toString()); // end tag <w:r> stream.writeEndElement(); // end tag <w:p> stream.writeEndElement(); // end tag <tc> stream.writeEndElement(); } } // end tag <tr> stream.writeEndElement(); } // end tag <tbl> stream.writeEndElement(); // end tag <sect> //stream.writeEndElement(); // end tag <body> stream.writeEndElement(); // end tag <wordDocument> stream.writeEndElement(); return true; }