]> git.sesse.net Git - kdenlive/blobdiff - src/dvdwizardmenu.cpp
Fix a couple of compile warnings because of unused and uninitialized variables.
[kdenlive] / src / dvdwizardmenu.cpp
index bfd0e7037c7c861b254e3e9c3e693240bd1ae7b5..625754c6b24bef9aced3391d5b6a314d9a9edfe0 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,12 +33,14 @@ 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()));
 
     m_view.add_button->setIcon(KIcon("document-new"));
     m_view.delete_button->setIcon(KIcon("trash-empty"));
+    m_view.zoom_button->setIcon(KIcon("zoom-in"));
+    m_view.unzoom_button->setIcon(KIcon("zoom-out"));
 
     m_view.add_button->setToolTip(i18n("Add new button"));
     m_view.delete_button->setToolTip(i18n("Delete current button"));
@@ -46,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());
@@ -81,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);
@@ -104,9 +106,18 @@ DvdWizardMenu::DvdWizardMenu(const QString &profile, QWidget *parent) :
 
     connect(m_view.add_button, SIGNAL(pressed()), this, SLOT(addButton()));
     connect(m_view.delete_button, SIGNAL(pressed()), this, SLOT(deleteButton()));
+    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()));
 
+    // 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);
 
 }
@@ -123,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();
@@ -135,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
@@ -156,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;
 }
@@ -228,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);
@@ -252,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()
@@ -280,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"))
@@ -298,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);
         }
     }
 }
@@ -321,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);
     }
@@ -385,58 +423,59 @@ 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);
+        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);
+        
+        QImage img(m_width, m_height, QImage::Format_Mono);
+        img.fill(Qt::white);
+        updateColor(Qt::black);
         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.setColor(0, m_view.text_color->color().rgb());
+        img.setColor(1, qRgba(0,0,0,0));
+#else
         img.setNumColors(4);
+#endif
         img.save(img1);
-        /*QImage saved;
-        if (m_view.menu_profile->currentIndex() < 2)
-            saved = img.scaled(720, 576);
-        else saved = img.scaled(720, 480);
-        saved.setNumColors(4);
-        saved.save(img1);*/
-
-        updateColor(m_view.selected_color->color());
+
+        img.fill(Qt::white);
         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);*/
+#if QT_VERSION >= 0x040600
+        img.setColor(0, m_view.highlighted_color->color().rgb());
+        img.setColor(1, qRgba(0,0,0,0));
+#else
         img.setNumColors(4);
-        img.save(img2);
-
+#endif
+        img.save(img3);        
 
-        updateColor(m_view.highlighted_color->color());
+        img.fill(Qt::white);
         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(img3);*/
-        img.setNumColors(4);
-        img.save(img3);
 
+#if QT_VERSION >= 0x040600
+        img.setColor(0, m_view.selected_color->color().rgb());
+        img.setColor(1, qRgba(0,0,0,0));
+#else
+        img.setNumColors(4);
+#endif
+        img.save(img2);
         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);
     }
 }
 
@@ -469,6 +508,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;
@@ -503,3 +547,112 @@ bool DvdWizardMenu::isPalMenu() const
 {
     return m_isPal;
 }
+
+QDomElement DvdWizardMenu::toXml() const
+{
+    QDomDocument doc;
+    QDomElement xml = doc.createElement("menu");
+    doc.appendChild(xml);
+    xml.setAttribute("enabled", m_view.create_menu->isChecked());
+    if (m_view.background_list->currentIndex() == 0) {
+        // Color bg
+        xml.setAttribute("background_color", m_view.background_color->color().name());
+    } else if (m_view.background_list->currentIndex() == 1) {
+        // Image bg
+        xml.setAttribute("background_image", m_view.background_image->url().path());
+    } else {
+        // Video bg
+        xml.setAttribute("background_video", m_view.background_image->url().path());
+    }
+    xml.setAttribute("text_color", m_view.text_color->color().name());
+    xml.setAttribute("selected_color", m_view.selected_color->color().name());
+    xml.setAttribute("highlighted_color", m_view.highlighted_color->color().name());
+
+    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) {
+            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("text", button->toPlainText());
+            QFont font = button->font();
+            xmlbutton.setAttribute("font_size", font.pixelSize());
+            xmlbutton.setAttribute("font_family", font.family());
+            xml.appendChild(xmlbutton);
+        }
+    }
+    return doc.documentElement();
+}
+
+
+void DvdWizardMenu::loadXml(QDomElement xml)
+{
+    kDebug() << "// LOADING MENU";
+    if (xml.isNull()) return;
+    kDebug() << "// LOADING MENU 1";
+    m_view.create_menu->setChecked(xml.attribute("enabled").toInt());
+    if (xml.hasAttribute("background_color")) {
+        m_view.background_list->setCurrentIndex(0);
+        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->setUrl(KUrl(xml.attribute("background_image")));
+    } else if (xml.hasAttribute("background_video")) {
+        m_view.background_list->setCurrentIndex(2);
+        m_view.background_image->setUrl(KUrl(xml.attribute("background_video")));
+    }
+
+    m_view.text_color->setColor(xml.attribute("text_color"));
+    m_view.selected_color->setColor(xml.attribute("selected_color"));
+    m_view.highlighted_color->setColor(xml.attribute("highlighted_color"));
+
+    QDomNodeList buttons = xml.elementsByTagName("button");
+    kDebug() << "// LOADING MENU 2" << buttons.count();
+
+    if (buttons.count() > 0) {
+        // 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) {
+                delete list.at(i);
+                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"));
+        QFont font(e.attribute("font_family"));
+        font.setPixelSize(e.attribute("font_size").toInt());
+        font.setStyleStrategy(QFont::NoAntialias);
+        button->setFont(font);
+        button->setTarget(e.attribute("target").toInt(), e.attribute("command"));
+        button->setBackMenu(e.attribute("backtomenu").toInt());
+        button->setDefaultTextColor(m_view.text_color->color());
+        button->setZValue(4);
+        m_scene->addItem(button);
+        button->setPos(e.attribute("posx").toDouble(), e.attribute("posy").toDouble());
+
+    }
+}
+
+void DvdWizardMenu::slotZoom()
+{
+    m_view.menu_preview->scale(2.0, 2.0);
+}
+
+void DvdWizardMenu::slotUnZoom()
+{
+    m_view.menu_preview->scale(0.5, 0.5);
+}
+