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 m_view.add_button->setIcon(KIcon("document-new"));
51 m_view.delete_button->setIcon(KIcon("trash-empty"));
52 m_view.zoom_button->setIcon(KIcon("zoom-in"));
53 m_view.unzoom_button->setIcon(KIcon("zoom-out"));
55 m_view.add_button->setToolTip(i18n("Add new button"));
56 m_view.delete_button->setToolTip(i18n("Delete current button"));
58 changeProfile(format);
61 // Create color background
62 m_color = new QGraphicsRectItem(0, 0, m_width, m_height);
63 m_color->setBrush(m_view.background_color->color());
64 m_color->setZValue(2);
65 m_scene->addItem(m_color);
68 // create background image
69 m_background = new QGraphicsPixmapItem();
70 m_background->setZValue(3);
71 //m_scene->addItem(m_background);
73 // create safe zone rect
74 int safeW = m_width / 20;
75 int safeH = m_height / 20;
76 m_safeRect = new QGraphicsRectItem(safeW, safeH, m_width - 2 * safeW, m_height - 2 * safeH);
78 pen.setStyle(Qt::DashLine);
80 m_safeRect->setPen(pen);
81 m_safeRect->setZValue(5);
82 m_scene->addItem(m_safeRect);
83 checkBackgroundType(0);
86 DvdButton *button = new DvdButton(m_view.play_text->text());
87 QFont font = m_view.font_family->currentFont();
88 font.setPixelSize(m_view.font_size->value());
89 //font.setStyleStrategy(QFont::NoAntialias);
90 #if KDE_IS_VERSION(4,6,0)
91 if (m_view.use_shadow->isChecked()) {
92 QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this);
93 shadow->setBlurRadius(7);
94 shadow->setOffset(4, 4);
95 button->setGraphicsEffect(shadow);
97 connect(m_view.use_shadow, SIGNAL(stateChanged(int)), this, SLOT(slotEnableShadows(int)));
98 #elif KDE_IS_VERSION(4,6,0)
99 m_view.use_shadow->setHidden(true);
101 button->setFont(font);
102 button->setDefaultTextColor(m_view.text_color->color());
103 button->setZValue(4);
104 QRectF r = button->sceneBoundingRect();
105 m_scene->addItem(button);
106 button->setPos((m_width - r.width()) / 2, (m_height - r.height()) / 2);
107 button->setSelected(true);
110 //m_view.menu_preview->resizefitInView(0, 0, m_width, m_height);
112 connect(m_view.play_text, SIGNAL(textChanged(const QString &)), this, SLOT(buildButton()));
113 connect(m_view.text_color, SIGNAL(changed(const QColor &)), this, SLOT(updateColor()));
114 connect(m_view.font_size, SIGNAL(valueChanged(int)), this, SLOT(buildButton()));
115 connect(m_view.font_family, SIGNAL(currentFontChanged(const QFont &)), this, SLOT(buildButton()));
116 connect(m_view.background_image, SIGNAL(textChanged(const QString &)), this, SLOT(buildImage()));
117 connect(m_view.background_color, SIGNAL(changed(const QColor &)), this, SLOT(buildColor()));
119 connect(m_view.background_list, SIGNAL(currentIndexChanged(int)), this, SLOT(checkBackgroundType(int)));
121 connect(m_view.target_list, SIGNAL(activated(int)), this, SLOT(setButtonTarget(int)));
122 connect(m_view.back_to_menu, SIGNAL(toggled(bool)), this, SLOT(setBackToMenu(bool)));
124 connect(m_view.add_button, SIGNAL(pressed()), this, SLOT(addButton()));
125 connect(m_view.delete_button, SIGNAL(pressed()), this, SLOT(deleteButton()));
126 connect(m_view.zoom_button, SIGNAL(pressed()), this, SLOT(slotZoom()));
127 connect(m_view.unzoom_button, SIGNAL(pressed()), this, SLOT(slotUnZoom()));
128 connect(m_scene, SIGNAL(selectionChanged()), this, SLOT(buttonChanged()));
129 connect(m_scene, SIGNAL(sceneChanged()), this, SIGNAL(completeChanged()));
131 // red background for error message
132 KColorScheme scheme(palette().currentColorGroup(), KColorScheme::Window, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
133 QPalette p = m_view.error_message->palette();
134 p.setColor(QPalette::Background, scheme.background(KColorScheme::NegativeBackground).color());
135 m_view.error_message->setAutoFillBackground(true);
136 m_view.error_message->setPalette(p);
137 m_view.menu_box->setEnabled(false);
139 #if KDE_IS_VERSION(4,7,0)
140 m_menuMessage = new KMessageWidget;
141 QGridLayout *s = static_cast <QGridLayout*> (layout());
142 s->addWidget(m_menuMessage, 7, 0, 1, -1);
143 m_menuMessage->hide();
144 m_view.error_message->hide();
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() == DvdButtonItem) {
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() == DvdButtonItem) {
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->show();
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->show();
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->show();
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->hide();
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->show();
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() == DvdButtonItem) {
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() == DvdButtonItem) {
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() == DvdButtonItem) {
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->setDefaultTextColor(m_view.text_color->color());
333 button->setZValue(4);
334 QRectF r = button->sceneBoundingRect();
335 m_scene->addItem(button);
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() == DvdButtonItem) {
351 void DvdWizardMenu::changeProfile(DVDFORMAT format)
356 m_finalSize = QSize(720, 576);
361 m_finalSize = QSize(720, 480);
366 m_finalSize = QSize(720, 480);
371 m_finalSize = QSize(720, 576);
378 void DvdWizardMenu::updatePreview()
380 m_scene->setProfile(m_width, m_height);
382 matrix.scale(0.5, 0.5);
383 m_view.menu_preview->setMatrix(matrix);
384 m_view.menu_preview->setMinimumSize(m_width / 2 + 4, m_height / 2 + 8);
386 if (m_color) m_color->setRect(0, 0, m_width, m_height);
388 int safeW = m_width / 20;
389 int safeH = m_height / 20;
390 if (m_safeRect) m_safeRect->setRect(safeW, safeH, m_width - 2 * safeW, m_height - 2 * safeH);
393 void DvdWizardMenu::setTargets(QStringList list, QStringList targetlist)
395 m_view.target_list->clear();
396 m_view.target_list->addItem(i18n("Play All"), "jump title 1");
398 for (int i = 0; i < list.count(); i++) {
399 if (targetlist.at(i).contains("chapter"))
400 m_view.target_list->addItem(list.at(i), targetlist.at(i));
402 m_view.target_list->addItem(KIcon("video-x-generic"), list.at(i), targetlist.at(i));
406 m_view.back_to_menu->setHidden(movieCount == 1);
409 void DvdWizardMenu::checkBackgroundType(int ix)
412 m_view.background_color->setVisible(true);
413 m_view.background_image->setVisible(false);
414 m_view.loop_movie->setVisible(false);
415 if (m_background->scene() != 0) m_scene->removeItem(m_background);
417 m_view.background_color->setVisible(false);
418 m_view.background_image->setVisible(true);
420 m_view.background_image->clear();
421 m_view.background_image->setFilter("*");
422 if (m_background->scene() != 0) m_scene->removeItem(m_background);
423 m_view.loop_movie->setVisible(false);
425 if (m_background->scene() != 0) m_scene->removeItem(m_background);
426 m_view.background_image->clear();
427 m_view.background_image->setFilter("video/mpeg");
428 m_view.loop_movie->setVisible(true);
431 emit completeChanged();
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());
498 // Check for button overlapping in case we changed text / size
499 emit completeChanged();
502 void DvdWizardMenu::updateColor()
504 updateColor(m_view.text_color->color());
505 m_view.menu_preview->viewport()->update();
508 void DvdWizardMenu::prepareUnderLines()
510 QList<QGraphicsItem *> list = m_scene->items();
511 for (int i = 0; i < list.count(); i++) {
512 if (list.at(i)->type() == DvdButtonItem) {
513 QRectF r = list.at(i)->sceneBoundingRect();
514 int bottom = r.bottom() - 1;
515 if (bottom % 2 == 1) bottom = bottom - 1;
516 int underlineHeight = r.height() / 10;
517 if (underlineHeight % 2 == 1) underlineHeight = underlineHeight - 1;
518 underlineHeight = qMin(underlineHeight, 10);
519 underlineHeight = qMax(underlineHeight, 2);
520 r.setTop(bottom - underlineHeight);
522 r.adjust(2, 0, -2, 0);
523 DvdButtonUnderline *underline = new DvdButtonUnderline(r);
524 m_scene->addItem(underline);
525 list.at(i)->setVisible(false);
530 void DvdWizardMenu::resetUnderLines()
532 QList<QGraphicsItem *> list = m_scene->items();
533 QList<QGraphicsItem *> toDelete;
534 for (int i = 0; i < list.count(); i++) {
535 if (list.at(i)->type() == DvdButtonUnderlineItem) {
536 toDelete.append(list.at(i));
538 if (list.at(i)->type() == DvdButtonItem) {
539 list.at(i)->setVisible(true);
542 while (!toDelete.isEmpty()) {
543 QGraphicsItem *item = toDelete.takeFirst();
548 void DvdWizardMenu::updateUnderlineColor(QColor c)
550 QList<QGraphicsItem *> list = m_scene->items();
551 for (int i = 0; i < list.count(); i++) {
552 if (list.at(i)->type() == DvdButtonUnderlineItem) {
553 DvdButtonUnderline *underline = static_cast < DvdButtonUnderline* >(list.at(i));
554 underline->setPen(Qt::NoPen);
556 underline->setBrush(c);
562 void DvdWizardMenu::updateColor(QColor c)
564 DvdButton *button = NULL;
565 QList<QGraphicsItem *> list = m_scene->items();
566 for (int i = 0; i < list.count(); i++) {
567 if (list.at(i)->type() == DvdButtonItem) {
568 button = static_cast < DvdButton* >(list.at(i));
569 button->setDefaultTextColor(c);
575 void DvdWizardMenu::createButtonImages(const QString &selected_image, const QString &highlighted_image, bool letterbox)
577 if (m_view.create_menu->isChecked()) {
578 m_scene->clearSelection();
579 QRectF source(0, 0, m_width, m_height);
581 if (!letterbox) target = QRectF(0, 0, m_finalSize.width(), m_finalSize.height());
583 // Scale the button images to fit a letterbox image
584 double factor = (double) m_width / m_finalSize.width();
585 int letterboxHeight = m_height / factor;
586 target = QRectF(0, (m_finalSize.height() - letterboxHeight) / 2, m_finalSize.width(), letterboxHeight);
588 if (m_safeRect->scene() != 0) m_scene->removeItem(m_safeRect);
589 if (m_color->scene() != 0) m_scene->removeItem(m_color);
590 if (m_background->scene() != 0) m_scene->removeItem(m_background);
592 #if QT_VERSION >= 0x040800
593 QImage img(m_finalSize.width(), m_finalSize.height(), QImage::Format_ARGB32);
594 img.fill(Qt::transparent);
595 updateUnderlineColor(m_view.highlighted_color->color());
597 QImage img(m_finalSize.width(), m_finalSize.height(), QImage::Format_Mono);
599 updateUnderlineColor(Qt::black);
603 //p.setRenderHints(QPainter::Antialiasing, false);
604 //p.setRenderHints(QPainter::TextAntialiasing, false);
605 m_scene->render(&p, target, source, Qt::IgnoreAspectRatio);
607 #if QT_VERSION >= 0x040800
608 #elif QT_VERSION >= 0x040600
609 img.setColor(0, m_view.highlighted_color->color().rgb());
610 img.setColor(1, qRgba(0,0,0,0));
614 img.save(highlighted_image);
616 #if QT_VERSION >= 0x040800
617 img.fill(Qt::transparent);
618 updateUnderlineColor(m_view.selected_color->color());
623 //p.setRenderHints(QPainter::Antialiasing, false);
624 //p.setRenderHints(QPainter::TextAntialiasing, false);
625 m_scene->render(&p, target, source, Qt::IgnoreAspectRatio);
627 #if QT_VERSION >= 0x040800
628 #elif QT_VERSION >= 0x040600
629 img.setColor(0, m_view.selected_color->color().rgb());
630 img.setColor(1, qRgba(0,0,0,0));
634 img.save(selected_image);
636 m_scene->addItem(m_safeRect);
637 m_scene->addItem(m_color);
638 if (m_view.background_list->currentIndex() > 0) m_scene->addItem(m_background);
643 void DvdWizardMenu::createBackgroundImage(const QString &img1, bool letterbox)
645 m_scene->clearSelection();
646 if (m_safeRect->scene() != 0) m_scene->removeItem(m_safeRect);
648 QImage img(m_width, m_height, QImage::Format_ARGB32);
650 //TODO: Should the image be scaled when letterboxing?
652 QRectF source(0, 0, m_width, m_height);
654 if (!letterbox) target = QRectF(0, 0, m_finalSize.width(), m_finalSize.height());
656 // Scale the button images to fit a letterbox image
657 double factor = (double) m_width / m_finalSize.width();
658 int letterboxHeight = m_height / factor;
659 target = QRectF(0, (m_finalSize.height() - letterboxHeight) / 2, m_finalSize.width(), letterboxHeight);
664 if (m_background->scene() != 0) m_scene->removeItem(m_background);
665 if (m_color->scene() != 0) m_scene->removeItem(m_color);
666 img.fill(Qt::transparent);
668 updateColor(m_view.text_color->color());
670 p.setRenderHints(QPainter::Antialiasing, true);
671 p.setRenderHints(QPainter::TextAntialiasing, true);
672 m_scene->render(&p, QRectF(0, 0, img.width(), img.height()));
673 //m_scene->render(&p, target, source, Qt::IgnoreAspectRatio);
676 m_scene->addItem(m_safeRect);
678 m_scene->addItem(m_background);
679 m_scene->addItem(m_color);
683 bool DvdWizardMenu::createMenu() const
685 return m_view.create_menu->isChecked();
688 bool DvdWizardMenu::loopMovie() const
690 return m_view.loop_movie->isChecked();
693 bool DvdWizardMenu::menuMovie() const
695 return m_view.background_list->currentIndex() == 2;
698 QString DvdWizardMenu::menuMoviePath() const
700 return m_view.background_image->url().path();
703 int DvdWizardMenu::menuMovieLength() const
705 return m_movieLength;
709 QMap <QString, QRect> DvdWizardMenu::buttonsInfo(bool letterbox)
711 QMap <QString, QRect> info;
712 QList<QGraphicsItem *> list = m_scene->items();
713 double ratiox = (double) m_finalSize.width() / m_width;
717 int letterboxHeight = m_height * ratiox;
718 ratioy = (double) letterboxHeight / m_finalSize.height();
719 offset = (m_finalSize.height() - letterboxHeight) / 2;
721 for (int i = 0; i < list.count(); i++) {
722 if (list.at(i)->type() == DvdButtonItem) {
723 DvdButton *button = static_cast < DvdButton* >(list.at(i));
724 QRectF r = button->sceneBoundingRect();
725 QRect adjustedRect(r.x() * ratiox, offset + r.y() * ratioy, r.width() * ratiox, r.height() * ratioy);
726 // Make sure y1 is not odd (requested by spumux)
727 if (adjustedRect.height() % 2 == 1) adjustedRect.setHeight(adjustedRect.height() + 1);
728 if (adjustedRect.y() % 2 == 1) adjustedRect.setY(adjustedRect.y() - 1);
729 QString command = button->command();
730 if (button->backMenu()) command.prepend("g1 = 999;");
731 info.insertMulti(command, adjustedRect);
737 QDomElement DvdWizardMenu::toXml() const
740 QDomElement xml = doc.createElement("menu");
741 doc.appendChild(xml);
742 xml.setAttribute("enabled", m_view.create_menu->isChecked());
743 if (m_view.background_list->currentIndex() == 0) {
745 xml.setAttribute("background_color", m_view.background_color->color().name());
746 } else if (m_view.background_list->currentIndex() == 1) {
748 xml.setAttribute("background_image", m_view.background_image->url().path());
751 xml.setAttribute("background_video", m_view.background_image->url().path());
753 xml.setAttribute("text_color", m_view.text_color->color().name());
754 xml.setAttribute("selected_color", m_view.selected_color->color().name());
755 xml.setAttribute("highlighted_color", m_view.highlighted_color->color().name());
756 xml.setAttribute("text_shadow", (int) m_view.use_shadow->isChecked());
758 QList<QGraphicsItem *> list = m_scene->items();
761 for (int i = 0; i < list.count(); i++) {
762 if (list.at(i)->type() == DvdButtonItem) {
764 DvdButton *button = static_cast < DvdButton* >(list.at(i));
765 QDomElement xmlbutton = doc.createElement("button");
766 xmlbutton.setAttribute("target", button->target());
767 xmlbutton.setAttribute("command", button->command());
768 xmlbutton.setAttribute("backtomenu", button->backMenu());
769 xmlbutton.setAttribute("posx", (int) button->pos().x());
770 xmlbutton.setAttribute("posy", (int) button->pos().y());
771 xmlbutton.setAttribute("text", button->toPlainText());
772 QFont font = button->font();
773 xmlbutton.setAttribute("font_size", font.pixelSize());
774 xmlbutton.setAttribute("font_family", font.family());
775 xml.appendChild(xmlbutton);
778 return doc.documentElement();
782 void DvdWizardMenu::loadXml(DVDFORMAT format, QDomElement xml)
784 kDebug() << "// LOADING MENU";
785 if (xml.isNull()) return;
786 kDebug() << "// LOADING MENU 1";
787 changeProfile(format);
788 m_view.create_menu->setChecked(xml.attribute("enabled").toInt());
789 if (xml.hasAttribute("background_color")) {
790 m_view.background_list->setCurrentIndex(0);
791 m_view.background_color->setColor(xml.attribute("background_color"));
792 } else if (xml.hasAttribute("background_image")) {
793 m_view.background_list->setCurrentIndex(1);
794 m_view.background_image->setUrl(KUrl(xml.attribute("background_image")));
795 } else if (xml.hasAttribute("background_video")) {
796 m_view.background_list->setCurrentIndex(2);
797 m_view.background_image->setUrl(KUrl(xml.attribute("background_video")));
800 m_view.text_color->setColor(xml.attribute("text_color"));
801 m_view.selected_color->setColor(xml.attribute("selected_color"));
802 m_view.highlighted_color->setColor(xml.attribute("highlighted_color"));
804 m_view.use_shadow->setChecked(xml.attribute("text_shadow").toInt());
806 QDomNodeList buttons = xml.elementsByTagName("button");
807 kDebug() << "// LOADING MENU 2" << buttons.count();
809 if (buttons.count() > 0) {
810 // Clear existing buttons
811 QList<QGraphicsItem *> list = m_scene->items();
813 for (int i = 0; i < list.count(); i++) {
814 if (list.at(i)->type() == DvdButtonItem) {
821 for (int i = 0; i < buttons.count(); i++) {
822 QDomElement e = buttons.at(i).toElement();
823 // create menu button
824 DvdButton *button = new DvdButton(e.attribute("text"));
825 QFont font(e.attribute("font_family"));
826 font.setPixelSize(e.attribute("font_size").toInt());
827 #if KDE_IS_VERSION(4,6,0)
828 if (m_view.use_shadow->isChecked()) {
829 QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this);
830 shadow->setBlurRadius(7);
831 shadow->setOffset(4, 4);
832 button->setGraphicsEffect(shadow);
836 //font.setStyleStrategy(QFont::NoAntialias);
837 button->setFont(font);
838 button->setTarget(e.attribute("target").toInt(), e.attribute("command"));
839 button->setBackMenu(e.attribute("backtomenu").toInt());
840 button->setDefaultTextColor(m_view.text_color->color());
841 button->setZValue(4);
842 m_scene->addItem(button);
843 button->setPos(e.attribute("posx").toInt(), e.attribute("posy").toInt());
848 void DvdWizardMenu::slotZoom()
850 m_view.menu_preview->scale(2.0, 2.0);
853 void DvdWizardMenu::slotUnZoom()
855 m_view.menu_preview->scale(0.5, 0.5);