]> git.sesse.net Git - kdenlive/blob - src/dvdwizardmenu.cpp
Fix crash in DVD Wizard:
[kdenlive] / src / dvdwizardmenu.cpp
1 /***************************************************************************
2  *   Copyright (C) 2009 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3  *                                                                         *
4  *   This program is free software; you can redistribute it and/or modify  *
5  *   it under the terms of the GNU General Public License as published by  *
6  *   the Free Software Foundation; either version 2 of the License, or     *
7  *   (at your option) any later version.                                   *
8  *                                                                         *
9  *   This program is distributed in the hope that it will be useful,       *
10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12  *   GNU General Public License for more details.                          *
13  *                                                                         *
14  *   You should have received a copy of the GNU General Public License     *
15  *   along with this program; if not, write to the                         *
16  *   Free Software Foundation, Inc.,                                       *
17  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
18  ***************************************************************************/
19
20 #include "dvdwizardmenu.h"
21
22 #include <KDebug>
23 #include <KColorScheme>
24 #include "kthumb.h"
25
26 DvdWizardMenu::DvdWizardMenu(const QString &profile, QWidget *parent) :
27         QWizardPage(parent),
28         m_color(NULL),
29         m_safeRect(NULL)
30 {
31     m_view.setupUi(this);
32     m_view.play_text->setText(i18n("Play"));
33     m_scene = new DvdScene(this);
34     m_view.menu_preview->setScene(m_scene);
35     m_view.menu_preview->setMouseTracking(true);
36     connect(m_view.create_menu, SIGNAL(toggled(bool)), m_view.menu_box, SLOT(setEnabled(bool)));
37     connect(m_view.create_menu, SIGNAL(toggled(bool)), this, SIGNAL(completeChanged()));
38
39     m_view.add_button->setIcon(KIcon("document-new"));
40     m_view.delete_button->setIcon(KIcon("trash-empty"));
41     m_view.zoom_button->setIcon(KIcon("zoom-in"));
42     m_view.unzoom_button->setIcon(KIcon("zoom-out"));
43
44     m_view.add_button->setToolTip(i18n("Add new button"));
45     m_view.delete_button->setToolTip(i18n("Delete current button"));
46
47     if (profile == "dv_ntsc" || profile == "dv_ntsc_wide") {
48         changeProfile(false);
49     } else changeProfile(true);
50
51
52     // Create color background
53     m_color = new QGraphicsRectItem(0, 0, m_width, m_height);
54     m_color->setBrush(m_view.background_color->color());
55     m_color->setZValue(2);
56     m_scene->addItem(m_color);
57
58
59     // create background image
60     m_background = new QGraphicsPixmapItem();
61     m_background->setZValue(3);
62     //m_scene->addItem(m_background);
63
64     // create safe zone rect
65     int safeW = m_width / 20;
66     int safeH = m_height / 20;
67     m_safeRect = new QGraphicsRectItem(safeW, safeH, m_width - 2 * safeW, m_height - 2 * safeH);
68     QPen pen(Qt::red);
69     pen.setStyle(Qt::DashLine);
70     pen.setWidth(3);
71     m_safeRect->setPen(pen);
72     m_safeRect->setZValue(5);
73     m_scene->addItem(m_safeRect);
74
75     checkBackgroundType(0);
76
77
78     // create menu button
79     DvdButton *button = new DvdButton(m_view.play_text->text());
80     QFont font = m_view.font_family->currentFont();
81     font.setPixelSize(m_view.font_size->value());
82     font.setStyleStrategy(QFont::NoAntialias);
83     button->setFont(font);
84     button->setDefaultTextColor(m_view.text_color->color());
85     button->setZValue(4);
86     QRectF r = button->sceneBoundingRect();
87     m_scene->addItem(button);
88     button->setPos((m_width - r.width()) / 2, (m_height - r.height()) / 2);
89     button->setSelected(true);
90
91
92     //m_view.menu_preview->resizefitInView(0, 0, m_width, m_height);
93
94     connect(m_view.play_text, SIGNAL(textChanged(const QString &)), this, SLOT(buildButton()));
95     connect(m_view.text_color, SIGNAL(changed(const QColor &)), this, SLOT(updateColor()));
96     connect(m_view.font_size, SIGNAL(valueChanged(int)), this, SLOT(buildButton()));
97     connect(m_view.font_family, SIGNAL(currentFontChanged(const QFont &)), this, SLOT(buildButton()));
98     connect(m_view.background_image, SIGNAL(textChanged(const QString &)), this, SLOT(buildImage()));
99     connect(m_view.background_color, SIGNAL(changed(const QColor &)), this, SLOT(buildColor()));
100
101     connect(m_view.background_list, SIGNAL(activated(int)), this, SLOT(checkBackgroundType(int)));
102
103     connect(m_view.target_list, SIGNAL(activated(int)), this, SLOT(setButtonTarget(int)));
104     connect(m_view.back_to_menu, SIGNAL(toggled(bool)), this, SLOT(setBackToMenu(bool)));
105
106     connect(m_view.add_button, SIGNAL(pressed()), this, SLOT(addButton()));
107     connect(m_view.delete_button, SIGNAL(pressed()), this, SLOT(deleteButton()));
108     connect(m_view.zoom_button, SIGNAL(pressed()), this, SLOT(slotZoom()));
109     connect(m_view.unzoom_button, SIGNAL(pressed()), this, SLOT(slotUnZoom()));
110     connect(m_scene, SIGNAL(selectionChanged()), this, SLOT(buttonChanged()));
111     connect(m_scene, SIGNAL(changed(const QList<QRectF> &)), this, SIGNAL(completeChanged()));
112
113     // red background for error message
114     KColorScheme scheme(palette().currentColorGroup(), KColorScheme::Window);
115     QPalette p = m_view.error_message->palette();
116     p.setColor(QPalette::Background, scheme.background(KColorScheme::NegativeBackground).color());
117     m_view.error_message->setAutoFillBackground(true);
118     m_view.error_message->setPalette(p);
119
120     m_view.menu_box->setEnabled(false);
121
122 }
123
124 DvdWizardMenu::~DvdWizardMenu()
125 {
126     delete m_color;
127     delete m_safeRect;
128     delete m_background;
129     delete m_scene;
130 }
131
132 // virtual
133
134 bool DvdWizardMenu::isComplete() const
135 {
136     m_view.error_message->setHidden(true);
137     if (!m_view.create_menu->isChecked()) return true;
138     QList <int> targets;
139     QList<QGraphicsItem *> list = m_scene->items();
140     int buttonCount = 0;
141     // check that the menu buttons don't collide
142     for (int i = 0; i < list.count(); i++) {
143         if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
144             buttonCount++;
145             DvdButton *button = static_cast < DvdButton* >(list.at(i));
146             QList<QGraphicsItem *> collisions = button->collidingItems();
147             if (!collisions.isEmpty()) {
148                 for (int j = 0; j < collisions.count(); j++) {
149                     if (collisions.at(j)->type() == button->type()) {
150                         m_view.error_message->setText(i18n("Buttons overlapping"));
151                         m_view.error_message->setHidden(false);
152                         return false;
153                     }
154                 }
155             }
156             targets.append(button->target());
157         }
158     }
159     if (buttonCount == 0) {
160         //We need at least one button
161         m_view.error_message->setText(i18n("No button in menu"));
162         m_view.error_message->setHidden(false);
163         return false;
164     }
165
166     if (!m_view.background_image->isHidden()) {
167         // Make sure user selected a valid image / video file
168         if (!QFile::exists(m_view.background_image->url().path())) {
169             m_view.error_message->setText(i18n("Missing background image"));
170             m_view.error_message->setHidden(false);
171             return false;
172         }
173     }
174
175     // check that we have a "Play all" entry
176     if (targets.contains(0)) return true;
177     // ... or that each video file has a button
178     for (int i = m_view.target_list->count() - 1; i > 0; i--) {
179         // If there is a vob file entry and it has no button assigned, don't allow to go further
180         if (m_view.target_list->itemIcon(i).isNull() == false && !targets.contains(i)) {
181             m_view.error_message->setText(i18n("No menu entry for %1", m_view.target_list->itemText(i)));
182             m_view.error_message->setHidden(false);
183             return false;
184         }
185     }
186     return true;
187 }
188
189 void DvdWizardMenu::setButtonTarget(int ix)
190 {
191     QList<QGraphicsItem *> list = m_scene->selectedItems();
192     for (int i = 0; i < list.count(); i++) {
193         if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
194             DvdButton *button = static_cast < DvdButton* >(list.at(i));
195             button->setTarget(ix, m_view.target_list->itemData(ix).toString());
196             break;
197         }
198     }
199     emit completeChanged();
200 }
201
202 void DvdWizardMenu::setBackToMenu(bool backToMenu)
203 {
204     QList<QGraphicsItem *> list = m_scene->selectedItems();
205     for (int i = 0; i < list.count(); i++) {
206         if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
207             DvdButton *button = static_cast < DvdButton* >(list.at(i));
208             button->setBackMenu(backToMenu);
209             break;
210         }
211     }
212     emit completeChanged();
213 }
214
215 void DvdWizardMenu::buttonChanged()
216 {
217     QList<QGraphicsItem *> list = m_scene->selectedItems();
218     bool foundButton = false;
219     for (int i = 0; i < list.count(); i++) {
220         if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
221             m_view.play_text->blockSignals(true);
222             m_view.font_size->blockSignals(true);
223             m_view.font_family->blockSignals(true);
224             m_view.target_list->blockSignals(true);
225             m_view.back_to_menu->blockSignals(true);
226             foundButton = true;
227             m_view.tabWidget->widget(0)->setEnabled(true);
228             DvdButton *button = static_cast < DvdButton* >(list.at(i));
229             m_view.target_list->setCurrentIndex(button->target());
230             m_view.play_text->setText(button->toPlainText());
231             m_view.back_to_menu->setChecked(button->backMenu());
232             QFont font = button->font();
233             m_view.font_size->setValue(font.pixelSize());
234             m_view.font_family->setCurrentFont(font);
235             m_view.play_text->blockSignals(false);
236             m_view.font_size->blockSignals(false);
237             m_view.font_family->blockSignals(false);
238             m_view.target_list->blockSignals(false);
239             m_view.back_to_menu->blockSignals(false);
240             break;
241         }
242     }
243     if (!foundButton) m_view.tabWidget->widget(0)->setEnabled(false);
244 }
245
246 void DvdWizardMenu::addButton()
247 {
248     m_scene->clearSelection();
249     DvdButton *button = new DvdButton(m_view.play_text->text());
250     QFont font = m_view.font_family->currentFont();
251     font.setPixelSize(m_view.font_size->value());
252     font.setStyleStrategy(QFont::NoAntialias);
253     button->setFont(font);
254     button->setDefaultTextColor(m_view.text_color->color());
255     button->setZValue(4);
256     QRectF r = button->sceneBoundingRect();
257     m_scene->addItem(button);
258     button->setPos((m_width - r.width()) / 2, (m_height - r.height()) / 2);
259     button->setSelected(true);
260 }
261
262 void DvdWizardMenu::deleteButton()
263 {
264     QList<QGraphicsItem *> list = m_scene->selectedItems();
265     for (int i = 0; i < list.count(); i++) {
266         if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
267             delete list.at(i);
268             break;
269         }
270     }
271 }
272
273 void DvdWizardMenu::changeProfile(bool isPal)
274 {
275     m_isPal = isPal;
276     if (isPal == false) {
277         m_width = 720;
278         m_height = 480;
279         m_isPal = false;
280         updatePreview();
281     } else {
282         m_width = 720;
283         m_height = 576;
284         m_isPal = true;
285         updatePreview();
286     }
287 }
288
289 void DvdWizardMenu::updatePreview()
290 {
291     m_scene->setProfile(m_width, m_height);
292     QMatrix matrix;
293     matrix.scale(0.5, 0.5);
294     m_view.menu_preview->setMatrix(matrix);
295     m_view.menu_preview->setMinimumSize(m_width / 2 + 4, m_height / 2 + 8);
296
297     if (m_color) m_color->setRect(0, 0, m_width, m_height);
298
299     int safeW = m_width / 20;
300     int safeH = m_height / 20;
301     if (m_safeRect) m_safeRect->setRect(safeW, safeH, m_width - 2 * safeW, m_height - 2 * safeH);
302 }
303
304 void DvdWizardMenu::setTargets(QStringList list, QStringList targetlist)
305 {
306     m_view.target_list->clear();
307     m_view.target_list->addItem(i18n("Play All"), "jump title 1");
308     int movieCount = 0;
309     for (int i = 0; i < list.count(); i++) {
310         if (targetlist.at(i).contains("chapter"))
311             m_view.target_list->addItem(list.at(i), targetlist.at(i));
312         else {
313             m_view.target_list->addItem(KIcon("video-x-generic"), list.at(i), targetlist.at(i));
314             movieCount++;
315         }
316     }
317     m_view.back_to_menu->setHidden(movieCount == 1);
318 }
319
320 void DvdWizardMenu::checkBackgroundType(int ix)
321 {
322     if (ix == 0) {
323         m_view.background_color->setVisible(true);
324         m_view.background_image->setVisible(false);
325         m_view.loop_movie->setVisible(false);
326         if (m_background->scene() != 0) m_scene->removeItem(m_background);
327     } else {
328         m_view.background_color->setVisible(false);
329         m_view.background_image->setVisible(true);
330         if (ix == 1) {
331             m_view.background_image->clear();
332             m_view.background_image->setFilter("*");
333             if (m_background->scene() != 0) m_scene->removeItem(m_background);
334             m_view.loop_movie->setVisible(false);
335         } else {
336             if (m_background->scene() != 0) m_scene->removeItem(m_background);
337             m_view.background_image->clear();
338             m_view.background_image->setFilter("video/mpeg");
339             m_view.loop_movie->setVisible(true);
340         }
341     }
342 }
343
344 void DvdWizardMenu::buildColor()
345 {
346     m_color->setBrush(m_view.background_color->color());
347 }
348
349 void DvdWizardMenu::buildImage()
350 {
351     emit completeChanged();
352     if (m_view.background_image->url().isEmpty()) {
353         if (m_background->scene() != 0) m_scene->removeItem(m_background);
354         return;
355     }
356     QPixmap pix;
357
358     if (m_view.background_list->currentIndex() == 1) {
359         // image background
360         if (!pix.load(m_view.background_image->url().path())) {
361             if (m_background->scene() != 0) m_scene->removeItem(m_background);
362             return;
363         }
364         pix = pix.scaled(m_width, m_height);
365     } else if (m_view.background_list->currentIndex() == 2) {
366         // video background
367         int w;
368         if (m_isPal) w = 768;
369         else w = 640;
370         pix = KThumb::getImage(m_view.background_image->url(), 0, w, m_height);
371         pix = pix.scaled(m_width, m_height);
372     }
373     m_background->setPixmap(pix);
374     m_scene->addItem(m_background);
375 }
376
377 void DvdWizardMenu::checkBackground()
378 {
379     if (m_view.background_list->currentIndex() != 1) {
380         if (m_background->scene() != 0) m_scene->removeItem(m_background);
381     } else {
382         m_scene->addItem(m_background);
383     }
384 }
385
386 void DvdWizardMenu::buildButton()
387 {
388     DvdButton *button = NULL;
389     QList<QGraphicsItem *> list = m_scene->selectedItems();
390     for (int i = 0; i < list.count(); i++) {
391         if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
392             button = static_cast < DvdButton* >(list.at(i));
393             break;
394         }
395     }
396     if (button == NULL) return;
397     button->setPlainText(m_view.play_text->text());
398     QFont font = m_view.font_family->currentFont();
399     font.setPixelSize(m_view.font_size->value());
400     font.setStyleStrategy(QFont::NoAntialias);
401     button->setFont(font);
402     button->setDefaultTextColor(m_view.text_color->color());
403 }
404
405 void DvdWizardMenu::updateColor()
406 {
407     updateColor(m_view.text_color->color());
408     m_view.menu_preview->viewport()->update();
409 }
410
411 void DvdWizardMenu::updateColor(QColor c)
412 {
413     DvdButton *button = NULL;
414     QList<QGraphicsItem *> list = m_scene->items();
415     for (int i = 0; i < list.count(); i++) {
416         if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
417             button = static_cast < DvdButton* >(list.at(i));
418             button->setDefaultTextColor(c);
419         }
420     }
421 }
422
423
424 void DvdWizardMenu::createButtonImages(const QString &img1, const QString &img2, const QString &img3)
425 {
426     if (m_view.create_menu->isChecked()) {
427         m_scene->clearSelection();
428         QImage img(m_width, m_height, QImage::Format_ARGB32_Premultiplied);
429         img.fill(Qt::transparent);
430         if (m_safeRect->scene() != 0) m_scene->removeItem(m_safeRect);
431         if (m_color->scene() != 0) m_scene->removeItem(m_color);
432         if (m_background->scene() != 0) m_scene->removeItem(m_background);
433         QPainter p(&img);
434         p.setRenderHints(QPainter::Antialiasing, false);
435         p.setRenderHints(QPainter::TextAntialiasing, false);
436         m_scene->render(&p, QRectF(0, 0, m_width, m_height));
437         p.end();
438 #if QT_VERSION >= 0x040600
439         img.setColorCount(4);
440 #else
441         img.setNumColors(4);
442 #endif
443         img.save(img1);
444
445         /*QImage saved;
446         if (m_view.menu_profile->currentIndex() < 2)
447             saved = img.scaled(720, 576);
448         else saved = img.scaled(720, 480);
449         saved.setNumColors(4);
450         saved.save(img1);*/
451
452         updateColor(m_view.selected_color->color());
453         img.fill(Qt::transparent);
454         p.begin(&img);
455         p.setRenderHints(QPainter::Antialiasing, false);
456         p.setRenderHints(QPainter::TextAntialiasing, false);
457         m_scene->render(&p, QRectF(0, 0, m_width, m_height));
458         p.end();
459         /*        if (m_view.menu_profile->currentIndex() < 2)
460                     saved = img.scaled(720, 576);
461                 else saved = img.scaled(720, 480);
462                 saved.setNumColors(4);
463                 saved.save(img2);*/
464 #if QT_VERSION >= 0x040600
465         img.setColorCount(4);
466 #else
467         img.setNumColors(4);
468 #endif
469         img.save(img2);
470
471
472         updateColor(m_view.highlighted_color->color());
473         img.fill(Qt::transparent);
474         p.begin(&img);
475         p.setRenderHints(QPainter::Antialiasing, false);
476         p.setRenderHints(QPainter::TextAntialiasing, false);
477         m_scene->render(&p, QRectF(0, 0, m_width, m_height));
478         p.end();
479         /*if (m_view.menu_profile->currentIndex() < 2)
480             saved = img.scaled(720, 576);
481         else saved = img.scaled(720, 480);
482         saved.setNumColors(4);
483         saved.save(img3);*/
484 #if QT_VERSION >= 0x040600
485         img.setColorCount(4);
486 #else
487         img.setNumColors(4);
488 #endif
489         img.save(img3);
490
491         updateColor();
492
493         m_scene->addItem(m_safeRect);
494         m_scene->addItem(m_color);
495         if (m_view.background_list->currentIndex() > 0) m_scene->addItem(m_background);
496     }
497 }
498
499
500 void DvdWizardMenu::createBackgroundImage(const QString &img1)
501 {
502     QImage img;
503     if (m_view.background_list->currentIndex() == 0) {
504         // color background
505         if (m_isPal)
506             img = QImage(768, 576, QImage::Format_ARGB32);
507         else
508             img = QImage(720, 540, QImage::Format_ARGB32);
509         img.fill(m_view.background_color->color().rgb());
510     } else if (m_view.background_list->currentIndex() == 1) {
511         img.load(m_view.background_image->url().path());
512         if (m_isPal) {
513             if (img.width() != 768 || img.height() != 576)
514                 img = img.scaled(768, 576, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
515         } else {
516             if (img.width() != 720 || img.height() != 540)
517                 img = img.scaled(720, 540, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
518         }
519     } else return;
520     img.save(img1);
521 }
522
523 bool DvdWizardMenu::createMenu() const
524 {
525     return m_view.create_menu->isChecked();
526 }
527
528 bool DvdWizardMenu::loopMovie() const
529 {
530     return m_view.loop_movie->isChecked();
531 }
532
533 bool DvdWizardMenu::menuMovie() const
534 {
535     return m_view.background_list->currentIndex() == 2;
536 }
537
538 QString DvdWizardMenu::menuMoviePath() const
539 {
540     return m_view.background_image->url().path();
541 }
542
543
544 QMap <QString, QRect> DvdWizardMenu::buttonsInfo()
545 {
546     QMap <QString, QRect> info;
547     QList<QGraphicsItem *> list = m_scene->items();
548     for (int i = 0; i < list.count(); i++) {
549         if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
550             DvdButton *button = static_cast < DvdButton* >(list.at(i));
551             QRect r = list.at(i)->sceneBoundingRect().toRect();
552             // Make sure y1 is not odd (requested by spumux)
553             if (r.height() % 2 == 1) r.setHeight(r.height() + 1);
554             if (r.y() % 2 == 1) r.setY(r.y() - 1);
555             QString command = button->command();
556             if (button->backMenu()) command.prepend("g1 = 999;");
557             info.insertMulti(command, r);
558         }
559     }
560     return info;
561 }
562
563 bool DvdWizardMenu::isPalMenu() const
564 {
565     return m_isPal;
566 }
567
568 QDomElement DvdWizardMenu::toXml() const
569 {
570     QDomDocument doc;
571     QDomElement xml = doc.createElement("menu");
572     doc.appendChild(xml);
573     xml.setAttribute("enabled", m_view.create_menu->isChecked());
574     if (m_view.background_list->currentIndex() == 0) {
575         // Color bg
576         xml.setAttribute("background_color", m_view.background_color->color().name());
577     } else if (m_view.background_list->currentIndex() == 1) {
578         // Image bg
579         xml.setAttribute("background_image", m_view.background_image->url().path());
580     } else {
581         // Video bg
582         xml.setAttribute("background_video", m_view.background_image->url().path());
583     }
584     xml.setAttribute("text_color", m_view.text_color->color().name());
585     xml.setAttribute("selected_color", m_view.selected_color->color().name());
586     xml.setAttribute("highlighted_color", m_view.highlighted_color->color().name());
587
588     QList<QGraphicsItem *> list = m_scene->items();
589     int buttonCount = 0;
590
591     for (int i = 0; i < list.count(); i++) {
592         if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
593             buttonCount++;
594             DvdButton *button = static_cast < DvdButton* >(list.at(i));
595             QDomElement xmlbutton = doc.createElement("button");
596             xmlbutton.setAttribute("target", button->target());
597             xmlbutton.setAttribute("command", button->command());
598             xmlbutton.setAttribute("backtomenu", button->backMenu());
599             xmlbutton.setAttribute("posx", button->pos().x());
600             xmlbutton.setAttribute("posy", button->pos().y());
601             xmlbutton.setAttribute("text", button->toPlainText());
602             QFont font = button->font();
603             xmlbutton.setAttribute("font_size", font.pixelSize());
604             xmlbutton.setAttribute("font_family", font.family());
605             xml.appendChild(xmlbutton);
606         }
607     }
608     return doc.documentElement();
609 }
610
611
612 void DvdWizardMenu::loadXml(QDomElement xml)
613 {
614     kDebug() << "// LOADING MENU";
615     if (xml.isNull()) return;
616     kDebug() << "// LOADING MENU 1";
617     m_view.create_menu->setChecked(xml.attribute("enabled").toInt());
618     if (xml.hasAttribute("background_color")) {
619         m_view.background_list->setCurrentIndex(0);
620         m_view.background_color->setColor(xml.attribute("background_color"));
621     } else if (xml.hasAttribute("background_image")) {
622         m_view.background_list->setCurrentIndex(1);
623         m_view.background_image->setUrl(KUrl(xml.attribute("background_image")));
624     } else if (xml.hasAttribute("background_video")) {
625         m_view.background_list->setCurrentIndex(2);
626         m_view.background_image->setUrl(KUrl(xml.attribute("background_video")));
627     }
628
629     m_view.text_color->setColor(xml.attribute("text_color"));
630     m_view.selected_color->setColor(xml.attribute("selected_color"));
631     m_view.highlighted_color->setColor(xml.attribute("highlighted_color"));
632
633     QDomNodeList buttons = xml.elementsByTagName("button");
634     kDebug() << "// LOADING MENU 2" << buttons.count();
635
636     if (buttons.count() > 0) {
637         // Clear existing buttons
638         QList<QGraphicsItem *> list = m_scene->items();
639
640         for (int i = 0; i < list.count(); i++) {
641             if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
642                 delete list.at(i);
643                 i--;
644             }
645         }
646     }
647
648     for (int i = 0; i < buttons.count(); i++) {
649         QDomElement e = buttons.at(i).toElement();
650         // create menu button
651         DvdButton *button = new DvdButton(e.attribute("text"));
652         QFont font(e.attribute("font_family"));
653         font.setPixelSize(e.attribute("font_size").toInt());
654         font.setStyleStrategy(QFont::NoAntialias);
655         button->setFont(font);
656         button->setTarget(e.attribute("target").toInt(), e.attribute("command"));
657         button->setBackMenu(e.attribute("backtomenu").toInt());
658         button->setDefaultTextColor(m_view.text_color->color());
659         button->setZValue(4);
660         QRectF r = button->sceneBoundingRect();
661         m_scene->addItem(button);
662         button->setPos(e.attribute("posx").toDouble(), e.attribute("posy").toDouble());
663
664     }
665 }
666
667 void DvdWizardMenu::slotZoom()
668 {
669     m_view.menu_preview->scale(2.0, 2.0);
670 }
671
672 void DvdWizardMenu::slotUnZoom()
673 {
674     m_view.menu_preview->scale(0.5, 0.5);
675 }
676