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 enum { DvdButtonItem = QGraphicsItem::UserType + 1, DvdButtonUnderlineItem = QGraphicsItem::UserType + 2 };
35 DvdWizardMenu::DvdWizardMenu(DVDFORMAT format, QWidget *parent) :
39 m_finalSize(720, 576),
43 m_view.play_text->setText(i18n("Play"));
44 m_scene = new DvdScene(this);
45 m_view.menu_preview->setScene(m_scene);
46 m_view.menu_preview->setMouseTracking(true);
47 connect(m_view.create_menu, SIGNAL(toggled(bool)), m_view.menu_box, SLOT(setEnabled(bool)));
48 connect(m_view.create_menu, SIGNAL(toggled(bool)), this, SIGNAL(completeChanged()));
50 #if KDE_IS_VERSION(4,7,0)
51 m_menuMessage = new KMessageWidget;
52 QGridLayout *s = static_cast <QGridLayout*> (layout());
53 s->addWidget(m_menuMessage, 7, 0, 1, -1);
54 m_menuMessage->hide();
55 m_view.error_message->hide();
58 m_view.add_button->setIcon(KIcon("document-new"));
59 m_view.delete_button->setIcon(KIcon("trash-empty"));
60 m_view.zoom_button->setIcon(KIcon("zoom-in"));
61 m_view.unzoom_button->setIcon(KIcon("zoom-out"));
63 m_view.add_button->setToolTip(i18n("Add new button"));
64 m_view.delete_button->setToolTip(i18n("Delete current button"));
66 changeProfile(format);
69 // Create color background
70 m_color = new QGraphicsRectItem(0, 0, m_width, m_height);
71 m_color->setBrush(m_view.background_color->color());
72 m_color->setZValue(2);
73 m_scene->addItem(m_color);
76 // create background image
77 m_background = new QGraphicsPixmapItem();
78 m_background->setZValue(3);
79 //m_scene->addItem(m_background);
81 // create safe zone rect
82 int safeW = m_width / 20;
83 int safeH = m_height / 20;
84 m_safeRect = new QGraphicsRectItem(safeW, safeH, m_width - 2 * safeW, m_height - 2 * safeH);
86 pen.setStyle(Qt::DashLine);
88 m_safeRect->setPen(pen);
89 m_safeRect->setZValue(5);
90 m_scene->addItem(m_safeRect);
91 checkBackgroundType(0);
94 DvdButton *button = new DvdButton(m_view.play_text->text());
95 QFont font = m_view.font_family->currentFont();
96 font.setPixelSize(m_view.font_size->value());
97 //font.setStyleStrategy(QFont::NoAntialias);
98 #if KDE_IS_VERSION(4,6,0)
99 if (m_view.use_shadow->isChecked()) {
100 QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this);
101 shadow->setBlurRadius(7);
102 shadow->setOffset(4, 4);
103 button->setGraphicsEffect(shadow);
105 connect(m_view.use_shadow, SIGNAL(stateChanged(int)), this, SLOT(slotEnableShadows(int)));
106 #elif KDE_IS_VERSION(4,6,0)
107 m_view.use_shadow->setHidden(true);
109 button->setFont(font);
110 button->setDefaultTextColor(m_view.text_color->color());
111 button->setZValue(4);
112 QRectF r = button->sceneBoundingRect();
113 m_scene->addItem(button);
114 button->setPos((m_width - r.width()) / 2, (m_height - r.height()) / 2);
115 button->setSelected(true);
118 //m_view.menu_preview->resizefitInView(0, 0, m_width, m_height);
120 connect(m_view.play_text, SIGNAL(textChanged(const QString &)), this, SLOT(buildButton()));
121 connect(m_view.text_color, SIGNAL(changed(const QColor &)), this, SLOT(updateColor()));
122 connect(m_view.font_size, SIGNAL(valueChanged(int)), this, SLOT(buildButton()));
123 connect(m_view.font_family, SIGNAL(currentFontChanged(const QFont &)), this, SLOT(buildButton()));
124 connect(m_view.background_image, SIGNAL(textChanged(const QString &)), this, SLOT(buildImage()));
125 connect(m_view.background_color, SIGNAL(changed(const QColor &)), this, SLOT(buildColor()));
127 connect(m_view.background_list, SIGNAL(currentIndexChanged(int)), this, SLOT(checkBackgroundType(int)));
129 connect(m_view.target_list, SIGNAL(activated(int)), this, SLOT(setButtonTarget(int)));
130 connect(m_view.back_to_menu, SIGNAL(toggled(bool)), this, SLOT(setBackToMenu(bool)));
132 connect(m_view.add_button, SIGNAL(pressed()), this, SLOT(addButton()));
133 connect(m_view.delete_button, SIGNAL(pressed()), this, SLOT(deleteButton()));
134 connect(m_view.zoom_button, SIGNAL(pressed()), this, SLOT(slotZoom()));
135 connect(m_view.unzoom_button, SIGNAL(pressed()), this, SLOT(slotUnZoom()));
136 connect(m_scene, SIGNAL(selectionChanged()), this, SLOT(buttonChanged()));
137 connect(m_scene, SIGNAL(changed(const QList<QRectF> &)), this, SIGNAL(completeChanged()));
139 // red background for error message
140 KColorScheme scheme(palette().currentColorGroup(), KColorScheme::Window, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
141 QPalette p = m_view.error_message->palette();
142 p.setColor(QPalette::Background, scheme.background(KColorScheme::NegativeBackground).color());
143 m_view.error_message->setAutoFillBackground(true);
144 m_view.error_message->setPalette(p);
146 m_view.menu_box->setEnabled(false);
150 DvdWizardMenu::~DvdWizardMenu()
158 void DvdWizardMenu::slotEnableShadows(int enable)
160 #if KDE_IS_VERSION(4,6,0)
161 QList<QGraphicsItem *> list = m_scene->items();
162 for (int i = 0; i < list.count(); i++) {
163 if (list.at(i)->type() == DvdButtonItem) {
165 QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this);
166 shadow->setBlurRadius(7);
167 shadow->setOffset(4, 4);
168 list.at(i)->setGraphicsEffect(shadow);
170 else list.at(i)->setGraphicsEffect(NULL);
177 bool DvdWizardMenu::isComplete() const
179 m_view.error_message->setHidden(true);
180 if (!m_view.create_menu->isChecked()) return true;
182 QList<QGraphicsItem *> list = m_scene->items();
184 // check that the menu buttons don't collide
185 for (int i = 0; i < list.count(); i++) {
186 if (list.at(i)->type() == DvdButtonItem) {
188 DvdButton *button = static_cast < DvdButton* >(list.at(i));
189 QList<QGraphicsItem *> collisions = button->collidingItems();
190 if (!collisions.isEmpty()) {
191 for (int j = 0; j < collisions.count(); j++) {
192 if (collisions.at(j)->type() == button->type()) {
193 #if KDE_IS_VERSION(4,7,0)
194 m_menuMessage->setText(i18n("Buttons overlapping"));
195 m_menuMessage->setMessageType(KMessageWidget::Warning);
196 m_menuMessage->animatedShow();
198 m_view.error_message->setText(i18n("Buttons overlapping"));
199 m_view.error_message->setHidden(false);
205 targets.append(button->target());
208 if (buttonCount == 0) {
209 //We need at least one button
210 #if KDE_IS_VERSION(4,7,0)
211 m_menuMessage->setText(i18n("No button in menu"));
212 m_menuMessage->setMessageType(KMessageWidget::Warning);
213 m_menuMessage->animatedShow();
215 m_view.error_message->setText(i18n("No button in menu"));
216 m_view.error_message->setHidden(false);
221 if (!m_view.background_image->isHidden()) {
222 // Make sure user selected a valid image /Â video file
223 if (!QFile::exists(m_view.background_image->url().path())) {
224 #if KDE_IS_VERSION(4,7,0)
225 m_menuMessage->setText(i18n("Missing background image"));
226 m_menuMessage->setMessageType(KMessageWidget::Warning);
227 m_menuMessage->animatedShow();
229 m_view.error_message->setText(i18n("Missing background image"));
230 m_view.error_message->setHidden(false);
236 #if KDE_IS_VERSION(4,7,0)
237 m_menuMessage->animatedHide();
240 // check that we have a "Play all" entry
241 if (targets.contains(0)) return true;
242 // ... or that each video file has a button
243 for (int i = m_view.target_list->count() - 1; i > 0; i--) {
244 // If there is a vob file entry and it has no button assigned, don't allow to go further
245 if (m_view.target_list->itemIcon(i).isNull() == false && !targets.contains(i)) {
246 #if KDE_IS_VERSION(4,7,0)
247 m_menuMessage->setText(i18n("No menu entry for %1", m_view.target_list->itemText(i)));
248 m_menuMessage->setMessageType(KMessageWidget::Warning);
249 m_menuMessage->animatedShow();
251 m_view.error_message->setText(i18n("No menu entry for %1", m_view.target_list->itemText(i)));
252 m_view.error_message->setHidden(false);
260 void DvdWizardMenu::setButtonTarget(int ix)
262 QList<QGraphicsItem *> list = m_scene->selectedItems();
263 for (int i = 0; i < list.count(); i++) {
264 if (list.at(i)->type() == DvdButtonItem) {
265 DvdButton *button = static_cast < DvdButton* >(list.at(i));
266 button->setTarget(ix, m_view.target_list->itemData(ix).toString());
270 emit completeChanged();
273 void DvdWizardMenu::setBackToMenu(bool backToMenu)
275 QList<QGraphicsItem *> list = m_scene->selectedItems();
276 for (int i = 0; i < list.count(); i++) {
277 if (list.at(i)->type() == DvdButtonItem) {
278 DvdButton *button = static_cast < DvdButton* >(list.at(i));
279 button->setBackMenu(backToMenu);
283 emit completeChanged();
286 void DvdWizardMenu::buttonChanged()
288 QList<QGraphicsItem *> list = m_scene->selectedItems();
289 bool foundButton = false;
290 for (int i = 0; i < list.count(); i++) {
291 if (list.at(i)->type() == DvdButtonItem) {
292 m_view.play_text->blockSignals(true);
293 m_view.font_size->blockSignals(true);
294 m_view.font_family->blockSignals(true);
295 m_view.target_list->blockSignals(true);
296 m_view.back_to_menu->blockSignals(true);
298 m_view.tabWidget->widget(0)->setEnabled(true);
299 DvdButton *button = static_cast < DvdButton* >(list.at(i));
300 m_view.target_list->setCurrentIndex(button->target());
301 m_view.play_text->setText(button->toPlainText());
302 m_view.back_to_menu->setChecked(button->backMenu());
303 QFont font = button->font();
304 m_view.font_size->setValue(font.pixelSize());
305 m_view.font_family->setCurrentFont(font);
306 m_view.play_text->blockSignals(false);
307 m_view.font_size->blockSignals(false);
308 m_view.font_family->blockSignals(false);
309 m_view.target_list->blockSignals(false);
310 m_view.back_to_menu->blockSignals(false);
314 if (!foundButton) m_view.tabWidget->widget(0)->setEnabled(false);
317 void DvdWizardMenu::addButton()
319 m_scene->clearSelection();
320 DvdButton *button = new DvdButton(m_view.play_text->text());
321 QFont font = m_view.font_family->currentFont();
322 font.setPixelSize(m_view.font_size->value());
323 #if KDE_IS_VERSION(4,6,0)
324 if (m_view.use_shadow->isChecked()) {
325 QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this);
326 shadow->setBlurRadius(7);
327 shadow->setOffset(4, 4);
328 button->setGraphicsEffect(shadow);
331 //font.setStyleStrategy(QFont::NoAntialias);
332 button->setFont(font);
333 button->setDefaultTextColor(m_view.text_color->color());
334 button->setZValue(4);
335 QRectF r = button->sceneBoundingRect();
336 m_scene->addItem(button);
337 button->setPos((m_width - r.width()) / 2, (m_height - r.height()) / 2);
338 button->setSelected(true);
341 void DvdWizardMenu::deleteButton()
343 QList<QGraphicsItem *> list = m_scene->selectedItems();
344 for (int i = 0; i < list.count(); i++) {
345 if (list.at(i)->type() == DvdButtonItem) {
352 void DvdWizardMenu::changeProfile(DVDFORMAT format)
357 m_finalSize = QSize(720, 576);
362 m_finalSize = QSize(720, 480);
367 m_finalSize = QSize(720, 480);
372 m_finalSize = QSize(720, 576);
379 void DvdWizardMenu::updatePreview()
381 m_scene->setProfile(m_width, m_height);
383 matrix.scale(0.5, 0.5);
384 m_view.menu_preview->setMatrix(matrix);
385 m_view.menu_preview->setMinimumSize(m_width / 2 + 4, m_height / 2 + 8);
387 if (m_color) m_color->setRect(0, 0, m_width, m_height);
389 int safeW = m_width / 20;
390 int safeH = m_height / 20;
391 if (m_safeRect) m_safeRect->setRect(safeW, safeH, m_width - 2 * safeW, m_height - 2 * safeH);
394 void DvdWizardMenu::setTargets(QStringList list, QStringList targetlist)
396 m_view.target_list->clear();
397 m_view.target_list->addItem(i18n("Play All"), "jump title 1");
399 for (int i = 0; i < list.count(); i++) {
400 if (targetlist.at(i).contains("chapter"))
401 m_view.target_list->addItem(list.at(i), targetlist.at(i));
403 m_view.target_list->addItem(KIcon("video-x-generic"), list.at(i), targetlist.at(i));
407 m_view.back_to_menu->setHidden(movieCount == 1);
410 void DvdWizardMenu::checkBackgroundType(int ix)
413 m_view.background_color->setVisible(true);
414 m_view.background_image->setVisible(false);
415 m_view.loop_movie->setVisible(false);
416 if (m_background->scene() != 0) m_scene->removeItem(m_background);
418 m_view.background_color->setVisible(false);
419 m_view.background_image->setVisible(true);
421 m_view.background_image->clear();
422 m_view.background_image->setFilter("*");
423 if (m_background->scene() != 0) m_scene->removeItem(m_background);
424 m_view.loop_movie->setVisible(false);
426 if (m_background->scene() != 0) m_scene->removeItem(m_background);
427 m_view.background_image->clear();
428 m_view.background_image->setFilter("video/mpeg");
429 m_view.loop_movie->setVisible(true);
434 void DvdWizardMenu::buildColor()
436 m_color->setBrush(m_view.background_color->color());
439 void DvdWizardMenu::buildImage()
441 emit completeChanged();
442 if (m_view.background_image->url().isEmpty()) {
443 if (m_background->scene() != 0) m_scene->removeItem(m_background);
448 if (m_view.background_list->currentIndex() == 1) {
450 if (!pix.load(m_view.background_image->url().path())) {
451 if (m_background->scene() != 0) m_scene->removeItem(m_background);
454 pix = pix.scaled(m_width, m_height);
455 } else if (m_view.background_list->currentIndex() == 2) {
458 QString profileName = DvdWizardVob::getDvdProfile(m_format);
459 Mlt::Profile profile(profileName.toUtf8().constData());
460 profile.set_explicit(true);
461 Mlt::Producer *producer = new Mlt::Producer(profile, m_view.background_image->url().path().toUtf8().data());
462 if (producer && producer->is_valid()) {
463 pix = QPixmap::fromImage(KThumb::getFrame(producer, 0, m_finalSize.width(), m_width, m_height));
464 m_movieLength = producer->get_length();
466 if (producer) delete producer;
468 m_background->setPixmap(pix);
469 m_scene->addItem(m_background);
472 void DvdWizardMenu::checkBackground()
474 if (m_view.background_list->currentIndex() != 1) {
475 if (m_background->scene() != 0) m_scene->removeItem(m_background);
477 m_scene->addItem(m_background);
481 void DvdWizardMenu::buildButton()
483 DvdButton *button = NULL;
484 QList<QGraphicsItem *> list = m_scene->selectedItems();
485 for (int i = 0; i < list.count(); i++) {
486 if (list.at(i)->type() == DvdButtonItem) {
487 button = static_cast < DvdButton* >(list.at(i));
491 if (button == NULL) return;
492 button->setPlainText(m_view.play_text->text());
493 QFont font = m_view.font_family->currentFont();
494 font.setPixelSize(m_view.font_size->value());
495 //font.setStyleStrategy(QFont::NoAntialias);
496 button->setFont(font);
497 button->setDefaultTextColor(m_view.text_color->color());
500 void DvdWizardMenu::updateColor()
502 updateColor(m_view.text_color->color());
503 m_view.menu_preview->viewport()->update();
506 void DvdWizardMenu::prepareUnderLines()
508 QList<QGraphicsItem *> list = m_scene->items();
509 for (int i = 0; i < list.count(); i++) {
510 if (list.at(i)->type() == DvdButtonItem) {
511 QRectF r = list.at(i)->sceneBoundingRect();
512 int bottom = r.bottom() - 1;
513 if (bottom % 2 == 1) bottom = bottom - 1;
514 int underlineHeight = r.height() / 10;
515 if (underlineHeight % 2 == 1) underlineHeight = underlineHeight - 1;
516 underlineHeight = qMin(underlineHeight, 10);
517 underlineHeight = qMax(underlineHeight, 2);
518 r.setTop(bottom - underlineHeight);
520 r.adjust(2, 0, -2, 0);
521 DvdButtonUnderline *underline = new DvdButtonUnderline(r);
522 m_scene->addItem(underline);
523 list.at(i)->setVisible(false);
528 void DvdWizardMenu::resetUnderLines()
530 QList<QGraphicsItem *> list = m_scene->items();
531 QList<QGraphicsItem *> toDelete;
532 for (int i = 0; i < list.count(); i++) {
533 if (list.at(i)->type() == DvdButtonUnderlineItem) {
534 toDelete.append(list.at(i));
536 if (list.at(i)->type() == DvdButtonItem) {
537 list.at(i)->setVisible(true);
540 while (!toDelete.isEmpty()) {
541 QGraphicsItem *item = toDelete.takeFirst();
546 void DvdWizardMenu::updateUnderlineColor(QColor c)
548 QList<QGraphicsItem *> list = m_scene->items();
549 for (int i = 0; i < list.count(); i++) {
550 if (list.at(i)->type() == DvdButtonUnderlineItem) {
551 DvdButtonUnderline *underline = static_cast < DvdButtonUnderline* >(list.at(i));
552 underline->setPen(Qt::NoPen);
554 underline->setBrush(c);
560 void DvdWizardMenu::updateColor(QColor c)
562 DvdButton *button = NULL;
563 QList<QGraphicsItem *> list = m_scene->items();
564 for (int i = 0; i < list.count(); i++) {
565 if (list.at(i)->type() == DvdButtonItem) {
566 button = static_cast < DvdButton* >(list.at(i));
567 button->setDefaultTextColor(c);
573 void DvdWizardMenu::createButtonImages(const QString &selected_image, const QString &highlighted_image, bool letterbox)
575 if (m_view.create_menu->isChecked()) {
576 m_scene->clearSelection();
577 QRectF source(0, 0, m_width, m_height);
579 if (!letterbox) target = QRectF(0, 0, m_finalSize.width(), m_finalSize.height());
581 // Scale the button images to fit a letterbox image
582 double factor = (double) m_width / m_finalSize.width();
583 int letterboxHeight = m_height / factor;
584 target = QRectF(0, (m_finalSize.height() - letterboxHeight) / 2, m_finalSize.width(), letterboxHeight);
586 if (m_safeRect->scene() != 0) m_scene->removeItem(m_safeRect);
587 if (m_color->scene() != 0) m_scene->removeItem(m_color);
588 if (m_background->scene() != 0) m_scene->removeItem(m_background);
590 #if QT_VERSION >= 0x040800
591 QImage img(m_finalSize.width(), m_finalSize.height(), QImage::Format_ARGB32);
592 img.fill(Qt::transparent);
593 updateUnderlineColor(m_view.highlighted_color->color());
595 QImage img(m_finalSize.width(), m_finalSize.height(), QImage::Format_Mono);
597 updateUnderlineColor(Qt::black);
601 //p.setRenderHints(QPainter::Antialiasing, false);
602 //p.setRenderHints(QPainter::TextAntialiasing, false);
603 m_scene->render(&p, target, source, Qt::IgnoreAspectRatio);
605 #if QT_VERSION >= 0x040800
606 #elif QT_VERSION >= 0x040600
607 img.setColor(0, m_view.highlighted_color->color().rgb());
608 img.setColor(1, qRgba(0,0,0,0));
612 img.save(highlighted_image);
614 #if QT_VERSION >= 0x040800
615 img.fill(Qt::transparent);
616 updateUnderlineColor(m_view.selected_color->color());
621 //p.setRenderHints(QPainter::Antialiasing, false);
622 //p.setRenderHints(QPainter::TextAntialiasing, false);
623 m_scene->render(&p, target, source, Qt::IgnoreAspectRatio);
625 #if QT_VERSION >= 0x040800
626 #elif QT_VERSION >= 0x040600
627 img.setColor(0, m_view.selected_color->color().rgb());
628 img.setColor(1, qRgba(0,0,0,0));
632 img.save(selected_image);
634 m_scene->addItem(m_safeRect);
635 m_scene->addItem(m_color);
636 if (m_view.background_list->currentIndex() > 0) m_scene->addItem(m_background);
641 void DvdWizardMenu::createBackgroundImage(const QString &img1, bool letterbox)
643 m_scene->clearSelection();
644 if (m_safeRect->scene() != 0) m_scene->removeItem(m_safeRect);
646 QImage img(m_width, m_height, QImage::Format_ARGB32);
648 //TODO: Should the image be scaled when letterboxing?
650 QRectF source(0, 0, m_width, m_height);
652 if (!letterbox) target = QRectF(0, 0, m_finalSize.width(), m_finalSize.height());
654 // Scale the button images to fit a letterbox image
655 double factor = (double) m_width / m_finalSize.width();
656 int letterboxHeight = m_height / factor;
657 target = QRectF(0, (m_finalSize.height() - letterboxHeight) / 2, m_finalSize.width(), letterboxHeight);
662 if (m_background->scene() != 0) m_scene->removeItem(m_background);
663 if (m_color->scene() != 0) m_scene->removeItem(m_color);
664 img.fill(Qt::transparent);
666 updateColor(m_view.text_color->color());
668 p.setRenderHints(QPainter::Antialiasing, true);
669 p.setRenderHints(QPainter::TextAntialiasing, true);
670 m_scene->render(&p, QRectF(0, 0, img.width(), img.height()));
671 //m_scene->render(&p, target, source, Qt::IgnoreAspectRatio);
674 m_scene->addItem(m_safeRect);
676 m_scene->addItem(m_background);
677 m_scene->addItem(m_color);
681 bool DvdWizardMenu::createMenu() const
683 return m_view.create_menu->isChecked();
686 bool DvdWizardMenu::loopMovie() const
688 return m_view.loop_movie->isChecked();
691 bool DvdWizardMenu::menuMovie() const
693 return m_view.background_list->currentIndex() == 2;
696 QString DvdWizardMenu::menuMoviePath() const
698 return m_view.background_image->url().path();
701 int DvdWizardMenu::menuMovieLength() const
703 return m_movieLength;
707 QMap <QString, QRect> DvdWizardMenu::buttonsInfo(bool letterbox)
709 QMap <QString, QRect> info;
710 QList<QGraphicsItem *> list = m_scene->items();
711 double ratiox = (double) m_finalSize.width() / m_width;
715 int letterboxHeight = m_height * ratiox;
716 ratioy = (double) letterboxHeight / m_finalSize.height();
717 offset = (m_finalSize.height() - letterboxHeight) / 2;
719 for (int i = 0; i < list.count(); i++) {
720 if (list.at(i)->type() == DvdButtonItem) {
721 DvdButton *button = static_cast < DvdButton* >(list.at(i));
722 QRectF r = button->sceneBoundingRect();
723 QRect adjustedRect(r.x() * ratiox, offset + r.y() * ratioy, r.width() * ratiox, r.height() * ratioy);
724 // Make sure y1 is not odd (requested by spumux)
725 if (adjustedRect.height() % 2 == 1) adjustedRect.setHeight(adjustedRect.height() + 1);
726 if (adjustedRect.y() % 2 == 1) adjustedRect.setY(adjustedRect.y() - 1);
727 QString command = button->command();
728 if (button->backMenu()) command.prepend("g1 = 999;");
729 info.insertMulti(command, adjustedRect);
735 QDomElement DvdWizardMenu::toXml() const
738 QDomElement xml = doc.createElement("menu");
739 doc.appendChild(xml);
740 xml.setAttribute("enabled", m_view.create_menu->isChecked());
741 if (m_view.background_list->currentIndex() == 0) {
743 xml.setAttribute("background_color", m_view.background_color->color().name());
744 } else if (m_view.background_list->currentIndex() == 1) {
746 xml.setAttribute("background_image", m_view.background_image->url().path());
749 xml.setAttribute("background_video", m_view.background_image->url().path());
751 xml.setAttribute("text_color", m_view.text_color->color().name());
752 xml.setAttribute("selected_color", m_view.selected_color->color().name());
753 xml.setAttribute("highlighted_color", m_view.highlighted_color->color().name());
754 xml.setAttribute("text_shadow", (int) m_view.use_shadow->isChecked());
756 QList<QGraphicsItem *> list = m_scene->items();
759 for (int i = 0; i < list.count(); i++) {
760 if (list.at(i)->type() == DvdButtonItem) {
762 DvdButton *button = static_cast < DvdButton* >(list.at(i));
763 QDomElement xmlbutton = doc.createElement("button");
764 xmlbutton.setAttribute("target", button->target());
765 xmlbutton.setAttribute("command", button->command());
766 xmlbutton.setAttribute("backtomenu", button->backMenu());
767 xmlbutton.setAttribute("posx", (int) button->pos().x());
768 xmlbutton.setAttribute("posy", (int) button->pos().y());
769 xmlbutton.setAttribute("text", button->toPlainText());
770 QFont font = button->font();
771 xmlbutton.setAttribute("font_size", font.pixelSize());
772 xmlbutton.setAttribute("font_family", font.family());
773 xml.appendChild(xmlbutton);
776 return doc.documentElement();
780 void DvdWizardMenu::loadXml(DVDFORMAT format, QDomElement xml)
782 kDebug() << "// LOADING MENU";
783 if (xml.isNull()) return;
784 kDebug() << "// LOADING MENU 1";
785 changeProfile(format);
786 m_view.create_menu->setChecked(xml.attribute("enabled").toInt());
787 if (xml.hasAttribute("background_color")) {
788 m_view.background_list->setCurrentIndex(0);
789 m_view.background_color->setColor(xml.attribute("background_color"));
790 } else if (xml.hasAttribute("background_image")) {
791 m_view.background_list->setCurrentIndex(1);
792 m_view.background_image->setUrl(KUrl(xml.attribute("background_image")));
793 } else if (xml.hasAttribute("background_video")) {
794 m_view.background_list->setCurrentIndex(2);
795 m_view.background_image->setUrl(KUrl(xml.attribute("background_video")));
798 m_view.text_color->setColor(xml.attribute("text_color"));
799 m_view.selected_color->setColor(xml.attribute("selected_color"));
800 m_view.highlighted_color->setColor(xml.attribute("highlighted_color"));
802 m_view.use_shadow->setChecked(xml.attribute("text_shadow").toInt());
804 QDomNodeList buttons = xml.elementsByTagName("button");
805 kDebug() << "// LOADING MENU 2" << buttons.count();
807 if (buttons.count() > 0) {
808 // Clear existing buttons
809 QList<QGraphicsItem *> list = m_scene->items();
811 for (int i = 0; i < list.count(); i++) {
812 if (list.at(i)->type() == DvdButtonItem) {
819 for (int i = 0; i < buttons.count(); i++) {
820 QDomElement e = buttons.at(i).toElement();
821 // create menu button
822 DvdButton *button = new DvdButton(e.attribute("text"));
823 QFont font(e.attribute("font_family"));
824 font.setPixelSize(e.attribute("font_size").toInt());
825 #if KDE_IS_VERSION(4,6,0)
826 if (m_view.use_shadow->isChecked()) {
827 QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this);
828 shadow->setBlurRadius(7);
829 shadow->setOffset(4, 4);
830 button->setGraphicsEffect(shadow);
834 //font.setStyleStrategy(QFont::NoAntialias);
835 button->setFont(font);
836 button->setTarget(e.attribute("target").toInt(), e.attribute("command"));
837 button->setBackMenu(e.attribute("backtomenu").toInt());
838 button->setDefaultTextColor(m_view.text_color->color());
839 button->setZValue(4);
840 m_scene->addItem(button);
841 button->setPos(e.attribute("posx").toInt(), e.attribute("posy").toInt());
846 void DvdWizardMenu::slotZoom()
848 m_view.menu_preview->scale(2.0, 2.0);
851 void DvdWizardMenu::slotUnZoom()
853 m_view.menu_preview->scale(0.5, 0.5);