]> git.sesse.net Git - kdenlive/blobdiff - src/dvdwizardmenu.cpp
Better to use nepomukcore
[kdenlive] / src / dvdwizardmenu.cpp
index fb162c89378850a422ce2ddce584a64d8c6b51c6..82e16c87817e72e64e3f1c5ae5403257e097ab33 100644 (file)
@@ -30,7 +30,9 @@
 
 #include "kthumb.h"
 
-DvdWizardMenu::DvdWizardMenu(const QString &profile, QWidget *parent) :
+enum { DvdButtonItem = QGraphicsItem::UserType + 1, DvdButtonUnderlineItem = QGraphicsItem::UserType + 2 };
+
+DvdWizardMenu::DvdWizardMenu(DVDFORMAT format, QWidget *parent) :
         QWizardPage(parent),
         m_color(NULL),
         m_safeRect(NULL),
@@ -44,14 +46,6 @@ DvdWizardMenu::DvdWizardMenu(const QString &profile, QWidget *parent) :
     m_view.menu_preview->setMouseTracking(true);
     connect(m_view.create_menu, SIGNAL(toggled(bool)), m_view.menu_box, SLOT(setEnabled(bool)));
     connect(m_view.create_menu, SIGNAL(toggled(bool)), this, SIGNAL(completeChanged()));
-    
-#if KDE_IS_VERSION(4,7,0)
-    m_menuMessage = new KMessageWidget;
-    QGridLayout *s =  static_cast <QGridLayout*> (layout());
-    s->addWidget(m_menuMessage, 7, 0, 1, -1);
-    m_menuMessage->hide();
-    m_view.error_message->hide();
-#endif
 
     m_view.add_button->setIcon(KIcon("document-new"));
     m_view.delete_button->setIcon(KIcon("trash-empty"));
@@ -61,9 +55,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
@@ -117,14 +109,14 @@ DvdWizardMenu::DvdWizardMenu(const QString &profile, QWidget *parent) :
 
     //m_view.menu_preview->resizefitInView(0, 0, m_width, m_height);
 
-    connect(m_view.play_text, SIGNAL(textChanged(const QString &)), this, SLOT(buildButton()));
-    connect(m_view.text_color, SIGNAL(changed(const QColor &)), this, SLOT(updateColor()));
+    connect(m_view.play_text, SIGNAL(textChanged(QString)), this, SLOT(buildButton()));
+    connect(m_view.text_color, SIGNAL(changed(QColor)), this, SLOT(updateColor()));
     connect(m_view.font_size, SIGNAL(valueChanged(int)), this, SLOT(buildButton()));
-    connect(m_view.font_family, SIGNAL(currentFontChanged(const QFont &)), this, SLOT(buildButton()));
-    connect(m_view.background_image, SIGNAL(textChanged(const QString &)), this, SLOT(buildImage()));
-    connect(m_view.background_color, SIGNAL(changed(const QColor &)), this, SLOT(buildColor()));
+    connect(m_view.font_family, SIGNAL(currentFontChanged(QFont)), this, SLOT(buildButton()));
+    connect(m_view.background_image, SIGNAL(textChanged(QString)), this, SLOT(buildImage()));
+    connect(m_view.background_color, SIGNAL(changed(QColor)), this, SLOT(buildColor()));
 
-    connect(m_view.background_list, SIGNAL(activated(int)), this, SLOT(checkBackgroundType(int)));
+    connect(m_view.background_list, SIGNAL(currentIndexChanged(int)), this, SLOT(checkBackgroundType(int)));
 
     connect(m_view.target_list, SIGNAL(activated(int)), this, SLOT(setButtonTarget(int)));
     connect(m_view.back_to_menu, SIGNAL(toggled(bool)), this, SLOT(setBackToMenu(bool)));
@@ -134,7 +126,7 @@ DvdWizardMenu::DvdWizardMenu(const QString &profile, QWidget *parent) :
     connect(m_view.zoom_button, SIGNAL(pressed()), this, SLOT(slotZoom()));
     connect(m_view.unzoom_button, SIGNAL(pressed()), this, SLOT(slotUnZoom()));
     connect(m_scene, SIGNAL(selectionChanged()), this, SLOT(buttonChanged()));
