Example #1
0
	WeiboDialogPrivate() {
		api = new WeiboApi;
		qreal x = 6;
		QGraphicsTextItem *title = new QGraphicsTextItem(titleBar);
		title->setPos(x, 12);
		title->setDefaultTextColor(Qt::white);
		QFont f;
		f.setPixelSize(23);
		f.setBold(true);
		title->setFont(f);
		title->setPlainText(QObject::tr("New weibo (Sina)"));
		qreal w = qApp->desktop()->width()/2 - 44;
		statusEdit = new TextEdit(central);
		statusEdit->setFont(f);
		statusEdit->setDefaultTextColor(Qt::blue);
		statusEdit->document()->setDocumentMargin(22);

		qreal y = 22;
		statusEdit->setPos(x, y);
		statusEdit->document()->setTextWidth(qApp->desktop()->width()/2 - 8);
		//statusEdit->setPlainText("Write something...");
        qreal h = qApp->desktop()->height()*0.618;
		statusEdit->resize(w, h);
		y += statusEdit->size().height() + 12;
		qreal hh = qMin<qreal>(qApp->desktop()->height()*0.314/2, 40); //TODO: calculate the line edit height
		f.setBold(true);
		QGraphicsTextItem *user = new QGraphicsTextItem(central);
        f.setPixelSize(20);
		user->setFont(f);
        user->document()->setDocumentMargin(4);
		user->setDefaultTextColor(QColor(33, 33, 33));
		user->setPlainText(QObject::tr("User"));
		user->setPos(x, y);
		userEdit = new TextEdit(central);
		userEdit->setPos(x + 120, y);
        userEdit->resize(w - 120, hh);
		userEdit->setDefaultTextColor(Qt::black);
        userEdit->document()->setDocumentMargin(11);
		userEdit->document()->setTextWidth(qApp->desktop()->width()/2 - 8);
        y += hh + 2;
		QGraphicsTextItem *passwd = new QGraphicsTextItem(central);
        passwd->setFont(f);
        passwd->document()->setDocumentMargin(4);
		passwd->setDefaultTextColor(QColor(33, 33, 33));
		passwd->setPlainText(QObject::tr("Password"));
		passwd->setPos(x, y);
		passwdEdit = new TextEdit(central);
		passwdEdit->setPos(x + 120, y);
        passwdEdit->resize(w - 120, hh);
		passwdEdit->setDefaultTextColor(Qt::black);
        passwdEdit->document()->setDocumentMargin(11);
		statusEdit->setTextInteractionFlags(Qt::TextEditorInteraction);
		userEdit->setTextInteractionFlags(Qt::TextEditorInteraction);
		passwdEdit->setTextInteractionFlags(Qt::TextEditorInteraction);

        f.setPixelSize(24);
        userEdit->setFont(f);
		passwdEdit->setFont(f);
		passwdEdit->setEchoMode(TextEdit::Password);
	}
