]> git.sesse.net Git - kdenlive/blobdiff - src/dvdwizardmenu.cpp
Fix handling of several movies in dvd, improve chapters handling
[kdenlive] / src / dvdwizardmenu.cpp
index 189c81632d96dae60f0d279e13b421f7a8f61e3a..fbe794013eb78c0682a04a291571e5fadaf33311 100644 (file)
 #include <KDebug>
 
 
-DvdWizardMenu::DvdWizardMenu(const QString &profile, QWidget *parent): QWizardPage(parent) {
+DvdWizardMenu::DvdWizardMenu(const QString &profile, QWidget *parent) :
+        QWizardPage(parent),
+        m_color(NULL),
+        m_safeRect(NULL)
+{
     m_view.setupUi(this);
     m_view.play_text->setText(i18n("Play"));
     m_scene = new DvdScene(this);
@@ -34,9 +38,8 @@ DvdWizardMenu::DvdWizardMenu(const QString &profile, QWidget *parent): QWizardPa
     m_view.add_button->setIcon(KIcon("document-new"));
     m_view.delete_button->setIcon(KIcon("trash-empty"));
 
-    // TODO: re-enable add button options
-    m_view.add_button->setVisible(false);
-    m_view.delete_button->setVisible(false);
+    m_view.add_button->setToolTip(i18n("Add new button"));
+    m_view.delete_button->setToolTip(i18n("Delete current button"));
 
     m_view.menu_profile->addItems(QStringList() << i18n("PAL") << i18n("NTSC"));
 
@@ -45,6 +48,8 @@ DvdWizardMenu::DvdWizardMenu(const QString &profile, QWidget *parent): QWizardPa
         m_isPal = false;
     } else m_isPal = true;
 
+    changeProfile(m_view.menu_profile->currentIndex());
+
     // Create color background
     m_color = new QGraphicsRectItem(0, 0, m_width, m_height);
     m_color->setBrush(m_view.background_color->color());
@@ -68,7 +73,6 @@ DvdWizardMenu::DvdWizardMenu(const QString &profile, QWidget *parent): QWizardPa
     m_safeRect->setZValue(5);
     m_scene->addItem(m_safeRect);
 
-    changeProfile(m_view.menu_profile->currentIndex());
     checkBackgroundType(0);
 
     connect(m_view.menu_profile, SIGNAL(activated(int)), this, SLOT(changeProfile(int)));
@@ -100,6 +104,7 @@ DvdWizardMenu::DvdWizardMenu(const QString &profile, QWidget *parent): QWizardPa
     connect(m_view.background_list, SIGNAL(activated(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)));
 
     connect(m_view.add_button, SIGNAL(pressed()), this, SLOT(addButton()));
     connect(m_view.delete_button, SIGNAL(pressed()), this, SLOT(deleteButton()));
@@ -110,7 +115,8 @@ DvdWizardMenu::DvdWizardMenu(const QString &profile, QWidget *parent): QWizardPa
 
 }
 