-    connect(m_scene, SIGNAL(changed(const QList<QRectF> &)), this, SIGNAL(completeChanged()));
+    connect(m_scene, SIGNAL(sceneChanged()), this, SIGNAL(completeChanged()));
 
     // red background for error message
     KColorScheme scheme(palette().currentColorGroup(), KColorScheme::Window, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
@@ -142,9 +134,16 @@ DvdWizardMenu::DvdWizardMenu(const QString &profile, QWidget *parent) :
     p.setColor(QPalette::Background, scheme.background(KColorScheme::NegativeBackground).color());
     m_view.error_message->setAutoFillBackground(true);
     m_view.error_message->setPalette(p);
-
     m_view.menu_box->setEnabled(false);
 
+#if KDE_IS_VERSION(4,7,0)
+    m_menuMessage = new KMessageWidget;
+    QGridLayout *s =  static_cast <QGridLayout*> (layout());
+    s->addWidget(m_menuMessage, 7, 0, 1, -1);
+    m_menuMessage->hide();
+    m_view.error_message->hide();
+#endif
+
 }
 
 DvdWizardMenu::~DvdWizardMenu()
@@ -159,8 +158,8 @@ void DvdWizardMenu::slotEnableShadows(int enable)
 {
 #if KDE_IS_VERSION(4,6,0)
     QList<QGraphicsItem *> list = m_scene->items();
-    for (int i = 0; i < list.count(); i++) {
-        if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
+    for (int i = 0; i < list.count(); ++i) {
+        if (list.at(i)->type() == DvdButtonItem) {
             if (enable) {
                QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this);
                shadow->setBlurRadius(7);
@@ -182,8 +181,8 @@ bool DvdWizardMenu::isComplete() const
     QList<QGraphicsItem *> list = m_scene->items();
     int buttonCount = 0;
     // check that the menu buttons don't collide
-    for (int i = 0; i < list.count(); i++) {
-        if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
+    for (int i = 0; i < list.count(); ++i) {
+        if (list.at(i)->type() == DvdButtonItem) {
             buttonCount++;
             DvdButton *button = static_cast < DvdButton* >(list.at(i));
             QList<QGraphicsItem *> collisions = button->collidingItems();
@@ -191,9 +190,9 @@ bool DvdWizardMenu::isComplete() const
                 for (int j = 0; j < collisions.count(); j++) {
                     if (collisions.at(j)->type() == button->type()) {
 #if KDE_IS_VERSION(4,7,0)
-                        m_menuMessage->setText(i18n("Buttons overlapping"));
-                        m_menuMessage->setMessageType(KMessageWidget::Warning);
-                        m_menuMessage->animatedShow();
+                       m_menuMessage->setText(i18n("Buttons overlapping"));
+                       m_menuMessage->setMessageType(KMessageWidget::Warning);
+                       m_menuMessage->show();
 #else
                         m_view.error_message->setText(i18n("Buttons overlapping"));
                         m_view.error_message->setHidden(false);
@@ -210,7 +209,7 @@ bool DvdWizardMenu::isComplete() const
 #if KDE_IS_VERSION(4,7,0)
         m_menuMessage->setText(i18n("No button in menu"));
         m_menuMessage->setMessageType(KMessageWidget::Warning);
-        m_menuMessage->animatedShow();
+        m_menuMessage->show();
 #else
         m_view.error_message->setText(i18n("No button in menu"));
         m_view.error_message->setHidden(false);
@@ -219,12 +218,12 @@ bool DvdWizardMenu::isComplete() const
     }
 
     if (!m_view.background_image->isHidden()) {
-        // Make sure user selected a valid image / video file
+        // Make sure user selected a valid image / video file
         if (!QFile::exists(m_view.background_image->url().path())) {
 #if KDE_IS_VERSION(4,7,0)
             m_menuMessage->setText(i18n("Missing background image"));
             m_menuMessage->setMessageType(KMessageWidget::Warning);
-            m_menuMessage->animatedShow();
+            m_menuMessage->show();
 #else
             m_view.error_message->setText(i18n("Missing background image"));
             m_view.error_message->setHidden(false);
@@ -234,19 +233,19 @@ bool DvdWizardMenu::isComplete() const
     }
     
 #if KDE_IS_VERSION(4,7,0)
-    m_menuMessage->animatedHide();
+    m_menuMessage->hide();
 #endif
 
     // check that we have a "Play all" entry
     if (targets.contains(0)) return true;
     // ... or that each video file has a button
-    for (int i = m_view.target_list->count() - 1; i > 0; i--) {
+    for (int i = m_view.target_list->count() - 1; i > 0; --i) {
         // If there is a vob file entry and it has no button assigned, don't allow to go further
         if (m_view.target_list->itemIcon(i).isNull() == false && !targets.contains(i)) {
 #if KDE_IS_VERSION(4,7,0)
             m_menuMessage->setText(i18n("No menu entry for %1", m_view.target_list->itemText(i)));
             m_menuMessage->setMessageType(KMessageWidget::Warning);
-            m_menuMessage->animatedShow();
+            m_menuMessage->show();
 #else
             m_view.error_message->setText(i18n("No menu entry for %1", m_view.target_list->itemText(i)));
             m_view.error_message->setHidden(false);
@@ -260,8 +259,8 @@ bool DvdWizardMenu::isComplete() const
 void DvdWizardMenu::setButtonTarget(int ix)
 {
     QList<QGraphicsItem *> list = m_scene->selectedItems();
-    for (int i = 0; i < list.count(); i++) {
-        if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
+    for (int i = 0; i < list.count(); ++i) {
+        if (list.at(i)->type() == DvdButtonItem) {
             DvdButton *button = static_cast < DvdButton* >(list.at(i));
             button->setTarget(ix, m_view.target_list->itemData(ix).toString());
             break;
@@ -273,8 +272,8 @@ void DvdWizardMenu::setButtonTarget(int ix)
 void DvdWizardMenu::setBackToMenu(bool backToMenu)
 {
     QList<QGraphicsItem *> list = m_scene->selectedItems();
-    for (int i = 0; i < list.count(); i++) {
-        if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
+    for (int i = 0; i < list.count(); ++i) {
+        if (list.at(i)->type() == DvdButtonItem) {
             DvdButton *button = static_cast < DvdButton* >(list.at(i));
             button->setBackMenu(backToMenu);
             break;
@@ -287,8 +286,8 @@ void DvdWizardMenu::buttonChanged()
 {
     QList<QGraphicsItem *> list = m_scene->selectedItems();
     bool foundButton = false;
-    for (int i = 0; i < list.count(); i++) {
-        if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
+    for (int i = 0; i < list.count(); ++i) {
+        if (list.at(i)->type() == DvdButtonItem) {
             m_view.play_text->blockSignals(true);
             m_view.font_size->blockSignals(true);
             m_view.font_family->blockSignals(true);
@@ -341,25 +340,37 @@ void DvdWizardMenu::addButton()
 void DvdWizardMenu::deleteButton()
 {
     QList<QGraphicsItem *> list = m_scene->selectedItems();
-    for (int i = 0; i < list.count(); i++) {
-        if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
+    for (int i = 0; i < list.count(); ++i) {
+        if (list.at(i)->type() == DvdButtonItem) {
             delete list.at(i);
             break;
         }
     }
 }
 
-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();
 }
@@ -384,7 +395,7 @@ void DvdWizardMenu::setTargets(QStringList list, QStringList targetlist)
     m_view.target_list->clear();
     m_view.target_list->addItem(i18n("Play All"), "jump title 1");
     int movieCount = 0;
-    for (int i = 0; i < list.count(); i++) {
+    for (int i = 0; i < list.count(); ++i) {
         if (targetlist.at(i).contains("chapter"))
             m_view.target_list->addItem(list.at(i), targetlist.at(i));
         else {
@@ -417,6 +428,7 @@ void DvdWizardMenu::checkBackgroundType(int ix)
             m_view.loop_movie->setVisible(true);
         }
     }
+    emit completeChanged();
 }
 
 void DvdWizardMenu::buildColor()
@@ -443,10 +455,10 @@ void DvdWizardMenu::buildImage()
     } else if (m_view.background_list->currentIndex() == 2) {
         // video background
         m_movieLength = -1;
-        QString standard = "dv_pal";
-        if (!m_isPal) standard = "dv_ntsc";
-       Mlt::Profile profile(standard.toUtf8().constData());
-       Mlt::Producer *producer = new Mlt::Producer(profile, m_view.background_image->url().path().toUtf8().data());
+       QString profileName = DvdWizardVob::getDvdProfile(m_format);
+       Mlt::Profile profile(profileName.toUtf8().constData());
+       profile.set_explicit(true);
+       Mlt::Producer *producer = new Mlt::Producer(profile, m_view.background_image->url().path().toUtf8().constData());
        if (producer && producer->is_valid()) {
            pix = QPixmap::fromImage(KThumb::getFrame(producer, 0, m_finalSize.width(), m_width, m_height));
            m_movieLength = producer->get_length();
@@ -470,8 +482,8 @@ void DvdWizardMenu::buildButton()
 {
     DvdButton *button = NULL;
     QList<QGraphicsItem *> list = m_scene->selectedItems();
-    for (int i = 0; i < list.count(); i++) {
-        if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
+    for (int i = 0; i < list.count(); ++i) {
+        if (list.at(i)->type() == DvdButtonItem) {
             button = static_cast < DvdButton* >(list.at(i));
             break;
         }
@@ -483,6 +495,8 @@ void DvdWizardMenu::buildButton()
     //font.setStyleStrategy(QFont::NoAntialias);
     button->setFont(font);
     button->setDefaultTextColor(m_view.text_color->color());
+    // Check for button overlapping in case we changed text / size
+    emit completeChanged();
 }
 
 void DvdWizardMenu::updateColor()
@@ -494,8 +508,8 @@ void DvdWizardMenu::updateColor()
 void DvdWizardMenu::prepareUnderLines()
 {
     QList<QGraphicsItem *> list = m_scene->items();
-    for (int i = 0; i < list.count(); i++) {
-        if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
+    for (int i = 0; i < list.count(); ++i) {
+        if (list.at(i)->type() == DvdButtonItem) {
            QRectF r = list.at(i)->sceneBoundingRect();
            int bottom = r.bottom() - 1;
            if (bottom % 2 == 1) bottom = bottom - 1;
@@ -504,9 +518,9 @@ void DvdWizardMenu::prepareUnderLines()
            underlineHeight = qMin(underlineHeight, 10);
            underlineHeight = qMax(underlineHeight, 2);
            r.setTop(bottom - underlineHeight);
+           r.setBottom(bottom);
            r.adjust(2, 0, -2, 0);
-           QGraphicsRectItem *underline = new QGraphicsRectItem(r);
-           underline->setData(Qt::UserRole, QString("underline"));
+           DvdButtonUnderline *underline = new DvdButtonUnderline(r);
            m_scene->addItem(underline);
            list.at(i)->setVisible(false);
        }
@@ -517,11 +531,11 @@ void DvdWizardMenu::resetUnderLines()
 {
     QList<QGraphicsItem *> list = m_scene->items();
     QList<QGraphicsItem *> toDelete;
-    for (int i = 0; i < list.count(); i++) {
-       if (list.at(i)->data(Qt::UserRole).toString() == "underline") {
+    for (int i = 0; i < list.count(); ++i) {
+       if (list.at(i)->type() == DvdButtonUnderlineItem) {
            toDelete.append(list.at(i));
        }
-        if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
+        if (list.at(i)->type() == DvdButtonItem) {
            list.at(i)->setVisible(true);
        }
     }
@@ -534,9 +548,9 @@ void DvdWizardMenu::resetUnderLines()
 void DvdWizardMenu::updateUnderlineColor(QColor c)
 {
     QList<QGraphicsItem *> list = m_scene->items();
-    for (int i = 0; i < list.count(); i++) {
-        if (list.at(i)->data(Qt::UserRole).toString() == "underline") {
-            QGraphicsRectItem *underline = static_cast < QGraphicsRectItem* >(list.at(i));
+    for (int i = 0; i < list.count(); ++i) {
+        if (list.at(i)->type() == DvdButtonUnderlineItem) {
+            DvdButtonUnderline *underline = static_cast < DvdButtonUnderline* >(list.at(i));
            underline->setPen(Qt::NoPen);
            c.setAlpha(150);
            underline->setBrush(c);
@@ -549,8 +563,8 @@ void DvdWizardMenu::updateColor(QColor c)
 {
     DvdButton *button = NULL;
     QList<QGraphicsItem *> list = m_scene->items();
-    for (int i = 0; i < list.count(); i++) {
-        if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
+    for (int i = 0; i < list.count(); ++i) {
+        if (list.at(i)->type() == DvdButtonItem) {
             button = static_cast < DvdButton* >(list.at(i));
             button->setDefaultTextColor(c);
         }
@@ -558,10 +572,19 @@ void DvdWizardMenu::updateColor(QColor c)
 }
 
 
-void DvdWizardMenu::createButtonImages(const QString &img1, const QString &img2, const QString &img3)
+void DvdWizardMenu::createButtonImages(const QString &selected_image, const QString &highlighted_image, 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);
@@ -569,36 +592,17 @@ void DvdWizardMenu::createButtonImages(const QString &img1, const QString &img2,
 #if QT_VERSION >= 0x040800
         QImage img(m_finalSize.width(), m_finalSize.height(), QImage::Format_ARGB32);
         img.fill(Qt::transparent);
-       updateUnderlineColor(m_view.text_color->color());
+       updateUnderlineColor(m_view.highlighted_color->color());
 #else
        QImage img(m_finalSize.width(), m_finalSize.height(), QImage::Format_Mono);
         img.fill(Qt::white);
        updateUnderlineColor(Qt::black);
 #endif
-        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);
-        p.end();
-#if QT_VERSION >= 0x040800
-#elif QT_VERSION >= 0x040600 
-        img.setColor(0, m_view.text_color->color().rgb());
-        img.setColor(1, qRgba(0,0,0,0));
-#else
-        img.setNumColors(4);
-#endif
-        img.save(img1);
-
-#if QT_VERSION >= 0x040800
-        img.fill(Qt::transparent);
-       updateUnderlineColor(m_view.highlighted_color->color());
-#else
-        img.fill(Qt::white);
-#endif
+       QPainter p;
         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
@@ -607,7 +611,7 @@ void DvdWizardMenu::createButtonImages(const QString &img1, const QString &img2,
 #else
         img.setNumColors(4);
 #endif
-        img.save(img3);
+        img.save(highlighted_image);
 
 #if QT_VERSION >= 0x040800
         img.fill(Qt::transparent);
@@ -618,7 +622,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
@@ -627,7 +631,7 @@ void DvdWizardMenu::createButtonImages(const QString &img1, const QString &img2,
 #else
         img.setNumColors(4);
 #endif
-        img.save(img2);
+        img.save(selected_image);
         resetUnderLines();
         m_scene->addItem(m_safeRect);
         m_scene->addItem(m_color);
@@ -636,17 +640,29 @@ void DvdWizardMenu::createButtonImages(const QString &img1, const QString &img2,
 }
 
 
-void DvdWizardMenu::createBackgroundImage(const QString &overlayMenu, const QString &img1)
+void DvdWizardMenu::createBackgroundImage(const QString &img1, bool letterbox)
 {
     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) {
+
+    //TODO: Should the image be scaled when letterboxing?
+    /*
+    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 (menuMovie()) {
        showBg = true;
-       m_scene->removeItem(m_background);
+       if (m_background->scene() != 0) 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());
@@ -654,6 +670,7 @@ void DvdWizardMenu::createBackgroundImage(const QString &overlayMenu, const QStr
     p.setRenderHints(QPainter::Antialiasing, true);
     p.setRenderHints(QPainter::TextAntialiasing, true);
     m_scene->render(&p, QRectF(0, 0, img.width(), img.height()));
+    //m_scene->render(&p, target, source, Qt::IgnoreAspectRatio);
     p.end();
     img.save(img1);
     m_scene->addItem(m_safeRect);
@@ -661,35 +678,6 @@ void DvdWizardMenu::createBackgroundImage(const QString &overlayMenu, const QStr
        m_scene->addItem(m_background);
        m_scene->addItem(m_color);
     }
-    return;
-       
-  
-    /*QImage img;
-    if (m_view.background_list->currentIndex() == 0) {
-        // color background
-        if (m_isPal)
-            img = QImage(768, 576, QImage::Format_ARGB32);
-        else
-            img = QImage(720, 540, QImage::Format_ARGB32);
-        img.fill(m_view.background_color->color().rgb());
-    } else if (m_view.background_list->currentIndex() == 1) {
-        img.load(m_view.background_image->url().path());
-        if (m_isPal) {
-            if (img.width() != 768 || img.height() != 576)
-                img = img.scaled(768, 576, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
-        } else {
-            if (img.width() != 720 || img.height() != 540)
-                img = img.scaled(720, 540, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
-        }
-    } else return;
-    // Overlay Normal menu
-    QImage menu(overlayMenu);
-    QPainter p(&img);
-    QRectF target(0, 0, img.width(), img.height());
-    QRectF src(0, 0, menu.width(), menu.height());
-    p.drawImage(target, menu, src);
-    p.end();
-    img.save(img1);*/
 }
 
 bool DvdWizardMenu::createMenu() const
@@ -718,16 +706,23 @@ int DvdWizardMenu::menuMovieLength() const
 }
 
 
-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;
-    for (int i = 0; i < list.count(); i++) {
-        if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
+    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() == DvdButtonItem) {
             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);
@@ -739,11 +734,6 @@ QMap <QString, QRect> DvdWizardMenu::buttonsInfo()
     return info;
 }
 
-bool DvdWizardMenu::isPalMenu() const
-{
-    return m_isPal;
-}
-
 QDomElement DvdWizardMenu::toXml() const
 {
     QDomDocument doc;
@@ -768,16 +758,16 @@ QDomElement DvdWizardMenu::toXml() const
     QList<QGraphicsItem *> list = m_scene->items();
     int buttonCount = 0;
 
-    for (int i = 0; i < list.count(); i++) {
-        if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
+    for (int i = 0; i < list.count(); ++i) {
+        if (list.at(i)->type() == DvdButtonItem) {
             buttonCount++;
             DvdButton *button = static_cast < DvdButton* >(list.at(i));
             QDomElement xmlbutton = doc.createElement("button");
             xmlbutton.setAttribute("target", button->target());
             xmlbutton.setAttribute("command", button->command());
             xmlbutton.setAttribute("backtomenu", button->backMenu());
-            xmlbutton.setAttribute("posx", button->pos().x());
-            xmlbutton.setAttribute("posy", button->pos().y());
+            xmlbutton.setAttribute("posx", (int) button->pos().x());
+            xmlbutton.setAttribute("posy", (int) button->pos().y());
             xmlbutton.setAttribute("text", button->toPlainText());
             QFont font = button->font();
             xmlbutton.setAttribute("font_size", font.pixelSize());
@@ -789,11 +779,12 @@ QDomElement DvdWizardMenu::toXml() const
 }
 
 
-void DvdWizardMenu::loadXml(QDomElement xml)
+void DvdWizardMenu::loadXml(DVDFORMAT format, const QDomElement &xml)
 {
     kDebug() << "// LOADING MENU";
     if (xml.isNull()) return;
     kDebug() << "// LOADING MENU 1";
+    changeProfile(format);
     m_view.create_menu->setChecked(xml.attribute("enabled").toInt());
     if (xml.hasAttribute("background_color")) {
         m_view.background_list->setCurrentIndex(0);
@@ -819,15 +810,15 @@ void DvdWizardMenu::loadXml(QDomElement xml)
         // Clear existing buttons
         QList<QGraphicsItem *> list = m_scene->items();
 
-        for (int i = 0; i < list.count(); i++) {
-            if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
+        for (int i = 0; i < list.count(); ++i) {
+            if (list.at(i)->type() == DvdButtonItem) {
                 delete list.at(i);
-                i--;
+                --i;
             }
         }
     }
 
-    for (int i = 0; i < buttons.count(); i++) {
+    for (int i = 0; i < buttons.count(); ++i) {
         QDomElement e = buttons.at(i).toElement();
         // create menu button
         DvdButton *button = new DvdButton(e.attribute("text"));
@@ -849,7 +840,7 @@ void DvdWizardMenu::loadXml(QDomElement xml)
         button->setDefaultTextColor(m_view.text_color->color());
         button->setZValue(4);
         m_scene->addItem(button);
-        button->setPos(e.attribute("posx").toDouble(), e.attribute("posy").toDouble());
+        button->setPos(e.attribute("posx").toInt(), e.attribute("posy").toInt());
 
     }
 }
@@ -864,3 +855,5 @@ void DvdWizardMenu::slotUnZoom()
     m_view.menu_preview->scale(0.5, 0.5);
 }
 
+
+#include "dvdwizardmenu.moc"