void CanvasGradientPrototype::addColorStop(qreal offset, const QString &color) { CanvasGradient *self = qscriptvalue_cast<CanvasGradient*>(thisObject()); if (!self || (self->value.type() == QGradient::NoGradient)) return; self->value.setColorAt(offset, colorFromString(color)); }
void Context2D::setShadowColor(const QString &str) { m_state.shadowColor = colorFromString(str); if (m_painter.device() == &m_shadowbuffer && m_state.shadowBlur>0) endPainting(); m_state.flags |= DirtyShadowColor; }
bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgEllipse(const QDomElement &element) { //ellipse horisontal and vertical radius qreal rx = element.attribute(aRx).toDouble(); qreal ry = element.attribute(aRy).toDouble(); QSvgGenerator *generator = createSvgGenerator(rx * 2, ry * 2); //fill and stroke color QColor fillColor = colorFromString(element.attribute(aFill)); QColor strokeColor = colorFromString(element.attribute(aStroke)); int strokeWidth = element.attribute(aStrokewidth).toInt(); //ellipse center coordinates qreal cx = element.attribute(aCx).toDouble(); qreal cy = element.attribute(aCy).toDouble(); //init painter to paint to svg QPainter painter; painter.begin(generator); QPen pen(strokeColor); pen.setWidth(strokeWidth); painter.setPen(pen); painter.setBrush(QBrush(fillColor)); painter.drawEllipse(0, 0, rx * 2, ry * 2); painter.end(); UBGraphicsSvgItem *svgItem = mCurrentScene->addSvg(QUrl::fromLocalFile(generator->fileName())); QTransform transform; QString textTransform = element.attribute(aTransform); svgItem->resetTransform(); if (!textTransform.isNull()) { transform = transformFromString(textTransform, svgItem); } repositionSvgItem(svgItem, rx * 2, ry * 2, cx - 2*rx, cy+ry, transform); hashSceneItem(element, svgItem); delete generator; return true; }
void EditFldDlg::chooseColor() { QColor color; if (sender() == ui->btnColorF) color = colorFromString(ui->lblColorF->styleSheet()); if (sender() == ui->btnColorB) color = colorFromString(ui->lblColorB->styleSheet()); QColorDialog *dlg = new QColorDialog(color, this); if (dlg->exec() == QDialog::Accepted) { color = dlg->selectedColor(); } else return; QString strColor = colorToString(color); if (sender() == ui->btnColorB) ui->lblColorB->setStyleSheet("QLabel {background-color: "+strColor+"}"); if (sender() == ui->btnColorF) ui->lblColorF->setStyleSheet("QLabel {background-color: "+strColor+"}"); encodeHighLightingString(); }
//! [3] void Context2D::setFillStyle(const QVariant &style) { if (style.canConvert<CanvasGradient>()) { CanvasGradient cg = qvariant_cast<CanvasGradient>(style); m_state.fillStyle = cg.value; } else { QColor color = colorFromString(style.toString()); m_state.fillStyle = color; } m_state.flags |= DirtyFillStyle; }
void Context2D::setFillStyle(const QVariant &style) { CanvasGradient * gradient= qobject_cast<CanvasGradient*>(style.value<QObject*>()); if (gradient) { m_state.fillStyle = gradient->value(); } else { QColor color = colorFromString(style.toString()); m_state.fillStyle = color; } m_state.flags |= DirtyFillStyle; }
QVariant read(int variantType, const QString &str) { QVariant value; bool conversionOk = true; switch (variantType) { case QMetaType::QPoint: value = pointFFromString(str, &conversionOk).toPoint(); break; case QMetaType::QPointF: value = pointFFromString(str, &conversionOk); break; case QMetaType::QSize: value = sizeFFromString(str, &conversionOk).toSize(); break; case QMetaType::QSizeF: value = sizeFFromString(str, &conversionOk); break; case QMetaType::QRect: value = rectFFromString(str, &conversionOk).toRect(); break; case QMetaType::QRectF: value = rectFFromString(str, &conversionOk); break; case QMetaType::QUrl: value = QVariant(QUrl(str)); break; case QMetaType::QColor: value = colorFromString(str, &conversionOk); break; case QMetaType::QVector3D: value = vector3DFromString(str, &conversionOk); break; default: { if (variantType == QMetaType::type("Enumeration")) { value = QVariant::fromValue<Enumeration>(enumerationFromString(str, &conversionOk)); } else { value = QVariant(str); value.convert(static_cast<QVariant::Type>(variantType)); } break; } } if (!conversionOk) { qWarning() << "Could not convert" << str << "to" << QMetaType::typeName(variantType); value = QVariant(str); } return value; }
Piece* Recorder::create(const QString& name, int x, int y, const QString& colorString) { if(!model_) { return NULL; } ChessBoardModel::PieceColor col = colorFromString(colorString); Piece* result = model_->create(name, x, y, col); if(result) { queueAction(new CreateAction(name, x, y, col)); } return result; }
/*! \reimp */ void QThemeRectItem::paint(QPainter *p, const QStyleOptionGraphicsItem *o, QWidget *w) { if (d->color.isModified()) p->setPen(colorFromString(d->color.value().toString())); else p->setPen(Qt::NoPen); QColor brush; if (d->brush.isModified()) { brush = colorFromString(d->brush.value().toString()); p->setBrush(brush); } else { p->setBrush(Qt::transparent); } if (d->alpha.isModified()) { brush.setAlpha(d->alpha.value().toInt()); p->setBrush(brush); } else { p->setBrush(Qt::transparent); } p->drawRect(boundingRect()); QThemeItem::paint(p, o, w); }
QVariant QDeclarativeStringConverters::variantFromString(const QString &s) { if (s.isEmpty()) return QVariant(s); bool ok = false; QRectF r = rectFFromString(s, &ok); if (ok) return QVariant(r); QColor c = colorFromString(s, &ok); if (ok) return QVariant(c); QPointF p = pointFFromString(s, &ok); if (ok) return QVariant(p); QSizeF sz = sizeFFromString(s, &ok); if (ok) return QVariant(sz); QVector3D v = vector3DFromString(s, &ok); if (ok) return QVariant::fromValue(v); return QVariant(s); }
/*! \internal */ void QThemeWidgetItem::parseColorGroup(const QMap<QString,QString> &cgatts) { if (!d->proxy || !d->proxy->widget()) return; QPalette pal = d->proxy->palette(); for (int i = 0; colorTable[i].role != QPalette::NColorRoles; ++i) { const QString curColorName = QString(colorTable[i].name).toLower(); QColor colour; for (QMap<QString,QString>::ConstIterator it = cgatts.begin(); it != cgatts.end(); ++it) { if (it.key().toLower() == curColorName) { colour = colorFromString(*it); break; } } if (colour.isValid()) { pal.setColor(QPalette::Active, colorTable[i].role, colour); pal.setColor(QPalette::Inactive, colorTable[i].role, colour); pal.setColor(QPalette::Disabled, colorTable[i].role, colour); } } d->proxy->setPalette(pal); }
QVariant QDeclarativeStringConverters::variantFromString(const QString &s, int preferredType, bool *ok) { switch (preferredType) { case QMetaType::Int: return QVariant(int(qRound(s.toDouble(ok)))); case QMetaType::UInt: return QVariant(uint(qRound(s.toDouble(ok)))); case QMetaType::QColor: return QVariant::fromValue(colorFromString(s, ok)); #ifndef QT_NO_DATESTRING case QMetaType::QDate: return QVariant::fromValue(dateFromString(s, ok)); case QMetaType::QTime: return QVariant::fromValue(timeFromString(s, ok)); case QMetaType::QDateTime: return QVariant::fromValue(dateTimeFromString(s, ok)); #endif // QT_NO_DATESTRING case QMetaType::QPointF: return QVariant::fromValue(pointFFromString(s, ok)); case QMetaType::QPoint: return QVariant::fromValue(pointFFromString(s, ok).toPoint()); case QMetaType::QSizeF: return QVariant::fromValue(sizeFFromString(s, ok)); case QMetaType::QSize: return QVariant::fromValue(sizeFFromString(s, ok).toSize()); case QMetaType::QRectF: return QVariant::fromValue(rectFFromString(s, ok)); case QMetaType::QRect: return QVariant::fromValue(rectFFromString(s, ok).toRect()); case QMetaType::QVector3D: return QVariant::fromValue(vector3DFromString(s, ok)); default: if (ok) *ok = false; return QVariant(); } }
void QtRPT::drawField(QDomNode n, int bandTop) { //В качестве параметра подается нод бэнда QDomNode c = n.firstChild(); while(!c.isNull()) { QDomElement e = c.toElement(); // try to convert the node to an element. if ((!e.isNull()) && (e.tagName() == "TContainerField")) { if (isFieldVisible(e)) { QFont font(e.attribute("fontFamily"),e.attribute("fontSize").toInt()); font.setBold(processHighligthing(e, FontBold).toInt()); font.setItalic(processHighligthing(e, FontItalic).toInt()); font.setUnderline(processHighligthing(e, FontUnderline).toInt()); painter.setFont(font); painter.setPen(Qt::black); int left_ = e.attribute("left").toInt()*koefRes_w; int top_ = (bandTop+e.attribute("top").toInt())*koefRes_h; int width_ = (e.attribute("width").toInt()-1)*koefRes_w;; int height_ = e.attribute("height").toInt()*koefRes_h; int cor = QFontMetrics(font).height() * koefRes_h; QRect textRect(left_, top_-height_, width_, height_); textRect.translate(0, cor ); QPen pen = painter.pen(); Qt::Alignment al; Qt::Alignment alH, alV; if (e.attribute("aligmentH") == "hRight") alH = Qt::AlignRight; if (e.attribute("aligmentH") == "hLeft") alH = Qt::AlignLeft; if (e.attribute("aligmentH") == "hCenter") alH = Qt::AlignHCenter; if (e.attribute("aligmentH") == "hJustify") alH = Qt::AlignJustify; if (e.attribute("aligmentV") == "vTop") alV = Qt::AlignTop; if (e.attribute("aligmentV") == "vBottom") alV = Qt::AlignBottom; if (e.attribute("aligmentV") == "vCenter") alV = Qt::AlignVCenter; al = alH | alV; if ( colorFromString(processHighligthing(e, BgColor).toString() ) != QColor(255,255,255,0)) painter.fillRect(left_+1,top_+1,width_-2,height_-2,colorFromString(processHighligthing(e, BgColor).toString())); /*if ( colorFromString(e.attribute("backgroundColor")) != QColor(255,255,255,0)) painter.fillRect(left_+1,top_+1,width_-2,height_-2,colorFromString(e.attribute("backgroundColor")));*/ //Set border width pen.setWidth(e.attribute("borderWidth","1").replace("px","").toInt()*5); //Set border style QString borderStyle = e.attribute("borderStyle","solid"); if (borderStyle == "dashed") pen.setStyle(Qt::DashLine); else if (borderStyle == "dotted") pen.setStyle(Qt::DotLine); else if (borderStyle == "dot-dash") pen.setStyle(Qt::DashDotLine); else if (borderStyle == "dot-dot-dash") pen.setStyle(Qt::DashDotDotLine); else pen.setStyle(Qt::SolidLine); if ( colorFromString(e.attribute("borderTop")) != QColor(255,255,255,0) ) { pen.setColor(colorFromString(e.attribute("borderTop"))); painter.setPen(pen); painter.drawLine(left_, top_, left_ + width_, top_); } if ( colorFromString(e.attribute("borderBottom")) != QColor(255,255,255,0) ) { pen.setColor(colorFromString(e.attribute("borderBottom"))); painter.setPen(pen); painter.drawLine(left_, top_ + height_, left_ + width_, top_ + height_); } if ( colorFromString(e.attribute("borderLeft")) != QColor(255,255,255,0) ) { pen.setColor(colorFromString(e.attribute("borderLeft"))); painter.setPen(pen); painter.drawLine(left_, top_, left_, top_ + height_); } if ( colorFromString(e.attribute("borderRight")) != QColor(255,255,255,0) ) { pen.setColor(colorFromString(e.attribute("borderRight"))); painter.setPen(pen); painter.drawLine(left_ + width_, top_, left_ + width_, top_ + height_); } if (e.attribute("type","label") == "label") { //NOT Proccess if field set as ImageField QString txt = sectionField(e.attribute("value"),false); //pen.setColor(colorFromString(e.attribute("fontColor"))); pen.setColor(colorFromString(processHighligthing(e, FontColor).toString())); painter.setPen(pen); painter.drawText(left_+10,top_,width_-10,height_, al | Qt::TextDontClip | Qt::TextWordWrap, txt); } if (e.attribute("type","label") == "labelImage") { //Proccess field as ImageField QImage image = sectionFieldImage(e.attribute("value")); if (!image.isNull()) { QRectF target(left_, top_, width_, height_); painter.drawImage(target,image); } } if (e.attribute("type","label") == "image") { //Proccess as static ImageField QByteArray byteArray; byteArray = QByteArray::fromBase64(e.attribute("picture","text").toLatin1()); QPixmap pixmap = QPixmap::fromImage(QImage::fromData(byteArray, "PNG")); painter.drawPixmap(left_,top_,width_,height_,pixmap); } } } c = c.nextSibling(); } }
bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgRect(const QDomElement &element) { qreal x1 = element.attribute(aX).toDouble(); qreal y1 = element.attribute(aY).toDouble(); //rect dimensions qreal width = element.attribute(aWidth).toDouble(); qreal height = element.attribute(aHeight).toDouble(); QString textFillColor = element.attribute(aFill); QString textStrokeColor = element.attribute(aStroke); QString textStrokeWidth = element.attribute(aStrokewidth); QColor fillColor = !textFillColor.isNull() ? colorFromString(textFillColor) : QColor(); QColor strokeColor = !textStrokeColor.isNull() ? colorFromString(textStrokeColor) : QColor(); int strokeWidth = textStrokeWidth.toInt(); x1 -= strokeWidth/2; y1 -= strokeWidth/2; width += strokeWidth; height += strokeWidth; //init svg generator with temp file QSvgGenerator *generator = createSvgGenerator(width, height); //init painter to paint to svg QPainter painter; painter.begin(generator); //fill rect if (fillColor.isValid()) { painter.setBrush(QBrush(fillColor)); painter.fillRect(0, 0, width, height, fillColor); } QPen pen; if (strokeColor.isValid()) { pen.setColor(strokeColor); } if (strokeWidth) pen.setWidth(strokeWidth); painter.setPen(pen); painter.drawRect(0, 0, width, height); painter.end(); UBGraphicsSvgItem *svgItem = mCurrentScene->addSvg(QUrl::fromLocalFile(generator->fileName())); QTransform transform; QString textTransform = element.attribute(aTransform); svgItem->resetTransform(); if (!textTransform.isNull()) { transform = transformFromString(textTransform, svgItem); } repositionSvgItem(svgItem, width, height, x1, y1, transform); hashSceneItem(element, svgItem); delete generator; return true; }
//Setup the style according the param void RptContainer::setSheetValue(Command param, QString value) { QString str = this->styleSheet(); int start; int end; if (value == "#ffffff") value = "rgba(255,255,255,0)"; switch(param) { case FontColor: { start = str.indexOf(";color:",0,Qt::CaseInsensitive); end = str.indexOf(";",start+1,Qt::CaseInsensitive); str.replace(start,end-start,";color:"+value); fontColor = colorFromString(value); break; } case BackgroundColor: { start = str.indexOf(";background-color:",0,Qt::CaseInsensitive); end = str.indexOf(";",start+1,Qt::CaseInsensitive); str.replace(start,end-start,";background-color:"+value); backgroundColor = colorFromString(value); break; } case BorderColor: { start = str.indexOf(";border-color:",0,Qt::CaseInsensitive); end = str.indexOf(";",start+1,Qt::CaseInsensitive); str.replace(start,end-start,";border-color:"+value); borderColor = colorFromString(value); QString tmpColor = getColorValueStr(FrameTop); if (tmpColor != "rgba(255,255,255,0)") { start = str.indexOf(";border-top-color:",0,Qt::CaseInsensitive); end = str.indexOf(";",start+1,Qt::CaseInsensitive); str.replace(start,end-start,";border-top-color:"+value); } tmpColor = getColorValueStr(FrameBottom); if (tmpColor != "rgba(255,255,255,0)") { start = str.indexOf(";border-bottom-color:",0,Qt::CaseInsensitive); end = str.indexOf(";",start+1,Qt::CaseInsensitive); str.replace(start,end-start,";border-bottom-color:"+value); } tmpColor = getColorValueStr(FrameLeft); if (tmpColor != "rgba(255,255,255,0)") { start = str.indexOf(";border-left-color:",0,Qt::CaseInsensitive); end = str.indexOf(";",start+1,Qt::CaseInsensitive); str.replace(start,end-start,";border-left-color:"+value); } tmpColor = getColorValueStr(FrameRight); if (tmpColor != "rgba(255,255,255,0)") { start = str.indexOf(";border-right-color:",0,Qt::CaseInsensitive); end = str.indexOf(";",start+1,Qt::CaseInsensitive); str.replace(start,end-start,";border-right-color:"+value); } break; } case FrameTop: { start = str.indexOf(";border-top-color:",0,Qt::CaseInsensitive); end = str.indexOf(";",start+1,Qt::CaseInsensitive); str.replace(start,end-start,";border-top-color:"+value); break; } case FrameBottom: { start = str.indexOf(";border-bottom-color:",0,Qt::CaseInsensitive); end = str.indexOf(";",start+1,Qt::CaseInsensitive); str.replace(start,end-start,";border-bottom-color:"+value); break; } case FrameLeft: { start = str.indexOf(";border-left-color:",0,Qt::CaseInsensitive); end = str.indexOf(";",start+1,Qt::CaseInsensitive); str.replace(start,end-start,";border-left-color:"+value); break; } case FrameRight: { start = str.indexOf(";border-right-color:",0,Qt::CaseInsensitive); end = str.indexOf(";",start+1,Qt::CaseInsensitive); str.replace(start,end-start,";border-right-color:"+value); break; } case FrameWidth: { start = str.indexOf(";border-width:",0,Qt::CaseInsensitive); end = str.indexOf(";",start+1,Qt::CaseInsensitive); str.replace(start,end-start,";border-width:"+value); borderWidth = value.replace("px","").toInt(); break; } case FrameStyle: { start = str.indexOf(";border-style:",0,Qt::CaseInsensitive); end = str.indexOf(";",start+1,Qt::CaseInsensitive); str.replace(start,end-start,";border-style:"+value); break; } default: return; } setStyleSheet(str); }
bool MStyleSheetAttribute::writeAttribute(MUniqueStringCache::Index filename, MStyle *style, const QMetaProperty &property, M::Orientation orientation) const { // first check if the attribute is cached orientation independent, if not found // check for the given orientation QVariant cachedVariant = variantCache[M::Landscape + 1][value][property.userType()]; if (cachedVariant.isValid()) { return property.write(style, cachedVariant); } else { cachedVariant = variantCache[orientation][value][property.userType()]; if (cachedVariant.isValid()) { style->setOrientationDependent(true); return property.write(style, cachedVariant); } } bool conversionOK = false; // most types are the same in landscape and portrait CacheOrientationFlags cacheOrientation = CacheOrientationFlags(PortraitFlag | LandscapeFlag); QLatin1String vs = MStyleSheetParser::stringCacheWithoutReverseLookup()->indexToString(value); QByteArray valueString = QByteArray::fromRawData(vs.latin1(), strlen(vs.latin1())); const int attributeType = property.userType(); if (attributeType == QMetaType::Bool) { bool result = booleanFromString(valueString, &conversionOK); if (conversionOK) { return fillProperty(property, style, cacheOrientation, result); } } else if (attributeType == QMetaType::Int) { int integer = attributeToInt(valueString, &conversionOK); if (conversionOK) { return fillProperty(property, style, cacheOrientation, integer); } } else if (attributeType == QMetaType::QColor) { if(valueString == "none") return fillProperty(property, style, cacheOrientation, QColor()); QColor color = colorFromString(valueString, &conversionOK); if (conversionOK) { return fillProperty(property, style, cacheOrientation, color); } } else if (attributeType == QMetaType::QReal) { qreal real = attributeToFloat(valueString, &conversionOK); if (conversionOK) { return fillProperty(property, style, cacheOrientation, real); } } else if (attributeType == qMetaTypeId<const QPixmap*>()) { if(valueString == "none") return fillProperty(property, style, cacheOrientation, qVariantFromValue((const QPixmap *) NULL)); //"image: image_id;" //"image: image_id 64px 64px;" //"image: "image id";" //"image: "image id" 64px 64px;" QList<QByteArray> list; if (valueString.startsWith('\"')) { //parse name inside quotes int idx = valueString.indexOf('\"', 1); if (idx != -1) { //get quoted image_id QByteArray imageid = valueString.mid(1, idx - 1); //split rest of the parameters QByteArray values = valueString.mid(idx + 1).trimmed(); list = values.split(' '); list.removeAll(""); //insert image_id as first parameter list.insert(0, imageid); } } else { //no quotes, just split the parameters list = valueString.split(' '); list.removeAll(""); } //only image_id if (list.size() == 1) { const QPixmap *pixmap = MTheme::pixmap(list.at(0)); return fillProperty(property, style, cacheOrientation, qVariantFromValue(pixmap), false); } //image_id + width + height else if (list.size() == 3) { int width = attributeToInt(list.at(1), &conversionOK, WidthAttribute, orientation, &cacheOrientation); int height = attributeToInt(list.at(2), &conversionOK, HeightAttribute, orientation, &cacheOrientation); const QPixmap *pixmap = MTheme::pixmap(list.at(0), QSize(width, height)); return fillProperty(property, style, cacheOrientation, qVariantFromValue(pixmap), false); } //no parameters else if (list.size() == 0) { //init null pixmap which is ok if someone does not want to use it return fillProperty(property, style, cacheOrientation, qVariantFromValue((const QPixmap *) NULL)); } } else if (attributeType == qMetaTypeId<const MScalableImage*>() || attributeType == qMetaTypeId<MBackgroundTiles>()) { //"background: image_id left right top bottom;" //"background: image_id;" //"background: "image id" left right top bottom;" //"background: "image id";" QList<QByteArray> list; if (valueString.startsWith('\"')) { //parse name inside quotes int idx = valueString.indexOf('\"', 1); if (idx != -1) { //get quoted image_id QByteArray imageid = valueString.mid(1, idx - 1); //split rest of the parameters QByteArray values = valueString.mid(idx + 1).trimmed(); list = values.split(' '); list.removeAll(""); //insert image_id as first parameter list.insert(0, imageid); } } else { //no quotes, just split the parameters list = valueString.split(' '); list.removeAll(""); } //no parameters if (valueString.isEmpty() || valueString == "none") { //init null image which is ok if someone does not want to use it if(attributeType == qMetaTypeId<const MScalableImage*>()) return fillProperty(property, style, cacheOrientation, qVariantFromValue((const MScalableImage *) NULL)); else return fillProperty(property, style, cacheOrientation, QVariant::fromValue(MBackgroundTiles()), false); } //only image_id else if (list.size() == 1) { if(attributeType == qMetaTypeId<const MScalableImage*>()) { const MScalableImage *image = MTheme::scalableImage(list.at(0), 0, 0, 0, 0); return fillProperty(property, style, cacheOrientation, qVariantFromValue(image), false); } else { return fillProperty(property, style, cacheOrientation, QVariant::fromValue(MBackgroundTiles(list.at(0), 0,0,0,0)), false); } } //image_id + border width paramaters else if (list.size() == 5) { //image_id and the border parameters if(attributeType == qMetaTypeId<const MScalableImage*>()) { const MScalableImage *image = MTheme::scalableImage(list.at(0), attributeToInt(list.at(1), &conversionOK), attributeToInt(list.at(2), &conversionOK), attributeToInt(list.at(3), &conversionOK), attributeToInt(list.at(4), &conversionOK)); return fillProperty(property, style, cacheOrientation, qVariantFromValue(image), false); } else { return fillProperty(property, style, cacheOrientation, QVariant::fromValue(MBackgroundTiles(list.at(0), attributeToInt(list.at(1), &conversionOK), attributeToInt(list.at(2), &conversionOK), attributeToInt(list.at(3), &conversionOK), attributeToInt(list.at(4), &conversionOK))), false); } } } else if (attributeType == QMetaType::QSize || attributeType == QMetaType::QSizeF) { //size: 25px 25px; //just split into pieces and create QSize or QSizeF depending on the attributeType QList<QByteArray> list = valueString.split(' '); list.removeAll(""); if (list.size() == 2) { if (attributeType == QMetaType::QSize) { int width = attributeToInt(list.at(0), &conversionOK, WidthAttribute, orientation, &cacheOrientation); int height = attributeToInt(list.at(1), &conversionOK, HeightAttribute, orientation, &cacheOrientation); return fillProperty(property, style, cacheOrientation, QSize(width, height)); } else { qreal width = attributeToFloat(list.at(0), &conversionOK, WidthAttribute, orientation, &cacheOrientation); qreal height = attributeToFloat(list.at(1), &conversionOK, HeightAttribute, orientation, &cacheOrientation); return fillProperty(property, style, cacheOrientation, QSizeF(width, height)); } } } else if (attributeType == QMetaType::QPoint || attributeType == QMetaType::QPointF) { //"point: 256px 123px; //just split into pieces and create QPoint or QPointF depending on the attributeType QList<QByteArray> list = valueString.split(' '); list.removeAll(""); if (list.size() == 2) { if (attributeType == QMetaType::QPoint) { int x = attributeToInt(list.at(0), &conversionOK, WidthAttribute, orientation, &cacheOrientation); int y = attributeToInt(list.at(1), &conversionOK, HeightAttribute, orientation, &cacheOrientation); return fillProperty(property, style, cacheOrientation, QPoint(x, y)); } else { qreal x = attributeToFloat(list.at(0), &conversionOK, WidthAttribute, orientation, &cacheOrientation); qreal y = attributeToFloat(list.at(1), &conversionOK, HeightAttribute, orientation, &cacheOrientation); return fillProperty(property, style, cacheOrientation, QPointF(x, y)); } } } else if (attributeType == QMetaType::QFont) { QFont font = fontFromString(valueString, &conversionOK); if (conversionOK) { return fillProperty(property, style, cacheOrientation, font); } } else if (attributeType == QMetaType::QString) { if (valueString.length() >= 2) { if ((valueString.at(0) == 0x22) && (valueString.at(valueString.length()-1) == 0x22)) { return fillProperty(property, style, cacheOrientation, QString(valueString.mid(1, valueString.length() - 2))); } } else if (valueString.length() == 0) { return fillProperty(property, style, cacheOrientation, QString()); } } else if (attributeType == QMetaType::QChar) { if (valueString.length() == 3) { if ((valueString.at(0) == '\'') && (valueString.at(2) == '\'')) { return fillProperty(property, style, cacheOrientation, static_cast<QChar>(valueString.at(1))); } } } else if (attributeType == qMetaTypeId<Qt::Alignment>()) { if (DataTypeConverter.ALIGNMENTS.contains(valueString)) { return fillProperty(property, style, cacheOrientation, qVariantFromValue(DataTypeConverter.ALIGNMENTS[valueString])); } } else if (attributeType == qMetaTypeId<Qt::Orientation>()) { if (DataTypeConverter.ORIENTATIONS.contains(valueString)) { return fillProperty(property, style, cacheOrientation, qVariantFromValue(DataTypeConverter.ORIENTATIONS[valueString])); } } else if (attributeType == qMetaTypeId<QTextCharFormat::UnderlineStyle>()) { if (DataTypeConverter.UNDERLINESTYLES.contains(valueString)) { return fillProperty(property, style, cacheOrientation, qVariantFromValue(DataTypeConverter.UNDERLINESTYLES[valueString])); } } else if (attributeType == qMetaTypeId<Qt::PenStyle>()) { if (DataTypeConverter.PENSTYLES.contains(valueString)) { return fillProperty(property, style, cacheOrientation, qVariantFromValue(DataTypeConverter.PENSTYLES[valueString])); } } else if (attributeType == qMetaTypeId<Qt::Axis>()) { if (DataTypeConverter.AXES.contains(valueString)) { return fillProperty(property, style, cacheOrientation, qVariantFromValue(DataTypeConverter.AXES[valueString])); } } else if (attributeType == qMetaTypeId<MFeedback>()) { MFeedback feedback(valueString); return fillProperty(property, style, cacheOrientation, qVariantFromValue(feedback)); } else if (attributeType == QMetaType::QEasingCurve) { QEasingCurve curve; // curve type QList<QByteArray> list = valueString.split(','); if (list.size() > 0) { if (DataTypeConverter.EASINGCURVETYPES.contains(list.at(0))) { int type = DataTypeConverter.EASINGCURVETYPES[list.at(0)]; if (type < FirstCustomType) curve.setType(static_cast<QEasingCurve::Type>(type)); else if (type == OvershotBezier) curve = MOvershotBezierEasingCurve(); // curve amplitude if (list.size() > 1) { curve.setAmplitude((qreal) list.at(1).toDouble()); // curve overshoot if (list.size() > 2) { curve.setOvershoot((qreal) list.at(2).toDouble()); // curve period if (list.size() > 3) { curve.setPeriod((qreal) list.at(3).toDouble()); } } } return fillProperty(property, style, cacheOrientation, qVariantFromValue(curve)); } } } else if (attributeType == qMetaTypeId<QTextOption::WrapMode>()) { if (DataTypeConverter.WRAPMODES.contains(valueString)) { return fillProperty(property, style, cacheOrientation, qVariantFromValue(DataTypeConverter.WRAPMODES[valueString])); } } MStyleSheetParser::outputParseError(MStyleSheetParser::stringCacheWithReverseLookup()->indexToString(filename), "Not a valid attribute(" + QLatin1String(property.typeName()) + "): " + MStyleSheetParser::stringCacheWithoutReverseLookup()->indexToString(name) + " : " + valueString, MStyleSheetParser::getLineNum(MStyleSheetParser::stringCacheWithReverseLookup()->indexToString(filename), position)); return false; }
void Context2D::setShadowColor(const QString &str) { m_state.shadowColor = colorFromString(str); m_state.flags |= DirtyShadowColor; }
TilePiece* Pony48Engine::loadTile(string sFilename) { TilePiece* ret = new TilePiece(); XMLDocument* doc = new XMLDocument(); int iErr = doc->LoadFile(sFilename.c_str()); if(iErr != XML_NO_ERROR) { errlog << "Error parsing XML file " << sFilename << ": Error " << iErr << endl; delete doc; return NULL; } XMLElement* root = doc->FirstChildElement("tile"); if(root == NULL) { errlog << "Error: No toplevel \"tile\" item in XML file " << sFilename << endl; delete doc; return NULL; } root->QueryIntAttribute("value", &ret->value); vector<Image*> vImages; for(XMLElement* img = root->FirstChildElement("img"); img != NULL; img = img->NextSiblingElement("img")) { const char* cPath = img->Attribute("path"); if(cPath != NULL) vImages.push_back(getImage(cPath)); } for(XMLElement* sound = root->FirstChildElement("sound"); sound != NULL; sound = sound->NextSiblingElement("sound")) { bool bPlaySoundImmediately = true; const char* cType = sound->Attribute("type"); if(cType) { string sType = cType; if(sType == "newhigh") //I have no idea how this happens, but apparently the highest tile can be this before it even returns. Wat bPlaySoundImmediately = ((m_highestTile == NULL) || (m_highestTile->value < ret->value)); } //Save all sfx if there's multiple vector<string> vSounds; for(XMLElement* fx = sound->FirstChildElement("fx"); fx != NULL; fx = fx->NextSiblingElement("fx")) { const char* cPath = fx->Attribute("path"); const char* cName = fx->Attribute("name"); if(cPath && cName) { createSound(cPath, cName); vSounds.push_back(cName); } } //Play one of these randomly if(vSounds.size() && bPlaySoundImmediately) playSound(vSounds[randInt(0, vSounds.size() - 1)], m_fVoxVolume); } physSegment* tmpseg = new physSegment(); int which = randInt(0, vImages.size()-1); tmpseg->img = vImages[which]; tmpseg->size = Point(TILE_WIDTH,TILE_HEIGHT); ret->seg = tmpseg; tmpseg = new physSegment(); tmpseg->img = getImage("res/tiles/tilebg.png"); tmpseg->size = Point(TILE_WIDTH,TILE_HEIGHT); const char* cBgColor = root->Attribute("bgcolor"); if(cBgColor != NULL) tmpseg->col = colorFromString(cBgColor); ret->bg = tmpseg; ret->origCol = tmpseg->col; delete doc; return ret; }