Example #2
0
QGraphicsTextItem * GraphicsButton::decorateKey(const QRectF & cell,int group,int level) {
  QString text = m_keydef->getDecoration(group,level);
  QGraphicsTextItem * item = new QGraphicsTextItem(this);

  int scriptCount = 0;
  /// Get the script for the text and use it as CSS selector
  /// selectors are case insensitive
  ///
  QString script;
  if (text.size() == 1) {
    script = UcdScripts::getScript(text.at(0).unicode());
    if ( ! script.isEmpty()) {
      scriptCount = 1;
    }
  }
  else {
    script = UcdScripts::getScript(text,&scriptCount);
    if (scriptCount != 1) {
      script = "default";
    }
  }
  script = script.toCaseFolded();
  if (! m_css.isEmpty())
    item->document()->setDefaultStyleSheet(m_css);
  /// this stops Arabic being moved to the right
  QTextOption topt;
  topt.setTextDirection(Qt::LeftToRight);
  item->document()->setDefaultTextOption(topt);
  QString sep("<br/>");
  QString html;
  QStringList w = text.toHtmlEscaped().split(QChar(' '),QString::SkipEmptyParts);
  //  QFont f("Amiri",30);
  //  item->setFont(f);
  //  html = QString("<html><body><span class=\"%1\">%2</span></body></html>").arg(script).arg(text);
  html = QString("<span class=\"%1\">%2</span>").arg(script).arg(w.join("<br/>"));

  item->setHtml(html);//Html(html);

  QRectF wr = item->boundingRect();

  /// align the text centrally in its bounding rect
  qreal dx = cell.width() - wr.width();
  qreal dy = cell.height() - wr.height();


  if (m_keydef->centerText(group,level)) {
    dy = dy/2;
  }
  else {
    int vpos = m_keydef->getVerticalAdjust(group,level);
    dy += vpos;
  }

  item->setPos(cell.topLeft() + QPointF(dx/2,dy));//dy/2));
  item->setDefaultTextColor(m_textColor);
  this->setBrush(QBrush(m_backgroundUpColor));
  this->setPen(QPen(m_textColor));
  return item;
}
Example #3
0
void loadFromXml( mlt_producer producer, QGraphicsScene *scene, const char *templateXml, const char *templateText )
{
	scene->clear();
	mlt_properties producer_props = MLT_PRODUCER_PROPERTIES( producer );
	QDomDocument doc;
	QString data = QString::fromUtf8(templateXml);
	QString replacementText = QString::fromUtf8(templateText);
	doc.setContent(data);
	QDomElement title = doc.documentElement();

	// Check for invalid title
	if ( title.isNull() || title.tagName() != "kdenlivetitle" ) return;
	
	// Check title locale
	if ( title.hasAttribute( "LC_NUMERIC" ) ) {
	    QString locale = title.attribute( "LC_NUMERIC" );
	    QLocale::setDefault( locale );
	}
	
        int originalWidth;
        int originalHeight;
	if ( title.hasAttribute("width") ) {
            originalWidth = title.attribute("width").toInt();
            originalHeight = title.attribute("height").toInt();
            scene->setSceneRect(0, 0, originalWidth, originalHeight);
        }
        else {
            originalWidth = scene->sceneRect().width();
            originalHeight = scene->sceneRect().height();
        }
        if ( title.hasAttribute( "out" ) ) {
            mlt_properties_set_position( producer_props, "_animation_out", title.attribute( "out" ).toDouble() );
        }
        else {
            mlt_properties_set_position( producer_props, "_animation_out", mlt_producer_get_out( producer ) );
        }
        
	mlt_properties_set_int( producer_props, "_original_width", originalWidth );
	mlt_properties_set_int( producer_props, "_original_height", originalHeight );

	QDomNode node;
	QDomNodeList items = title.elementsByTagName("item");
        for ( int i = 0; i < items.count(); i++ )
	{
		QGraphicsItem *gitem = NULL;
		node = items.item( i );
		QDomNamedNodeMap nodeAttributes = node.attributes();
		int zValue = nodeAttributes.namedItem( "z-index" ).nodeValue().toInt();
		if ( zValue > -1000 )
		{
			if ( nodeAttributes.namedItem( "type" ).nodeValue() == "QGraphicsTextItem" )
			{
				QDomNamedNodeMap txtProperties = node.namedItem( "content" ).attributes();
				QFont font( txtProperties.namedItem( "font" ).nodeValue() );
				QDomNode propsNode = txtProperties.namedItem( "font-bold" );
				if ( !propsNode.isNull() )
				{
					// Old: Bold/Not bold.
					font.setBold( propsNode.nodeValue().toInt() );
				}
				else
				{
					// New: Font weight (QFont::)
					font.setWeight( txtProperties.namedItem( "font-weight" ).nodeValue().toInt() );
				}
				font.setItalic( txtProperties.namedItem( "font-italic" ).nodeValue().toInt() );
				font.setUnderline( txtProperties.namedItem( "font-underline" ).nodeValue().toInt() );
				// Older Kdenlive version did not store pixel size but point size
				if ( txtProperties.namedItem( "font-pixel-size" ).isNull() )
				{
					QFont f2;
					f2.setPointSize( txtProperties.namedItem( "font-size" ).nodeValue().toInt() );
					font.setPixelSize( QFontInfo( f2 ).pixelSize() );
				}
				else
					font.setPixelSize( txtProperties.namedItem( "font-pixel-size" ).nodeValue().toInt() );
				QColor col( stringToColor( txtProperties.namedItem( "font-color" ).nodeValue() ) );
				QString text = node.namedItem( "content" ).firstChild().nodeValue();
				if ( !replacementText.isEmpty() )
				{
					text = text.replace( "%s", replacementText );
				}
				QGraphicsTextItem *txt = scene->addText(text, font);
				if (txtProperties.namedItem("font-outline").nodeValue().toDouble()>0.0){
					QTextDocument *doc = txt->document();
					// Make sure some that the text item does not request refresh by itself
					doc->blockSignals(true);
					QTextCursor cursor(doc);
					cursor.select(QTextCursor::Document);
					QTextCharFormat format;
					format.setTextOutline(
							QPen(QColor( stringToColor( txtProperties.namedItem( "font-outline-color" ).nodeValue() ) ),
							txtProperties.namedItem("font-outline").nodeValue().toDouble(),
							Qt::SolidLine,Qt::RoundCap,Qt::RoundJoin)
					);
					format.setForeground(QBrush(col));

					cursor.mergeCharFormat(format);
				} else {
					txt->setDefaultTextColor( col );
				}
				
				// Effects
				if (!txtProperties.namedItem( "typewriter" ).isNull()) {
					// typewriter effect
					mlt_properties_set_int( producer_props, "_animated", 1 );
					QStringList effetData = QStringList() << "typewriter" << text << txtProperties.namedItem( "typewriter" ).nodeValue();
					txt->setData(0, effetData);
					if ( !txtProperties.namedItem( "textwidth" ).isNull() )
						txt->setData( 1, txtProperties.namedItem( "textwidth" ).nodeValue() );
				}
				
				if ( txtProperties.namedItem( "alignment" ).isNull() == false )
				{
					txt->setTextWidth( txt->boundingRect().width() );
					QTextOption opt = txt->document()->defaultTextOption ();
					opt.setAlignment(( Qt::Alignment ) txtProperties.namedItem( "alignment" ).nodeValue().toInt() );
					txt->document()->setDefaultTextOption (opt);
				}
					if ( !txtProperties.namedItem( "kdenlive-axis-x-inverted" ).isNull() )
				{
					//txt->setData(OriginXLeft, txtProperties.namedItem("kdenlive-axis-x-inverted").nodeValue().toInt());
				}
				if ( !txtProperties.namedItem( "kdenlive-axis-y-inverted" ).isNull() )
				{
					//txt->setData(OriginYTop, txtProperties.namedItem("kdenlive-axis-y-inverted").nodeValue().toInt());
				}
					gitem = txt;
			}
			else if ( nodeAttributes.namedItem( "type" ).nodeValue() == "QGraphicsRectItem" )
			{
				QString rect = node.namedItem( "content" ).attributes().namedItem( "rect" ).nodeValue();
				QString br_str = node.namedItem( "content" ).attributes().namedItem( "brushcolor" ).nodeValue();
				QString pen_str = node.namedItem( "content" ).attributes().namedItem( "pencolor" ).nodeValue();
				double penwidth = node.namedItem( "content" ).attributes().namedItem( "penwidth") .nodeValue().toDouble();
				QGraphicsRectItem *rec = scene->addRect( stringToRect( rect ), QPen( QBrush( stringToColor( pen_str ) ), penwidth, Qt::SolidLine, Qt::SquareCap, Qt::RoundJoin ), QBrush( stringToColor( br_str ) ) );
				gitem = rec;
			}
			else if ( nodeAttributes.namedItem( "type" ).nodeValue() == "QGraphicsPixmapItem" )
			{
				const QString url = node.namedItem( "content" ).attributes().namedItem( "url" ).nodeValue();
				const QString base64 = items.item(i).namedItem("content").attributes().namedItem("base64").nodeValue();
				QImage img;
				if (base64.isEmpty()){
					img.load(url);
				}else{
					img.loadFromData(QByteArray::fromBase64(base64.toAscii()));
				}
				ImageItem *rec = new ImageItem(img);
				scene->addItem( rec );
				gitem = rec;
			}
			else if ( nodeAttributes.namedItem( "type" ).nodeValue() == "QGraphicsSvgItem" )
			{
				QString url = items.item(i).namedItem("content").attributes().namedItem("url").nodeValue();
				QString base64 = items.item(i).namedItem("content").attributes().namedItem("base64").nodeValue();
				QGraphicsSvgItem *rec = NULL;
				if (base64.isEmpty()){
					rec = new QGraphicsSvgItem(url);
				}else{
					rec = new QGraphicsSvgItem();
					QSvgRenderer *renderer= new QSvgRenderer(QByteArray::fromBase64(base64.toAscii()), rec );
					rec->setSharedRenderer(renderer);
				}
				if (rec){
					scene->addItem(rec);
					gitem = rec;
				}
			}
		}
		//pos and transform
		if ( gitem )
		{
			QPointF p( node.namedItem( "position" ).attributes().namedItem( "x" ).nodeValue().toDouble(),
			           node.namedItem( "position" ).attributes().namedItem( "y" ).nodeValue().toDouble() );
			gitem->setPos( p );
			gitem->setTransform( stringToTransform( node.namedItem( "position" ).firstChild().firstChild().nodeValue() ) );
			int zValue = nodeAttributes.namedItem( "z-index" ).nodeValue().toInt();
			gitem->setZValue( zValue );

#if QT_VERSION >= 0x040600
			// effects
			QDomNode eff = items.item(i).namedItem("effect");
			if (!eff.isNull()) {
				QDomElement e = eff.toElement();
				if (e.attribute("type") == "blur") {
					QGraphicsBlurEffect *blur = new QGraphicsBlurEffect();
					blur->setBlurRadius(e.attribute("blurradius").toInt());
					gitem->setGraphicsEffect(blur);
				}
				else if (e.attribute("type") == "shadow") {
					QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect();
					shadow->setBlurRadius(e.attribute("blurradius").toInt());
					shadow->setOffset(e.attribute("xoffset").toInt(), e.attribute("yoffset").toInt());
					gitem->setGraphicsEffect(shadow);
				}
			}
#endif
		}
	}

	QDomNode n = title.firstChildElement("background");
	if (!n.isNull()) {
		QColor color = QColor( stringToColor( n.attributes().namedItem( "color" ).nodeValue() ) );
                if (color.alpha() > 0) {
                        QGraphicsRectItem *rec = scene->addRect(0, 0, scene->width(), scene->height() , QPen( Qt::NoPen ), QBrush( color ) );
                        rec->setZValue(-1100);
                }
	  
	}

	QString startRect;
	n = title.firstChildElement( "startviewport" );
        // Check if node exists, if it has an x attribute, it is an old version title, don't use viewport
	if (!n.isNull() && !n.toElement().hasAttribute("x"))
	{
		startRect = n.attributes().namedItem( "rect" ).nodeValue();
	}
	n = title.firstChildElement( "endviewport" );
        // Check if node exists, if it has an x attribute, it is an old version title, don't use viewport
	if (!n.isNull() && !n.toElement().hasAttribute("x"))
	{
		QString rect = n.attributes().namedItem( "rect" ).nodeValue();
		if (startRect != rect)
			mlt_properties_set( producer_props, "_endrect", rect.toUtf8().data() );
	}
	if (!startRect.isEmpty()) {
	  	mlt_properties_set( producer_props, "_startrect", startRect.toUtf8().data() );
	}
	return;
}