]> git.sesse.net Git - kdenlive/blobdiff - src/dvdwizardmenu.cpp
Fix DVD menus with more than 9 buttons:
[kdenlive] / src / dvdwizardmenu.cpp
index ad921c157db1405431229d187bbe9d23c5f60c29..2a204dc7459f192d186d57a8ebcf1a8b739017db 100644 (file)
  ***************************************************************************/
 
 #include "dvdwizardmenu.h"
+#include "kdenlivesettings.h"
 
 #include <KDebug>
-
+#include <KColorScheme>
+#include "kthumb.h"
 
 DvdWizardMenu::DvdWizardMenu(const QString &profile, QWidget *parent) :
         QWizardPage(parent),
@@ -31,7 +33,7 @@ DvdWizardMenu::DvdWizardMenu(const QString &profile, QWidget *parent) :
     m_view.play_text->setText(i18n("Play"));
     m_scene = new DvdScene(this);
     m_view.menu_preview->setScene(m_scene);
-
+    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()));
 
@@ -48,7 +50,6 @@ DvdWizardMenu::DvdWizardMenu(const QString &profile, QWidget *parent) :
     } else changeProfile(true);
 
 
-
     // Create color background
     m_color = new QGraphicsRectItem(0, 0, m_width, m_height);
     m_color->setBrush(m_view.background_color->color());
@@ -83,7 +84,6 @@ DvdWizardMenu::DvdWizardMenu(const QString &profile, QWidget *parent) :
     button->setFont(font);
     button->setDefaultTextColor(m_view.text_color->color());
     button->setZValue(4);
-    button->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
     QRectF r = button->sceneBoundingRect();
     m_scene->addItem(button);
     button->setPos((m_width - r.width()) / 2, (m_height - r.height()) / 2);
@@ -111,6 +111,13 @@ DvdWizardMenu::DvdWizardMenu(const QString &profile, QWidget *parent) :
     connect(m_scene, SIGNAL(selectionChanged()), this, SLOT(buttonChanged()));
     connect(m_scene, SIGNAL(changed(const QList<QRectF> &)), this, SIGNAL(completeChanged()));
 
+    // red background for error message
+    KColorScheme scheme(palette().currentColorGroup(), KColorScheme::Window, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
+    QPalette p = m_view.error_message->palette();
+    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);
 
 }
@@ -127,6 +134,7 @@ DvdWizardMenu::~DvdWizardMenu()
 
 bool DvdWizardMenu::isComplete() const
 {
+    m_view.error_message->setHidden(true);
     if (!m_view.create_menu->isChecked()) return true;
     QList <int> targets;
     QList<QGraphicsItem *> list = m_scene->items();
@@ -139,20 +147,30 @@ bool DvdWizardMenu::isComplete() const
             QList<QGraphicsItem *> collisions = button->collidingItems();
             if (!collisions.isEmpty()) {
                 for (int j = 0; j < collisions.count(); j++) {
-                    if (collisions.at(j)->type() == button->type()) return false;
+                    if (collisions.at(j)->type() == button->type()) {
+                        m_view.error_message->setText(i18n("Buttons overlapping"));
+                        m_view.error_message->setHidden(false);
+                        return false;
+                    }
                 }
             }
             targets.append(button->target());
         }
     }
     if (buttonCount == 0) {
-        // We need at least one button
+        //We need at least one button
+        m_view.error_message->setText(i18n("No button in menu"));
+        m_view.error_message->setHidden(false);
         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;
+        if (!QFile::exists(m_view.background_image->url().path())) {
+            m_view.error_message->setText(i18n("Missing background image"));
+            m_view.error_message->setHidden(false);
+            return false;
+        }
     }
 
     // check that we have a "Play all" entry
@@ -160,7 +178,11 @@ bool DvdWizardMenu::isComplete() const
     // ... or that each video file has a button
     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)) return false;