-DvdWizardMenu::~DvdWizardMenu() {
+DvdWizardMenu::~DvdWizardMenu()
+{
     delete m_color;
     delete m_safeRect;
     delete m_background;
@@ -119,7 +125,8 @@ DvdWizardMenu::~DvdWizardMenu() {
 
 // virtual
 
-bool DvdWizardMenu::isComplete() const {
+bool DvdWizardMenu::isComplete() const
+{
     if (!m_view.create_menu->isChecked()) return true;
     QList <int> targets;
     QList<QGraphicsItem *> list = m_scene->items();
@@ -132,35 +139,60 @@ bool DvdWizardMenu::isComplete() const {
             QList<QGraphicsItem *> collisions = button->collidingItems();
             if (!collisions.isEmpty()) {
                 for (int j = 0; j < collisions.count(); j++) {
-                    if (list.at(j)->type() == button->type()) return false;
+                    if (collisions.at(j)->type() == button->type()) return false;
                 }
             }
             targets.append(button->target());
         }
     }
-    if (buttonCount == 0) return false;
+    if (buttonCount == 0) {
+        // We need at least one button
+        return false;
+    }
+
+    if (!m_view.background_image->isHidden()) {
+        // Make sure user selected a valid image / video file
+        if (!QFile::exists(m_view.background_image->url().path())) return false;
+    }
+
     // 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--) {
-        if (!targets.contains(i)) return false;
+        // 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)) return false;
     }
     return true;
 }
 
-void DvdWizardMenu::setButtonTarget(int ix) {
+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) {
+            DvdButton *button = static_cast < DvdButton* >(list.at(i));
+            button->setTarget(ix, m_view.target_list->itemData(ix).toString());
+            break;
+        }
+    }
+    emit completeChanged();
+}
+
+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) {
             DvdButton *button = static_cast < DvdButton* >(list.at(i));
-            button->setTarget(ix);
+            button->setBackMenu(backToMenu);
             break;
         }
     }
     emit completeChanged();
 }
 
