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