+        if (m_view.target_list->itemIcon(i).isNull() == false && !targets.contains(i)) {
+            m_view.error_message->setText(i18n("No menu entry for %1", m_view.target_list->itemText(i)));
+            m_view.error_message->setHidden(false);
+            return false;
+        }
     }
     return true;
 }
@@ -232,7 +254,6 @@ void DvdWizardMenu::addButton()
     button->setFont(font);
     button->setDefaultTextColor(m_view.text_color->color());
     button->setZValue(4);
-    button->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
     QRectF r = button->sceneBoundingRect();
     m_scene->addItem(button);
     button->setPos((m_width - r.width()) / 2, (m_height - r.height()) / 2);
@@ -256,14 +277,11 @@ void DvdWizardMenu::changeProfile(bool isPal)
     if (isPal == false) {
         m_width = 720;
         m_height = 480;
-        m_isPal = false;
-        updatePreview();
     } else {
         m_width = 720;
         m_height = 576;
-        m_isPal = true;
-        updatePreview();
     }
+    updatePreview();
 }
 
 void DvdWizardMenu::updatePreview()
@@ -284,7 +302,7 @@ void DvdWizardMenu::updatePreview()
 void DvdWizardMenu::setTargets(QStringList list, QStringList targetlist)
 {
     m_view.target_list->clear();
-    m_view.target_list->addItem(i18n("Play All"), "title 1");
+    m_view.target_list->addItem(i18n("Play All"), "jump title 1");
     int movieCount = 0;
     for (int i = 0; i < list.count(); i++) {
         if (targetlist.at(i).contains("chapter"))
@@ -302,16 +320,21 @@ void DvdWizardMenu::checkBackgroundType(int ix)
     if (ix == 0) {
         m_view.background_color->setVisible(true);
         m_view.background_image->setVisible(false);
-        m_scene->removeItem(m_background);
+        m_view.loop_movie->setVisible(false);
+        if (m_background->scene() != 0) m_scene->removeItem(m_background);
     } else {
         m_view.background_color->setVisible(false);
         m_view.background_image->setVisible(true);
         if (ix == 1) {
+            m_view.background_image->clear();
             m_view.background_image->setFilter("*");
-            m_scene->addItem(m_background);
+            if (m_background->scene() != 0) m_scene->removeItem(m_background);
+            m_view.loop_movie->setVisible(false);
         } else {
-            m_scene->removeItem(m_background);
+            if (m_background->scene() != 0) m_scene->removeItem(m_background);
+            m_view.background_image->clear();
             m_view.background_image->setFilter("video/mpeg");
+            m_view.loop_movie->setVisible(true);
         }
     }
 }
@@ -325,23 +348,34 @@ void DvdWizardMenu::buildImage()
 {
     emit completeChanged();
     if (m_view.background_image->url().isEmpty()) {
-        m_scene->removeItem(m_background);
+        if (m_background->scene() != 0) m_scene->removeItem(m_background);
         return;
     }
     QPixmap pix;
-    if (!pix.load(m_view.background_image->url().path())) {
-        m_scene->removeItem(m_background);
-        return;
+
+    if (m_view.background_list->currentIndex() == 1) {
+        // image background
+        if (!pix.load(m_view.background_image->url().path())) {
+            if (m_background->scene() != 0) m_scene->removeItem(m_background);
+            return;
+        }
+        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);
     }
-    pix = pix.scaled(m_width, m_height);
     m_background->setPixmap(pix);
-    if (m_view.background_list->currentIndex() == 1) m_scene->addItem(m_background);
+    m_scene->addItem(m_background);
 }
 
 void DvdWizardMenu::checkBackground()
 {
     if (m_view.background_list->currentIndex() != 1) {
-        m_scene->removeItem(m_background);
+        if (m_background->scene() != 0) m_scene->removeItem(m_background);
     } else {
         m_scene->addItem(m_background);
     }
@@ -389,17 +423,23 @@ void DvdWizardMenu::createButtonImages(const QString &img1, const QString &img2,
 {
     if (m_view.create_menu->isChecked()) {
         m_scene->clearSelection();
-        QImage img(m_width, m_height, QImage::Format_ARGB32);
+        QImage img(m_width, m_height, QImage::Format_ARGB32_Premultiplied);
+        img.fill(Qt::transparent);
+        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);
         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();
+#if QT_VERSION >= 0x040600
+        img.setColorCount(4);
+#else
         img.setNumColors(4);
+#endif
         img.save(img1);
+
         /*QImage saved;
         if (m_view.menu_profile->currentIndex() < 2)
             saved = img.scaled(720, 576);
@@ -408,6 +448,7 @@ void DvdWizardMenu::createButtonImages(const QString &img1, const QString &img2,
         saved.save(img1);*/
 
         updateColor(m_view.selected_color->color());
+        img.fill(Qt::transparent);
         p.begin(&img);
         p.setRenderHints(QPainter::Antialiasing, false);
         p.setRenderHints(QPainter::TextAntialiasing, false);
@@ -418,11 +459,16 @@ void DvdWizardMenu::createButtonImages(const QString &img1, const QString &img2,
                 else saved = img.scaled(720, 480);
                 saved.setNumColors(4);
                 saved.save(img2);*/
+#if QT_VERSION >= 0x040600
+        img.setColorCount(4);
+#else
         img.setNumColors(4);
+#endif
         img.save(img2);
 
 
         updateColor(m_view.highlighted_color->color());
+        img.fill(Qt::transparent);
         p.begin(&img);
         p.setRenderHints(QPainter::Antialiasing, false);
         p.setRenderHints(QPainter::TextAntialiasing, false);
@@ -433,14 +479,18 @@ void DvdWizardMenu::createButtonImages(const QString &img1, const QString &img2,
         else saved = img.scaled(720, 480);
         saved.setNumColors(4);
         saved.save(img3);*/
+#if QT_VERSION >= 0x040600
+        img.setColorCount(4);
+#else
         img.setNumColors(4);
+#endif
         img.save(img3);
 
         updateColor();
 
         m_scene->addItem(m_safeRect);
         m_scene->addItem(m_color);
-        if (m_view.background_list->currentIndex() == 1) m_scene->addItem(m_background);
+        if (m_view.background_list->currentIndex() > 0) m_scene->addItem(m_background);
     }
 }
 
@@ -473,6 +523,11 @@ bool DvdWizardMenu::createMenu() const
     return m_view.create_menu->isChecked();
 }
 
+bool DvdWizardMenu::loopMovie() const
+{
+    return m_view.loop_movie->isChecked();
+}
+
 bool DvdWizardMenu::menuMovie() const
 {
     return m_view.background_list->currentIndex() == 2;
@@ -563,10 +618,10 @@ void DvdWizardMenu::loadXml(QDomElement xml)
         m_view.background_color->setColor(xml.attribute("background_color"));
     } else if (xml.hasAttribute("background_image")) {
         m_view.background_list->setCurrentIndex(1);
-        m_view.background_image->setPath(xml.attribute("background_image"));
+        m_view.background_image->setUrl(KUrl(xml.attribute("background_image")));
     } else if (xml.hasAttribute("background_video")) {
         m_view.background_list->setCurrentIndex(2);
-        m_view.background_image->setPath(xml.attribute("background_video"));
+        m_view.background_image->setUrl(KUrl(xml.attribute("background_video")));
     }
 
     m_view.text_color->setColor(xml.attribute("text_color"));
@@ -600,7 +655,6 @@ void DvdWizardMenu::loadXml(QDomElement xml)
         button->setBackMenu(e.attribute("backtomenu").toInt());
         button->setDefaultTextColor(m_view.text_color->color());
         button->setZValue(4);
-        button->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
         QRectF r = button->sceneBoundingRect();
         m_scene->addItem(button);
         button->setPos(e.attribute("posx").toDouble(), e.attribute("posy").toDouble());