]> git.sesse.net Git - kdenlive/blobdiff - src/dvdwizardmenu.cpp
Rewrote DVD creation, should now support correctly 4:3 and 16:9 menus, letterbox...
[kdenlive] / src / dvdwizardmenu.cpp
index 38ac05a719ee74df68a56523817680411d6a3736..ca8af2a85828e827c21055a67007aef84ccd351b 100644 (file)
 
 #include "kthumb.h"
 
-DvdWizardMenu::DvdWizardMenu(const QString &profile, QWidget *parent) :
+DvdWizardMenu::DvdWizardMenu(DVDFORMAT format, QWidget *parent) :
         QWizardPage(parent),
         m_color(NULL),
         m_safeRect(NULL),
-        m_finalSize(720, 576)
+        m_finalSize(720, 576),
+        m_movieLength(-1)
 {
     m_view.setupUi(this);
     m_view.play_text->setText(i18n("Play"));
@@ -60,9 +61,7 @@ DvdWizardMenu::DvdWizardMenu(const QString &profile, QWidget *parent) :
     m_view.add_button->setToolTip(i18n("Add new button"));
     m_view.delete_button->setToolTip(i18n("Delete current button"));
 
-    if (profile == "dv_ntsc" || profile == "dv_ntsc_wide") {
-        changeProfile(false);
-    } else changeProfile(true);
+    changeProfile(format);
 
 
     // Create color background
@@ -329,10 +328,10 @@ void DvdWizardMenu::addButton()
 #endif
     //font.setStyleStrategy(QFont::NoAntialias);
     button->setFont(font);
+    button->setDefaultTextColor(m_view.text_color->color());
     button->setZValue(4);
     QRectF r = button->sceneBoundingRect();
     m_scene->addItem(button);
-    updateColor(m_view.text_color->color());
     button->setPos((m_width - r.width()) / 2, (m_height - r.height()) / 2);
     button->setSelected(true);
 }
@@ -348,17 +347,29 @@ void DvdWizardMenu::deleteButton()
     }
 }
 
-void DvdWizardMenu::changeProfile(bool isPal)
-{
-    m_isPal = isPal;
-    if (isPal == false) {
-       m_finalSize = QSize(720, 480);
-        m_width = 640;
-        m_height = 480;
-    } else {
-       m_finalSize = QSize(720, 576);
-        m_width = 768;
-        m_height = 576;
+void DvdWizardMenu::changeProfile(DVDFORMAT format)
+{
+    m_format = format;
+    switch (m_format) {
+       case PAL_WIDE:
+           m_finalSize = QSize(720, 576);
+           m_width = 1024;
+           m_height = 576;
+           break;
+       case NTSC_WIDE:
+           m_finalSize = QSize(720, 480);
+           m_width = 853;
+           m_height = 480;
+           break;
+       case NTSC:
+           m_finalSize = QSize(720, 480);
+           m_width = 640;
+           m_height = 480;
+           break;
+       default:
+           m_finalSize = QSize(720, 576);
+           m_width = 768;
+           m_height = 576;
     }
     updatePreview();
 }
@@ -441,11 +452,15 @@ void DvdWizardMenu::buildImage()
         pix = pix.scaled(m_width, m_height);
     } else if (m_view.background_list->currentIndex() == 2) {
         // video background
-        int w;
-        if (m_isPal) w = 768;
-        else w = 640;
-        pix = KThumb::getImage(m_view.background_image->url(), 0, w, m_height);
-        pix = pix.scaled(m_width, m_height);
+        m_movieLength = -1;
+       Mlt::Profile profile;
+       profile.set_explicit(false);
+       Mlt::Producer *producer = new Mlt::Producer(profile, m_view.background_image->url().path().toUtf8().data());
+       if (producer && producer->is_valid()) {
+           pix = QPixmap::fromImage(KThumb::getFrame(producer, 0, m_finalSize.width(), m_width, m_height));
+           m_movieLength = producer->get_length();
+       }
+       if (producer) delete producer;
     }
     m_background->setPixmap(pix);
     m_scene->addItem(m_background);
@@ -552,10 +567,19 @@ void DvdWizardMenu::updateColor(QColor c)
 }
 
 
