X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fdvdwizardmenu.cpp;h=ab7390d67c633187006996c387f404ff54c804ec;hb=98b9fcdb9c5a4e84489b37d253a7491d6a4d17ef;hp=fefa8e80e412e2993506b9c090b72b4ac18114a4;hpb=5ee798aed90c5a3a50024e6b5bd26753e03ec7cc;p=kdenlive diff --git a/src/dvdwizardmenu.cpp b/src/dvdwizardmenu.cpp index fefa8e80..ab7390d6 100644 --- a/src/dvdwizardmenu.cpp +++ b/src/dvdwizardmenu.cpp @@ -23,7 +23,9 @@ DvdWizardMenu::DvdWizardMenu(const QString &profile, QWidget *parent) : - QWizardPage(parent) + QWizardPage(parent), + m_color(NULL), + m_safeRect(NULL) { m_view.setupUi(this); m_view.play_text->setText(i18n("Play")); @@ -36,16 +38,14 @@ DvdWizardMenu::DvdWizardMenu(const QString &profile, QWidget *parent) : m_view.add_button->setIcon(KIcon("document-new")); m_view.delete_button->setIcon(KIcon("trash-empty")); - // TODO: re-enable add button options - m_view.add_button->setVisible(false); - m_view.delete_button->setVisible(false); - - m_view.menu_profile->addItems(QStringList() << i18n("PAL") << i18n("NTSC")); + 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") { - m_view.menu_profile->setCurrentIndex(1); - m_isPal = false; - } else m_isPal = true; + changeProfile(false); + } else changeProfile(true); + + // Create color background m_color = new QGraphicsRectItem(0, 0, m_width, m_height); @@ -70,10 +70,8 @@ DvdWizardMenu::DvdWizardMenu(const QString &profile, QWidget *parent) : m_safeRect->setZValue(5); m_scene->addItem(m_safeRect); - changeProfile(m_view.menu_profile->currentIndex()); checkBackgroundType(0); - connect(m_view.menu_profile, SIGNAL(activated(int)), this, SLOT(changeProfile(int))); // create menu button DvdButton *button = new DvdButton(m_view.play_text->text()); @@ -102,6 +100,7 @@ DvdWizardMenu::DvdWizardMenu(const QString &profile, QWidget *parent) : connect(m_view.background_list, SIGNAL(activated(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))); connect(m_view.add_button, SIGNAL(pressed()), this, SLOT(addButton())); connect(m_view.delete_button, SIGNAL(pressed()), this, SLOT(deleteButton())); @@ -156,7 +155,8 @@ bool DvdWizardMenu::isComplete() const 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--) { - if (!targets.contains(i)) return false; + // 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)) return false; } return true; } @@ -167,7 +167,20 @@ void DvdWizardMenu::setButtonTarget(int ix) for (int i = 0; i < list.count(); i++) { if (list.at(i)->type() == QGraphicsItem::UserType + 1) { DvdButton *button = static_cast < DvdButton* >(list.at(i)); - button->setTarget(ix); + button->setTarget(ix, m_view.target_list->itemData(ix).toString()); + break; + } + } + emit completeChanged(); +} + +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) { + DvdButton *button = static_cast < DvdButton* >(list.at(i)); + button->setBackMenu(backToMenu); break; } } @@ -184,11 +197,13 @@ void DvdWizardMenu::buttonChanged() m_view.font_size->blockSignals(true); m_view.font_family->blockSignals(true); m_view.target_list->blockSignals(true); + m_view.back_to_menu->blockSignals(true); foundButton = true; m_view.tabWidget->widget(0)->setEnabled(true); DvdButton *button = static_cast < DvdButton* >(list.at(i)); m_view.target_list->setCurrentIndex(button->target()); m_view.play_text->setText(button->toPlainText()); + m_view.back_to_menu->setChecked(button->backMenu()); QFont font = button->font(); m_view.font_size->setValue(font.pixelSize()); m_view.font_family->setCurrentFont(font); @@ -196,6 +211,7 @@ void DvdWizardMenu::buttonChanged() m_view.font_size->blockSignals(false); m_view.font_family->blockSignals(false); m_view.target_list->blockSignals(false); + m_view.back_to_menu->blockSignals(false); break; } } @@ -230,21 +246,19 @@ void DvdWizardMenu::deleteButton() } } -void DvdWizardMenu::changeProfile(int ix) +void DvdWizardMenu::changeProfile(bool isPal) { - switch (ix) { - case 1: + m_isPal = isPal; + if (isPal == false) { m_width = 720; m_height = 480; m_isPal = false; updatePreview(); - break; - default: + } else { m_width = 720; m_height = 576; m_isPal = true; updatePreview(); - break; } } @@ -256,23 +270,27 @@ void DvdWizardMenu::updatePreview() m_view.menu_preview->setMatrix(matrix); m_view.menu_preview->setMinimumSize(m_width / 2 + 4, m_height / 2 + 8); - m_color->setRect(0, 0, m_width, m_height); + if (m_color) m_color->setRect(0, 0, m_width, m_height); int safeW = m_width / 20; int safeH = m_height / 20; - m_safeRect->setRect(safeW, safeH, m_width - 2 * safeW, m_height - 2 * safeH); + if (m_safeRect) m_safeRect->setRect(safeW, safeH, m_width - 2 * safeW, m_height - 2 * safeH); } -void DvdWizardMenu::setTargets(QStringList /*list*/) +void DvdWizardMenu::setTargets(QStringList list, QStringList targetlist) { - m_targets = QStringList() << i18n("Play All"); - // TODO: re-enable different targets - /* - if (list.count() > 1) { - m_targets += list; + m_view.target_list->clear(); + m_view.target_list->addItem(i18n("Play All"), "title 1"); + int movieCount = 0; + 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 { + m_view.target_list->addItem(KIcon("video-x-generic"), list.at(i), targetlist.at(i)); + movieCount++; + } } - m_view.target_list->clear();*/ - m_view.target_list->addItems(m_targets); + m_view.back_to_menu->setHidden(movieCount == 1); } void DvdWizardMenu::checkBackgroundType(int ix) @@ -369,38 +387,50 @@ void DvdWizardMenu::createButtonImages(const QString &img1, const QString &img2, m_scene->clearSelection(); QImage img(m_width, m_height, QImage::Format_ARGB32); QPainter p(&img); + p.setRenderHints(QPainter::Antialiasing, false); + p.setRenderHints(QPainter::TextAntialiasing, false); m_scene->removeItem(m_safeRect); m_scene->removeItem(m_color); m_scene->removeItem(m_background); m_scene->render(&p, QRectF(0, 0, m_width, m_height)); p.end(); - QImage saved; + img.setNumColors(4); + 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); + saved.save(img1);*/ updateColor(m_view.selected_color->color()); 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.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 (m_view.menu_profile->currentIndex() < 2) + saved = img.scaled(720, 576); + else saved = img.scaled(720, 480); + saved.setNumColors(4); + saved.save(img2);*/ + img.setNumColors(4); + img.save(img2); updateColor(m_view.highlighted_color->color()); 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.end(); - if (m_view.menu_profile->currentIndex() < 2) + /*if (m_view.menu_profile->currentIndex() < 2) saved = img.scaled(720, 576); else saved = img.scaled(720, 480); saved.setNumColors(4); - saved.save(img3); + saved.save(img3);*/ + img.setNumColors(4); + img.save(img3); updateColor(); @@ -450,9 +480,9 @@ QString DvdWizardMenu::menuMoviePath() const } -QMap DvdWizardMenu::buttonsInfo() +QMap DvdWizardMenu::buttonsInfo() { - QMap info; + QMap info; QList list = m_scene->items(); for (int i = 0; i < list.count(); i++) { if (list.at(i)->type() == QGraphicsItem::UserType + 1) { @@ -461,7 +491,9 @@ QMap DvdWizardMenu::buttonsInfo() // 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); - info.insertMulti(button->target(), r); + QString command = button->command(); + if (button->backMenu()) command.prepend("g1 = 999;"); + info.insertMulti(command, r); } } return info; @@ -471,3 +503,104 @@ bool DvdWizardMenu::isPalMenu() const { return m_isPal; } + +QDomElement DvdWizardMenu::toXml() const +{ + QDomDocument doc; + if (!m_view.create_menu->isChecked()) return doc.documentElement(); + QDomElement xml = doc.createElement("menu"); + doc.appendChild(xml); + if (m_view.background_list->currentIndex() == 0) { + // Color bg + xml.setAttribute("background_color", m_view.background_color->color().name()); + } else if (m_view.background_list->currentIndex() == 1) { + // Image bg + xml.setAttribute("background_image", m_view.background_image->text()); + } else { + // Video bg + xml.setAttribute("background_video", m_view.background_image->text()); + } + 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()); + + QList list = m_scene->items(); + int buttonCount = 0; + + for (int i = 0; i < list.count(); i++) { + if (list.at(i)->type() == QGraphicsItem::UserType + 1) { + 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("text", button->toPlainText()); + QFont font = button->font(); + xmlbutton.setAttribute("font_size", font.pixelSize()); + xmlbutton.setAttribute("font_family", font.family()); + xml.appendChild(xmlbutton); + } + } + return doc.documentElement(); +} + + +void DvdWizardMenu::loadXml(QDomElement xml) +{ + kDebug() << "// LOADING MENU"; + if (xml.isNull()) return; + kDebug() << "// LOADING MENU 1"; + m_view.create_menu->setChecked(true) ; + if (xml.hasAttribute("background_color")) { + m_view.background_list->setCurrentIndex(0); + m_view.background_color->setColor(xml.attribute("background_color")); + } else if (xml.hasAttribute("background_image")) { + m_view.background_list->setCurrentIndex(1); + m_view.background_image->setPath(xml.attribute("background_image")); + } else if (xml.hasAttribute("background_video")) { + m_view.background_list->setCurrentIndex(2); + m_view.background_image->setPath(xml.attribute("background_video")); + } + + m_view.text_color->setColor(xml.attribute("text_color")); + m_view.selected_color->setColor(xml.attribute("selected_color")); + m_view.highlighted_color->setColor(xml.attribute("highlighted_color")); + + QDomNodeList buttons = xml.elementsByTagName("button"); + kDebug() << "// LOADING MENU 2" << buttons.count(); + + if (buttons.count() > 0) { + // Clear existing buttons + QList list = m_scene->items(); + + for (int i = 0; i < list.count(); i++) { + if (list.at(i)->type() == QGraphicsItem::UserType + 1) { + delete list.at(i); + 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); + 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); + button->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); + QRectF r = button->sceneBoundingRect(); + m_scene->addItem(button); + button->setPos(e.attribute("posx").toDouble(), e.attribute("posy").toDouble()); + + } +} +