void QuickInterpreter::setVariable( QObject *context, const QString &func, const QSArgument &value ) { QSObject val; switch(value.type()) { case QSArgument::Variant: { QuickScriptVariant qsvar(this, value.variant()); if (qsvar.isNative()) val = qsvar.toNative(); else val = qsvar; break; } case QSArgument::QObjectPtr: val = wrap( value.qobject() ); break; case QSArgument::VoidPointer: qWarning( "QuickInterpreter::setVariable: don't know what to do with " "QSArgument::VoidPointer here..." ); return; default: return; } if (context) wrap(context).put(func, val); else env()->globalObject().put(func, val); }
/** Draws the label */ int MLabelObject::draw(FLStylePainter *p) { // Draw the pixmap if (!paintFunction.isEmpty()) { FLDomNodeInterface *dni = 0; QSArgumentList l; l << QVariant(text); if (!domNodeData.isNull()) { dni = new FLDomNodeInterface(domNodeData); l << dni; } QSArgument v = aqApp->call(paintFunction, l, 0); QSArgument::Type tp = v.type(); if (tp != QSArgument::Invalid) { QPixmap pix; if (tp == QSArgument::VoidPointer) { QPixmap *vPix = static_cast<QPixmap *>(v.ptr()); if (vPix) pix = *vPix; } else if (tp == QSArgument::Variant) pix = v.variant().toPixmap(); if (!pix.isNull() && drawPixmap(p, &pix)) return (changeHeight ? height : 0); } } if (pixmap && pixmap->isNull()) { delete pixmap; pixmap = 0; } else if (pixmap && drawPixmap(p, pixmap)) return (changeHeight ? height : 0); if (text.isEmpty()) { drawBase(p); return 0; } #if defined(Q_OS_MACX) FLStylePainter *pt = new FLStylePainter; int retVal = 0; uint originalHeight = height; QFont fnt; int tf; // Horizontal switch (hAlignment) { case MLabelObject::Left: tf = QPainter::AlignLeft; break; case MLabelObject::Center: tf = QPainter::AlignHCenter; break; case MLabelObject::Right: tf = QPainter::AlignRight; } // Vertical switch (vAlignment) { case MLabelObject::Top: tf = tf | QPainter::AlignTop; break; case MLabelObject::Bottom: tf = tf | QPainter::AlignBottom; break; case MLabelObject::Middle: tf = tf | QPainter::AlignVCenter; } // Word wrap if (wordWrap) tf = tf | QPainter::WordBreak; int nw = width * 4; int nh = height * 4; QPixmap pm(nw, nh); pm.fill(backgroundColor); pt->painter()->begin(&pm); fnt.setFamily(fontFamily); fnt.setPointSizeFloat(fontSize * 4); fnt.setWeight(fontWeight); fnt.setItalic(fontItalic); pt->painter()->setFont(fnt); if (changeHeight) { QRect maxRect(p->painter()->boundingRect(0, 0, nw, nh, tf, text)); if (maxRect.height() > height) { height = maxRect.height(); retVal = height; } } drawBase(pt); pt->painter()->setPen(foregroundColor); if (!transparent) { pt->painter()->setBackgroundColor(backgroundColor); pt->painter()->setBackgroundMode(Qt::OpaqueMode); } if (adjustFontSize && !wordWrap && !changeHeight) { float factor = (float)nw / (float)p->painter()->fontMetrics().width(text); if (factor < 1.0) { QFont f = p->painter()->font(); f.setPointSizeFloat(f.pointSizeFloat() * factor); p->painter()->setFont(f); } } pt->painter()->drawText(0, 0, nw, nh, tf, text); pt->painter()->end(); delete pt; drawPixmap(p, &pm); height = originalHeight; return retVal; #else int retVal = 0; uint originalHeight = height; QFont fnt; int tf; Qt::BGMode oldBgMode; QColor oldBgColor; bool restoreBg = false; // Horizontal switch (hAlignment) { case MLabelObject::Left: tf = QPainter::AlignLeft; break; case MLabelObject::Center: tf = QPainter::AlignHCenter; break; case MLabelObject::Right: tf = QPainter::AlignRight; } // Vertical switch (vAlignment) { case MLabelObject::Top: tf = tf | QPainter::AlignTop; break; case MLabelObject::Bottom: tf = tf | QPainter::AlignBottom; break; case MLabelObject::Middle: tf = tf | QPainter::AlignVCenter; } // Word wrap if (wordWrap) tf = tf | QPainter::WordBreak; fnt.setFamily(fontFamily); fnt.setPointSizeFloat(fontSize); fnt.setWeight(fontWeight); fnt.setItalic(fontItalic); p->painter()->setFont(fnt); if (changeHeight) { QRect maxRect(p->painter()->boundingRect(0, 0, width, height, tf, text)); if (maxRect.height() > height) { height = maxRect.height(); retVal = height; } } drawBase(p); p->painter()->setPen(foregroundColor); if (!transparent) { restoreBg = true; oldBgMode = p->painter()->backgroundMode(); oldBgColor = p->painter()->backgroundColor(); p->painter()->setBackgroundColor(backgroundColor); p->painter()->setBackgroundMode(Qt::OpaqueMode); } if (!p->drawText(text, tf, this)) { bool restore = false; if (p->errCode() == FLStylePainter::IdNotFound) { p->painter()->save(QObject::name()); p->applyTransforms(); p->painter()->translate(xpos, ypos); restore = true; } if (adjustFontSize && !wordWrap && !changeHeight) { float factor = (float)width / (float)p->painter()->fontMetrics().width(text); if (factor < 1.0) { QFont f = p->painter()->font(); f.setPointSizeFloat(f.pointSizeFloat() * factor); p->painter()->setFont(f); } } p->painter()->drawText(0, 0, width, height, tf, text); if (restore) p->painter()->restore(); } if (restoreBg) { p->painter()->setBackgroundMode(oldBgMode); p->painter()->setBackgroundColor(oldBgColor); } height = originalHeight; return retVal; #endif }