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(DVDFORMAT format, QWidget *parent) :
37 m_finalSize(720, 576),
41 m_view.play_text->setText(i18n("Play"));
42 m_scene = new DvdScene(this);
43 m_view.menu_preview->setScene(m_scene);
44 m_view.menu_preview->setMouseTracking(true);
45 connect(m_view.create_menu, SIGNAL(toggled(bool)), m_view.menu_box, SLOT(setEnabled(bool)));
46 connect(m_view.create_menu, SIGNAL(toggled(bool)), this, SIGNAL(completeChanged()));
48 #if KDE_IS_VERSION(4,7,0)
49 m_menuMessage = new KMessageWidget;
50 QGridLayout *s = static_cast <QGridLayout*> (layout());
51 s->addWidget(m_menuMessage, 7, 0, 1, -1);
52 m_menuMessage->hide();
53 m_view.error_message->hide();
56 m_view.add_button->setIcon(KIcon("document-new"));
57 m_view.delete_button->setIcon(KIcon("trash-empty"));
58 m_view.zoom_button->setIcon(KIcon("zoom-in"));
59 m_view.unzoom_button->setIcon(KIcon("zoom-out"));
61 m_view.add_button->setToolTip(i18n("Add new button"));
62 m_view.delete_button->setToolTip(i18n("Delete current button"));
64 changeProfile(format);
67 // Create color background
68 m_color = new QGraphicsRectItem(0, 0, m_width, m_height);
69 m_color->setBrush(m_view.background_color->color());
70 m_color->setZValue(2);
71 m_scene->addItem(m_color);
74 // create background image
75 m_background = new QGraphicsPixmapItem();
76 m_background->setZValue(3);
77 //m_scene->addItem(m_background);
79 // create safe zone rect
80 int safeW = m_width / 20;
81 int safeH = m_height / 20;
82 m_safeRect = new QGraphicsRectItem(safeW, safeH, m_width - 2 * safeW, m_height - 2 * safeH);
84 pen.setStyle(Qt::DashLine);
86 m_safeRect->setPen(pen);
87 m_safeRect->setZValue(5);
88 m_scene->addItem(m_safeRect);
89 checkBackgroundType(0);
92 DvdButton *button = new DvdButton(m_view.play_text->text());
93 QFont font = m_view.font_family->currentFont();
94 font.setPixelSize(m_view.font_size->value());
95 //font.setStyleStrategy(QFont::NoAntialias);
96 #if KDE_IS_VERSION(4,6,0)
97 if (m_view.use_shadow->isChecked()) {
98 QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this);
99 shadow->setBlurRadius(7);
100 shadow->setOffset(4, 4);
101 button->setGraphicsEffect(shadow);
103 connect(m_view.use_shadow, SIGNAL(stateChanged(int)), this, SLOT(slotEnableShadows(int)));
104 #elif KDE_IS_VERSION(4,6,0)
105 m_view.use_shadow->setHidden(true);
107 button->setFont(font);
108 button->setDefaultTextColor(m_view.text_color->color());
109 button->setZValue(4);
110 QRectF r = button->sceneBoundingRect();
111 m_scene->addItem(button);
112 button->setPos((m_width - r.width()) / 2, (m_height - r.height()) / 2);
113 button->setSelected(true);
116 //m_view.menu_preview->resizefitInView(0, 0, m_width, m_height);
118 connect(m_view.play_text, SIGNAL(textChanged(const QString &)), this, SLOT(buildButton()));
119 connect(m_view.text_color, SIGNAL(changed(const QColor &)), this, SLOT(updateColor()));
120 connect(m_view.font_size, SIGNAL(valueChanged(int)), this, SLOT(buildButton()));
121 connect(m_view.font_family, SIGNAL(currentFontChanged(const QFont &)), this, SLOT(buildButton()));
122 connect(m_view.background_image, SIGNAL(textChanged(const QString &)), this, SLOT(buildImage()));
123 connect(m_view.background_color, SIGNAL(changed(const QColor &)), this, SLOT(buildColor()));
125 connect(m_view.background_list, SIGNAL(activated(int)), this, SLOT(checkBackgroundType(int)));
127 connect(m_view.target_list, SIGNAL(activated(int)), this, SLOT(setButtonTarget(int)));
128 connect(m_view.back_to_menu, SIGNAL(toggled(bool)), this, SLOT(setBackToMenu(bool)));
130 connect(m_view.add_button, SIGNAL(pressed()), this, SLOT(addButton()));
131 connect(m_view.delete_button, SIGNAL(pressed()), this, SLOT(deleteButton()));
132 connect(m_view.zoom_button, SIGNAL(pressed()), this, SLOT(slotZoom()));
133 connect(m_view.unzoom_button, SIGNAL(pressed()), this, SLOT(slotUnZoom()));
134 connect(m_scene, SIGNAL(selectionChanged()), this, SLOT(buttonChanged()));
135 connect(m_scene, SIGNAL(changed(const QList<QRectF> &)), this, SIGNAL(completeChanged()));
137 // red background for error message
138 KColorScheme scheme(palette().currentColorGroup(), KColorScheme::Window, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
139 QPalette p = m_view.error_message->palette();
140 p.setColor(QPalette::Background, scheme.background(KColorScheme::NegativeBackground).color());
141 m_view.error_message->setAutoFillBackground(true);
142 m_view.error_message->setPalette(p);
144 m_view.menu_box->setEnabled(false);
148 DvdWizardMenu::~DvdWizardMenu()
156 void DvdWizardMenu::slotEnableShadows(int enable)
158 #if KDE_IS_VERSION(4,6,0)
159 QList<QGraphicsItem *> list = m_scene->items();
160 for (int i = 0; i < list.count(); i++) {
161 if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
163 QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this);
164 shadow->setBlurRadius(7);
165 shadow->setOffset(4, 4);
166 list.at(i)->setGraphicsEffect(shadow);
168 else list.at(i)->setGraphicsEffect(NULL);
175 bool DvdWizardMenu::isComplete() const
177 m_view.error_message->setHidden(true);
178 if (!m_view.create_menu->isChecked()) return true;
180 QList<QGraphicsItem *> list = m_scene->items();
182 // check that the menu buttons don't collide
183 for (int i = 0; i < list.count(); i++) {
184 if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
186 DvdButton *button = static_cast < DvdButton* >(list.at(i));
187 QList<QGraphicsItem *> collisions = button->collidingItems();
188 if (!collisions.isEmpty()) {
189 for (int j = 0; j < collisions.count(); j++) {
190 if (collisions.at(j)->type() == button->type()) {
191 #if KDE_IS_VERSION(4,7,0)
192 m_menuMessage->setText(i18n("Buttons overlapping"));
193 m_menuMessage->setMessageType(KMessageWidget::Warning);
194 m_menuMessage->animatedShow();
196 m_view.error_message->setText(i18n("Buttons overlapping"));
197 m_view.error_message->setHidden(false);
203 targets.append(button->target());
206 if (buttonCount == 0) {
207 //We need at least one button
208 #if KDE_IS_VERSION(4,7,0)
209 m_menuMessage->setText(i18n("No button in menu"));
210 m_menuMessage->setMessageType(KMessageWidget::Warning);
211 m_menuMessage->animatedShow();
213 m_view.error_message->setText(i18n("No button in menu"));
214 m_view.error_message->setHidden(false);
219 if (!m_view.background_image->isHidden()) {
220 // Make sure user selected a valid image /Â video file
221 if (!QFile::exists(m_view.background_image->url().path())) {
222 #if KDE_IS_VERSION(4,7,0)
223 m_menuMessage->setText(i18n("Missing background image"));
224 m_menuMessage->setMessageType(KMessageWidget::Warning);
225 m_menuMessage->animatedShow();
227 m_view.error_message->setText(i18n("Missing background image"));
228 m_view.error_message->setHidden(false);
234 #if KDE_IS_VERSION(4,7,0)
235 m_menuMessage->animatedHide();
238 // check that we have a "Play all" entry
239 if (targets.contains(0)) return true;
240 // ... or that each video file has a button
241 for (int i = m_view.target_list->count() - 1; i > 0; i--) {
242 // If there is a vob file entry and it has no button assigned, don't allow to go further
243 if (m_view.target_list->itemIcon(i).isNull() == false && !targets.contains(i)) {
244 #if KDE_IS_VERSION(4,7,0)
245 m_menuMessage->setText(i18n("No menu entry for %1", m_view.target_list->itemText(i)));
246 m_menuMessage->setMessageType(KMessageWidget::Warning);
247 m_menuMessage->animatedShow();
249 m_view.error_message->setText(i18n("No menu entry for %1", m_view.target_list->itemText(i)));
250 m_view.error_message->setHidden(false);
258 void DvdWizardMenu::setButtonTarget(int ix)
260 QList<QGraphicsItem *> list = m_scene->selectedItems();
261 for (int i = 0; i < list.count(); i++) {
262 if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
263 DvdButton *button = static_cast < DvdButton* >(list.at(i));
264 button->setTarget(ix, m_view.target_list->itemData(ix).toString());
268 emit completeChanged();
271 void DvdWizardMenu::setBackToMenu(bool backToMenu)
273 QList<QGraphicsItem *> list = m_scene->selectedItems();
274 for (int i = 0; i < list.count(); i++) {
275 if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
276 DvdButton *button = static_cast < DvdButton* >(list.at(i));
277 button->setBackMenu(backToMenu);
281 emit completeChanged();
284 void DvdWizardMenu::buttonChanged()
286 QList<QGraphicsItem *> list = m_scene->selectedItems();
287 bool foundButton = false;
288 for (int i = 0; i < list.count(); i++) {
289 if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
290 m_view.play_text->blockSignals(true);
291 m_view.font_size->blockSignals(true);
292 m_view.font_family->blockSignals(true);
293 m_view.target_list->blockSignals(true);
294 m_view.back_to_menu->blockSignals(true);
296 m_view.tabWidget->widget(0)->setEnabled(true);
297 DvdButton *button = static_cast < DvdButton* >(list.at(i));
298 m_view.target_list->setCurrentIndex(button->target());
299 m_view.play_text->setText(button->toPlainText());
300 m_view.back_to_menu->setChecked(button->backMenu());
301 QFont font = button->font();
302 m_view.font_size->setValue(font.pixelSize());
303 m_view.font_family->setCurrentFont(font);
304 m_view.play_text->blockSignals(false);
305 m_view.font_size->blockSignals(false);
306 m_view.font_family->blockSignals(false);
307 m_view.target_list->blockSignals(false);
308 m_view.back_to_menu->blockSignals(false);
312 if (!foundButton) m_view.tabWidget->widget(0)->setEnabled(false);
315 void DvdWizardMenu::addButton()
317 m_scene->clearSelection();
318 DvdButton *button = new DvdButton(m_view.play_text->text());
319 QFont font = m_view.font_family->currentFont();
320 font.setPixelSize(m_view.font_size->value());
321 #if KDE_IS_VERSION(4,6,0)
322 if (m_view.use_shadow->isChecked()) {
323 QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this);
324 shadow->setBlurRadius(7);
325 shadow->setOffset(4, 4);
326 button->setGraphicsEffect(shadow);
329 //font.setStyleStrategy(QFont::NoAntialias);
330 button->setFont(font);
331 button->setDefaultTextColor(m_view.text_color->color());
332 button->setZValue(4);
333 QRectF r = button->sceneBoundingRect();
334 m_scene->addItem(button);
335 button->setPos((m_width - r.width()) / 2, (m_height - r.height()) / 2);
336 button->setSelected(true);
339 void DvdWizardMenu::deleteButton()
341 QList<QGraphicsItem *> list = m_scene->selectedItems();
342 for (int i = 0; i < list.count(); i++) {
343 if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
350 void DvdWizardMenu::changeProfile(DVDFORMAT format)
355 m_finalSize = QSize(720, 576);
360 m_finalSize = QSize(720, 480);
365 m_finalSize = QSize(720, 480);
370 m_finalSize = QSize(720, 576);
377 void DvdWizardMenu::updatePreview()
379 m_scene->setProfile(m_width, m_height);
381 matrix.scale(0.5, 0.5);
382 m_view.menu_preview->setMatrix(matrix);
383 m_view.menu_preview->setMinimumSize(m_width / 2 + 4, m_height / 2 + 8);
385 if (m_color) m_color->setRect(0, 0, m_width, m_height);
387 int safeW = m_width / 20;
388 int safeH = m_height / 20;
389 if (m_safeRect) m_safeRect->setRect(safeW, safeH, m_width - 2 * safeW, m_height - 2 * safeH);
392 void DvdWizardMenu::setTargets(QStringList list, QStringList targetlist)
394 m_view.target_list->clear();
395 m_view.target_list->addItem(i18n("Play All"), "jump title 1");
397 for (int i = 0; i < list.count(); i++) {
398 if (targetlist.at(i).contains("chapter"))
399 m_view.target_list->addItem(list.at(i), targetlist.at(i));
401 m_view.target_list->addItem(KIcon("video-x-generic"), list.at(i), targetlist.at(i));
405 m_view.back_to_menu->setHidden(movieCount == 1);
408 void DvdWizardMenu::checkBackgroundType(int ix)
411 m_view.background_color->setVisible(true);
412 m_view.background_image->setVisible(false);
413 m_view.loop_movie->setVisible(false);
414 if (m_background->scene() != 0) m_scene->removeItem(m_background);
416 m_view.background_color->setVisible(false);
417 m_view.background_image->setVisible(true);
419 m_view.background_image->clear();
420 m_view.background_image->setFilter("*");
421 if (m_background->scene() != 0) m_scene->removeItem(m_background);
422 m_view.loop_movie->setVisible(false);
424 if (m_background->scene() != 0) m_scene->removeItem(m_background);
425 m_view.background_image->clear();
426 m_view.background_image->setFilter("video/mpeg");
427 m_view.loop_movie->setVisible(true);
432 void DvdWizardMenu::buildColor()
434 m_color->setBrush(m_view.background_color->color());
437 void DvdWizardMenu::buildImage()
439 emit completeChanged();
440 if (m_view.background_image->url().isEmpty()) {
441 if (m_background->scene() != 0) m_scene->removeItem(m_background);
446 if (m_view.background_list->currentIndex() == 1) {
448 if (!pix.load(m_view.background_image->url().path())) {
449 if (m_background->scene() != 0) m_scene->removeItem(m_background);
452 pix = pix.scaled(m_width, m_height);
453 } else if (m_view.background_list->currentIndex() == 2) {
456 QString profileName = DvdWizardVob::getDvdProfile(m_format);
457 Mlt::Profile profile(profileName.toUtf8().constData());
458 profile.set_explicit(true);
459 Mlt::Producer *producer = new Mlt::Producer(profile, m_view.background_image->url().path().toUtf8().data());
460 if (producer && producer->is_valid()) {
461 pix = QPixmap::fromImage(KThumb::getFrame(producer, 0, m_finalSize.width(), m_width, m_height));
462 m_movieLength = producer->get_length();
464 if (producer) delete producer;
466 m_background->setPixmap(pix);
467 m_scene->addItem(m_background);
470 void DvdWizardMenu::checkBackground()
472 if (m_view.background_list->currentIndex() != 1) {
473 if (m_background->scene() != 0) m_scene->removeItem(m_background);
475 m_scene->addItem(m_background);
479 void DvdWizardMenu::buildButton()
481 DvdButton *button = NULL;
482 QList<QGraphicsItem *> list = m_scene->selectedItems();
483 for (int i = 0; i < list.count(); i++) {
484 if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
485 button = static_cast < DvdButton* >(list.at(i));
489 if (button == NULL) return;
490 button->setPlainText(m_view.play_text->text());
491 QFont font = m_view.font_family->currentFont();
492 font.setPixelSize(m_view.font_size->value());
493 //font.setStyleStrategy(QFont::NoAntialias);
494 button->setFont(font);
495 button->setDefaultTextColor(m_view.text_color->color());
498 void DvdWizardMenu::updateColor()
500 updateColor(m_view.text_color->color());
501 m_view.menu_preview->viewport()->update();
504 void DvdWizardMenu::prepareUnderLines()
506 QList<QGraphicsItem *> list = m_scene->items();
507 for (int i = 0; i < list.count(); i++) {
508 if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
509 QRectF r = list.at(i)->sceneBoundingRect();
510 int bottom = r.bottom() - 1;
511 if (bottom % 2 == 1) bottom = bottom - 1;
512 int underlineHeight = r.height() / 10;
513 if (underlineHeight % 2 == 1) underlineHeight = underlineHeight - 1;
514 underlineHeight = qMin(underlineHeight, 10);
515 underlineHeight = qMax(underlineHeight, 2);
516 r.setTop(bottom - underlineHeight);
517 r.adjust(2, 0, -2, 0);
518 QGraphicsRectItem *underline = new QGraphicsRectItem(r);
519 underline->setData(Qt::UserRole, QString("underline"));
520 m_scene->addItem(underline);
521 list.at(i)->setVisible(false);
526 void DvdWizardMenu::resetUnderLines()
528 QList<QGraphicsItem *> list = m_scene->items();
529 QList<QGraphicsItem *> toDelete;
530 for (int i = 0; i < list.count(); i++) {
531 if (list.at(i)->data(Qt::UserRole).toString() == "underline") {
532 toDelete.append(list.at(i));
534 if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
535 list.at(i)->setVisible(true);
538 while (!toDelete.isEmpty()) {
539 QGraphicsItem *item = toDelete.takeFirst();
544 void DvdWizardMenu::updateUnderlineColor(QColor c)
546 QList<QGraphicsItem *> list = m_scene->items();
547 for (int i = 0; i < list.count(); i++) {
548 if (list.at(i)->data(Qt::UserRole).toString() == "underline") {
549 QGraphicsRectItem *underline = static_cast < QGraphicsRectItem* >(list.at(i));
550 underline->setPen(Qt::NoPen);
552 underline->setBrush(c);
558 void DvdWizardMenu::updateColor(QColor c)
560 DvdButton *button = NULL;
561 QList<QGraphicsItem *> list = m_scene->items();
562 for (int i = 0; i < list.count(); i++) {
563 if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
564 button = static_cast < DvdButton* >(list.at(i));
565 button->setDefaultTextColor(c);
571 void DvdWizardMenu::createButtonImages(const QString &img1, const QString &img2, const QString &img3, bool letterbox)
573 if (m_view.create_menu->isChecked()) {
574 m_scene->clearSelection();
575 QRectF source(0, 0, m_width, m_height);
577 if (!letterbox) target = QRectF(0, 0, m_finalSize.width(), m_finalSize.height());
579 // Scale the button images to fit a letterbox image
580 double factor = (double) m_width / m_finalSize.width();
581 int letterboxHeight = m_height / factor;
582 target = QRectF(0, (m_finalSize.height() - letterboxHeight) / 2, m_finalSize.width(), letterboxHeight);
584 if (m_safeRect->scene() != 0) m_scene->removeItem(m_safeRect);
585 if (m_color->scene() != 0) m_scene->removeItem(m_color);
586 if (m_background->scene() != 0) m_scene->removeItem(m_background);
588 #if QT_VERSION >= 0x040800
589 QImage img(m_finalSize.width(), m_finalSize.height(), QImage::Format_ARGB32);
590 img.fill(Qt::transparent);
591 updateUnderlineColor(m_view.text_color->color());
593 QImage img(m_finalSize.width(), m_finalSize.height(), QImage::Format_Mono);
595 updateUnderlineColor(Qt::black);
598 //p.setRenderHints(QPainter::Antialiasing, false);
599 //p.setRenderHints(QPainter::TextAntialiasing, false);
600 m_scene->render(&p, target, source, Qt::IgnoreAspectRatio);
602 #if QT_VERSION >= 0x040800
603 #elif QT_VERSION >= 0x040600
604 img.setColor(0, m_view.text_color->color().rgb());
605 img.setColor(1, qRgba(0,0,0,0));
611 #if QT_VERSION >= 0x040800
612 img.fill(Qt::transparent);
613 updateUnderlineColor(m_view.highlighted_color->color());
618 //p.setRenderHints(QPainter::Antialiasing, false);
619 //p.setRenderHints(QPainter::TextAntialiasing, false);
620 m_scene->render(&p, target, source, Qt::IgnoreAspectRatio);
622 #if QT_VERSION >= 0x040800
623 #elif QT_VERSION >= 0x040600
624 img.setColor(0, m_view.highlighted_color->color().rgb());
625 img.setColor(1, qRgba(0,0,0,0));
631 #if QT_VERSION >= 0x040800
632 img.fill(Qt::transparent);
633 updateUnderlineColor(m_view.selected_color->color());
638 //p.setRenderHints(QPainter::Antialiasing, false);
639 //p.setRenderHints(QPainter::TextAntialiasing, false);
640 m_scene->render(&p, target, source, Qt::IgnoreAspectRatio);
642 #if QT_VERSION >= 0x040800
643 #elif QT_VERSION >= 0x040600
644 img.setColor(0, m_view.selected_color->color().rgb());
645 img.setColor(1, qRgba(0,0,0,0));
651 m_scene->addItem(m_safeRect);
652 m_scene->addItem(m_color);
653 if (m_view.background_list->currentIndex() > 0) m_scene->addItem(m_background);
658 void DvdWizardMenu::createBackgroundImage(const QString &overlayMenu, const QString &img1)
660 m_scene->clearSelection();
661 if (m_safeRect->scene() != 0) m_scene->removeItem(m_safeRect);
663 QImage img(m_width, m_height, QImage::Format_ARGB32);
664 if (menuMovie() && m_background->scene() != 0) {
666 m_scene->removeItem(m_background);
667 if (m_color->scene() != 0) m_scene->removeItem(m_color);
668 if (m_safeRect->scene() != 0) m_scene->removeItem(m_safeRect);
669 img.fill(Qt::transparent);
671 updateColor(m_view.text_color->color());
673 p.setRenderHints(QPainter::Antialiasing, true);
674 p.setRenderHints(QPainter::TextAntialiasing, true);
675 m_scene->render(&p, QRectF(0, 0, img.width(), img.height()));
678 m_scene->addItem(m_safeRect);
680 m_scene->addItem(m_background);
681 m_scene->addItem(m_color);
687 if (m_view.background_list->currentIndex() == 0) {
690 img = QImage(768, 576, QImage::Format_ARGB32);
692 img = QImage(720, 540, QImage::Format_ARGB32);
693 img.fill(m_view.background_color->color().rgb());
694 } else if (m_view.background_list->currentIndex() == 1) {
695 img.load(m_view.background_image->url().path());
697 if (img.width() != 768 || img.height() != 576)
698 img = img.scaled(768, 576, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
700 if (img.width() != 720 || img.height() != 540)
701 img = img.scaled(720, 540, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
704 // Overlay Normal menu
705 QImage menu(overlayMenu);
707 QRectF target(0, 0, img.width(), img.height());
708 QRectF src(0, 0, menu.width(), menu.height());
709 p.drawImage(target, menu, src);
714 bool DvdWizardMenu::createMenu() const
716 return m_view.create_menu->isChecked();
719 bool DvdWizardMenu::loopMovie() const
721 return m_view.loop_movie->isChecked();
724 bool DvdWizardMenu::menuMovie() const
726 return m_view.background_list->currentIndex() == 2;
729 QString DvdWizardMenu::menuMoviePath() const
731 return m_view.background_image->url().path();
734 int DvdWizardMenu::menuMovieLength() const
736 return m_movieLength;
740 QMap <QString, QRect> DvdWizardMenu::buttonsInfo(bool letterbox)
742 QMap <QString, QRect> info;
743 QList<QGraphicsItem *> list = m_scene->items();
744 double ratiox = (double) m_finalSize.width() / m_width;
748 int letterboxHeight = m_height * ratiox;
749 ratioy = (double) letterboxHeight / m_finalSize.height();
750 offset = (m_finalSize.height() - letterboxHeight) / 2;
752 for (int i = 0; i < list.count(); i++) {
753 if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
754 DvdButton *button = static_cast < DvdButton* >(list.at(i));
755 QRectF r = button->sceneBoundingRect();
756 QRect adjustedRect(r.x() * ratiox, offset + r.y() * ratioy, r.width() * ratiox, r.height() * ratioy);
757 // Make sure y1 is not odd (requested by spumux)
758 if (adjustedRect.height() % 2 == 1) adjustedRect.setHeight(adjustedRect.height() + 1);
759 if (adjustedRect.y() % 2 == 1) adjustedRect.setY(adjustedRect.y() - 1);
760 QString command = button->command();
761 if (button->backMenu()) command.prepend("g1 = 999;");
762 info.insertMulti(command, adjustedRect);
768 QDomElement DvdWizardMenu::toXml() const
771 QDomElement xml = doc.createElement("menu");
772 doc.appendChild(xml);
773 xml.setAttribute("enabled", m_view.create_menu->isChecked());
774 if (m_view.background_list->currentIndex() == 0) {
776 xml.setAttribute("background_color", m_view.background_color->color().name());
777 } else if (m_view.background_list->currentIndex() == 1) {
779 xml.setAttribute("background_image", m_view.background_image->url().path());
782 xml.setAttribute("background_video", m_view.background_image->url().path());
784 xml.setAttribute("text_color", m_view.text_color->color().name());
785 xml.setAttribute("selected_color", m_view.selected_color->color().name());
786 xml.setAttribute("highlighted_color", m_view.highlighted_color->color().name());
787 xml.setAttribute("text_shadow", (int) m_view.use_shadow->isChecked());
789 QList<QGraphicsItem *> list = m_scene->items();
792 for (int i = 0; i < list.count(); i++) {
793 if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
795 DvdButton *button = static_cast < DvdButton* >(list.at(i));
796 QDomElement xmlbutton = doc.createElement("button");
797 xmlbutton.setAttribute("target", button->target());
798 xmlbutton.setAttribute("command", button->command());
799 xmlbutton.setAttribute("backtomenu", button->backMenu());
800 xmlbutton.setAttribute("posx", button->pos().x());
801 xmlbutton.setAttribute("posy", button->pos().y());
802 xmlbutton.setAttribute("text", button->toPlainText());
803 QFont font = button->font();
804 xmlbutton.setAttribute("font_size", font.pixelSize());
805 xmlbutton.setAttribute("font_family", font.family());
806 xml.appendChild(xmlbutton);
809 return doc.documentElement();
813 void DvdWizardMenu::loadXml(QDomElement xml)
815 kDebug() << "// LOADING MENU";
816 if (xml.isNull()) return;
817 kDebug() << "// LOADING MENU 1";
818 m_view.create_menu->setChecked(xml.attribute("enabled").toInt());
819 if (xml.hasAttribute("background_color")) {
820 m_view.background_list->setCurrentIndex(0);
821 m_view.background_color->setColor(xml.attribute("background_color"));
822 } else if (xml.hasAttribute("background_image")) {
823 m_view.background_list->setCurrentIndex(1);
824 m_view.background_image->setUrl(KUrl(xml.attribute("background_image")));
825 } else if (xml.hasAttribute("background_video")) {
826 m_view.background_list->setCurrentIndex(2);
827 m_view.background_image->setUrl(KUrl(xml.attribute("background_video")));
830 m_view.text_color->setColor(xml.attribute("text_color"));
831 m_view.selected_color->setColor(xml.attribute("selected_color"));
832 m_view.highlighted_color->setColor(xml.attribute("highlighted_color"));
834 m_view.use_shadow->setChecked(xml.attribute("text_shadow").toInt());
836 QDomNodeList buttons = xml.elementsByTagName("button");
837 kDebug() << "// LOADING MENU 2" << buttons.count();
839 if (buttons.count() > 0) {
840 // Clear existing buttons
841 QList<QGraphicsItem *> list = m_scene->items();
843 for (int i = 0; i < list.count(); i++) {
844 if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
851 for (int i = 0; i < buttons.count(); i++) {
852 QDomElement e = buttons.at(i).toElement();
853 // create menu button
854 DvdButton *button = new DvdButton(e.attribute("text"));
855 QFont font(e.attribute("font_family"));
856 font.setPixelSize(e.attribute("font_size").toInt());
857 #if KDE_IS_VERSION(4,6,0)
858 if (m_view.use_shadow->isChecked()) {
859 QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this);
860 shadow->setBlurRadius(7);
861 shadow->setOffset(4, 4);
862 button->setGraphicsEffect(shadow);
866 //font.setStyleStrategy(QFont::NoAntialias);
867 button->setFont(font);
868 button->setTarget(e.attribute("target").toInt(), e.attribute("command"));
869 button->setBackMenu(e.attribute("backtomenu").toInt());
870 button->setDefaultTextColor(m_view.text_color->color());
871 button->setZValue(4);
872 m_scene->addItem(button);
873 button->setPos(e.attribute("posx").toDouble(), e.attribute("posy").toDouble());
878 void DvdWizardMenu::slotZoom()
880 m_view.menu_preview->scale(2.0, 2.0);
883 void DvdWizardMenu::slotUnZoom()
885 m_view.menu_preview->scale(0.5, 0.5);