1 /***************************************************************************
2 * Copyright (C) 2009 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #include "dvdwizardmenu.h"
21 #include "kdenlivesettings.h"
24 #include <KColorScheme>
26 #if KDE_IS_VERSION(4,6,0)
27 #include <QGraphicsDropShadowEffect>
33 DvdWizardMenu::DvdWizardMenu(const QString &profile, QWidget *parent) :
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 if (profile == "dv_ntsc" || profile == "dv_ntsc_wide") {
66 } else changeProfile(true);
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(activated(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() == QGraphicsItem::UserType + 1) {
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() == QGraphicsItem::UserType + 1) {
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() == QGraphicsItem::UserType + 1) {
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() == QGraphicsItem::UserType + 1) {
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() == QGraphicsItem::UserType + 1) {
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() == QGraphicsItem::UserType + 1) {
352 void DvdWizardMenu::changeProfile(bool isPal)
355 if (isPal == false) {
356 m_finalSize = QSize(720, 480);
360 m_finalSize = QSize(720, 576);
367 void DvdWizardMenu::updatePreview()
369 m_scene->setProfile(m_width, m_height);
371 matrix.scale(0.5, 0.5);
372 m_view.menu_preview->setMatrix(matrix);
373 m_view.menu_preview->setMinimumSize(m_width / 2 + 4, m_height / 2 + 8);
375 if (m_color) m_color->setRect(0, 0, m_width, m_height);
377 int safeW = m_width / 20;
378 int safeH = m_height / 20;
379 if (m_safeRect) m_safeRect->setRect(safeW, safeH, m_width - 2 * safeW, m_height - 2 * safeH);
382 void DvdWizardMenu::setTargets(QStringList list, QStringList targetlist)
384 m_view.target_list->clear();
385 m_view.target_list->addItem(i18n("Play All"), "jump title 1");
387 for (int i = 0; i < list.count(); i++) {
388 if (targetlist.at(i).contains("chapter"))
389 m_view.target_list->addItem(list.at(i), targetlist.at(i));
391 m_view.target_list->addItem(KIcon("video-x-generic"), list.at(i), targetlist.at(i));
395 m_view.back_to_menu->setHidden(movieCount == 1);
398 void DvdWizardMenu::checkBackgroundType(int ix)
401 m_view.background_color->setVisible(true);
402 m_view.background_image->setVisible(false);
403 m_view.loop_movie->setVisible(false);
404 if (m_background->scene() != 0) m_scene->removeItem(m_background);
406 m_view.background_color->setVisible(false);
407 m_view.background_image->setVisible(true);
409 m_view.background_image->clear();
410 m_view.background_image->setFilter("*");
411 if (m_background->scene() != 0) m_scene->removeItem(m_background);
412 m_view.loop_movie->setVisible(false);
414 if (m_background->scene() != 0) m_scene->removeItem(m_background);
415 m_view.background_image->clear();
416 m_view.background_image->setFilter("video/mpeg");
417 m_view.loop_movie->setVisible(true);
422 void DvdWizardMenu::buildColor()
424 m_color->setBrush(m_view.background_color->color());
427 void DvdWizardMenu::buildImage()
429 emit completeChanged();
430 if (m_view.background_image->url().isEmpty()) {
431 if (m_background->scene() != 0) m_scene->removeItem(m_background);
436 if (m_view.background_list->currentIndex() == 1) {
438 if (!pix.load(m_view.background_image->url().path())) {
439 if (m_background->scene() != 0) m_scene->removeItem(m_background);
442 pix = pix.scaled(m_width, m_height);
443 } else if (m_view.background_list->currentIndex() == 2) {
446 QString standard = "dv_pal";
447 if (!m_isPal) standard = "dv_ntsc";
448 Mlt::Profile profile(standard.toUtf8().constData());
449 Mlt::Producer *producer = new Mlt::Producer(profile, m_view.background_image->url().path().toUtf8().data());
450 if (producer && producer->is_valid()) {
451 pix = QPixmap::fromImage(KThumb::getFrame(producer, 0, m_finalSize.width(), m_width, m_height));
452 m_movieLength = producer->get_length();
454 if (producer) delete producer;
456 m_background->setPixmap(pix);
457 m_scene->addItem(m_background);
460 void DvdWizardMenu::checkBackground()
462 if (m_view.background_list->currentIndex() != 1) {
463 if (m_background->scene() != 0) m_scene->removeItem(m_background);
465 m_scene->addItem(m_background);
469 void DvdWizardMenu::buildButton()
471 DvdButton *button = NULL;
472 QList<QGraphicsItem *> list = m_scene->selectedItems();
473 for (int i = 0; i < list.count(); i++) {
474 if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
475 button = static_cast < DvdButton* >(list.at(i));
479 if (button == NULL) return;
480 button->setPlainText(m_view.play_text->text());
481 QFont font = m_view.font_family->currentFont();
482 font.setPixelSize(m_view.font_size->value());
483 //font.setStyleStrategy(QFont::NoAntialias);
484 button->setFont(font);
485 button->setDefaultTextColor(m_view.text_color->color());
488 void DvdWizardMenu::updateColor()
490 updateColor(m_view.text_color->color());
491 m_view.menu_preview->viewport()->update();
494 void DvdWizardMenu::prepareUnderLines()
496 QList<QGraphicsItem *> list = m_scene->items();
497 for (int i = 0; i < list.count(); i++) {
498 if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
499 QRectF r = list.at(i)->sceneBoundingRect();
500 int bottom = r.bottom() - 1;
501 if (bottom % 2 == 1) bottom = bottom - 1;
502 int underlineHeight = r.height() / 10;
503 if (underlineHeight % 2 == 1) underlineHeight = underlineHeight - 1;
504 underlineHeight = qMin(underlineHeight, 10);
505 underlineHeight = qMax(underlineHeight, 2);
506 r.setTop(bottom - underlineHeight);
507 r.adjust(2, 0, -2, 0);
508 QGraphicsRectItem *underline = new QGraphicsRectItem(r);
509 underline->setData(Qt::UserRole, QString("underline"));
510 m_scene->addItem(underline);
511 list.at(i)->setVisible(false);
516 void DvdWizardMenu::resetUnderLines()
518 QList<QGraphicsItem *> list = m_scene->items();
519 QList<QGraphicsItem *> toDelete;
520 for (int i = 0; i < list.count(); i++) {
521 if (list.at(i)->data(Qt::UserRole).toString() == "underline") {
522 toDelete.append(list.at(i));
524 if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
525 list.at(i)->setVisible(true);
528 while (!toDelete.isEmpty()) {
529 QGraphicsItem *item = toDelete.takeFirst();
534 void DvdWizardMenu::updateUnderlineColor(QColor c)
536 QList<QGraphicsItem *> list = m_scene->items();
537 for (int i = 0; i < list.count(); i++) {
538 if (list.at(i)->data(Qt::UserRole).toString() == "underline") {
539 QGraphicsRectItem *underline = static_cast < QGraphicsRectItem* >(list.at(i));
540 underline->setPen(Qt::NoPen);
542 underline->setBrush(c);
548 void DvdWizardMenu::updateColor(QColor c)
550 DvdButton *button = NULL;
551 QList<QGraphicsItem *> list = m_scene->items();
552 for (int i = 0; i < list.count(); i++) {
553 if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
554 button = static_cast < DvdButton* >(list.at(i));
555 button->setDefaultTextColor(c);
561 void DvdWizardMenu::createButtonImages(const QString &img1, const QString &img2, const QString &img3)
563 if (m_view.create_menu->isChecked()) {
564 m_scene->clearSelection();
565 if (m_safeRect->scene() != 0) m_scene->removeItem(m_safeRect);
566 if (m_color->scene() != 0) m_scene->removeItem(m_color);
567 if (m_background->scene() != 0) m_scene->removeItem(m_background);
569 #if QT_VERSION >= 0x040800
570 QImage img(m_finalSize.width(), m_finalSize.height(), QImage::Format_ARGB32);
571 img.fill(Qt::transparent);
572 updateUnderlineColor(m_view.text_color->color());
574 QImage img(m_finalSize.width(), m_finalSize.height(), QImage::Format_Mono);
576 updateUnderlineColor(Qt::black);
579 //p.setRenderHints(QPainter::Antialiasing, false);
580 //p.setRenderHints(QPainter::TextAntialiasing, false);
581 m_scene->render(&p, QRectF(0, 0, m_finalSize.width(), m_finalSize.height()), QRectF(0, 0, m_width, m_height), Qt::IgnoreAspectRatio);
583 #if QT_VERSION >= 0x040800
584 #elif QT_VERSION >= 0x040600
585 img.setColor(0, m_view.text_color->color().rgb());
586 img.setColor(1, qRgba(0,0,0,0));
592 #if QT_VERSION >= 0x040800
593 img.fill(Qt::transparent);
594 updateUnderlineColor(m_view.highlighted_color->color());
599 //p.setRenderHints(QPainter::Antialiasing, false);
600 //p.setRenderHints(QPainter::TextAntialiasing, false);
601 m_scene->render(&p, QRectF(0, 0, m_finalSize.width(), m_finalSize.height()), QRectF(0, 0, m_width, m_height), Qt::IgnoreAspectRatio);
603 #if QT_VERSION >= 0x040800
604 #elif QT_VERSION >= 0x040600
605 img.setColor(0, m_view.highlighted_color->color().rgb());
606 img.setColor(1, qRgba(0,0,0,0));
612 #if QT_VERSION >= 0x040800
613 img.fill(Qt::transparent);
614 updateUnderlineColor(m_view.selected_color->color());
619 //p.setRenderHints(QPainter::Antialiasing, false);
620 //p.setRenderHints(QPainter::TextAntialiasing, false);
621 m_scene->render(&p, QRectF(0, 0, m_finalSize.width(), m_finalSize.height()), QRectF(0, 0, m_width, m_height), Qt::IgnoreAspectRatio);
623 #if QT_VERSION >= 0x040800
624 #elif QT_VERSION >= 0x040600
625 img.setColor(0, m_view.selected_color->color().rgb());
626 img.setColor(1, qRgba(0,0,0,0));
632 m_scene->addItem(m_safeRect);
633 m_scene->addItem(m_color);
634 if (m_view.background_list->currentIndex() > 0) m_scene->addItem(m_background);
639 void DvdWizardMenu::createBackgroundImage(const QString &overlayMenu, const QString &img1)
641 m_scene->clearSelection();
642 if (m_safeRect->scene() != 0) m_scene->removeItem(m_safeRect);
644 QImage img(m_width, m_height, QImage::Format_ARGB32);
645 if (menuMovie() && m_background->scene() != 0) {
647 m_scene->removeItem(m_background);
648 if (m_color->scene() != 0) m_scene->removeItem(m_color);
649 if (m_safeRect->scene() != 0) m_scene->removeItem(m_safeRect);
650 img.fill(Qt::transparent);
652 updateColor(m_view.text_color->color());
654 p.setRenderHints(QPainter::Antialiasing, true);
655 p.setRenderHints(QPainter::TextAntialiasing, true);
656 m_scene->render(&p, QRectF(0, 0, img.width(), img.height()));
659 m_scene->addItem(m_safeRect);
661 m_scene->addItem(m_background);
662 m_scene->addItem(m_color);
668 if (m_view.background_list->currentIndex() == 0) {
671 img = QImage(768, 576, QImage::Format_ARGB32);
673 img = QImage(720, 540, QImage::Format_ARGB32);
674 img.fill(m_view.background_color->color().rgb());
675 } else if (m_view.background_list->currentIndex() == 1) {
676 img.load(m_view.background_image->url().path());
678 if (img.width() != 768 || img.height() != 576)
679 img = img.scaled(768, 576, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
681 if (img.width() != 720 || img.height() != 540)
682 img = img.scaled(720, 540, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
685 // Overlay Normal menu
686 QImage menu(overlayMenu);
688 QRectF target(0, 0, img.width(), img.height());
689 QRectF src(0, 0, menu.width(), menu.height());
690 p.drawImage(target, menu, src);
695 bool DvdWizardMenu::createMenu() const
697 return m_view.create_menu->isChecked();
700 bool DvdWizardMenu::loopMovie() const
702 return m_view.loop_movie->isChecked();
705 bool DvdWizardMenu::menuMovie() const
707 return m_view.background_list->currentIndex() == 2;
710 QString DvdWizardMenu::menuMoviePath() const
712 return m_view.background_image->url().path();
715 int DvdWizardMenu::menuMovieLength() const
717 return m_movieLength;
721 QMap <QString, QRect> DvdWizardMenu::buttonsInfo()
723 QMap <QString, QRect> info;
724 QList<QGraphicsItem *> list = m_scene->items();
725 double ratio = (double) m_finalSize.width() / m_width;
726 for (int i = 0; i < list.count(); i++) {
727 if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
728 DvdButton *button = static_cast < DvdButton* >(list.at(i));
729 QRectF r = button->sceneBoundingRect();
730 QRect adjustedRect(r.x() * ratio, r.y(), r.width() * ratio, r.height());
731 // Make sure y1 is not odd (requested by spumux)
732 if (adjustedRect.height() % 2 == 1) adjustedRect.setHeight(adjustedRect.height() + 1);
733 if (adjustedRect.y() % 2 == 1) adjustedRect.setY(adjustedRect.y() - 1);
734 QString command = button->command();
735 if (button->backMenu()) command.prepend("g1 = 999;");
736 info.insertMulti(command, adjustedRect);
742 bool DvdWizardMenu::isPalMenu() const
747 QDomElement DvdWizardMenu::toXml() const
750 QDomElement xml = doc.createElement("menu");
751 doc.appendChild(xml);
752 xml.setAttribute("enabled", m_view.create_menu->isChecked());
753 if (m_view.background_list->currentIndex() == 0) {
755 xml.setAttribute("background_color", m_view.background_color->color().name());
756 } else if (m_view.background_list->currentIndex() == 1) {
758 xml.setAttribute("background_image", m_view.background_image->url().path());
761 xml.setAttribute("background_video", m_view.background_image->url().path());
763 xml.setAttribute("text_color", m_view.text_color->color().name());
764 xml.setAttribute("selected_color", m_view.selected_color->color().name());
765 xml.setAttribute("highlighted_color", m_view.highlighted_color->color().name());
766 xml.setAttribute("text_shadow", (int) m_view.use_shadow->isChecked());
768 QList<QGraphicsItem *> list = m_scene->items();
771 for (int i = 0; i < list.count(); i++) {
772 if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
774 DvdButton *button = static_cast < DvdButton* >(list.at(i));
775 QDomElement xmlbutton = doc.createElement("button");
776 xmlbutton.setAttribute("target", button->target());
777 xmlbutton.setAttribute("command", button->command());
778 xmlbutton.setAttribute("backtomenu", button->backMenu());
779 xmlbutton.setAttribute("posx", button->pos().x());
780 xmlbutton.setAttribute("posy", button->pos().y());
781 xmlbutton.setAttribute("text", button->toPlainText());
782 QFont font = button->font();
783 xmlbutton.setAttribute("font_size", font.pixelSize());
784 xmlbutton.setAttribute("font_family", font.family());
785 xml.appendChild(xmlbutton);
788 return doc.documentElement();
792 void DvdWizardMenu::loadXml(QDomElement xml)
794 kDebug() << "// LOADING MENU";
795 if (xml.isNull()) return;
796 kDebug() << "// LOADING MENU 1";
797 m_view.create_menu->setChecked(xml.attribute("enabled").toInt());
798 if (xml.hasAttribute("background_color")) {
799 m_view.background_list->setCurrentIndex(0);
800 m_view.background_color->setColor(xml.attribute("background_color"));
801 } else if (xml.hasAttribute("background_image")) {
802 m_view.background_list->setCurrentIndex(1);
803 m_view.background_image->setUrl(KUrl(xml.attribute("background_image")));
804 } else if (xml.hasAttribute("background_video")) {
805 m_view.background_list->setCurrentIndex(2);
806 m_view.background_image->setUrl(KUrl(xml.attribute("background_video")));
809 m_view.text_color->setColor(xml.attribute("text_color"));
810 m_view.selected_color->setColor(xml.attribute("selected_color"));
811 m_view.highlighted_color->setColor(xml.attribute("highlighted_color"));
813 m_view.use_shadow->setChecked(xml.attribute("text_shadow").toInt());
815 QDomNodeList buttons = xml.elementsByTagName("button");
816 kDebug() << "// LOADING MENU 2" << buttons.count();
818 if (buttons.count() > 0) {
819 // Clear existing buttons
820 QList<QGraphicsItem *> list = m_scene->items();
822 for (int i = 0; i < list.count(); i++) {
823 if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
830 for (int i = 0; i < buttons.count(); i++) {
831 QDomElement e = buttons.at(i).toElement();
832 // create menu button
833 DvdButton *button = new DvdButton(e.attribute("text"));
834 QFont font(e.attribute("font_family"));
835 font.setPixelSize(e.attribute("font_size").toInt());
836 #if KDE_IS_VERSION(4,6,0)
837 if (m_view.use_shadow->isChecked()) {
838 QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this);
839 shadow->setBlurRadius(7);
840 shadow->setOffset(4, 4);
841 button->setGraphicsEffect(shadow);
845 //font.setStyleStrategy(QFont::NoAntialias);
846 button->setFont(font);
847 button->setTarget(e.attribute("target").toInt(), e.attribute("command"));
848 button->setBackMenu(e.attribute("backtomenu").toInt());
849 button->setDefaultTextColor(m_view.text_color->color());
850 button->setZValue(4);
851 m_scene->addItem(button);
852 button->setPos(e.attribute("posx").toDouble(), e.attribute("posy").toDouble());
857 void DvdWizardMenu::slotZoom()
859 m_view.menu_preview->scale(2.0, 2.0);
862 void DvdWizardMenu::slotUnZoom()
864 m_view.menu_preview->scale(0.5, 0.5);