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