-void DvdWizardMenu::buttonChanged() {
+void DvdWizardMenu::buttonChanged()
+{
     QList<QGraphicsItem *> list = m_scene->selectedItems();
     bool foundButton = false;
     for (int i = 0; i < list.count(); i++) {
@@ -169,11 +201,13 @@ void DvdWizardMenu::buttonChanged() {
             m_view.font_size->blockSignals(true);
             m_view.font_family->blockSignals(true);
             m_view.target_list->blockSignals(true);
+            m_view.back_to_menu->blockSignals(true);
             foundButton = true;
             m_view.tabWidget->widget(0)->setEnabled(true);
             DvdButton *button = static_cast < DvdButton* >(list.at(i));
             m_view.target_list->setCurrentIndex(button->target());
             m_view.play_text->setText(button->toPlainText());
+            m_view.back_to_menu->setChecked(button->backMenu());
             QFont font = button->font();
             m_view.font_size->setValue(font.pixelSize());
             m_view.font_family->setCurrentFont(font);
@@ -181,13 +215,15 @@ void DvdWizardMenu::buttonChanged() {
             m_view.font_size->blockSignals(false);
             m_view.font_family->blockSignals(false);
             m_view.target_list->blockSignals(false);
+            m_view.back_to_menu->blockSignals(false);
             break;
         }
     }
     if (!foundButton) m_view.tabWidget->widget(0)->setEnabled(false);
 }
 
-void DvdWizardMenu::addButton() {
+void DvdWizardMenu::addButton()
+{
     m_scene->clearSelection();
     DvdButton *button = new DvdButton(m_view.play_text->text());
     QFont font = m_view.font_family->currentFont();
@@ -203,7 +239,8 @@ void DvdWizardMenu::addButton() {
     button->setSelected(true);
 }
 
-void DvdWizardMenu::deleteButton() {
+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) {
@@ -213,7 +250,8 @@ void DvdWizardMenu::deleteButton() {
     }
 }
 
-void DvdWizardMenu::changeProfile(int ix) {
+void DvdWizardMenu::changeProfile(int ix)
+{
     switch (ix) {
     case 1:
         m_width = 720;
@@ -230,32 +268,39 @@ void DvdWizardMenu::changeProfile(int ix) {
     }
 }
 
-void DvdWizardMenu::updatePreview() {
+void DvdWizardMenu::updatePreview()
+{
     m_scene->setProfile(m_width, m_height);
     QMatrix matrix;
     matrix.scale(0.5, 0.5);
     m_view.menu_preview->setMatrix(matrix);
     m_view.menu_preview->setMinimumSize(m_width / 2 + 4, m_height / 2 + 8);
 
-    m_color->setRect(0, 0, m_width, m_height);
+    if (m_color) m_color->setRect(0, 0, m_width, m_height);
 
     int safeW = m_width / 20;
     int safeH = m_height / 20;
-    m_safeRect->setRect(safeW, safeH, m_width - 2 * safeW, m_height - 2 * safeH);
+    if (m_safeRect) m_safeRect->setRect(safeW, safeH, m_width - 2 * safeW, m_height - 2 * safeH);
 }
 
-void DvdWizardMenu::setTargets(QStringList list) {
-    m_targets = QStringList() << i18n("Play All");
-    // TODO: re-enable different targets
-    /*
-    if (list.count() > 1) {
-    m_targets += list;
+void DvdWizardMenu::setTargets(QStringList list, QStringList targetlist)
+{
+    m_view.target_list->clear();
+    m_view.target_list->addItem(i18n("Play All"), "title 1");
+    int movieCount = 0;
+    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 {
+            m_view.target_list->addItem(KIcon("video-x-generic"), list.at(i), targetlist.at(i));
+            movieCount++;
+        }
     }
-    m_view.target_list->clear();*/
-    m_view.target_list->addItems(m_targets);
+    m_view.back_to_menu->setHidden(movieCount == 1);
 }
 
-void DvdWizardMenu::checkBackgroundType(int ix) {
+void DvdWizardMenu::checkBackgroundType(int ix)
+{
     if (ix == 0) {
         m_view.background_color->setVisible(true);
         m_view.background_image->setVisible(false);
@@ -273,11 +318,14 @@ void DvdWizardMenu::checkBackgroundType(int ix) {
     }
 }
 
-void DvdWizardMenu::buildColor() {
+void DvdWizardMenu::buildColor()
+{
     m_color->setBrush(m_view.background_color->color());
 }
 
-void DvdWizardMenu::buildImage() {
+void DvdWizardMenu::buildImage()
+{
+    emit completeChanged();
     if (m_view.background_image->url().isEmpty()) {
         m_scene->removeItem(m_background);
         return;
@@ -292,7 +340,8 @@ void DvdWizardMenu::buildImage() {
     if (m_view.background_list->currentIndex() == 1) m_scene->addItem(m_background);
 }
 
-void DvdWizardMenu::checkBackground() {
+void DvdWizardMenu::checkBackground()
+{
     if (m_view.background_list->currentIndex() != 1) {
         m_scene->removeItem(m_background);
     } else {
@@ -300,7 +349,8 @@ void DvdWizardMenu::checkBackground() {
     }
 }
 
-void DvdWizardMenu::buildButton() {
+void DvdWizardMenu::buildButton()
+{
     DvdButton *button = NULL;
     QList<QGraphicsItem *> list = m_scene->selectedItems();
     for (int i = 0; i < list.count(); i++) {
@@ -318,12 +368,14 @@ void DvdWizardMenu::buildButton() {
     button->setDefaultTextColor(m_view.text_color->color());
 }
 
-void DvdWizardMenu::updateColor() {
+void DvdWizardMenu::updateColor()
+{
     updateColor(m_view.text_color->color());
     m_view.menu_preview->viewport()->update();
 }
 
-void DvdWizardMenu::updateColor(QColor c) {
+void DvdWizardMenu::updateColor(QColor c)
+{
     DvdButton *button = NULL;
     QList<QGraphicsItem *> list = m_scene->items();
     for (int i = 0; i < list.count(); i++) {
@@ -335,43 +387,56 @@ 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)
+{
     if (m_view.create_menu->isChecked()) {
         m_scene->clearSelection();
         QImage img(m_width, m_height, QImage::Format_ARGB32);
         QPainter p(&img);
+        p.setRenderHints(QPainter::Antialiasing, false);
+        p.setRenderHints(QPainter::TextAntialiasing, false);
         m_scene->removeItem(m_safeRect);
         m_scene->removeItem(m_color);
         m_scene->removeItem(m_background);
         m_scene->render(&p, QRectF(0, 0, m_width, m_height));
         p.end();
         img.setNumColors(4);
-        QImage saved;
+        img.save(img1);
+        /*QImage saved;
         if (m_view.menu_profile->currentIndex() < 2)
             saved = img.scaled(720, 576);
         else saved = img.scaled(720, 480);
-        saved.save(img1);
+        saved.setNumColors(4);
+        saved.save(img1);*/
 
         updateColor(m_view.selected_color->color());
         p.begin(&img);
+        p.setRenderHints(QPainter::Antialiasing, false);
+        p.setRenderHints(QPainter::TextAntialiasing, false);
         m_scene->render(&p, QRectF(0, 0, m_width, m_height));
         p.end();
+        /*        if (m_view.menu_profile->currentIndex() < 2)
+                    saved = img.scaled(720, 576);
+                else saved = img.scaled(720, 480);
+                saved.setNumColors(4);
+                saved.save(img2);*/
         img.setNumColors(4);
-        if (m_view.menu_profile->currentIndex() < 2)
-            saved = img.scaled(720, 576);
-        else saved = img.scaled(720, 480);
-        saved.save(img2);
+        img.save(img2);
 
 
         updateColor(m_view.highlighted_color->color());
         p.begin(&img);
+        p.setRenderHints(QPainter::Antialiasing, false);
+        p.setRenderHints(QPainter::TextAntialiasing, false);
         m_scene->render(&p, QRectF(0, 0, m_width, m_height));
         p.end();
-        img.setNumColors(4);
-        if (m_view.menu_profile->currentIndex() < 2)
+        /*if (m_view.menu_profile->currentIndex() < 2)
             saved = img.scaled(720, 576);
         else saved = img.scaled(720, 480);
-        saved.save(img3);
+        saved.setNumColors(4);
+        saved.save(img3);*/
+        img.setNumColors(4);
+        img.save(img3);
 
         updateColor();
 
@@ -382,7 +447,8 @@ void DvdWizardMenu::createButtonImages(const QString &img1, const QString &img2,
 }
 
 
-void DvdWizardMenu::createBackgroundImage(const QString &img1) {
+void DvdWizardMenu::createBackgroundImage(const QString &img1)
+{
     QImage img;
     if (m_view.background_list->currentIndex() == 0) {
         // color background
@@ -404,21 +470,25 @@ void DvdWizardMenu::createBackgroundImage(const QString &img1) {
     img.save(img1);
 }
 
-bool DvdWizardMenu::createMenu() const {
+bool DvdWizardMenu::createMenu() const
+{
     return m_view.create_menu->isChecked();
 }
 
-bool DvdWizardMenu::menuMovie() const {
+bool DvdWizardMenu::menuMovie() const
+{
     return m_view.background_list->currentIndex() == 2;
 }
 
-QString DvdWizardMenu::menuMoviePath() const {
+QString DvdWizardMenu::menuMoviePath() const
+{
     return m_view.background_image->url().path();
 }
 
 
-QMap <int, QRect> DvdWizardMenu::buttonsInfo() {
-    QMap <int, QRect> info;
+QMap <QString, QRect> DvdWizardMenu::buttonsInfo()
+{
+    QMap <QString, QRect> info;
     QList<QGraphicsItem *> list = m_scene->items();
     for (int i = 0; i < list.count(); i++) {
         if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
@@ -427,12 +497,15 @@ QMap <int, QRect> DvdWizardMenu::buttonsInfo() {
             // Make sure y1 is not odd (requested by spumux)
             if (r.height() % 2 == 1) r.setHeight(r.height() + 1);
             if (r.y() % 2 == 1) r.setY(r.y() - 1);
-            info.insertMulti(button->target(), r);
+            QString command = button->command();
+            if (button->backMenu()) command.prepend("g1 = 999;");
+            info.insertMulti(command, r);
         }
     }
     return info;
 }
 
-bool DvdWizardMenu::isPalMenu() const {
+bool DvdWizardMenu::isPalMenu() const
+{
     return m_isPal;
 }