]> git.sesse.net Git - mlt/blobdiff - src/modules/qimage/kdenlivetitle_wrapper.cpp
Add support for Qt 5, drop support for Qt 3 and KDE 3.
[mlt] / src / modules / qimage / kdenlivetitle_wrapper.cpp
index 54469905ad0beadba8eb20fbec94da9ca98c137a..2d5bc4d6bf0df243cebfbc52348a552213771f4a 100755 (executable)
 
 #include "kdenlivetitle_wrapper.h"
 
-#include <QtGui/QImage>
-#include <QtGui/QPainter>
-#include <QtCore/QDebug>
-#include <QtGui/QApplication>
-#include <QtCore/QMutex>
-#include <QtGui/QGraphicsScene>
-#include <QtGui/QGraphicsTextItem>
-#include <QtSvg/QGraphicsSvgItem>
-#include <QtSvg/QSvgRenderer>
-#include <QtGui/QTextCursor>
-#include <QtGui/QTextDocument>
-#include <QtGui/QStyleOptionGraphicsItem>
-
-#include <QtCore/QString>
-
-#include <QtXml/QDomElement>
-#include <QtCore/QRectF>
-#include <QtGui/QColor>
-#include <QtGui/QWidget>
+#include <QImage>
+#include <QPainter>
+#include <QDebug>
+#include <QApplication>
+#include <QMutex>
+#include <QGraphicsScene>
+#include <QGraphicsTextItem>
+#include <QGraphicsSvgItem>
+#include <QSvgRenderer>
+#include <QTextCursor>
+#include <QTextDocument>
+#include <QStyleOptionGraphicsItem>
+
+#include <QString>
+
+#include <QDomElement>
+#include <QRectF>
+#include <QColor>
+#include <QWidget>
 #include <framework/mlt_log.h>
 
 #if QT_VERSION >= 0x040600
-#include <QtGui/QGraphicsEffect>
-#include <QtGui/QGraphicsBlurEffect>
-#include <QtGui/QGraphicsDropShadowEffect>
+#include <QGraphicsEffect>
+#include <QGraphicsBlurEffect>
+#include <QGraphicsDropShadowEffect>
 #endif
 
 static QApplication *app = NULL;
+Q_DECLARE_METATYPE(QTextCursor);
 
 class ImageItem: public QGraphicsItem
 {
@@ -197,8 +198,10 @@ void loadFromXml( mlt_producer producer, QGraphicsScene *scene, const char *temp
                                }
                                QGraphicsTextItem *txt = scene->addText(text, font);
                                if (txtProperties.namedItem("font-outline").nodeValue().toDouble()>0.0){
-                                       qRegisterMetaType<QTextCursor>( "QTextCursor" );
-                                       QTextCursor cursor(txt->document());
+                                       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(
@@ -219,6 +222,8 @@ void loadFromXml( mlt_producer producer, QGraphicsScene *scene, const char *temp
                                        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 )
@@ -255,7 +260,7 @@ void loadFromXml( mlt_producer producer, QGraphicsScene *scene, const char *temp
                                if (base64.isEmpty()){
                                        img.load(url);
                                }else{
-                                       img.loadFromData(QByteArray::fromBase64(base64.toAscii()));
+                                       img.loadFromData(QByteArray::fromBase64(base64.toLatin1()));
                                }
                                ImageItem *rec = new ImageItem(img);
                                scene->addItem( rec );
@@ -270,7 +275,7 @@ void loadFromXml( mlt_producer producer, QGraphicsScene *scene, const char *temp
                                        rec = new QGraphicsSvgItem(url);
                                }else{
                                        rec = new QGraphicsSvgItem();
-                                       QSvgRenderer *renderer= new QSvgRenderer(QByteArray::fromBase64(base64.toAscii()), rec );
+                                       QSvgRenderer *renderer= new QSvgRenderer(QByteArray::fromBase64(base64.toLatin1()), rec );
                                        rec->setSharedRenderer(renderer);
                                }
                                if (rec){
@@ -392,7 +397,6 @@ void drawKdenliveTitle( producer_ktitle self, mlt_frame frame, int width, int he
                                        {
                                                mlt_log_panic( MLT_PRODUCER_SERVICE( producer ), "Error, cannot render titles without an X11 environment.\nPlease either run melt from an X session or use a fake X server like xvfb:\nxvfb-run -a melt (...)\n" );
                                                pthread_mutex_unlock( &self->mutex );
-                                               exit(1);
                                                return;
                                        }
 #endif
@@ -400,6 +404,7 @@ void drawKdenliveTitle( producer_ktitle self, mlt_frame frame, int width, int he
                                        const char *localename = mlt_properties_get_lcnumeric( MLT_SERVICE_PROPERTIES( MLT_PRODUCER_SERVICE( producer ) ) );
                                        QLocale::setDefault( QLocale( localename ) );
                                }
+                               qRegisterMetaType<QTextCursor>( "QTextCursor" );
                        }
                        scene = new QGraphicsScene();
                        scene->setItemIndexMethod( QGraphicsScene::NoIndex );
@@ -441,16 +446,21 @@ void drawKdenliveTitle( producer_ktitle self, mlt_frame frame, int width, int he
                                    // the keystroke delay and a start offset, both in frames
                                    QStringList values = params.at( 2 ).split( ";" );
                                    int interval = qMax( 0, ( ( int ) position - values.at( 1 ).toInt()) / values.at( 0 ).toInt() );
-                                       qRegisterMetaType<QTextCursor>( "QTextCursor" );
-                                       QTextCursor cursor = titem->textCursor();
+                                   QTextCursor cursor = titem->textCursor();
                                    cursor.movePosition(QTextCursor::EndOfBlock);
                                    // get the font format
                                    QTextCharFormat format = cursor.charFormat();
                                    cursor.select(QTextCursor::Document);
                                    QString txt = params.at( 1 ).left( interval );
-                                   // If the string to insert is empty, insert a space so that we don't loose
+                                   // If the string to insert is empty, insert a space / linebreak so that we don't loose
                                    // formatting infos for the next iterations
-                                   cursor.insertText(txt.isEmpty() ? " " : txt, format);
+                                   int lines = params.at( 1 ).count( '\n' );
+                                   QString empty = " ";
+                                   for (int i = 0; i < lines; i++)
+                                           empty.append( "\n " );
+                                   cursor.insertText( txt.isEmpty() ? empty : txt, format );
+                                   if ( !titem->data( 1 ).isNull() )
+                                         titem->setTextWidth( titem->data( 1 ).toDouble() );
                            }
                    }
                }