#include <QtGui/QApplication>
#include <QtCore/QDebug>
#include <QtCore/QFile>
-#include <QtGui/QGraphicsView>
#include <QtGui/QGraphicsScene>
#include <QtGui/QGraphicsTextItem>
#include <QtGui/QGraphicsPolygonItem>
{
titleclass=new Title( QString( c ) );
}
- void refresh_kdenlivetitle( uint8_t* buffer, int width, int height , double position, char *templatexml, char *templatetext )
+ void refresh_kdenlivetitle( uint8_t* buffer, int width, int height , double position, char *templatexml, char *templatetext, int force_refresh )
{
+ if (force_refresh) titleclass->reloadXml(templatexml, templatetext);
titleclass->drawKdenliveTitle( buffer, width, height, position, templatexml, templatetext );
}
}
-Title::Title( const QString& filename ):m_filename( filename ),m_scene( NULL )
+
+Title::Title( const QString& filename ):m_filename( filename ), sceneLoaded( false )
{
//must be extracted from kdenlive title
- start =new QGraphicsPolygonItem( QPolygonF( QRectF( 100, 100, 600, 600 ) ) );
- ;
- end=new QGraphicsPolygonItem( QPolygonF( QRectF( 0, 0, 300, 300 ) ) );
- ;
+ /*m_start( QPolygonF( QRectF( 100, 100, 600, 600 ) ) );
+ m_end( QPolygonF( QRectF( 0, 0, 300, 300 ) ) );*/
+}
+
+void Title::reloadXml(char *templatexml, char *templatetext)
+{
+ loadDocument( m_filename, QString( templatexml ), QString( templatetext ) );
}
+
void Title::drawKdenliveTitle( uint8_t * buffer, int width, int height, double position, char *templatexml, char *templatetext )
{
- if ( !m_scene )
+ if ( !sceneLoaded )
{
int argc=0;
char* argv[1];
if ( ! QApplication::activeWindow() )
//if (!app)
app=new QApplication( argc,argv );
- m_scene=new QGraphicsScene;
- loadDocument( m_filename, start, end, QString( templatexml ), QString( templatetext ) );
+ loadDocument( m_filename, QString( templatexml ), QString( templatetext ) );
}
//must be extracted from kdenlive title
QImage *img=new QImage( width,height,QImage::Format_ARGB32 );
img->fill( 0 );
- QRectF rstart=start->boundingRect();
- QRectF rend=end->boundingRect();
- QPointF topleft=rstart.topLeft()+( rend.topLeft()-rstart.topLeft() )*position;
- QPointF bottomRight=rstart.bottomRight()+( rend.bottomRight()-rstart.bottomRight() )*position;
QPainter p1;
p1.begin( img );
p1.setRenderHints( QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::HighQualityAntialiasing );//|QPainter::SmoothPixmapTransform );
- m_scene->render( &p1,QRect( 0,0,width,height ),QRectF( topleft,bottomRight ) );
+
+ if (m_start.polygon().isEmpty() && m_end.polygon().isEmpty()) {
+ m_scene.render( &p1,QRect( 0, 0, width, height ) );
+ }
+ else {
+ QRectF rstart=m_start.boundingRect();
+ QRectF rend=m_end.boundingRect();
+ QPointF topleft=rstart.topLeft()+( rend.topLeft()-rstart.topLeft() )*position;
+ QPointF bottomRight=rstart.bottomRight()+( rend.bottomRight()-rstart.bottomRight() )*position;
+ m_scene.render( &p1,QRect( 0,0,width,height ),QRectF( topleft,bottomRight ) );
+ }
p1.end();
uint8_t *pointer=img->bits();
QRgb* src = ( QRgb* ) pointer;
}
delete img;
}
-int Title::loadDocument( const QString& url, QGraphicsPolygonItem* startv, QGraphicsPolygonItem* endv, const QString templateXml, const QString templateText )
+
+int Title::loadDocument( const QString& url, const QString templateXml, const QString templateText )
{
QDomDocument doc;
- if ( !m_scene )
- return -1;
+ sceneLoaded = true;
if ( !templateXml.isEmpty() )
{
doc.setContent( templateXml );
file.close();
}
}
- return loadFromXml( doc, startv, endv, templateText );
+ return loadFromXml( doc, templateText );
}
-int Title::loadFromXml( QDomDocument doc, QGraphicsPolygonItem* startv, QGraphicsPolygonItem* endv, const QString templateText )
+int Title::loadFromXml( QDomDocument doc, const QString templateText )
{
+ m_scene.clear();
QDomNodeList titles = doc.elementsByTagName( "kdenlivetitle" );
int maxZValue = 0;
if ( titles.size() )
{
QString text = items.item( i ).namedItem( "content" ).firstChild().nodeValue();
text = text.replace( "%s", templateText );
- txt = m_scene->addText( text, font );
+ txt = m_scene.addText( text, font );
}
- else txt = m_scene->addText( items.item( i ).namedItem( "content" ).firstChild().nodeValue(), font );
+ else txt = m_scene.addText( items.item( i ).namedItem( "content" ).firstChild().nodeValue(), font );
txt->setDefaultTextColor( col );
txt->setTextInteractionFlags( Qt::NoTextInteraction );
if ( txtProperties.namedItem( "alignment" ).isNull() == false )
QString br_str = items.item( i ).namedItem( "content" ).attributes().namedItem( "brushcolor" ).nodeValue();
QString pen_str = items.item( i ).namedItem( "content" ).attributes().namedItem( "pencolor" ).nodeValue();
double penwidth = items.item( i ).namedItem( "content" ).attributes().namedItem( "penwidth" ).nodeValue().toDouble();
- QGraphicsRectItem *rec = m_scene->addRect( stringToRect( rect ), QPen( QBrush( stringToColor( pen_str ) ), penwidth ), QBrush( stringToColor( br_str ) ) );
+ QGraphicsRectItem *rec = m_scene.addRect( stringToRect( rect ), QPen( QBrush( stringToColor( pen_str ) ), penwidth ), QBrush( stringToColor( br_str ) ) );
gitem = rec;
}
else if ( items.item( i ).attributes().namedItem( "type" ).nodeValue() == "QGraphicsPixmapItem" )
{
QString url = items.item( i ).namedItem( "content" ).attributes().namedItem( "url" ).nodeValue();
QPixmap pix( url );
- QGraphicsPixmapItem *rec = m_scene->addPixmap( pix );
+ QGraphicsPixmapItem *rec = m_scene.addPixmap( pix );
rec->setData( Qt::UserRole, url );
gitem = rec;
}
{
QString url = items.item( i ).namedItem( "content" ).attributes().namedItem( "url" ).nodeValue();
//QGraphicsSvgItem *rec = new QGraphicsSvgItem(url);
- //m_scene->addItem(rec);
+ //m_scene.addItem(rec);
//rec->setData(Qt::UserRole, url);
//gitem = rec;
}
{
QColor color = QColor( stringToColor( items.item( i ).attributes().namedItem( "color" ).nodeValue() ) );
//color.setAlpha(items.item(i).attributes().namedItem("alpha").nodeValue().toInt());
- QList<QGraphicsItem *> items = m_scene->items();
+ QList<QGraphicsItem *> items = m_scene.items();
for ( int i = 0; i < items.size(); i++ )
{
if ( items.at( i )->zValue() == -1100 )
}
}
}
- else if ( items.item( i ).nodeName() == "startviewport" && startv )
+ else if ( items.item( i ).nodeName() == "startviewport" )
{
QString rect = items.item( i ).attributes().namedItem( "rect" ).nodeValue();
- startv->setPolygon( stringToRect( rect ) );
+ m_start.setPolygon( stringToRect( rect ) );
}
- else if ( items.item( i ).nodeName() == "endviewport" && endv )
+ else if ( items.item( i ).nodeName() == "endviewport" )
{
QString rect = items.item( i ).attributes().namedItem( "rect" ).nodeValue();
- endv->setPolygon( stringToRect( rect ) );
+ m_end.setPolygon( stringToRect( rect ) );
}
}
}
extern void init_qt();
-extern void refresh_kdenlivetitle( uint8_t*, int, int, double, char*, char* );
+extern void refresh_kdenlivetitle( uint8_t*, int, int, double, char*, char*, int );
static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_format *format, int *width, int *height, int writable )
{
mlt_producer producer = mlt_properties_get_data( properties, "producer_kdenlivetitle", NULL );
// Obtain properties of producer
- // save extra data
- //mlt_properties producer_props = MLT_PRODUCER_PROPERTIES( producer );
+ mlt_properties producer_props = MLT_PRODUCER_PROPERTIES( producer );
+
// Allocate the image
int size = *width * ( *height ) * 4;
mlt_position out = mlt_producer_get_out( producer );
mlt_position time = mlt_frame_get_position( frame );
double position = ( double )( time - in ) / ( double )( out - in + 1 );
- refresh_kdenlivetitle( *buffer, *width, *height, position, mlt_properties_get( MLT_PRODUCER_PROPERTIES( producer ), "templatexml" ), mlt_properties_get( MLT_PRODUCER_PROPERTIES( producer ), "templatetext" ) );
+ if ( mlt_properties_get_int( producer_props, "force_reload" ) ) {
+ refresh_kdenlivetitle( *buffer, *width, *height, position, mlt_properties_get( producer_props, "xmldata" ), mlt_properties_get( producer_props, "templatetext" ), 1);
+ mlt_properties_set_int( producer_props, "force_reload", 0 );
+ }
+ else refresh_kdenlivetitle( *buffer, *width, *height, position, mlt_properties_get( producer_props, "xmldata" ), mlt_properties_get( producer_props, "templatetext" ), 0);
mlt_log_debug( MLT_PRODUCER_SERVICE( producer ), "width:%d height:%d %s\n", *width, *height, mlt_image_format_name( *format ) );
}
this->close = ( mlt_destructor ) producer_close;
mlt_properties properties = MLT_PRODUCER_PROPERTIES( this );
mlt_properties_set( properties, "resource", arg );
-
}
return this;