]> git.sesse.net Git - kdenlive/blob - src/dvdwizardmenu.cpp
89ce70c7f68eb06cb3a67a696ead928095ef3823
[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     } else {
281         m_width = 720;
282         m_height = 576;
283     }
284     updatePreview();
285 }
286
287 void DvdWizardMenu::updatePreview()
288 {
289     m_scene->setProfile(m_width, m_height);
290     QMatrix matrix;
291     matrix.scale(0.5, 0.5);
292     m_view.menu_preview->setMatrix(matrix);
293     m_view.menu_preview->setMinimumSize(m_width / 2 + 4, m_height / 2 + 8);
294
295     if (m_color) m_color->setRect(0, 0, m_width, m_height);
296
297     int safeW = m_width / 20;
298     int safeH = m_height / 20;
299     if (m_safeRect) m_safeRect->setRect(safeW, safeH, m_width - 2 * safeW, m_height - 2 * safeH);
300 }
301
302 void DvdWizardMenu::setTargets(QStringList list, QStringList targetlist)
303 {
304     m_view.target_list->clear();
305     m_view.target_list->addItem(i18n("Play All"), "jump title 1");
306     int movieCount = 0;
307     for (int i = 0; i < list.count(); i++) {
308         if (targetlist.at(i).contains("chapter"))
309             m_view.target_list->addItem(list.at(i), targetlist.at(i));
310         else {
311             m_view.target_list->addItem(KIcon("video-x-generic"), list.at(i), targetlist.at(i));
312             movieCount++;
313         }
314     }
315     m_view.back_to_menu->setHidden(movieCount == 1);
316 }
317
318 void DvdWizardMenu::checkBackgroundType(int ix)
319 {
320     if (ix == 0) {
321         m_view.background_color->setVisible(true);
322         m_view.background_image->setVisible(false);
323         m_view.loop_movie->setVisible(false);
324         if (m_background->scene() != 0) m_scene->removeItem(m_background);
325     } else {
326         m_view.background_color->setVisible(false);
327         m_view.background_image->setVisible(true);
328         if (ix == 1) {
329             m_view.background_image->clear();
330             m_view.background_image->setFilter("*");
331             if (m_background->scene() != 0) m_scene->removeItem(m_background);
332             m_view.loop_movie->setVisible(false);
333         } else {
334             if (m_background->scene() != 0) m_scene->removeItem(m_background);
335             m_view.background_image->clear();
336             m_view.background_image->setFilter("video/mpeg");
337             m_view.loop_movie->setVisible(true);
338         }
339     }
340 }
341
342 void DvdWizardMenu::buildColor()
343 {
344     m_color->setBrush(m_view.background_color->color());
345 }
346
347 void DvdWizardMenu::buildImage()
348 {
349     emit completeChanged();
350     if (m_view.background_image->url().isEmpty()) {
351         if (m_background->scene() != 0) m_scene->removeItem(m_background);
352         return;
353     }
354     QPixmap pix;
355
356     if (m_view.background_list->currentIndex() == 1) {
357         // image background
358         if (!pix.load(m_view.background_image->url().path())) {
359             if (m_background->scene() != 0) m_scene->removeItem(m_background);
360             return;
361         }
362         pix = pix.scaled(m_width, m_height);
363     } else if (m_view.background_list->currentIndex() == 2) {
364         // video background
365         int w;
366         if (m_isPal) w = 768;
367         else w = 640;
368         pix = KThumb::getImage(m_view.background_image->url(), 0, w, m_height);
369         pix = pix.scaled(m_width, m_height);
370     }
371     m_background->setPixmap(pix);
372     m_scene->addItem(m_background);
373 }
374
375 void DvdWizardMenu::checkBackground()
376 {
377     if (m_view.background_list->currentIndex() != 1) {
378         if (m_background->scene() != 0) m_scene->removeItem(m_background);
379     } else {
380         m_scene->addItem(m_background);
381     }
382 }
383
384 void DvdWizardMenu::buildButton()
385 {
386     DvdButton *button = NULL;
387     QList<QGraphicsItem *> list = m_scene->selectedItems();
388     for (int i = 0; i < list.count(); i++) {
389         if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
390             button = static_cast < DvdButton* >(list.at(i));
391             break;
392         }
393     }
394     if (button == NULL) return;
395     button->setPlainText(m_view.play_text->text());
396     QFont font = m_view.font_family->currentFont();
397     font.setPixelSize(m_view.font_size->value());
398     font.setStyleStrategy(QFont::NoAntialias);
399     button->setFont(font);
400     button->setDefaultTextColor(m_view.text_color->color());
401 }
402
403 void DvdWizardMenu::updateColor()
404 {
405     updateColor(m_view.text_color->color());
406     m_view.menu_preview->viewport()->update();
407 }
408
409 void DvdWizardMenu::updateColor(QColor c)
410 {
411     DvdButton *button = NULL;
412     QList<QGraphicsItem *> list = m_scene->items();
413     for (int i = 0; i < list.count(); i++) {
414         if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
415             button = static_cast < DvdButton* >(list.at(i));
416             button->setDefaultTextColor(c);
417         }
418     }
419 }
420
421
422 void DvdWizardMenu::createButtonImages(const QString &img1, const QString &img2, const QString &img3)
423 {
424     if (m_view.create_menu->isChecked()) {
425         m_scene->clearSelection();
426         if (m_safeRect->scene() != 0) m_scene->removeItem(m_safeRect);
427         if (m_color->scene() != 0) m_scene->removeItem(m_color);
428         if (m_background->scene() != 0) m_scene->removeItem(m_background);
429         
430         QImage img(m_width, m_height, QImage::Format_Mono);
431         img.fill(Qt::white);
432         updateColor(Qt::black);
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.setColor(0, m_view.text_color->color().rgb());
440         img.setColor(1, qRgba(0,0,0,0));
441 #else
442         img.setNumColors(4);
443 #endif
444         img.save(img1);
445
446         img.fill(Qt::white);
447         p.begin(&img);
448         p.setRenderHints(QPainter::Antialiasing, false);
449         p.setRenderHints(QPainter::TextAntialiasing, false);
450         m_scene->render(&p, QRectF(0, 0, m_width, m_height));
451         p.end();
452 #if QT_VERSION >= 0x040600
453         img.setColor(0, m_view.highlighted_color->color().rgb());
454         img.setColor(1, qRgba(0,0,0,0));
455 #else
456         img.setNumColors(4);
457 #endif
458         img.save(img3);        
459
460         img.fill(Qt::white);
461         p.begin(&img);
462         p.setRenderHints(QPainter::Antialiasing, false);
463         p.setRenderHints(QPainter::TextAntialiasing, false);
464         m_scene->render(&p, QRectF(0, 0, m_width, m_height));
465         p.end();
466
467 #if QT_VERSION >= 0x040600
468         img.setColor(0, m_view.selected_color->color().rgb());
469         img.setColor(1, qRgba(0,0,0,0));
470 #else
471         img.setNumColors(4);
472 #endif
473         img.save(img2);
474         updateColor();
475
476         m_scene->addItem(m_safeRect);
477         m_scene->addItem(m_color);
478         if (m_view.background_list->currentIndex() > 0) m_scene->addItem(m_background);
479     }
480 }
481
482
483 void DvdWizardMenu::createBackgroundImage(const QString &img1)
484 {
485     QImage img;
486     if (m_view.background_list->currentIndex() == 0) {
487         // color background
488         if (m_isPal)
489             img = QImage(768, 576, QImage::Format_ARGB32);
490         else
491             img = QImage(720, 540, QImage::Format_ARGB32);
492         img.fill(m_view.background_color->color().rgb());
493     } else if (m_view.background_list->currentIndex() == 1) {
494         img.load(m_view.background_image->url().path());
495         if (m_isPal) {
496             if (img.width() != 768 || img.height() != 576)
497                 img = img.scaled(768, 576, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
498         } else {
499             if (img.width() != 720 || img.height() != 540)
500                 img = img.scaled(720, 540, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
501         }
502     } else return;
503     img.save(img1);
504 }
505
506 bool DvdWizardMenu::createMenu() const
507 {
508     return m_view.create_menu->isChecked();
509 }
510
511 bool DvdWizardMenu::loopMovie() const
512 {
513     return m_view.loop_movie->isChecked();
514 }
515
516 bool DvdWizardMenu::menuMovie() const
517 {
518     return m_view.background_list->currentIndex() == 2;
519 }
520
521 QString DvdWizardMenu::menuMoviePath() const
522 {
523     return m_view.background_image->url().path();
524 }
525
526
527 QMap <QString, QRect> DvdWizardMenu::buttonsInfo()
528 {
529     QMap <QString, QRect> info;
530     QList<QGraphicsItem *> list = m_scene->items();
531     for (int i = 0; i < list.count(); i++) {
532         if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
533             DvdButton *button = static_cast < DvdButton* >(list.at(i));
534             QRect r = list.at(i)->sceneBoundingRect().toRect();
535             // Make sure y1 is not odd (requested by spumux)
536             if (r.height() % 2 == 1) r.setHeight(r.height() + 1);
537             if (r.y() % 2 == 1) r.setY(r.y() - 1);
538             QString command = button->command();
539             if (button->backMenu()) command.prepend("g1 = 999;");
540             info.insertMulti(command, r);
541         }
542     }
543     return info;
544 }
545
546 bool DvdWizardMenu::isPalMenu() const
547 {
548     return m_isPal;
549 }
550
551 QDomElement DvdWizardMenu::toXml() const
552 {
553     QDomDocument doc;
554     QDomElement xml = doc.createElement("menu");
555     doc.appendChild(xml);
556     xml.setAttribute("enabled", m_view.create_menu->isChecked());
557     if (m_view.background_list->currentIndex() == 0) {
558         // Color bg
559         xml.setAttribute("background_color", m_view.background_color->color().name());
560     } else if (m_view.background_list->currentIndex() == 1) {
561         // Image bg
562         xml.setAttribute("background_image", m_view.background_image->url().path());
563     } else {
564         // Video bg
565         xml.setAttribute("background_video", m_view.background_image->url().path());
566     }
567     xml.setAttribute("text_color", m_view.text_color->color().name());
568     xml.setAttribute("selected_color", m_view.selected_color->color().name());
569     xml.setAttribute("highlighted_color", m_view.highlighted_color->color().name());
570
571     QList<QGraphicsItem *> list = m_scene->items();
572     int buttonCount = 0;
573
574     for (int i = 0; i < list.count(); i++) {
575         if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
576             buttonCount++;
577             DvdButton *button = static_cast < DvdButton* >(list.at(i));
578             QDomElement xmlbutton = doc.createElement("button");
579             xmlbutton.setAttribute("target", button->target());
580             xmlbutton.setAttribute("command", button->command());
581             xmlbutton.setAttribute("backtomenu", button->backMenu());
582             xmlbutton.setAttribute("posx", button->pos().x());
583             xmlbutton.setAttribute("posy", button->pos().y());
584             xmlbutton.setAttribute("text", button->toPlainText());
585             QFont font = button->font();
586             xmlbutton.setAttribute("font_size", font.pixelSize());
587             xmlbutton.setAttribute("font_family", font.family());
588             xml.appendChild(xmlbutton);
589         }
590     }
591     return doc.documentElement();
592 }
593
594
595 void DvdWizardMenu::loadXml(QDomElement xml)
596 {
597     kDebug() << "// LOADING MENU";
598     if (xml.isNull()) return;
599     kDebug() << "// LOADING MENU 1";
600     m_view.create_menu->setChecked(xml.attribute("enabled").toInt());
601     if (xml.hasAttribute("background_color")) {
602         m_view.background_list->setCurrentIndex(0);
603         m_view.background_color->setColor(xml.attribute("background_color"));
604     } else if (xml.hasAttribute("background_image")) {
605         m_view.background_list->setCurrentIndex(1);
606         m_view.background_image->setUrl(KUrl(xml.attribute("background_image")));
607     } else if (xml.hasAttribute("background_video")) {
608         m_view.background_list->setCurrentIndex(2);
609         m_view.background_image->setUrl(KUrl(xml.attribute("background_video")));
610     }
611
612     m_view.text_color->setColor(xml.attribute("text_color"));
613     m_view.selected_color->setColor(xml.attribute("selected_color"));
614     m_view.highlighted_color->setColor(xml.attribute("highlighted_color"));
615
616     QDomNodeList buttons = xml.elementsByTagName("button");
617     kDebug() << "// LOADING MENU 2" << buttons.count();
618
619     if (buttons.count() > 0) {
620         // Clear existing buttons
621         QList<QGraphicsItem *> list = m_scene->items();
622
623         for (int i = 0; i < list.count(); i++) {
624             if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
625                 delete list.at(i);
626                 i--;
627             }
628         }
629     }
630
631     for (int i = 0; i < buttons.count(); i++) {
632         QDomElement e = buttons.at(i).toElement();
633         // create menu button
634         DvdButton *button = new DvdButton(e.attribute("text"));
635         QFont font(e.attribute("font_family"));
636         font.setPixelSize(e.attribute("font_size").toInt());
637         font.setStyleStrategy(QFont::NoAntialias);
638         button->setFont(font);
639         button->setTarget(e.attribute("target").toInt(), e.attribute("command"));
640         button->setBackMenu(e.attribute("backtomenu").toInt());
641         button->setDefaultTextColor(m_view.text_color->color());
642         button->setZValue(4);
643         QRectF r = button->sceneBoundingRect();
644         m_scene->addItem(button);
645         button->setPos(e.attribute("posx").toDouble(), e.attribute("posy").toDouble());
646
647     }
648 }
649
650 void DvdWizardMenu::slotZoom()
651 {
652     m_view.menu_preview->scale(2.0, 2.0);
653 }
654
655 void DvdWizardMenu::slotUnZoom()
656 {
657     m_view.menu_preview->scale(0.5, 0.5);
658 }
659