def setText(self, txt): if not self.labelFunction_: if QtWidgets.QApplication.multiLangEnabled() and txt: self.text_ = txt.decode("utf8") if self.text_ == txt: self.text_ = FLUtil.translate(self, "app", txt) else: self.text_ = txt else: dni = 0 argList = QtCore.QSArgumentList() argList << txt if self.domNodeData_ and not self.domNodeData_.isNull(): dni = FLDomDocument(self.domNodeData_) argList << dni v = self.labelFunction_(*argList) if v: txtFun = str(v) if QtWidgets.QApplication.multiLangEnabled() and txtFun: self.text_ = txtFun.decode("utf8") if self.text_ == txtFun: self.text_ = FLUtil.translate(self, "app", txtFun) else: self.text_ = txtFun if dni: del dni
def draw(self, p): if not self.paintFunction_: dni = 0 argList = QtCore.QSArgumentList() argList << self.text_ if self.domNodeData_ and not self.domNodeData_.isNull(): dni = FLDomDocument(self.domNodeData_) argList << dni v = self.paintFunction_(*argList) tp = type(v) # if (tp != QSArgument::Invalid) { #FIXME if tp: pix = QtGui.QPixmap() if tp == QtCore.QSArgument.VoidPointer: vPix = QtGui.QPixmap(v.ptr()) if vPix: pix = vPix else: pix = v.toPixmap() if not pix.isNull() and self.drawPixmap(p, pix): return self.height_ if self.changeHeight_ else 0 if self.pixmap_ and self.pixmap_.isNull(): self.pixmap_ = None elif self.pixmap_ and self.drawPixmap(p, self.pixmap_): return self.height_ if self.changeHeight_ else 0 if False: # MAC #FIXME pass else: # LINUX/WIN32 originalHeight = self.height_ tf = 0 if self.hAlignment_ == self.HAlignment.Left: tf = QtGui.QPainter.AlignLeft elif self.hAlignment_ == self.HAlignment.Center: tf = QtGui.QPainter.AlignHCenter elif self.hAlignment_ == self.HAlignment.Right: tf = QtGui.QPainter.AlignRight if self.vAlignment_ == self.VAlignment.Top: tf = tf | QtGui.QPainter.AlignTop elif self.vAlignment_ == self.VAlignment.Bottom: tf = tf | QtGui.QPainter.AlignBottom elif self.vAlignment_ == self.VAlignment.Middle: tf = tf | QtGui.QPainter.AlignVCenter if self.wordWrap_: tf = tf | QtGui.QPainter.WordBreak fnt = QtGui.QFont() fnt.setFamily(self.fontFamily_) fnt.setPointSizeFloat(self.fontSize_) fnt.setWeight(self.fontWeight_) fnt.setItalic(self.fontItalic_) p.painter().setFont(fnt) retVal = 0 if self.changeHeight_: maxRect = p.painter().boundingRect(0, 0, self.width_, self.height_, tf, self.text_) if maxRect.height() > self.height_: self.height_ = maxRect.height() retVal = self.height_ self.drawBase(p) p.painter().setPen(self.foregroundColor_) restoreBg = False oldBgMode = QtGui.BGMode() oldBgColor = QtGui.QColor() if not self.transparent_: restoreBg = True oldBgMode = p.painter().backgroundMode() oldBgColor = p.painter().backgroundColor() p.painter().setBackgroundColor(self.backgroundColor_) p.painter().setBackgroundMode(Qt.OpaqueMode) if not p.drawText(self.text_, tf, self): restore = False if p.errCode() == FLStylePainter.IdNotFound: # p.painter().save(Qt.QObject.name()) p.painter().save(self.name()) p.applyTransforms() p.painter().translate(self.xpos_, self.ypos_) restore = True w = p.painter().fontMetrics().width(self.text_) afs = self.adjustFontSize_ if afs and not self.wordWrap_ and not self.changeHeight_: factor = float(self.width_) / float(w) if factor < 1.0: f = p.painter().font() f.setPointSizeFloat(f.pointSizeFloat() * factor) p.painter().setFont(f) if restore: p.painter().restore() if restoreBg: p.painter().setBackgroundMode(oldBgMode) p.painter().setBackgroundColor(oldBgColor) self.height_ = originalHeight return retVal