]> git.sesse.net Git - kdenlive/blobdiff - src/dvdwizardmenu.cpp
Fix crash when table has not row
[kdenlive] / src / dvdwizardmenu.cpp
index 167baa8cbf8e417fb23b47b58fee53b6780ae458..89d20dcb99bc6ad313b32d2b29f7b0cdfe9eaea9 100644 (file)
@@ -46,14 +46,6 @@ DvdWizardMenu::DvdWizardMenu(DVDFORMAT format, 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"));
@@ -117,12 +109,12 @@ DvdWizardMenu::DvdWizardMenu(DVDFORMAT format, 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(currentIndexChanged(int)), this, SLOT(checkBackgroundType(int)));
 
@@ -134,7 +126,7 @@ DvdWizardMenu::DvdWizardMenu(DVDFORMAT format, 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(DVDFORMAT format, 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,7 +158,7 @@ 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++) {
+    for (int i = 0; i < list.count(); ++i) {
         if (list.at(i)->type() == DvdButtonItem) {
             if (enable) {
                QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this);
@@ -182,7 +181,7 @@ 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++) {
+    for (int i = 0; i < list.count(); ++i) {
         if (list.at(i)->type() == DvdButtonItem) {
             buttonCount++;
             DvdButton *button = static_cast < DvdButton* >(list.at(i));
@@ -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);
@@ -224,7 +223,7 @@ bool DvdWizardMenu::isComplete() const
 #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,7 +259,7 @@ bool DvdWizardMenu::isComplete() const
 void DvdWizardMenu::setButtonTarget(int ix)
 {
     QList<QGraphicsItem *> list = m_scene->selectedItems();
-    for (int i = 0; i < list.count(); i++) {
+    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());
@@ -273,7 +272,7 @@ void DvdWizardMenu::setButtonTarget(int ix)
 void DvdWizardMenu::setBackToMenu(bool backToMenu)
 {
     QList<QGraphicsItem *> list = m_scene->selectedItems();
-    for (int i = 0; i < list.count(); i++) {
+    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);
@@ -287,7 +286,7 @@ void DvdWizardMenu::buttonChanged()
 {
     QList<QGraphicsItem *> list = m_scene->selectedItems();
     bool foundButton = false;
-    for (int i = 0; i < list.count(); i++) {
+    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);
@@ -341,7 +340,7 @@ void DvdWizardMenu::addButton()
 void DvdWizardMenu::deleteButton()
 {
     QList<QGraphicsItem *> list = m_scene->selectedItems();
-    for (int i = 0; i < list.count(); i++) {
+    for (int i = 0; i < list.count(); ++i) {
         if (list.at(i)->type() == DvdButtonItem) {
             delete list.at(i);
             break;
@@ -396,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 {
@@ -429,6 +428,7 @@ void DvdWizardMenu::checkBackgroundType(int ix)
             m_view.loop_movie->setVisible(true);
         }
     }
+    emit completeChanged();
 }
 
 void DvdWizardMenu::buildColor()
@@ -458,7 +458,7 @@ void DvdWizardMenu::buildImage()
        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().data());
+       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();
@@ -482,7 +482,7 @@ void DvdWizardMenu::buildButton()
 {
     DvdButton *button = NULL;
     QList<QGraphicsItem *> list = m_scene->selectedItems();
-    for (int i = 0; i < list.count(); i++) {
+    for (int i = 0; i < list.count(); ++i) {
         if (list.at(i)->type() == DvdButtonItem) {
             button = static_cast < DvdButton* >(list.at(i));
             break;
@@ -495,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()
@@ -506,7 +508,7 @@ void DvdWizardMenu::updateColor()
 void DvdWizardMenu::prepareUnderLines()
 {
     QList<QGraphicsItem *> list = m_scene->items();
-    for (int i = 0; i < list.count(); i++) {
+    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;
@@ -529,7 +531,7 @@ void DvdWizardMenu::resetUnderLines()
 {
     QList<QGraphicsItem *> list = m_scene->items();
     QList<QGraphicsItem *> toDelete;
-    for (int i = 0; i < list.count(); i++) {
+    for (int i = 0; i < list.count(); ++i) {
        if (list.at(i)->type() == DvdButtonUnderlineItem) {
            toDelete.append(list.at(i));
        }
@@ -546,7 +548,7 @@ void DvdWizardMenu::resetUnderLines()
 void DvdWizardMenu::updateUnderlineColor(QColor c)
 {
     QList<QGraphicsItem *> list = m_scene->items();
-    for (int i = 0; i < list.count(); 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);
@@ -561,7 +563,7 @@ void DvdWizardMenu::updateColor(QColor c)
 {
     DvdButton *button = NULL;
     QList<QGraphicsItem *> list = m_scene->items();
-    for (int i = 0; i < list.count(); i++) {
+    for (int i = 0; i < list.count(); ++i) {
         if (list.at(i)->type() == DvdButtonItem) {
             button = static_cast < DvdButton* >(list.at(i));
             button->setDefaultTextColor(c);
@@ -716,7 +718,7 @@ QMap <QString, QRect> DvdWizardMenu::buttonsInfo(bool letterbox)
        ratioy = (double) letterboxHeight / m_finalSize.height();
        offset = (m_finalSize.height() - letterboxHeight) / 2;
     }
-    for (int i = 0; i < list.count(); i++) {
+    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();
@@ -756,7 +758,7 @@ QDomElement DvdWizardMenu::toXml() const
     QList<QGraphicsItem *> list = m_scene->items();
     int buttonCount = 0;
 
-    for (int i = 0; i < list.count(); i++) {
+    for (int i = 0; i < list.count(); ++i) {
         if (list.at(i)->type() == DvdButtonItem) {
             buttonCount++;
             DvdButton *button = static_cast < DvdButton* >(list.at(i));
@@ -808,15 +810,15 @@ void DvdWizardMenu::loadXml(DVDFORMAT format, QDomElement xml)
         // Clear existing buttons
         QList<QGraphicsItem *> list = m_scene->items();
 
-        for (int i = 0; i < list.count(); i++) {
+        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"));
@@ -853,3 +855,5 @@ void DvdWizardMenu::slotUnZoom()
     m_view.menu_preview->scale(0.5, 0.5);
 }
 
+
+#include "dvdwizardmenu.moc"