-void DvdWizardMenu::createButtonImages(const QString &img1, const QString &img2, const QString &img3)
+void DvdWizardMenu::createButtonImages(const QString &img1, const QString &img2, const QString &img3, bool letterbox)
 {
     if (m_view.create_menu->isChecked()) {
         m_scene->clearSelection();
+       QRectF source(0, 0, m_width, m_height);
+       QRectF target;
+       if (!letterbox) target = QRectF(0, 0, m_finalSize.width(), m_finalSize.height());
+       else {
+           // Scale the button images to fit a letterbox image
+           double factor = (double) m_width / m_finalSize.width();
+           int letterboxHeight = m_height / factor;
+           target = QRectF(0, (m_finalSize.height() - letterboxHeight) / 2, m_finalSize.width(), letterboxHeight);
+       }
         if (m_safeRect->scene() != 0) m_scene->removeItem(m_safeRect);
         if (m_color->scene() != 0) m_scene->removeItem(m_color);
         if (m_background->scene() != 0) m_scene->removeItem(m_background);
@@ -572,7 +596,7 @@ void DvdWizardMenu::createButtonImages(const QString &img1, const QString &img2,
         QPainter p(&img);
         //p.setRenderHints(QPainter::Antialiasing, false);
         //p.setRenderHints(QPainter::TextAntialiasing, false);
-        m_scene->render(&p, QRectF(0, 0, m_finalSize.width(), m_finalSize.height()), QRectF(0, 0, m_width, m_height), Qt::IgnoreAspectRatio);
+        m_scene->render(&p, target, source, Qt::IgnoreAspectRatio);
         p.end();
 #if QT_VERSION >= 0x040800
 #elif QT_VERSION >= 0x040600 
@@ -592,7 +616,7 @@ void DvdWizardMenu::createButtonImages(const QString &img1, const QString &img2,
         p.begin(&img);
         //p.setRenderHints(QPainter::Antialiasing, false);
         //p.setRenderHints(QPainter::TextAntialiasing, false);
-       m_scene->render(&p, QRectF(0, 0, m_finalSize.width(), m_finalSize.height()), QRectF(0, 0, m_width, m_height), Qt::IgnoreAspectRatio);
+       m_scene->render(&p, target, source, Qt::IgnoreAspectRatio);
         p.end();
 #if QT_VERSION >= 0x040800
 #elif QT_VERSION >= 0x040600
@@ -612,7 +636,7 @@ void DvdWizardMenu::createButtonImages(const QString &img1, const QString &img2,
        p.begin(&img);
         //p.setRenderHints(QPainter::Antialiasing, false);
         //p.setRenderHints(QPainter::TextAntialiasing, false);
-        m_scene->render(&p, QRectF(0, 0, m_finalSize.width(), m_finalSize.height()), QRectF(0, 0, m_width, m_height), Qt::IgnoreAspectRatio);
+        m_scene->render(&p, target, source, Qt::IgnoreAspectRatio);
         p.end();
 #if QT_VERSION >= 0x040800
 #elif QT_VERSION >= 0x040600
@@ -634,7 +658,15 @@ void DvdWizardMenu::createBackgroundImage(const QString &overlayMenu, const QStr
 {
     m_scene->clearSelection();
     if (m_safeRect->scene() != 0) m_scene->removeItem(m_safeRect);
+    bool showBg = false;
     QImage img(m_width, m_height, QImage::Format_ARGB32);
+    if (menuMovie() && m_background->scene() != 0) {
+       showBg = true;
+       m_scene->removeItem(m_background);
+       if (m_color->scene() != 0) m_scene->removeItem(m_color);
+       if (m_safeRect->scene() != 0) m_scene->removeItem(m_safeRect);
+       img.fill(Qt::transparent);
+    }
     updateColor(m_view.text_color->color());
     QPainter p(&img);
     p.setRenderHints(QPainter::Antialiasing, true);
@@ -643,6 +675,10 @@ void DvdWizardMenu::createBackgroundImage(const QString &overlayMenu, const QStr
     p.end();
     img.save(img1);
     m_scene->addItem(m_safeRect);
+    if (showBg) {
+       m_scene->addItem(m_background);
+       m_scene->addItem(m_color);
+    }
     return;
        
   
@@ -694,17 +730,29 @@ QString DvdWizardMenu::menuMoviePath() const
     return m_view.background_image->url().path();
 }
 
+int DvdWizardMenu::menuMovieLength() const
+{
+  return m_movieLength;
+}
+
 
-QMap <QString, QRect> DvdWizardMenu::buttonsInfo()
+QMap <QString, QRect> DvdWizardMenu::buttonsInfo(bool letterbox)
 {
     QMap <QString, QRect> info;
     QList<QGraphicsItem *> list = m_scene->items();
-    double ratio = (double) m_finalSize.width() / m_width;
+    double ratiox = (double) m_finalSize.width() / m_width;
+    double ratioy = 1;
+    int offset = 0;
+    if (letterbox) {
+       int letterboxHeight = m_height * ratiox;
+       ratioy = (double) letterboxHeight / m_finalSize.height();
+       offset = (m_finalSize.height() - letterboxHeight) / 2;
+    }
     for (int i = 0; i < list.count(); i++) {
         if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
             DvdButton *button = static_cast < DvdButton* >(list.at(i));
            QRectF r = button->sceneBoundingRect();
-           QRect adjustedRect(r.x() * ratio, r.y(), r.width() * ratio, r.height());
+           QRect adjustedRect(r.x() * ratiox, offset + r.y() * ratioy, r.width() * ratiox, r.height() * ratioy);
            // Make sure y1 is not odd (requested by spumux)
             if (adjustedRect.height() % 2 == 1) adjustedRect.setHeight(adjustedRect.height() + 1);
             if (adjustedRect.y() % 2 == 1) adjustedRect.setY(adjustedRect.y() - 1);
@@ -716,11 +764,6 @@ QMap <QString, QRect> DvdWizardMenu::buttonsInfo()
     return info;
 }
 
-bool DvdWizardMenu::isPalMenu() const
-{
-    return m_isPal;
-}
-
 QDomElement DvdWizardMenu::toXml() const
 {
     QDomDocument doc;