1 /***************************************************************************
2 * Copyright (C) 2009 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
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. *
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. *
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 ***************************************************************************/
20 #include "dvdwizardmenu.h"
21 #include "kdenlivesettings.h"
24 #include <KColorScheme>
26 #if KDE_IS_VERSION(4,6,0)
27 #include <QGraphicsDropShadowEffect>
33 DvdWizardMenu::DvdWizardMenu(const QString &profile, QWidget *parent) :
40 m_view.play_text->setText(i18n("Play"));
41 m_scene = new DvdScene(this);
42 m_view.menu_preview->setScene(m_scene);
43 m_view.menu_preview->setMouseTracking(true);
44 connect(m_view.create_menu, SIGNAL(toggled(bool)), m_view.menu_box, SLOT(setEnabled(bool)));
45 connect(m_view.create_menu, SIGNAL(toggled(bool)), this, SIGNAL(completeChanged()));
47 #if KDE_IS_VERSION(4,7,0)
48 m_menuMessage = new KMessageWidget;
49 QGridLayout *s = static_cast <QGridLayout*> (layout());
50 s->addWidget(m_menuMessage, 7, 0, 1, -1);
51 m_menuMessage->hide();
52 m_view.error_message->hide();
55 m_view.add_button->setIcon(KIcon("document-new"));
56 m_view.delete_button->setIcon(KIcon("trash-empty"));
57 m_view.zoom_button->setIcon(KIcon("zoom-in"));
58 m_view.unzoom_button->setIcon(KIcon("zoom-out"));
60 m_view.add_button->setToolTip(i18n("Add new button"));
61 m_view.delete_button->setToolTip(i18n("Delete current button"));
63 if (profile == "dv_ntsc" || profile == "dv_ntsc_wide") {
65 } else changeProfile(true);
68 // Create color background
69 m_color = new QGraphicsRectItem(0, 0, m_width, m_height);
70 m_color->setBrush(m_view.background_color->color());
71 m_color->setZValue(2);
72 m_scene->addItem(m_color);
75 // create background image
76 m_background = new QGraphicsPixmapItem();
77 m_background->setZValue(3);
78 //m_scene->addItem(m_background);
80 // create safe zone rect
81 int safeW = m_width / 20;
82 int safeH = m_height / 20;
83 m_safeRect = new QGraphicsRectItem(safeW, safeH, m_width - 2 * safeW, m_height - 2 * safeH);
85 pen.setStyle(Qt::DashLine);
87 m_safeRect->setPen(pen);
88 m_safeRect->setZValue(5);
89 m_scene->addItem(m_safeRect);
90 checkBackgroundType(0);
93 DvdButton *button = new DvdButton(m_view.play_text->text());
94 QFont font = m_view.font_family->currentFont();
95 font.setPixelSize(m_view.font_size->value());
96 //font.setStyleStrategy(QFont::NoAntialias);
97 #if KDE_IS_VERSION(4,6,0)
98 if (m_view.use_shadow->isChecked()) {
99 QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this);
100 shadow->setBlurRadius(7);
101 shadow->setOffset(4, 4);
102 button->setGraphicsEffect(shadow);
104 connect(m_view.use_shadow, SIGNAL(stateChanged(int)), this, SLOT(slotEnableShadows(int)));
105 #elif KDE_IS_VERSION(4,6,0)
106 m_view.use_shadow->setHidden(true);
108 button->setFont(font);
109 button->setDefaultTextColor(m_view.text_color->color());
110 button->setZValue(4);
111 QRectF r = button->sceneBoundingRect();
112 m_scene->addItem(button);
113 button->setPos((m_width - r.width()) / 2, (m_height - r.height()) / 2);
114 button->setSelected(true);
117 //m_view.menu_preview->resizefitInView(0, 0, m_width, m_height);
119 connect(m_view.play_text, SIGNAL(textChanged(const QString &)), this, SLOT(buildButton()));
120 connect(m_view.text_color, SIGNAL(changed(const QColor &)), this, SLOT(updateColor()));
121 connect(m_view.font_size, SIGNAL(valueChanged(int)), this, SLOT(buildButton()));
122 connect(m_view.font_family, SIGNAL(currentFontChanged(const QFont &)), this, SLOT(buildButton()));
123 connect(m_view.background_image, SIGNAL(textChanged(const QString &)), this, SLOT(buildImage()));
124 connect(m_view.background_color, SIGNAL(changed(const QColor &)), this, SLOT(buildColor()));
126 connect(m_view.background_list, SIGNAL(activated(int)), this, SLOT(checkBackgroundType(int)));
128 connect(m_view.target_list, SIGNAL(activated(int)), this, SLOT(setButtonTarget(int)));
129 connect(m_view.back_to_menu, SIGNAL(toggled(bool)), this, SLOT(setBackToMenu(bool)));
131 connect(m_view.add_button, SIGNAL(pressed()), this, SLOT(addButton()));
132 connect(m_view.delete_button, SIGNAL(pressed()), this, SLOT(deleteButton()));
133 connect(m_view.zoom_button, SIGNAL(pressed()), this, SLOT(slotZoom()));
134 connect(m_view.unzoom_button, SIGNAL(pressed()), this, SLOT(slotUnZoom()));
135 connect(m_scene, SIGNAL(selectionChanged()), this, SLOT(buttonChanged()));
136 connect(m_scene, SIGNAL(changed(const QList<QRectF> &)), this, SIGNAL(completeChanged()));
138 // red background for error message
139 KColorScheme scheme(palette().currentColorGroup(), KColorScheme::Window, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
140 QPalette p = m_view.error_message->palette();
141 p.setColor(QPalette::Background, scheme.background(KColorScheme::NegativeBackground).color());
142 m_view.error_message->setAutoFillBackground(true);
143 m_view.error_message->setPalette(p);
145 m_view.menu_box->setEnabled(false);
149 DvdWizardMenu::~DvdWizardMenu()
157 void DvdWizardMenu::slotEnableShadows(int enable)
159 #if KDE_IS_VERSION(4,6,0)
160 QList<QGraphicsItem *> list = m_scene->items();
161 for (int i = 0; i < list.count(); i++) {
162 if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
164 QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this);
165 shadow->setBlurRadius(7);
166 shadow->setOffset(4, 4);
167 list.at(i)->setGraphicsEffect(shadow);
169 else list.at(i)->setGraphicsEffect(NULL);
176 bool DvdWizardMenu::isComplete() const
178 m_view.error_message->setHidden(true);
179 if (!m_view.create_menu->isChecked()) return true;
181 QList<QGraphicsItem *> list = m_scene->items();
183 // check that the menu buttons don't collide
184 for (int i = 0; i < list.count(); i++) {
185 if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
187 DvdButton *button = static_cast < DvdButton* >(list.at(i));
188 QList<QGraphicsItem *> collisions = button->collidingItems();
189 if (!collisions.isEmpty()) {
190 for (int j = 0; j < collisions.count(); j++) {
191 if (collisions.at(j)->type() == button->type()) {
192 #if KDE_IS_VERSION(4,7,0)
193 m_menuMessage->setText(i18n("Buttons overlapping"));
194 m_menuMessage->setMessageType(KMessageWidget::Warning);
195 m_menuMessage->animatedShow();
197 m_view.error_message->setText(i18n("Buttons overlapping"));
198 m_view.error_message->setHidden(false);
204 targets.append(button->target());
207 if (buttonCount == 0) {
208 //We need at least one button
209 #if KDE_IS_VERSION(4,7,0)
210 m_menuMessage->setText(i18n("No button in menu"));
211 m_menuMessage->setMessageType(KMessageWidget::Warning);
212 m_menuMessage->animatedShow();
214 m_view.error_message->setText(i18n("No button in menu"));
215 m_view.error_message->setHidden(false);
220 if (!m_view.background_image->isHidden()) {
221 // Make sure user selected a valid image /Â video file
222 if (!QFile::exists(m_view.background_image->url().path())) {
223 #if KDE_IS_VERSION(4,7,0)
224 m_menuMessage->setText(i18n("Missing background image"));
225 m_menuMessage->setMessageType(KMessageWidget::Warning);
226 m_menuMessage->animatedShow();
228 m_view.error_message->setText(i18n("Missing background image"));
229 m_view.error_message->setHidden(false);
235 #if KDE_IS_VERSION(4,7,0)
236 m_menuMessage->animatedHide();
239 // check that we have a "Play all" entry
240 if (targets.contains(0)) return true;
241 // ... or that each video file has a button
242 for (int i = m_view.target_list->count() - 1; i > 0; i--) {
243 // If there is a vob file entry and it has no button assigned, don't allow to go further
244 if (m_view.target_list->itemIcon(i).isNull() == false && !targets.contains(i)) {
245 #if KDE_IS_VERSION(4,7,0)
246 m_menuMessage->setText(i18n("No menu entry for %1", m_view.target_list->itemText(i)));
247 m_menuMessage->setMessageType(KMessageWidget::Warning);
248 m_menuMessage->animatedShow();
250 m_view.error_message->setText(i18n("No menu entry for %1", m_view.target_list->itemText(i)));
251 m_view.error_message->setHidden(false);
259 void DvdWizardMenu::setButtonTarget(int ix)
261 QList<QGraphicsItem *> list = m_scene->selectedItems();
262 for (int i = 0; i < list.count(); i++) {
263 if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
264 DvdButton *button = static_cast < DvdButton* >(list.at(i));
265 button->setTarget(ix, m_view.target_list->itemData(ix).toString());
269 emit completeChanged();
272 void DvdWizardMenu::setBackToMenu(bool backToMenu)
274 QList<QGraphicsItem *> list = m_scene->selectedItems();
275 for (int i = 0; i < list.count(); i++) {
276 if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
277 DvdButton *button = static_cast < DvdButton* >(list.at(i));
278 button->setBackMenu(backToMenu);
282 emit completeChanged();
285 void DvdWizardMenu::buttonChanged()
287 QList<QGraphicsItem *> list = m_scene->selectedItems();
288 bool foundButton = false;
289 for (int i = 0; i < list.count(); i++) {
290 if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
291 m_view.play_text->blockSignals(true);
292 m_view.font_size->blockSignals(true);
293 m_view.font_family->blockSignals(true);
294 m_view.target_list->blockSignals(true);
295 m_view.back_to_menu->blockSignals(true);
297 m_view.tabWidget->widget(0)->setEnabled(true);
298 DvdButton *button = static_cast < DvdButton* >(list.at(i));
299 m_view.target_list->setCurrentIndex(button->target());
300 m_view.play_text->setText(button->toPlainText());
301 m_view.back_to_menu->setChecked(button->backMenu());
302 QFont font = button->font();
303 m_view.font_size->setValue(font.pixelSize());
304 m_view.font_family->setCurrentFont(font);
305 m_view.play_text->blockSignals(false);
306 m_view.font_size->blockSignals(false);
307 m_view.font_family->blockSignals(false);
308 m_view.target_list->blockSignals(false);
309 m_view.back_to_menu->blockSignals(false);
313 if (!foundButton) m_view.tabWidget->widget(0)->setEnabled(false);
316 void DvdWizardMenu::addButton()
318 m_scene->clearSelection();
319 DvdButton *button = new DvdButton(m_view.play_text->text());
320 QFont font = m_view.font_family->currentFont();
321 font.setPixelSize(m_view.font_size->value());
322 #if KDE_IS_VERSION(4,6,0)
323 if (m_view.use_shadow->isChecked()) {
324 QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this);
325 shadow->setBlurRadius(7);
326 shadow->setOffset(4, 4);
327 button->setGraphicsEffect(shadow);
330 //font.setStyleStrategy(QFont::NoAntialias);
331 button->setFont(font);
332 button->setZValue(4);
333 QRectF r = button->sceneBoundingRect();
334 m_scene->addItem(button);
335 updateColor(m_view.text_color->color());
336 button->setPos((m_width - r.width()) / 2, (m_height - r.height()) / 2);
337 button->setSelected(true);
340 void DvdWizardMenu::deleteButton()
342 QList<QGraphicsItem *> list = m_scene->selectedItems();
343 for (int i = 0; i < list.count(); i++) {
344 if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
351 void DvdWizardMenu::changeProfile(bool isPal)
354 if (isPal == false) {
355 m_finalSize = QSize(720, 480);
359 m_finalSize = QSize(720, 576);
366 void DvdWizardMenu::updatePreview()
368 m_scene->setProfile(m_width, m_height);
370 matrix.scale(0.5, 0.5);
371 m_view.menu_preview->setMatrix(matrix);
372 m_view.menu_preview->setMinimumSize(m_width / 2 + 4, m_height / 2 + 8);
374 if (m_color) m_color->setRect(0, 0, m_width, m_height);
376 int safeW = m_width / 20;
377 int safeH = m_height / 20;
378 if (m_safeRect) m_safeRect->setRect(safeW, safeH, m_width - 2 * safeW, m_height - 2 * safeH);
381 void DvdWizardMenu::setTargets(QStringList list, QStringList targetlist)
383 m_view.target_list->clear();
384 m_view.target_list->addItem(i18n("Play All"), "jump title 1");
386 for (int i = 0; i < list.count(); i++) {
387 if (targetlist.at(i).contains("chapter"))
388 m_view.target_list->addItem(list.at(i), targetlist.at(i));
390 m_view.target_list->addItem(KIcon("video-x-generic"), list.at(i), targetlist.at(i));
394 m_view.back_to_menu->setHidden(movieCount == 1);
397 void DvdWizardMenu::checkBackgroundType(int ix)
400 m_view.background_color->setVisible(true);
401 m_view.background_image->setVisible(false);
402 m_view.loop_movie->setVisible(false);
403 if (m_background->scene() != 0) m_scene->removeItem(m_background);
405 m_view.background_color->setVisible(false);
406 m_view.background_image->setVisible(true);
408 m_view.background_image->clear();
409 m_view.background_image->setFilter("*");
410 if (m_background->scene() != 0) m_scene->removeItem(m_background);
411 m_view.loop_movie->setVisible(false);
413 if (m_background->scene() != 0) m_scene->removeItem(m_background);
414 m_view.background_image->clear();
415 m_view.background_image->setFilter("video/mpeg");
416 m_view.loop_movie->setVisible(true);
421 void DvdWizardMenu::buildColor()
423 m_color->setBrush(m_view.background_color->color());
426 void DvdWizardMenu::buildImage()
428 emit completeChanged();
429 if (m_view.background_image->url().isEmpty()) {
430 if (m_background->scene() != 0) m_scene->removeItem(m_background);
435 if (m_view.background_list->currentIndex() == 1) {
437 if (!pix.load(m_view.background_image->url().path())) {
438 if (m_background->scene() != 0) m_scene->removeItem(m_background);
441 pix = pix.scaled(m_width, m_height);
442 } else if (m_view.background_list->currentIndex() == 2) {
445 if (m_isPal) w = 768;
447 pix = KThumb::getImage(m_view.background_image->url(), 0, w, m_height);
448 pix = pix.scaled(m_width, m_height);
450 m_background->setPixmap(pix);
451 m_scene->addItem(m_background);
454 void DvdWizardMenu::checkBackground()
456 if (m_view.background_list->currentIndex() != 1) {
457 if (m_background->scene() != 0) m_scene->removeItem(m_background);
459 m_scene->addItem(m_background);
463 void DvdWizardMenu::buildButton()
465 DvdButton *button = NULL;
466 QList<QGraphicsItem *> list = m_scene->selectedItems();
467 for (int i = 0; i < list.count(); i++) {
468 if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
469 button = static_cast < DvdButton* >(list.at(i));
473 if (button == NULL) return;
474 button->setPlainText(m_view.play_text->text());
475 QFont font = m_view.font_family->currentFont();
476 font.setPixelSize(m_view.font_size->value());
477 //font.setStyleStrategy(QFont::NoAntialias);
478 button->setFont(font);
479 button->setDefaultTextColor(m_view.text_color->color());
482 void DvdWizardMenu::updateColor()
484 updateColor(m_view.text_color->color());
485 m_view.menu_preview->viewport()->update();
488 void DvdWizardMenu::prepareUnderLines()
490 QList<QGraphicsItem *> list = m_scene->items();
491 for (int i = 0; i < list.count(); i++) {
492 if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
493 QRectF r = list.at(i)->sceneBoundingRect();
494 int bottom = r.bottom() - 1;
495 if (bottom % 2 == 1) bottom = bottom - 1;
496 int underlineHeight = r.height() / 10;
497 if (underlineHeight % 2 == 1) underlineHeight = underlineHeight - 1;
498 underlineHeight = qMin(underlineHeight, 10);
499 underlineHeight = qMax(underlineHeight, 2);
500 r.setTop(bottom - underlineHeight);
501 r.adjust(2, 0, -2, 0);
502 QGraphicsRectItem *underline = new QGraphicsRectItem(r);
503 underline->setData(Qt::UserRole, QString("underline"));
504 m_scene->addItem(underline);
505 list.at(i)->setVisible(false);
510 void DvdWizardMenu::resetUnderLines()
512 QList<QGraphicsItem *> list = m_scene->items();
513 QList<QGraphicsItem *> toDelete;
514 for (int i = 0; i < list.count(); i++) {
515 if (list.at(i)->data(Qt::UserRole).toString() == "underline") {
516 toDelete.append(list.at(i));
518 if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
519 list.at(i)->setVisible(true);
522 while (!toDelete.isEmpty()) {
523 QGraphicsItem *item = toDelete.takeFirst();
528 void DvdWizardMenu::updateUnderlineColor(QColor c)
530 QList<QGraphicsItem *> list = m_scene->items();
531 for (int i = 0; i < list.count(); i++) {
532 if (list.at(i)->data(Qt::UserRole).toString() == "underline") {
533 QGraphicsRectItem *underline = static_cast < QGraphicsRectItem* >(list.at(i));
534 underline->setPen(Qt::NoPen);
536 underline->setBrush(c);
542 void DvdWizardMenu::updateColor(QColor c)
544 DvdButton *button = NULL;
545 QList<QGraphicsItem *> list = m_scene->items();
546 for (int i = 0; i < list.count(); i++) {
547 if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
548 button = static_cast < DvdButton* >(list.at(i));
549 button->setDefaultTextColor(c);
555 void DvdWizardMenu::createButtonImages(const QString &img1, const QString &img2, const QString &img3)
557 if (m_view.create_menu->isChecked()) {
558 m_scene->clearSelection();
559 if (m_safeRect->scene() != 0) m_scene->removeItem(m_safeRect);
560 if (m_color->scene() != 0) m_scene->removeItem(m_color);
561 if (m_background->scene() != 0) m_scene->removeItem(m_background);
563 #if QT_VERSION >= 0x040800
564 QImage img(m_finalSize.width(), m_finalSize.height(), QImage::Format_ARGB32);
565 img.fill(Qt::transparent);
566 updateUnderlineColor(m_view.text_color->color());
568 QImage img(m_finalSize.width(), m_finalSize.height(), QImage::Format_Mono);
570 updateUnderlineColor(Qt::black);
573 //p.setRenderHints(QPainter::Antialiasing, false);
574 //p.setRenderHints(QPainter::TextAntialiasing, false);
575 m_scene->render(&p, QRectF(0, 0, m_finalSize.width(), m_finalSize.height()), QRectF(0, 0, m_width, m_height), Qt::IgnoreAspectRatio);
577 #if QT_VERSION >= 0x040800
578 #elif QT_VERSION >= 0x040600
579 img.setColor(0, m_view.text_color->color().rgb());
580 img.setColor(1, qRgba(0,0,0,0));
586 #if QT_VERSION >= 0x040800
587 img.fill(Qt::transparent);
588 updateUnderlineColor(m_view.highlighted_color->color());
593 //p.setRenderHints(QPainter::Antialiasing, false);
594 //p.setRenderHints(QPainter::TextAntialiasing, false);
595 m_scene->render(&p, QRectF(0, 0, m_finalSize.width(), m_finalSize.height()), QRectF(0, 0, m_width, m_height), Qt::IgnoreAspectRatio);
597 #if QT_VERSION >= 0x040800
598 #elif QT_VERSION >= 0x040600
599 img.setColor(0, m_view.highlighted_color->color().rgb());
600 img.setColor(1, qRgba(0,0,0,0));
606 #if QT_VERSION >= 0x040800
607 img.fill(Qt::transparent);
608 updateUnderlineColor(m_view.selected_color->color());
613 //p.setRenderHints(QPainter::Antialiasing, false);
614 //p.setRenderHints(QPainter::TextAntialiasing, false);
615 m_scene->render(&p, QRectF(0, 0, m_finalSize.width(), m_finalSize.height()), QRectF(0, 0, m_width, m_height), Qt::IgnoreAspectRatio);
617 #if QT_VERSION >= 0x040800
618 #elif QT_VERSION >= 0x040600
619 img.setColor(0, m_view.selected_color->color().rgb());
620 img.setColor(1, qRgba(0,0,0,0));
626 m_scene->addItem(m_safeRect);
627 m_scene->addItem(m_color);
628 if (m_view.background_list->currentIndex() > 0) m_scene->addItem(m_background);
633 void DvdWizardMenu::createBackgroundImage(const QString &overlayMenu, const QString &img1)
635 m_scene->clearSelection();
636 if (m_safeRect->scene() != 0) m_scene->removeItem(m_safeRect);
637 QImage img(m_width, m_height, QImage::Format_ARGB32);
638 updateColor(m_view.text_color->color());
640 p.setRenderHints(QPainter::Antialiasing, true);
641 p.setRenderHints(QPainter::TextAntialiasing, true);
642 m_scene->render(&p, QRectF(0, 0, img.width(), img.height()));
645 m_scene->addItem(m_safeRect);
650 if (m_view.background_list->currentIndex() == 0) {
653 img = QImage(768, 576, QImage::Format_ARGB32);
655 img = QImage(720, 540, QImage::Format_ARGB32);
656 img.fill(m_view.background_color->color().rgb());
657 } else if (m_view.background_list->currentIndex() == 1) {
658 img.load(m_view.background_image->url().path());
660 if (img.width() != 768 || img.height() != 576)
661 img = img.scaled(768, 576, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
663 if (img.width() != 720 || img.height() != 540)
664 img = img.scaled(720, 540, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
667 // Overlay Normal menu
668 QImage menu(overlayMenu);
670 QRectF target(0, 0, img.width(), img.height());
671 QRectF src(0, 0, menu.width(), menu.height());
672 p.drawImage(target, menu, src);
677 bool DvdWizardMenu::createMenu() const
679 return m_view.create_menu->isChecked();
682 bool DvdWizardMenu::loopMovie() const
684 return m_view.loop_movie->isChecked();
687 bool DvdWizardMenu::menuMovie() const
689 return m_view.background_list->currentIndex() == 2;
692 QString DvdWizardMenu::menuMoviePath() const
694 return m_view.background_image->url().path();
698 QMap <QString, QRect> DvdWizardMenu::buttonsInfo()
700 QMap <QString, QRect> info;
701 QList<QGraphicsItem *> list = m_scene->items();
702 double ratio = (double) m_finalSize.width() / m_width;
703 for (int i = 0; i < list.count(); i++) {
704 if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
705 DvdButton *button = static_cast < DvdButton* >(list.at(i));
706 QRectF r = button->sceneBoundingRect();
707 QRect adjustedRect(r.x() * ratio, r.y(), r.width() * ratio, r.height());
708 // Make sure y1 is not odd (requested by spumux)
709 if (adjustedRect.height() % 2 == 1) adjustedRect.setHeight(adjustedRect.height() + 1);
710 if (adjustedRect.y() % 2 == 1) adjustedRect.setY(adjustedRect.y() - 1);
711 QString command = button->command();
712 if (button->backMenu()) command.prepend("g1 = 999;");
713 info.insertMulti(command, adjustedRect);
719 bool DvdWizardMenu::isPalMenu() const
724 QDomElement DvdWizardMenu::toXml() const
727 QDomElement xml = doc.createElement("menu");
728 doc.appendChild(xml);
729 xml.setAttribute("enabled", m_view.create_menu->isChecked());
730 if (m_view.background_list->currentIndex() == 0) {
732 xml.setAttribute("background_color", m_view.background_color->color().name());
733 } else if (m_view.background_list->currentIndex() == 1) {
735 xml.setAttribute("background_image", m_view.background_image->url().path());
738 xml.setAttribute("background_video", m_view.background_image->url().path());
740 xml.setAttribute("text_color", m_view.text_color->color().name());
741 xml.setAttribute("selected_color", m_view.selected_color->color().name());
742 xml.setAttribute("highlighted_color", m_view.highlighted_color->color().name());
743 xml.setAttribute("text_shadow", (int) m_view.use_shadow->isChecked());
745 QList<QGraphicsItem *> list = m_scene->items();
748 for (int i = 0; i < list.count(); i++) {
749 if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
751 DvdButton *button = static_cast < DvdButton* >(list.at(i));
752 QDomElement xmlbutton = doc.createElement("button");
753 xmlbutton.setAttribute("target", button->target());
754 xmlbutton.setAttribute("command", button->command());
755 xmlbutton.setAttribute("backtomenu", button->backMenu());
756 xmlbutton.setAttribute("posx", button->pos().x());
757 xmlbutton.setAttribute("posy", button->pos().y());
758 xmlbutton.setAttribute("text", button->toPlainText());
759 QFont font = button->font();
760 xmlbutton.setAttribute("font_size", font.pixelSize());
761 xmlbutton.setAttribute("font_family", font.family());
762 xml.appendChild(xmlbutton);
765 return doc.documentElement();
769 void DvdWizardMenu::loadXml(QDomElement xml)
771 kDebug() << "// LOADING MENU";
772 if (xml.isNull()) return;
773 kDebug() << "// LOADING MENU 1";
774 m_view.create_menu->setChecked(xml.attribute("enabled").toInt());
775 if (xml.hasAttribute("background_color")) {
776 m_view.background_list->setCurrentIndex(0);
777 m_view.background_color->setColor(xml.attribute("background_color"));
778 } else if (xml.hasAttribute("background_image")) {
779 m_view.background_list->setCurrentIndex(1);
780 m_view.background_image->setUrl(KUrl(xml.attribute("background_image")));
781 } else if (xml.hasAttribute("background_video")) {
782 m_view.background_list->setCurrentIndex(2);
783 m_view.background_image->setUrl(KUrl(xml.attribute("background_video")));
786 m_view.text_color->setColor(xml.attribute("text_color"));
787 m_view.selected_color->setColor(xml.attribute("selected_color"));
788 m_view.highlighted_color->setColor(xml.attribute("highlighted_color"));
790 m_view.use_shadow->setChecked(xml.attribute("text_shadow").toInt());
792 QDomNodeList buttons = xml.elementsByTagName("button");
793 kDebug() << "// LOADING MENU 2" << buttons.count();
795 if (buttons.count() > 0) {
796 // Clear existing buttons
797 QList<QGraphicsItem *> list = m_scene->items();
799 for (int i = 0; i < list.count(); i++) {
800 if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
807 for (int i = 0; i < buttons.count(); i++) {
808 QDomElement e = buttons.at(i).toElement();
809 // create menu button
810 DvdButton *button = new DvdButton(e.attribute("text"));
811 QFont font(e.attribute("font_family"));
812 font.setPixelSize(e.attribute("font_size").toInt());
813 #if KDE_IS_VERSION(4,6,0)
814 if (m_view.use_shadow->isChecked()) {
815 QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this);
816 shadow->setBlurRadius(7);
817 shadow->setOffset(4, 4);
818 button->setGraphicsEffect(shadow);
822 //font.setStyleStrategy(QFont::NoAntialias);
823 button->setFont(font);
824 button->setTarget(e.attribute("target").toInt(), e.attribute("command"));
825 button->setBackMenu(e.attribute("backtomenu").toInt());
826 button->setDefaultTextColor(m_view.text_color->color());
827 button->setZValue(4);
828 m_scene->addItem(button);
829 button->setPos(e.attribute("posx").toDouble(), e.attribute("posy").toDouble());
834 void DvdWizardMenu::slotZoom()
836 m_view.menu_preview->scale(2.0, 2.0);
839 void DvdWizardMenu::slotUnZoom()
841 m_view.menu_preview->scale(0.5, 0.5);