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 Mlt::Profile profile;
457 profile.set_explicit(false);
458 Mlt::Producer *producer = new Mlt::Producer(profile, m_view.background_image->url().path().toUtf8().data());
459 if (producer && producer->is_valid()) {
460 pix = QPixmap::fromImage(KThumb::getFrame(producer, 0, m_finalSize.width(), m_width, m_height));
461 m_movieLength = producer->get_length();
463 if (producer) delete producer;
465 m_background->setPixmap(pix);
466 m_scene->addItem(m_background);
469 void DvdWizardMenu::checkBackground()
471 if (m_view.background_list->currentIndex() != 1) {
472 if (m_background->scene() != 0) m_scene->removeItem(m_background);
474 m_scene->addItem(m_background);
478 void DvdWizardMenu::buildButton()
480 DvdButton *button = NULL;
481 QList<QGraphicsItem *> list = m_scene->selectedItems();
482 for (int i = 0; i < list.count(); i++) {
483 if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
484 button = static_cast < DvdButton* >(list.at(i));
488 if (button == NULL) return;
489 button->setPlainText(m_view.play_text->text());
490 QFont font = m_view.font_family->currentFont();
491 font.setPixelSize(m_view.font_size->value());
492 //font.setStyleStrategy(QFont::NoAntialias);
493 button->setFont(font);
494 button->setDefaultTextColor(m_view.text_color->color());
497 void DvdWizardMenu::updateColor()
499 updateColor(m_view.text_color->color());
500 m_view.menu_preview->viewport()->update();
503 void DvdWizardMenu::prepareUnderLines()
505 QList<QGraphicsItem *> list = m_scene->items();
506 for (int i = 0; i < list.count(); i++) {
507 if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
508 QRectF r = list.at(i)->sceneBoundingRect();
509 int bottom = r.bottom() - 1;
510 if (bottom % 2 == 1) bottom = bottom - 1;
511 int underlineHeight = r.height() / 10;
512 if (underlineHeight % 2 == 1) underlineHeight = underlineHeight - 1;
513 underlineHeight = qMin(underlineHeight, 10);
514 underlineHeight = qMax(underlineHeight, 2);
515 r.setTop(bottom - underlineHeight);
516 r.adjust(2, 0, -2, 0);
517 QGraphicsRectItem *underline = new QGraphicsRectItem(r);
518 underline->setData(Qt::UserRole, QString("underline"));
519 m_scene->addItem(underline);
520 list.at(i)->setVisible(false);
525 void DvdWizardMenu::resetUnderLines()
527 QList<QGraphicsItem *> list = m_scene->items();
528 QList<QGraphicsItem *> toDelete;
529 for (int i = 0; i < list.count(); i++) {
530 if (list.at(i)->data(Qt::UserRole).toString() == "underline") {
531 toDelete.append(list.at(i));
533 if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
534 list.at(i)->setVisible(true);
537 while (!toDelete.isEmpty()) {
538 QGraphicsItem *item = toDelete.takeFirst();
543 void DvdWizardMenu::updateUnderlineColor(QColor c)
545 QList<QGraphicsItem *> list = m_scene->items();
546 for (int i = 0; i < list.count(); i++) {
547 if (list.at(i)->data(Qt::UserRole).toString() == "underline") {
548 QGraphicsRectItem *underline = static_cast < QGraphicsRectItem* >(list.at(i));
549 underline->setPen(Qt::NoPen);
551 underline->setBrush(c);
557 void DvdWizardMenu::updateColor(QColor c)
559 DvdButton *button = NULL;
560 QList<QGraphicsItem *> list = m_scene->items();
561 for (int i = 0; i < list.count(); i++) {
562 if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
563 button = static_cast < DvdButton* >(list.at(i));
564 button->setDefaultTextColor(c);
570 void DvdWizardMenu::createButtonImages(const QString &img1, const QString &img2, const QString &img3, bool letterbox)
572 if (m_view.create_menu->isChecked()) {
573 m_scene->clearSelection();
574 QRectF source(0, 0, m_width, m_height);
576 if (!letterbox) target = QRectF(0, 0, m_finalSize.width(), m_finalSize.height());
578 // Scale the button images to fit a letterbox image
579 double factor = (double) m_width / m_finalSize.width();
580 int letterboxHeight = m_height / factor;
581 target = QRectF(0, (m_finalSize.height() - letterboxHeight) / 2, m_finalSize.width(), letterboxHeight);
583 if (m_safeRect->scene() != 0) m_scene->removeItem(m_safeRect);
584 if (m_color->scene() != 0) m_scene->removeItem(m_color);
585 if (m_background->scene() != 0) m_scene->removeItem(m_background);
587 #if QT_VERSION >= 0x040800
588 QImage img(m_finalSize.width(), m_finalSize.height(), QImage::Format_ARGB32);
589 img.fill(Qt::transparent);
590 updateUnderlineColor(m_view.text_color->color());
592 QImage img(m_finalSize.width(), m_finalSize.height(), QImage::Format_Mono);
594 updateUnderlineColor(Qt::black);
597 //p.setRenderHints(QPainter::Antialiasing, false);
598 //p.setRenderHints(QPainter::TextAntialiasing, false);
599 m_scene->render(&p, target, source, Qt::IgnoreAspectRatio);
601 #if QT_VERSION >= 0x040800
602 #elif QT_VERSION >= 0x040600
603 img.setColor(0, m_view.text_color->color().rgb());
604 img.setColor(1, qRgba(0,0,0,0));
610 #if QT_VERSION >= 0x040800
611 img.fill(Qt::transparent);
612 updateUnderlineColor(m_view.highlighted_color->color());
617 //p.setRenderHints(QPainter::Antialiasing, false);
618 //p.setRenderHints(QPainter::TextAntialiasing, false);
619 m_scene->render(&p, target, source, Qt::IgnoreAspectRatio);
621 #if QT_VERSION >= 0x040800
622 #elif QT_VERSION >= 0x040600
623 img.setColor(0, m_view.highlighted_color->color().rgb());
624 img.setColor(1, qRgba(0,0,0,0));
630 #if QT_VERSION >= 0x040800
631 img.fill(Qt::transparent);
632 updateUnderlineColor(m_view.selected_color->color());
637 //p.setRenderHints(QPainter::Antialiasing, false);
638 //p.setRenderHints(QPainter::TextAntialiasing, false);
639 m_scene->render(&p, target, source, Qt::IgnoreAspectRatio);
641 #if QT_VERSION >= 0x040800
642 #elif QT_VERSION >= 0x040600
643 img.setColor(0, m_view.selected_color->color().rgb());
644 img.setColor(1, qRgba(0,0,0,0));
650 m_scene->addItem(m_safeRect);
651 m_scene->addItem(m_color);
652 if (m_view.background_list->currentIndex() > 0) m_scene->addItem(m_background);
657 void DvdWizardMenu::createBackgroundImage(const QString &overlayMenu, const QString &img1)
659 m_scene->clearSelection();
660 if (m_safeRect->scene() != 0) m_scene->removeItem(m_safeRect);
662 QImage img(m_width, m_height, QImage::Format_ARGB32);
663 if (menuMovie() && m_background->scene() != 0) {
665 m_scene->removeItem(m_background);
666 if (m_color->scene() != 0) m_scene->removeItem(m_color);
667 if (m_safeRect->scene() != 0) m_scene->removeItem(m_safeRect);
668 img.fill(Qt::transparent);
670 updateColor(m_view.text_color->color());
672 p.setRenderHints(QPainter::Antialiasing, true);
673 p.setRenderHints(QPainter::TextAntialiasing, true);
674 m_scene->render(&p, QRectF(0, 0, img.width(), img.height()));
677 m_scene->addItem(m_safeRect);
679 m_scene->addItem(m_background);
680 m_scene->addItem(m_color);
686 if (m_view.background_list->currentIndex() == 0) {
689 img = QImage(768, 576, QImage::Format_ARGB32);
691 img = QImage(720, 540, QImage::Format_ARGB32);
692 img.fill(m_view.background_color->color().rgb());
693 } else if (m_view.background_list->currentIndex() == 1) {
694 img.load(m_view.background_image->url().path());
696 if (img.width() != 768 || img.height() != 576)
697 img = img.scaled(768, 576, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
699 if (img.width() != 720 || img.height() != 540)
700 img = img.scaled(720, 540, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
703 // Overlay Normal menu
704 QImage menu(overlayMenu);
706 QRectF target(0, 0, img.width(), img.height());
707 QRectF src(0, 0, menu.width(), menu.height());
708 p.drawImage(target, menu, src);
713 bool DvdWizardMenu::createMenu() const
715 return m_view.create_menu->isChecked();
718 bool DvdWizardMenu::loopMovie() const
720 return m_view.loop_movie->isChecked();
723 bool DvdWizardMenu::menuMovie() const
725 return m_view.background_list->currentIndex() == 2;
728 QString DvdWizardMenu::menuMoviePath() const
730 return m_view.background_image->url().path();
733 int DvdWizardMenu::menuMovieLength() const
735 return m_movieLength;
739 QMap <QString, QRect> DvdWizardMenu::buttonsInfo(bool letterbox)
741 QMap <QString, QRect> info;
742 QList<QGraphicsItem *> list = m_scene->items();
743 double ratiox = (double) m_finalSize.width() / m_width;
747 int letterboxHeight = m_height * ratiox;
748 ratioy = (double) letterboxHeight / m_finalSize.height();
749 offset = (m_finalSize.height() - letterboxHeight) / 2;
751 for (int i = 0; i < list.count(); i++) {
752 if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
753 DvdButton *button = static_cast < DvdButton* >(list.at(i));
754 QRectF r = button->sceneBoundingRect();
755 QRect adjustedRect(r.x() * ratiox, offset + r.y() * ratioy, r.width() * ratiox, r.height() * ratioy);
756 // Make sure y1 is not odd (requested by spumux)
757 if (adjustedRect.height() % 2 == 1) adjustedRect.setHeight(adjustedRect.height() + 1);
758 if (adjustedRect.y() % 2 == 1) adjustedRect.setY(adjustedRect.y() - 1);
759 QString command = button->command();
760 if (button->backMenu()) command.prepend("g1 = 999;");
761 info.insertMulti(command, adjustedRect);
767 QDomElement DvdWizardMenu::toXml() const
770 QDomElement xml = doc.createElement("menu");
771 doc.appendChild(xml);
772 xml.setAttribute("enabled", m_view.create_menu->isChecked());
773 if (m_view.background_list->currentIndex() == 0) {
775 xml.setAttribute("background_color", m_view.background_color->color().name());
776 } else if (m_view.background_list->currentIndex() == 1) {
778 xml.setAttribute("background_image", m_view.background_image->url().path());
781 xml.setAttribute("background_video", m_view.background_image->url().path());
783 xml.setAttribute("text_color", m_view.text_color->color().name());
784 xml.setAttribute("selected_color", m_view.selected_color->color().name());
785 xml.setAttribute("highlighted_color", m_view.highlighted_color->color().name());
786 xml.setAttribute("text_shadow", (int) m_view.use_shadow->isChecked());
788 QList<QGraphicsItem *> list = m_scene->items();
791 for (int i = 0; i < list.count(); i++) {
792 if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
794 DvdButton *button = static_cast < DvdButton* >(list.at(i));
795 QDomElement xmlbutton = doc.createElement("button");
796 xmlbutton.setAttribute("target", button->target());
797 xmlbutton.setAttribute("command", button->command());
798 xmlbutton.setAttribute("backtomenu", button->backMenu());
799 xmlbutton.setAttribute("posx", button->pos().x());
800 xmlbutton.setAttribute("posy", button->pos().y());
801 xmlbutton.setAttribute("text", button->toPlainText());
802 QFont font = button->font();
803 xmlbutton.setAttribute("font_size", font.pixelSize());
804 xmlbutton.setAttribute("font_family", font.family());
805 xml.appendChild(xmlbutton);
808 return doc.documentElement();
812 void DvdWizardMenu::loadXml(QDomElement xml)
814 kDebug() << "// LOADING MENU";
815 if (xml.isNull()) return;
816 kDebug() << "// LOADING MENU 1";
817 m_view.create_menu->setChecked(xml.attribute("enabled").toInt());
818 if (xml.hasAttribute("background_color")) {
819 m_view.background_list->setCurrentIndex(0);
820 m_view.background_color->setColor(xml.attribute("background_color"));
821 } else if (xml.hasAttribute("background_image")) {
822 m_view.background_list->setCurrentIndex(1);
823 m_view.background_image->setUrl(KUrl(xml.attribute("background_image")));
824 } else if (xml.hasAttribute("background_video")) {
825 m_view.background_list->setCurrentIndex(2);
826 m_view.background_image->setUrl(KUrl(xml.attribute("background_video")));
829 m_view.text_color->setColor(xml.attribute("text_color"));
830 m_view.selected_color->setColor(xml.attribute("selected_color"));
831 m_view.highlighted_color->setColor(xml.attribute("highlighted_color"));
833 m_view.use_shadow->setChecked(xml.attribute("text_shadow").toInt());
835 QDomNodeList buttons = xml.elementsByTagName("button");
836 kDebug() << "// LOADING MENU 2" << buttons.count();
838 if (buttons.count() > 0) {
839 // Clear existing buttons
840 QList<QGraphicsItem *> list = m_scene->items();
842 for (int i = 0; i < list.count(); i++) {
843 if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
850 for (int i = 0; i < buttons.count(); i++) {
851 QDomElement e = buttons.at(i).toElement();
852 // create menu button
853 DvdButton *button = new DvdButton(e.attribute("text"));
854 QFont font(e.attribute("font_family"));
855 font.setPixelSize(e.attribute("font_size").toInt());
856 #if KDE_IS_VERSION(4,6,0)
857 if (m_view.use_shadow->isChecked()) {
858 QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this);
859 shadow->setBlurRadius(7);
860 shadow->setOffset(4, 4);
861 button->setGraphicsEffect(shadow);
865 //font.setStyleStrategy(QFont::NoAntialias);
866 button->setFont(font);
867 button->setTarget(e.attribute("target").toInt(), e.attribute("command"));
868 button->setBackMenu(e.attribute("backtomenu").toInt());
869 button->setDefaultTextColor(m_view.text_color->color());
870 button->setZValue(4);
871 m_scene->addItem(button);
872 button->setPos(e.attribute("posx").toDouble(), e.attribute("posy").toDouble());
877 void DvdWizardMenu::slotZoom()
879 m_view.menu_preview->scale(2.0, 2.0);
882 void DvdWizardMenu::slotUnZoom()
884 m_view.menu_preview->scale(0.5, 0.5);