X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fdvdwizardmenu.cpp;h=e6ce7c81d132cf016195523c9102d28253b61a83;hb=29ceabd2afc227e0fb8b586c567eeaf7921b542e;hp=e9c68835464bab781fb3263e9b9fd962c049ccb5;hpb=64008a1e158de53a36ec9de041155d07e53cbb16;p=kdenlive diff --git a/src/dvdwizardmenu.cpp b/src/dvdwizardmenu.cpp index e9c68835..e6ce7c81 100644 --- a/src/dvdwizardmenu.cpp +++ b/src/dvdwizardmenu.cpp @@ -18,15 +18,26 @@ ***************************************************************************/ #include "dvdwizardmenu.h" +#include "kdenlivesettings.h" #include #include + +#if KDE_IS_VERSION(4,6,0) +#include +#endif + + #include "kthumb.h" -DvdWizardMenu::DvdWizardMenu(const QString &profile, QWidget *parent) : - QWizardPage(parent), - m_color(NULL), - m_safeRect(NULL) +enum { DvdButtonItem = QGraphicsItem::UserType + 1, DvdButtonUnderlineItem = QGraphicsItem::UserType + 2 }; + +DvdWizardMenu::DvdWizardMenu(DVDFORMAT format, QWidget *parent) : + QWizardPage(parent), + m_color(NULL), + m_safeRect(NULL), + m_finalSize(720, 576), + m_movieLength(-1) { m_view.setupUi(this); m_view.play_text->setText(i18n("Play")); @@ -44,9 +55,7 @@ DvdWizardMenu::DvdWizardMenu(const QString &profile, QWidget *parent) : m_view.add_button->setToolTip(i18n("Add new button")); m_view.delete_button->setToolTip(i18n("Delete current button")); - if (profile == "dv_ntsc" || profile == "dv_ntsc_wide") { - changeProfile(false); - } else changeProfile(true); + changeProfile(format); // Create color background @@ -71,15 +80,24 @@ DvdWizardMenu::DvdWizardMenu(const QString &profile, QWidget *parent) : m_safeRect->setPen(pen); m_safeRect->setZValue(5); m_scene->addItem(m_safeRect); - checkBackgroundType(0); - // create menu button DvdButton *button = new DvdButton(m_view.play_text->text()); QFont font = m_view.font_family->currentFont(); font.setPixelSize(m_view.font_size->value()); - font.setStyleStrategy(QFont::NoAntialias); + //font.setStyleStrategy(QFont::NoAntialias); +#if KDE_IS_VERSION(4,6,0) + if (m_view.use_shadow->isChecked()) { + QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this); + shadow->setBlurRadius(7); + shadow->setOffset(4, 4); + button->setGraphicsEffect(shadow); + } + connect(m_view.use_shadow, SIGNAL(stateChanged(int)), this, SLOT(slotEnableShadows(int))); +#elif KDE_IS_VERSION(4,6,0) + m_view.use_shadow->setHidden(true); +#endif button->setFont(font); button->setDefaultTextColor(m_view.text_color->color()); button->setZValue(4); @@ -91,14 +109,14 @@ DvdWizardMenu::DvdWizardMenu(const QString &profile, QWidget *parent) : //m_view.menu_preview->resizefitInView(0, 0, m_width, m_height); - connect(m_view.play_text, SIGNAL(textChanged(const QString &)), this, SLOT(buildButton())); - connect(m_view.text_color, SIGNAL(changed(const QColor &)), this, SLOT(updateColor())); + connect(m_view.play_text, SIGNAL(textChanged(QString)), this, SLOT(buildButton())); + connect(m_view.text_color, SIGNAL(changed(QColor)), this, SLOT(updateColor())); connect(m_view.font_size, SIGNAL(valueChanged(int)), this, SLOT(buildButton())); - connect(m_view.font_family, SIGNAL(currentFontChanged(const QFont &)), this, SLOT(buildButton())); - connect(m_view.background_image, SIGNAL(textChanged(const QString &)), this, SLOT(buildImage())); - connect(m_view.background_color, SIGNAL(changed(const QColor &)), this, SLOT(buildColor())); + connect(m_view.font_family, SIGNAL(currentFontChanged(QFont)), this, SLOT(buildButton())); + connect(m_view.background_image, SIGNAL(textChanged(QString)), this, SLOT(buildImage())); + connect(m_view.background_color, SIGNAL(changed(QColor)), this, SLOT(buildColor())); - connect(m_view.background_list, SIGNAL(activated(int)), this, SLOT(checkBackgroundType(int))); + connect(m_view.background_list, SIGNAL(currentIndexChanged(int)), this, SLOT(checkBackgroundType(int))); connect(m_view.target_list, SIGNAL(activated(int)), this, SLOT(setButtonTarget(int))); connect(m_view.back_to_menu, SIGNAL(toggled(bool)), this, SLOT(setBackToMenu(bool))); @@ -108,17 +126,24 @@ DvdWizardMenu::DvdWizardMenu(const QString &profile, QWidget *parent) : connect(m_view.zoom_button, SIGNAL(pressed()), this, SLOT(slotZoom())); connect(m_view.unzoom_button, SIGNAL(pressed()), this, SLOT(slotUnZoom())); connect(m_scene, SIGNAL(selectionChanged()), this, SLOT(buttonChanged())); - connect(m_scene, SIGNAL(changed(const QList &)), this, SIGNAL(completeChanged())); + connect(m_scene, SIGNAL(sceneChanged()), this, SIGNAL(completeChanged())); // red background for error message - KColorScheme scheme(palette().currentColorGroup(), KColorScheme::Window); + KColorScheme scheme(palette().currentColorGroup(), KColorScheme::Window, KSharedConfig::openConfig(KdenliveSettings::colortheme())); QPalette p = m_view.error_message->palette(); p.setColor(QPalette::Background, scheme.background(KColorScheme::NegativeBackground).color()); m_view.error_message->setAutoFillBackground(true); m_view.error_message->setPalette(p); - m_view.menu_box->setEnabled(false); +#if KDE_IS_VERSION(4,7,0) + m_menuMessage = new KMessageWidget; + QGridLayout *s = static_cast (layout()); + s->addWidget(m_menuMessage, 7, 0, 1, -1); + m_menuMessage->hide(); + m_view.error_message->hide(); +#endif + } DvdWizardMenu::~DvdWizardMenu() @@ -129,8 +154,25 @@ DvdWizardMenu::~DvdWizardMenu() delete m_scene; } -// virtual +void DvdWizardMenu::slotEnableShadows(int enable) +{ +#if KDE_IS_VERSION(4,6,0) + QList list = m_scene->items(); + for (int i = 0; i < list.count(); ++i) { + if (list.at(i)->type() == DvdButtonItem) { + if (enable) { + QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this); + shadow->setBlurRadius(7); + shadow->setOffset(4, 4); + list.at(i)->setGraphicsEffect(shadow); + } + else list.at(i)->setGraphicsEffect(NULL); + } + } +#endif +} +// virtual bool DvdWizardMenu::isComplete() const { m_view.error_message->setHidden(true); @@ -139,16 +181,22 @@ bool DvdWizardMenu::isComplete() const QList list = m_scene->items(); int buttonCount = 0; // check that the menu buttons don't collide - for (int i = 0; i < list.count(); i++) { - if (list.at(i)->type() == QGraphicsItem::UserType + 1) { + for (int i = 0; i < list.count(); ++i) { + if (list.at(i)->type() == DvdButtonItem) { buttonCount++; DvdButton *button = static_cast < DvdButton* >(list.at(i)); QList collisions = button->collidingItems(); if (!collisions.isEmpty()) { - for (int j = 0; j < collisions.count(); j++) { + for (int j = 0; j < collisions.count(); ++j) { if (collisions.at(j)->type() == button->type()) { +#if KDE_IS_VERSION(4,7,0) + m_menuMessage->setText(i18n("Buttons overlapping")); + m_menuMessage->setMessageType(KMessageWidget::Warning); + m_menuMessage->show(); +#else m_view.error_message->setText(i18n("Buttons overlapping")); m_view.error_message->setHidden(false); +#endif return false; } } @@ -158,28 +206,50 @@ bool DvdWizardMenu::isComplete() const } if (buttonCount == 0) { //We need at least one button +#if KDE_IS_VERSION(4,7,0) + m_menuMessage->setText(i18n("No button in menu")); + m_menuMessage->setMessageType(KMessageWidget::Warning); + m_menuMessage->show(); +#else m_view.error_message->setText(i18n("No button in menu")); m_view.error_message->setHidden(false); +#endif return false; } if (!m_view.background_image->isHidden()) { - // Make sure user selected a valid image / video file + // Make sure user selected a valid image / video file if (!QFile::exists(m_view.background_image->url().path())) { +#if KDE_IS_VERSION(4,7,0) + m_menuMessage->setText(i18n("Missing background image")); + m_menuMessage->setMessageType(KMessageWidget::Warning); + m_menuMessage->show(); +#else m_view.error_message->setText(i18n("Missing background image")); m_view.error_message->setHidden(false); +#endif return false; } } + +#if KDE_IS_VERSION(4,7,0) + m_menuMessage->hide(); +#endif // check that we have a "Play all" entry if (targets.contains(0)) return true; // ... or that each video file has a button - for (int i = m_view.target_list->count() - 1; i > 0; i--) { + for (int i = m_view.target_list->count() - 1; i > 0; --i) { // If there is a vob file entry and it has no button assigned, don't allow to go further if (m_view.target_list->itemIcon(i).isNull() == false && !targets.contains(i)) { +#if KDE_IS_VERSION(4,7,0) + m_menuMessage->setText(i18n("No menu entry for %1", m_view.target_list->itemText(i))); + m_menuMessage->setMessageType(KMessageWidget::Warning); + m_menuMessage->show(); +#else m_view.error_message->setText(i18n("No menu entry for %1", m_view.target_list->itemText(i))); m_view.error_message->setHidden(false); +#endif return false; } } @@ -189,8 +259,8 @@ bool DvdWizardMenu::isComplete() const void DvdWizardMenu::setButtonTarget(int ix) { QList list = m_scene->selectedItems(); - for (int i = 0; i < list.count(); i++) { - if (list.at(i)->type() == QGraphicsItem::UserType + 1) { + for (int i = 0; i < list.count(); ++i) { + if (list.at(i)->type() == DvdButtonItem) { DvdButton *button = static_cast < DvdButton* >(list.at(i)); button->setTarget(ix, m_view.target_list->itemData(ix).toString()); break; @@ -202,8 +272,8 @@ void DvdWizardMenu::setButtonTarget(int ix) void DvdWizardMenu::setBackToMenu(bool backToMenu) { QList list = m_scene->selectedItems(); - for (int i = 0; i < list.count(); i++) { - if (list.at(i)->type() == QGraphicsItem::UserType + 1) { + for (int i = 0; i < list.count(); ++i) { + if (list.at(i)->type() == DvdButtonItem) { DvdButton *button = static_cast < DvdButton* >(list.at(i)); button->setBackMenu(backToMenu); break; @@ -216,8 +286,8 @@ void DvdWizardMenu::buttonChanged() { QList list = m_scene->selectedItems(); bool foundButton = false; - for (int i = 0; i < list.count(); i++) { - if (list.at(i)->type() == QGraphicsItem::UserType + 1) { + for (int i = 0; i < list.count(); ++i) { + if (list.at(i)->type() == DvdButtonItem) { m_view.play_text->blockSignals(true); m_view.font_size->blockSignals(true); m_view.font_family->blockSignals(true); @@ -249,7 +319,15 @@ void DvdWizardMenu::addButton() DvdButton *button = new DvdButton(m_view.play_text->text()); QFont font = m_view.font_family->currentFont(); font.setPixelSize(m_view.font_size->value()); - font.setStyleStrategy(QFont::NoAntialias); +#if KDE_IS_VERSION(4,6,0) + if (m_view.use_shadow->isChecked()) { + QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this); + shadow->setBlurRadius(7); + shadow->setOffset(4, 4); + button->setGraphicsEffect(shadow); + } +#endif + //font.setStyleStrategy(QFont::NoAntialias); button->setFont(font); button->setDefaultTextColor(m_view.text_color->color()); button->setZValue(4); @@ -262,28 +340,39 @@ void DvdWizardMenu::addButton() void DvdWizardMenu::deleteButton() { QList list = m_scene->selectedItems(); - for (int i = 0; i < list.count(); i++) { - if (list.at(i)->type() == QGraphicsItem::UserType + 1) { + for (int i = 0; i < list.count(); ++i) { + if (list.at(i)->type() == DvdButtonItem) { delete list.at(i); break; } } } -void DvdWizardMenu::changeProfile(bool isPal) +void DvdWizardMenu::changeProfile(DVDFORMAT format) { - m_isPal = isPal; - if (isPal == false) { - m_width = 720; + m_format = format; + switch (m_format) { + case PAL_WIDE: + m_finalSize = QSize(720, 576); + m_width = 1024; + m_height = 576; + break; + case NTSC_WIDE: + m_finalSize = QSize(720, 480); + m_width = 853; m_height = 480; - m_isPal = false; - updatePreview(); - } else { - m_width = 720; + break; + case NTSC: + m_finalSize = QSize(720, 480); + m_width = 640; + m_height = 480; + break; + default: + m_finalSize = QSize(720, 576); + m_width = 768; m_height = 576; - m_isPal = true; - updatePreview(); } + updatePreview(); } void DvdWizardMenu::updatePreview() @@ -301,12 +390,12 @@ void DvdWizardMenu::updatePreview() if (m_safeRect) m_safeRect->setRect(safeW, safeH, m_width - 2 * safeW, m_height - 2 * safeH); } -void DvdWizardMenu::setTargets(QStringList list, QStringList targetlist) +void DvdWizardMenu::setTargets(const QStringList &list, const QStringList &targetlist) { m_view.target_list->clear(); m_view.target_list->addItem(i18n("Play All"), "jump title 1"); int movieCount = 0; - for (int i = 0; i < list.count(); i++) { + for (int i = 0; i < list.count(); ++i) { if (targetlist.at(i).contains("chapter")) m_view.target_list->addItem(list.at(i), targetlist.at(i)); else { @@ -339,6 +428,7 @@ void DvdWizardMenu::checkBackgroundType(int ix) m_view.loop_movie->setVisible(true); } } + emit completeChanged(); } void DvdWizardMenu::buildColor() @@ -364,11 +454,16 @@ void DvdWizardMenu::buildImage() pix = pix.scaled(m_width, m_height); } else if (m_view.background_list->currentIndex() == 2) { // video background - int w; - if (m_isPal) w = 768; - else w = 640; - pix = KThumb::getImage(m_view.background_image->url(), 0, w, m_height); - pix = pix.scaled(m_width, m_height); + m_movieLength = -1; + QString profileName = DvdWizardVob::getDvdProfile(m_format); + Mlt::Profile profile(profileName.toUtf8().constData()); + profile.set_explicit(true); + Mlt::Producer *producer = new Mlt::Producer(profile, m_view.background_image->url().path().toUtf8().constData()); + if (producer && producer->is_valid()) { + pix = QPixmap::fromImage(KThumb::getFrame(producer, 0, m_finalSize.width(), m_width, m_height)); + m_movieLength = producer->get_length(); + } + if (producer) delete producer; } m_background->setPixmap(pix); m_scene->addItem(m_background); @@ -387,8 +482,8 @@ void DvdWizardMenu::buildButton() { DvdButton *button = NULL; QList list = m_scene->selectedItems(); - for (int i = 0; i < list.count(); i++) { - if (list.at(i)->type() == QGraphicsItem::UserType + 1) { + for (int i = 0; i < list.count(); ++i) { + if (list.at(i)->type() == DvdButtonItem) { button = static_cast < DvdButton* >(list.at(i)); break; } @@ -397,9 +492,11 @@ void DvdWizardMenu::buildButton() button->setPlainText(m_view.play_text->text()); QFont font = m_view.font_family->currentFont(); font.setPixelSize(m_view.font_size->value()); - font.setStyleStrategy(QFont::NoAntialias); + //font.setStyleStrategy(QFont::NoAntialias); button->setFont(font); button->setDefaultTextColor(m_view.text_color->color()); + // Check for button overlapping in case we changed text / size + emit completeChanged(); } void DvdWizardMenu::updateColor() @@ -408,12 +505,66 @@ void DvdWizardMenu::updateColor() m_view.menu_preview->viewport()->update(); } -void DvdWizardMenu::updateColor(QColor c) +void DvdWizardMenu::prepareUnderLines() +{ + QList list = m_scene->items(); + for (int i = 0; i < list.count(); ++i) { + if (list.at(i)->type() == DvdButtonItem) { + QRectF r = list.at(i)->sceneBoundingRect(); + int bottom = r.bottom() - 1; + if (bottom % 2 == 1) bottom = bottom - 1; + int underlineHeight = r.height() / 10; + if (underlineHeight % 2 == 1) underlineHeight = underlineHeight - 1; + underlineHeight = qMin(underlineHeight, 10); + underlineHeight = qMax(underlineHeight, 2); + r.setTop(bottom - underlineHeight); + r.setBottom(bottom); + r.adjust(2, 0, -2, 0); + DvdButtonUnderline *underline = new DvdButtonUnderline(r); + m_scene->addItem(underline); + list.at(i)->setVisible(false); + } + } +} + +void DvdWizardMenu::resetUnderLines() +{ + QList list = m_scene->items(); + QList toDelete; + for (int i = 0; i < list.count(); ++i) { + if (list.at(i)->type() == DvdButtonUnderlineItem) { + toDelete.append(list.at(i)); + } + if (list.at(i)->type() == DvdButtonItem) { + list.at(i)->setVisible(true); + } + } + while (!toDelete.isEmpty()) { + QGraphicsItem *item = toDelete.takeFirst(); + delete item; + } +} + +void DvdWizardMenu::updateUnderlineColor(QColor c) +{ + QList list = m_scene->items(); + for (int i = 0; i < list.count(); ++i) { + if (list.at(i)->type() == DvdButtonUnderlineItem) { + DvdButtonUnderline *underline = static_cast < DvdButtonUnderline* >(list.at(i)); + underline->setPen(Qt::NoPen); + c.setAlpha(150); + underline->setBrush(c); + } + } +} + + +void DvdWizardMenu::updateColor(const QColor &c) { DvdButton *button = NULL; QList list = m_scene->items(); - for (int i = 0; i < list.count(); i++) { - if (list.at(i)->type() == QGraphicsItem::UserType + 1) { + for (int i = 0; i < list.count(); ++i) { + if (list.at(i)->type() == DvdButtonItem) { button = static_cast < DvdButton* >(list.at(i)); button->setDefaultTextColor(c); } @@ -421,75 +572,67 @@ void DvdWizardMenu::updateColor(QColor c) } -void DvdWizardMenu::createButtonImages(const QString &img1, const QString &img2, const QString &img3) +void DvdWizardMenu::createButtonImages(const QString &selected_image, const QString &highlighted_image, bool letterbox) { if (m_view.create_menu->isChecked()) { m_scene->clearSelection(); - QImage img(m_width, m_height, QImage::Format_ARGB32_Premultiplied); - img.fill(Qt::transparent); + QRectF source(0, 0, m_width, m_height); + QRectF target; + if (!letterbox) target = QRectF(0, 0, m_finalSize.width(), m_finalSize.height()); + else { + // Scale the button images to fit a letterbox image + double factor = (double) m_width / m_finalSize.width(); + int letterboxHeight = m_height / factor; + target = QRectF(0, (m_finalSize.height() - letterboxHeight) / 2, m_finalSize.width(), letterboxHeight); + } if (m_safeRect->scene() != 0) m_scene->removeItem(m_safeRect); if (m_color->scene() != 0) m_scene->removeItem(m_color); if (m_background->scene() != 0) m_scene->removeItem(m_background); - QPainter p(&img); - p.setRenderHints(QPainter::Antialiasing, false); - p.setRenderHints(QPainter::TextAntialiasing, false); - m_scene->render(&p, QRectF(0, 0, m_width, m_height)); - p.end(); -#if QT_VERSION >= 0x040600 - img.setColorCount(4); + prepareUnderLines(); +#if QT_VERSION >= 0x040800 + QImage img(m_finalSize.width(), m_finalSize.height(), QImage::Format_ARGB32); + img.fill(Qt::transparent); + updateUnderlineColor(m_view.highlighted_color->color()); #else - img.setNumColors(4); + QImage img(m_finalSize.width(), m_finalSize.height(), QImage::Format_Mono); + img.fill(Qt::white); + updateUnderlineColor(Qt::black); #endif - img.save(img1); - - /*QImage saved; - if (m_view.menu_profile->currentIndex() < 2) - saved = img.scaled(720, 576); - else saved = img.scaled(720, 480); - saved.setNumColors(4); - saved.save(img1);*/ - - updateColor(m_view.selected_color->color()); - img.fill(Qt::transparent); + QPainter p; p.begin(&img); - p.setRenderHints(QPainter::Antialiasing, false); - p.setRenderHints(QPainter::TextAntialiasing, false); - m_scene->render(&p, QRectF(0, 0, m_width, m_height)); + //p.setRenderHints(QPainter::Antialiasing, false); + //p.setRenderHints(QPainter::TextAntialiasing, false); + m_scene->render(&p, target, source, Qt::IgnoreAspectRatio); p.end(); - /* if (m_view.menu_profile->currentIndex() < 2) - saved = img.scaled(720, 576); - else saved = img.scaled(720, 480); - saved.setNumColors(4); - saved.save(img2);*/ -#if QT_VERSION >= 0x040600 - img.setColorCount(4); +#if QT_VERSION >= 0x040800 +#elif QT_VERSION >= 0x040600 + img.setColor(0, m_view.highlighted_color->color().rgb()); + img.setColor(1, qRgba(0,0,0,0)); #else img.setNumColors(4); #endif - img.save(img2); - + img.save(highlighted_image); - updateColor(m_view.highlighted_color->color()); +#if QT_VERSION >= 0x040800 img.fill(Qt::transparent); + updateUnderlineColor(m_view.selected_color->color()); +#else + img.fill(Qt::white); +#endif p.begin(&img); - p.setRenderHints(QPainter::Antialiasing, false); - p.setRenderHints(QPainter::TextAntialiasing, false); - m_scene->render(&p, QRectF(0, 0, m_width, m_height)); + //p.setRenderHints(QPainter::Antialiasing, false); + //p.setRenderHints(QPainter::TextAntialiasing, false); + m_scene->render(&p, target, source, Qt::IgnoreAspectRatio); p.end(); - /*if (m_view.menu_profile->currentIndex() < 2) - saved = img.scaled(720, 576); - else saved = img.scaled(720, 480); - saved.setNumColors(4); - saved.save(img3);*/ -#if QT_VERSION >= 0x040600 - img.setColorCount(4); +#if QT_VERSION >= 0x040800 +#elif QT_VERSION >= 0x040600 + img.setColor(0, m_view.selected_color->color().rgb()); + img.setColor(1, qRgba(0,0,0,0)); #else img.setNumColors(4); #endif - img.save(img3); - - updateColor(); - + img.save(selected_image); + resetUnderLines(); m_scene->addItem(m_safeRect); m_scene->addItem(m_color); if (m_view.background_list->currentIndex() > 0) m_scene->addItem(m_background); @@ -497,27 +640,46 @@ void DvdWizardMenu::createButtonImages(const QString &img1, const QString &img2, } -void DvdWizardMenu::createBackgroundImage(const QString &img1) +void DvdWizardMenu::createBackgroundImage(const QString &img1, bool letterbox) { - QImage img; - if (m_view.background_list->currentIndex() == 0) { - // color background - if (m_isPal) - img = QImage(768, 576, QImage::Format_ARGB32); - else - img = QImage(720, 540, QImage::Format_ARGB32); - img.fill(m_view.background_color->color().rgb()); - } else if (m_view.background_list->currentIndex() == 1) { - img.load(m_view.background_image->url().path()); - if (m_isPal) { - if (img.width() != 768 || img.height() != 576) - img = img.scaled(768, 576, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); - } else { - if (img.width() != 720 || img.height() != 540) - img = img.scaled(720, 540, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); - } - } else return; + Q_UNUSED(letterbox) + + m_scene->clearSelection(); + if (m_safeRect->scene() != 0) m_scene->removeItem(m_safeRect); + bool showBg = false; + QImage img(m_width, m_height, QImage::Format_ARGB32); + + //TODO: Should the image be scaled when letterboxing? + /* + QRectF source(0, 0, m_width, m_height); + QRectF target; + if (!letterbox) target = QRectF(0, 0, m_finalSize.width(), m_finalSize.height()); + else { + // Scale the button images to fit a letterbox image + double factor = (double) m_width / m_finalSize.width(); + int letterboxHeight = m_height / factor; + target = QRectF(0, (m_finalSize.height() - letterboxHeight) / 2, m_finalSize.width(), letterboxHeight); + }*/ + + if (menuMovie()) { + showBg = true; + if (m_background->scene() != 0) m_scene->removeItem(m_background); + if (m_color->scene() != 0) m_scene->removeItem(m_color); + img.fill(Qt::transparent); + } + updateColor(m_view.text_color->color()); + QPainter p(&img); + p.setRenderHints(QPainter::Antialiasing, true); + p.setRenderHints(QPainter::TextAntialiasing, true); + m_scene->render(&p, QRectF(0, 0, img.width(), img.height())); + //m_scene->render(&p, target, source, Qt::IgnoreAspectRatio); + p.end(); img.save(img1); + m_scene->addItem(m_safeRect); + if (showBg) { + m_scene->addItem(m_background); + m_scene->addItem(m_color); + } } bool DvdWizardMenu::createMenu() const @@ -540,31 +702,40 @@ QString DvdWizardMenu::menuMoviePath() const return m_view.background_image->url().path(); } +int DvdWizardMenu::menuMovieLength() const +{ + return m_movieLength; +} + -QMap DvdWizardMenu::buttonsInfo() +QMap DvdWizardMenu::buttonsInfo(bool letterbox) { QMap info; QList list = m_scene->items(); - for (int i = 0; i < list.count(); i++) { - if (list.at(i)->type() == QGraphicsItem::UserType + 1) { + double ratiox = (double) m_finalSize.width() / m_width; + double ratioy = 1; + int offset = 0; + if (letterbox) { + int letterboxHeight = m_height * ratiox; + ratioy = (double) letterboxHeight / m_finalSize.height(); + offset = (m_finalSize.height() - letterboxHeight) / 2; + } + for (int i = 0; i < list.count(); ++i) { + if (list.at(i)->type() == DvdButtonItem) { DvdButton *button = static_cast < DvdButton* >(list.at(i)); - QRect r = list.at(i)->sceneBoundingRect().toRect(); + QRectF r = button->sceneBoundingRect(); + QRect adjustedRect(r.x() * ratiox, offset + r.y() * ratioy, r.width() * ratiox, r.height() * ratioy); // Make sure y1 is not odd (requested by spumux) - if (r.height() % 2 == 1) r.setHeight(r.height() + 1); - if (r.y() % 2 == 1) r.setY(r.y() - 1); + if (adjustedRect.height() % 2 == 1) adjustedRect.setHeight(adjustedRect.height() + 1); + if (adjustedRect.y() % 2 == 1) adjustedRect.setY(adjustedRect.y() - 1); QString command = button->command(); if (button->backMenu()) command.prepend("g1 = 999;"); - info.insertMulti(command, r); + info.insertMulti(command, adjustedRect); } } return info; } -bool DvdWizardMenu::isPalMenu() const -{ - return m_isPal; -} - QDomElement DvdWizardMenu::toXml() const { QDomDocument doc; @@ -584,20 +755,21 @@ QDomElement DvdWizardMenu::toXml() const xml.setAttribute("text_color", m_view.text_color->color().name()); xml.setAttribute("selected_color", m_view.selected_color->color().name()); xml.setAttribute("highlighted_color", m_view.highlighted_color->color().name()); + xml.setAttribute("text_shadow", (int) m_view.use_shadow->isChecked()); QList list = m_scene->items(); int buttonCount = 0; - for (int i = 0; i < list.count(); i++) { - if (list.at(i)->type() == QGraphicsItem::UserType + 1) { + for (int i = 0; i < list.count(); ++i) { + if (list.at(i)->type() == DvdButtonItem) { buttonCount++; DvdButton *button = static_cast < DvdButton* >(list.at(i)); QDomElement xmlbutton = doc.createElement("button"); xmlbutton.setAttribute("target", button->target()); xmlbutton.setAttribute("command", button->command()); xmlbutton.setAttribute("backtomenu", button->backMenu()); - xmlbutton.setAttribute("posx", button->pos().x()); - xmlbutton.setAttribute("posy", button->pos().y()); + xmlbutton.setAttribute("posx", (int) button->pos().x()); + xmlbutton.setAttribute("posy", (int) button->pos().y()); xmlbutton.setAttribute("text", button->toPlainText()); QFont font = button->font(); xmlbutton.setAttribute("font_size", font.pixelSize()); @@ -609,11 +781,12 @@ QDomElement DvdWizardMenu::toXml() const } -void DvdWizardMenu::loadXml(QDomElement xml) +void DvdWizardMenu::loadXml(DVDFORMAT format, const QDomElement &xml) { kDebug() << "// LOADING MENU"; if (xml.isNull()) return; kDebug() << "// LOADING MENU 1"; + changeProfile(format); m_view.create_menu->setChecked(xml.attribute("enabled").toInt()); if (xml.hasAttribute("background_color")) { m_view.background_list->setCurrentIndex(0); @@ -630,6 +803,8 @@ void DvdWizardMenu::loadXml(QDomElement xml) m_view.selected_color->setColor(xml.attribute("selected_color")); m_view.highlighted_color->setColor(xml.attribute("highlighted_color")); + m_view.use_shadow->setChecked(xml.attribute("text_shadow").toInt()); + QDomNodeList buttons = xml.elementsByTagName("button"); kDebug() << "// LOADING MENU 2" << buttons.count(); @@ -637,29 +812,37 @@ void DvdWizardMenu::loadXml(QDomElement xml) // Clear existing buttons QList list = m_scene->items(); - for (int i = 0; i < list.count(); i++) { - if (list.at(i)->type() == QGraphicsItem::UserType + 1) { + for (int i = 0; i < list.count(); ++i) { + if (list.at(i)->type() == DvdButtonItem) { delete list.at(i); - i--; + --i; } } } - for (int i = 0; i < buttons.count(); i++) { + for (int i = 0; i < buttons.count(); ++i) { QDomElement e = buttons.at(i).toElement(); // create menu button DvdButton *button = new DvdButton(e.attribute("text")); QFont font(e.attribute("font_family")); font.setPixelSize(e.attribute("font_size").toInt()); - font.setStyleStrategy(QFont::NoAntialias); +#if KDE_IS_VERSION(4,6,0) + if (m_view.use_shadow->isChecked()) { + QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this); + shadow->setBlurRadius(7); + shadow->setOffset(4, 4); + button->setGraphicsEffect(shadow); + } +#endif + + //font.setStyleStrategy(QFont::NoAntialias); button->setFont(font); button->setTarget(e.attribute("target").toInt(), e.attribute("command")); button->setBackMenu(e.attribute("backtomenu").toInt()); button->setDefaultTextColor(m_view.text_color->color()); button->setZValue(4); - QRectF r = button->sceneBoundingRect(); m_scene->addItem(button); - button->setPos(e.attribute("posx").toDouble(), e.attribute("posy").toDouble()); + button->setPos(e.attribute("posx").toInt(), e.attribute("posy").toInt()); } } @@ -674,3 +857,5 @@ void DvdWizardMenu::slotUnZoom() m_view.menu_preview->scale(0.5, 0.5); } + +#include "dvdwizardmenu.moc"