📄 ncreportdesignerresourcehandler.cpp
字号:
w->p.fontWeight = we; } if ( e.hasAttribute("fontItalic") ) w->p.fontItalic = (e.attribute("fontItalic")=="true"); if ( e.hasAttribute("fontUnderline") ) w->p.fontUnderline = (e.attribute("fontUnderline")=="true"); if ( e.hasAttribute("fontStrikeOut") ) w->p.fontStrikeOut = (e.attribute("fontStrikeOut")=="true"); if ( e.hasAttribute("rotation") ) w->p.rotation = e.attribute("rotation").toInt(); if ( e.hasAttribute("alignmentH") ) { Qt::AlignmentFlags al= Qt::AlignLeft; QString att = e.attribute("alignmentH"); if (att == "left") al = Qt::AlignLeft; else if (att == "right") al = Qt::AlignRight; else if (att == "center") al = Qt::AlignHCenter; w->p.alignmentH = al; } if ( e.hasAttribute("alignmentV") ) { Qt::AlignmentFlags al= Qt::AlignVCenter; QString att = e.attribute("alignmentV"); if (att == "top") al = Qt::AlignTop; else if (att == "bottom") al = Qt::AlignBottom; else if (att == "center") al = Qt::AlignVCenter; w->p.alignmentV = al; } if ( e.hasAttribute("wordbreak") ) w->p.wordbreak = (e.attribute("wordbreak")=="true"); if ( e.hasAttribute("richText") ) w->p.isRichText = (e.attribute("richText")=="true"); if ( e.hasAttribute("dynamicHeight") ) w->p.dynamicHeight = (e.attribute("dynamicHeight")=="true"); if ( e.hasAttribute("loadFromFile") ) w->p.loadFromFile = (e.attribute("loadFromFile")=="true"); if ( e.hasAttribute("forecolor") ) w->p.forecolor = colorToString(e.attribute("forecolor")); if ( e.hasAttribute("backcolor") ) w->p.forecolor = colorToString(e.attribute("backcolor")); if ( e.hasAttribute("fillColor") ) w->p.fillColor = colorToString(e.attribute("fillColor")); if ( e.hasAttribute("lineColor") ) w->p.lineColor = colorToString(e.attribute("lineColor")); if ( e.hasAttribute("lineWidth") ) w->p.lineWidth = e.attribute("lineWidth").toInt(); if ( e.hasAttribute("lineStyle") ) { Qt::PenStyle ps = Qt::SolidLine; QString ls = e.attribute("lineStyle"); if (ls == "solid") ps = Qt::SolidLine; else if (ls == "dash") ps = Qt::DashLine; else if (ls == "dot") ps = Qt::DotLine; else if (ls == "dashdotdot") ps = Qt::DashDotDotLine; else if (ls == "dashdot") ps = Qt::DashDotLine; else if (ls == "nopen") ps = Qt::NoPen; w->p.lineStyle = ps; } if ( e.hasAttribute("fillStyle") ) { w->p.fillStyle = WProperty::transparent; if ( e.attribute("fillStyle") == "filled" ) w->p.fillStyle = WProperty::filled; } if ( e.hasAttribute("resource") ) { // image resource w->p.resource = e.attribute("resource"); } if ( w->p.fontName.isEmpty() && !document->po.defaultFontName.isEmpty() ) w->p.fontName = document->po.defaultFontName; w->p.text = e.text(); //------------------------ // Geometry settings //------------------------ QRect r; int coordX = m->measureToPixel( w->p._posX )+pasteOffset; int coordY = m->measureToPixel( w->p._posY )+pasteOffset;/* if ( pasteOffset == -1 ) { // copy - paste to the topleft corner coordX = 0; coordY = 0; }*/ if ( e.tagName() == "line" ) { r.setTopLeft( QPoint( m->measureToPixel(_fromX)+pasteOffset, m->measureToPixel(_fromY)+pasteOffset ) ); //r.setX( coordX ); //r.setY( coordY ); if ( _fromY==_toY ) { // horizontal w->setMaximumHeight( w->p.lineWidth ); r.setHeight( w->p.lineWidth ); r.setWidth( m->measureToPixel(_toX-_fromX) ); } else { w->setMaximumWidth( w->p.lineWidth ); r.setWidth( w->p.lineWidth ); r.setHeight( m->measureToPixel(_toY-_fromY) ); } } else if ( e.tagName() == "label" || e.tagName() == "field" ) { if ( w->p._width<=0 || w->p._height<=0 ) setWidgetOptimalSizeForFont( w, w->p._width<=0, w->p._height<=0 ); r.setRect( coordX, coordY, m->measureToPixel( w->p._width ), m->measureToPixel( w->p._height ) ); } else if ( e.tagName() == "rectangle" || e.tagName() == "ellipse" ) { int wi = 0; if ( w->p._width<=0 ) wi = designArea->width(); else wi = m->measureToPixel( w->p._width ); r.setRect( coordX, coordY, wi, m->measureToPixel( w->p._height ) ); } else if ( e.tagName() == "pixmap" || e.tagName() == "image" ) { r.setRect( coordX, coordY, m->measureToPixel( w->p._width ), m->measureToPixel( w->p._height ) ); } else r.setRect( coordX, coordY, m->measureToPixel( w->p._width ), m->measureToPixel( w->p._height ) ); //designArea->checkGeometry( r ); w->setGeometry( r );}void NCReportDesignerResourceHandler::setWidgetOptimalSizeForFont( NCReportDesignerWidget *w, bool setWidth, bool setHeight ){ QFont f; if ( w->p.fontName.isEmpty() ) f.setFamily( w->p.fontName ); if ( w->p.fontSize == 0 ) f.setPointSize( 10 ); else f.setPointSize( w->p.fontSize ); f.setWeight( w->p.fontWeight ); f.setItalic( w->p.fontItalic ); f.setUnderline( w->p.fontUnderline ); f.setStrikeOut( w->p.fontStrikeOut ); QFontMetrics fm(f); if ( setWidth ) w->p._width = m->pixelToMeasure( fm.width( w->p.text )+ TRIM_DEFAULT_TEXTWIDTH ); if ( setHeight ) w->p._height = m->pixelToMeasure( fm.height() + TRIM_DEFAULT_TEXTHEIGHT ); }void NCReportDesignerResourceHandler::saveWidget( NCReportDesignerWidget *w, QTextStream & ts, int indent ){ //Measurement *m = designArea->measurement(); //const char qm='\"'; // tag ts << makeIndent( indent ) << "<" << w->tagname; // properties if ( w->useFType ) ts << " ftype=\"" << w->p.ftype << "\""; if ( w->useType && w->p.type!="text") ts << " type=\"" << w->p.type << "\""; if ( w->useSize ) ts << " posX=\"" << m->pixelToMeasureStr(w->x()) << "\" posY=\"" << m->pixelToMeasureStr(w->y()) << "\" width=\"" << m->pixelToMeasureStr(w->width()) << "\" height=\"" << m->pixelToMeasureStr(w->height()) << "\""; if ( w->usePointFromTo ) { if ( w->orient == Qt::Horizontal ) ts << " fromX=\"" << m->pixelToMeasureStr(w->x()) << "\" fromY=\"" << m->pixelToMeasureStr(w->y()) << "\" toX=\"" << m->pixelToMeasureStr(w->x()+w->width()) << "\" toY=\"" << m->pixelToMeasureStr(w->y()) << "\""; else ts << " fromX=\"" << m->pixelToMeasureStr(w->x()) << "\" fromY=\"" << m->pixelToMeasureStr(w->y()) << "\" toX=\"" << m->pixelToMeasureStr(w->x()) << "\" toY=\"" << m->pixelToMeasureStr(w->y()+w->height()) << "\""; } if ( w->useLineWidth ) ts << " lineWidth=\"" << w->p.lineWidth << "\""; if ( w->useLineStyle ) { QString ls; switch ( w->p.lineStyle ) { case Qt::SolidLine: ls="solid"; break; case Qt::DashLine: ls="dash"; break; case Qt::DotLine: ls="dot"; break; case Qt::DashDotLine: ls="dashdot"; break; case Qt::DashDotDotLine: ls="dashdotdot"; break; case Qt::NoPen: ls="nopen"; break; default: ls=""; } ts << " lineStyle=\"" << ls << "\""; } if ( w->useFontSize && w->p.fontSize != document->po.defaultFontSize ) ts << " fontSize=\"" << w->p.fontSize << "\""; if ( w->useFontWeight && w->p.fontWeight==QFont::Bold ) { ts << " fontWeight=\"bold\""; } if ( w->useFontName && !w->p.fontName.isEmpty() && w->p.fontName != document->po.defaultFontName ) ts << " fontName=\"" << w->p.fontName << "\""; if ( w->useFontItalic && w->p.fontItalic ) ts << " fontItalic=\"" << (w->p.fontItalic ? "true" : "false") << "\""; if ( w->useFontStrikeOut && w->p.fontStrikeOut ) ts << " fontStrikeOut=\"" << (w->p.fontStrikeOut ? "true" : "false") << "\""; if ( w->useFontUnderline && w->p.fontUnderline ) ts << " fontUnderline=\"" << (w->p.fontUnderline ? "true" : "false") << "\""; if ( w->useAlignment ) { QString s; if ( w->p.alignmentH != Qt::AlignLeft ) { switch ( w->p.alignmentH ) { case Qt::AlignLeft: s="left"; break; case Qt::AlignRight: s="right"; break; case Qt::AlignHCenter: s="center"; break; default: break; } ts << " alignmentH=\"" << s << "\""; } if ( w->p.alignmentV != Qt::AlignTop ) { switch ( w->p.alignmentV ) { case Qt::AlignTop: s="top"; break; case Qt::AlignBottom: s="bottom"; break; case Qt::AlignVCenter: s="center"; break; default: break; } ts << " alignmentV=\"" << s << "\""; } } if ( w->useWordBreak && w->p.wordbreak ) ts << " wordbreak=\"" << (w->p.wordbreak ? "true" : "false") << "\""; if ( w->useRichText && w->p.isRichText ) ts << " richText=\"" << (w->p.isRichText ? "true" : "false") << "\""; if ( w->useDynamicHeight && w->p.dynamicHeight ) ts << " dynamicHeight=\"" << (w->p.dynamicHeight ? "true" : "false") << "\""; if ( w->useLoadFromFile && w->p.loadFromFile ) ts << " loadFromFile=\"" << (w->p.loadFromFile ? "true" : "false") << "\""; //if ( useText ) // ts << " text=\"" << text << "\""; if ( w->usePrintWhen && !w->p.printWhen.isEmpty() ) ts << " printWhen=\"" << w->p.printWhen << "\""; if ( w->useRotation && w->p.rotation>0 ) ts << " rotation=\"" << w->p.rotation << "\""; if ( w->useLineColor ) ts << " lineColor=\"" << colorToString(w->p.lineColor) << "\""; if ( w->useFillColor ) ts << " fillColor=\"" << colorToString(w->p.fillColor) << "\""; if ( w->useForeColor ) ts << " forecolor=\"" << colorToString(w->p.forecolor) << "\""; if ( w->useBackColor ) ts << " backcolor=\"" << colorToString(w->p.backcolor) << "\""; if ( w->useFillStyle ) ts << " fillStyle=\"" << (w->p.fillStyle==WProperty::transparent ? "transparent" : "filled") << "\""; if ( w->useResource ) ts << " resource=\"" << w->p.resource << "\""; if ( w->useDataFormat && w->p.type == "numeric" ) { if ( w->p.numBlankIfZero ) ts << " numBlankIfZero=\"" << "true" << "\""; if ( w->p.numDigitNo >= 0 ) ts << " numDigitNo=\"" << w->p.numDigitNo << "\""; if ( w->p.numSeparation ) ts << " numSeparation=\"" << "true" << "\""; if ( w->p.numSeparator != ' ' ) ts << " numSeparator=\"" << w->p.numSeparator << "\""; if ( w->p.numDigitPoint != '.' ) ts << " numDigitPoint=\"" << w->p.numDigitPoint << "\""; if ( !w->p.numFormat.isEmpty() ) ts << " numFormat=\"" << w->p.numFormat << "\""; } if ( w->useDataFormat && !w->p.dateFormat.isEmpty() ) ts << " dateFormat=\"" << w->p.dateFormat << "\""; if ( !w->p.embedString.isEmpty() ) ts << " embedString=\"" << w->p.embedString << "\""; if ( !w->p.callFunction.isEmpty() ) ts << " callFunction=\"" << w->p.callFunction << "\""; if ( !w->p.lookupClass.isEmpty() ) ts << " lookupClass=\"" << w->p.lookupClass << "\""; // tag end ts << ">"; if ( w->useText ) { //if ( w->p.text.isEmpty() ) // ts << w->p.resource; // pixmap/image //else ts << entitize( w->p.text ); } ts << "</" << w->tagname << ">\r\n" ;}QColor NCReportDesignerResourceHandler::stringToColor( const QString &colorstring ){ QColor color; bool ok; colorstring.right(6).toInt( &ok, 16 ); if ( ok && colorstring.startsWith("#") && colorstring.length() == 7 ) { color = QColor( colorstring.mid(1,2).toInt( &ok, 16), colorstring.mid(3,2).toInt( &ok, 16), colorstring.mid(5,2).toInt( &ok, 16) ); } return color;}QString NCReportDesignerResourceHandler::colorToString( const QColor & col ){ QString webcol; if ( col.isValid() ) { // got a file name webcol.sprintf( "#%02X%02X%02X", col.red(), col.green(), col.blue() ); } return webcol;}QString NCReportDesignerResourceHandler::entitize( const QString & s, bool isAttrib ){ QString s2 = s; s2 = s2.stripWhiteSpace(); s2 = s2.replace( "&", "&" ); s2 = s2.replace( ">", ">" ); s2 = s2.replace( "<", "<" ); if ( isAttrib ) { s2 = s2.replace( "\"", """ ); s2 = s2.replace( "'", "'" ); } return s2;}QString NCReportDesignerResourceHandler::makeIndent( int indent ){ QString s; s.fill( ' ', indent * 4 ); return s;}void NCReportDesignerResourceHandler::removeXMLComments( QString & doc ){ if ( doc.contains("<!--") ==0 ) return; doc.replace( QRegExp("<!--([^<]*)-->"), "" );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -