From 14bf85958b5658a81bf2d3c934445fe7db3c863d Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mardelle Date: Wed, 21 Jan 2009 10:12:21 +0000 Subject: [PATCH] Some work on the dvd wizard svn path=/branches/KDE4/; revision=2935 --- src/CMakeLists.txt | 1 + src/dvdwizard.cpp | 336 ++++----- src/dvdwizard.h | 20 +- src/dvdwizardmenu.cpp | 438 ++++++++++++ src/dvdwizardmenu.h | 147 ++++ src/dvdwizardvob.cpp | 6 + src/dvdwizardvob.h | 1 + src/widgets/dvdwizardmenu_ui.ui | 1127 ++++--------------------------- 8 files changed, 872 insertions(+), 1204 deletions(-) create mode 100644 src/dvdwizardmenu.cpp create mode 100644 src/dvdwizardmenu.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b798b74d..ec57db78 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -147,6 +147,7 @@ set(kdenlive_SRCS changetrackcommand.cpp movegroupcommand.cpp dvdwizardvob.cpp + dvdwizardmenu.cpp dvdwizard.cpp ) diff --git a/src/dvdwizard.cpp b/src/dvdwizard.cpp index 1cdff176..5f603b6d 100644 --- a/src/dvdwizard.cpp +++ b/src/dvdwizard.cpp @@ -45,68 +45,9 @@ DvdWizard::DvdWizard(const QString &url, const QString &profile, QWidget *parent if (!url.isEmpty()) m_pageVob->setUrl(url); - m_width = 720; - if (m_profile.startsWith("dv_pal")) m_height = 576; - else m_height = 480; - - QWizardPage *page2 = new QWizardPage; - page2->setTitle(i18n("Create Dvd Menu")); - m_menu.setupUi(page2); - m_menu.play_text->setText(i18n("Play")); - m_scene = new QGraphicsScene(0, 0, m_width, m_height, this); - m_menu.menu_preview->setScene(m_scene); - - // Create color background - m_color = new QGraphicsRectItem(0, 0, m_width, m_height); - m_color->setBrush(m_menu.background_color->color()); - m_scene->addItem(m_color); - - // create background image - m_background = new QGraphicsPixmapItem(); - //m_scene->addItem(m_background); - - // create menu button - m_button = new QGraphicsTextItem(m_menu.play_text->text()); - QFont font = m_menu.font_family->currentFont(); - font.setPixelSize(m_menu.font_size->value()); - font.setStyleStrategy(QFont::NoAntialias); - m_button->setFont(font); - m_button->setDefaultTextColor(m_menu.text_color->color()); - m_button->setZValue(2); - m_button->setFlags(QGraphicsItem::ItemIsMovable); - QRectF r = m_button->sceneBoundingRect(); - m_button->setPos((m_width - r.width()) / 2, (m_height - r.height()) / 2); - m_scene->addItem(m_button); - - // create safe zone rect - int safeW = m_width / 20; - int safeH = m_height / 20; - m_safeRect = new QGraphicsRectItem(safeW, safeH, m_width - 2 * safeW, m_height - 2 * safeH); - QPen pen(Qt::red); - pen.setStyle(Qt::DashLine); - pen.setWidth(3); - m_safeRect->setPen(pen); - m_safeRect->setZValue(3); - m_scene->addItem(m_safeRect); - - addPage(page2); - //m_menu.menu_preview->resize(m_width / 2, m_height / 2); - m_menu.menu_preview->setSceneRect(0, 0, m_width, m_height); - QMatrix matrix; - matrix.scale(0.5, 0.5); - m_menu.menu_preview->setMatrix(matrix); - m_menu.menu_preview->setMinimumSize(m_width / 2 + 4, m_height / 2 + 8); - //m_menu.menu_preview->resizefitInView(0, 0, m_width, m_height); - - connect(m_menu.is_color, SIGNAL(toggled(bool)), this, SLOT(checkBackground())); - connect(m_menu.play_text, SIGNAL(textChanged(const QString &)), this, SLOT(buildButton())); - connect(m_menu.text_color, SIGNAL(changed(const QColor &)), this, SLOT(buildButton())); - connect(m_menu.font_size, SIGNAL(valueChanged(int)), this, SLOT(buildButton())); - connect(m_menu.font_family, SIGNAL(currentFontChanged(const QFont &)), this, SLOT(buildButton())); - connect(m_menu.background_image, SIGNAL(textChanged(const QString &)), this, SLOT(buildImage())); - connect(m_menu.background_color, SIGNAL(changed(const QColor &)), this, SLOT(buildColor())); - connect(m_menu.create_menu, SIGNAL(toggled(bool)), m_menu.menu_box, SLOT(setEnabled(bool))); - m_menu.menu_box->setEnabled(false); + m_pageMenu = new DvdWizardMenu(m_profile, this); + m_pageMenu->setTitle(i18n("Create Dvd Menu")); + addPage(m_pageMenu); QWizardPage *page3 = new QWizardPage; @@ -129,63 +70,22 @@ DvdWizard::DvdWizard(const QString &url, const QString &profile, QWidget *parent } DvdWizard::~DvdWizard() { - delete m_button; - delete m_color; - delete m_safeRect; - delete m_background; - delete m_scene; - m_menuFile.remove(); + // m_menuFile.remove(); } void DvdWizard::slotPageChanged(int page) { kDebug() << "// PAGE CHGD: " << page; if (page == 1) { - //if (m_vob.vob_1->text().isEmpty()) back(); - } - if (page == 3) { + m_pageMenu->setTargets(m_pageVob->selectedUrls()); + } else if (page == 2) { + m_pageMenu->buttonsInfo(); + } else if (page == 3) { KIO::NetAccess::del(KUrl(m_iso.tmp_folder->url().path() + "/DVD"), this); QTimer::singleShot(300, this, SLOT(generateDvd())); } } -void DvdWizard::buildColor() { - m_color->setBrush(m_menu.background_color->color()); -} - -void DvdWizard::buildImage() { - if (m_menu.background_image->url().isEmpty()) { - m_scene->removeItem(m_background); - return; - } - QPixmap pix; - if (!pix.load(m_menu.background_image->url().path())) { - m_scene->removeItem(m_background); - return; - } - pix = pix.scaled(m_width, m_height); - m_background->setPixmap(pix); - if (!m_menu.is_color->isChecked()) m_scene->addItem(m_background); -} - -void DvdWizard::checkBackground() { - if (m_menu.is_color->isChecked()) { - m_scene->addItem(m_color); - m_scene->removeItem(m_background); - } else { - m_scene->addItem(m_background); - m_scene->removeItem(m_color); - } -} - -void DvdWizard::buildButton() { - m_button->setPlainText(m_menu.play_text->text()); - QFont font = m_menu.font_family->currentFont(); - font.setPixelSize(m_menu.font_size->value()); - font.setStyleStrategy(QFont::NoAntialias); - m_button->setFont(font); - m_button->setDefaultTextColor(m_menu.text_color->color()); -} void DvdWizard::generateDvd() { @@ -230,86 +130,53 @@ void DvdWizard::generateDvd() { QListWidgetItem *images = m_status.job_progress->item(0); images->setIcon(KIcon("system-run")); qApp->processEvents(); + QMap buttons = m_pageMenu->buttonsInfo(); + QStringList buttonsTarget; - if (m_menu.create_menu->isChecked()) { - - QImage img(m_width, m_height, QImage::Format_ARGB32); - QPainter p(&img); - 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(); - img.setNumColors(4); - img.save(temp1.fileName()); - - m_button->setDefaultTextColor(m_menu.selected_color->color()); - p.begin(&img); - m_scene->render(&p, QRectF(0, 0, m_width, m_height)); - p.end(); - img.setNumColors(4); - img.save(temp2.fileName()); - - m_button->setDefaultTextColor(m_menu.highlighted_color->color()); - p.begin(&img); - m_scene->render(&p, QRectF(0, 0, m_width, m_height)); - p.end(); - img.setNumColors(4); - img.save(temp3.fileName()); - - m_scene->removeItem(m_button); - if (m_menu.is_color->isChecked()) m_scene->addItem(m_color); - else m_scene->addItem(m_background); - - - p.begin(&img); - m_scene->render(&p, QRectF(0, 0, m_width, m_height)); - p.end(); - img.save(temp4.fileName()); + if (m_pageMenu->createMenu()) { + m_pageMenu->createButtonImages(temp1.fileName(), temp2.fileName(), temp3.fileName()); + m_pageMenu->createBackgroundImage(temp4.fileName()); images->setIcon(KIcon("dialog-ok")); kDebug() << "/// STARTING MLT VOB CREATION"; + if (!m_pageMenu->menuMovie()) { + // create menu vob file + QListWidgetItem *vobitem = m_status.job_progress->item(1); + vobitem->setIcon(KIcon("system-run")); + qApp->processEvents(); + + QStringList args; + args.append("-profile"); + if (m_pageMenu->isPalMenu()) args.append("dv_pal"); + else args.append("dv_ntsc"); + args.append(temp4.fileName()); + args.append("in=0"); + args.append("out=100"); + args << "-consumer" << "avformat:" + temp5.fileName(); + if (m_pageMenu->isPalMenu()) { + args << "f=dvd" << "vcodec=mpeg2video" << "acodec=ac3" << "b=5000k" << "maxrate=8000k" << "minrate=0" << "bufsize=1835008" << "mux_packet_s=2048" << "mux_rate=10080000" << "ab=192k" << "ar=48000" << "s=720x576" << "g=15" << "me_range=63" << "trellis=1" << "profile=dv_pal"; + } else { + args << "f=dvd" << "vcodec=mpeg2video" << "acodec=ac3" << "b=6000k" << "maxrate=9000k" << "minrate=0" << "bufsize=1835008" << "mux_packet_s=2048" << "mux_rate=10080000" << "ab=192k" << "ar=48000" << "s=720x480" << "g=18" << "me_range=63" << "trellis=1" << "profile=dv_ntsc"; + } - // create menu vob file - QListWidgetItem *vobitem = m_status.job_progress->item(1); - vobitem->setIcon(KIcon("system-run")); - qApp->processEvents(); - - QStringList args; - args.append("-profile"); - args.append(m_profile); - args.append(temp4.fileName()); - args.append("in=0"); - args.append("out=100"); - args << "-consumer" << "avformat:" + temp5.fileName(); - if (m_profile == "dv_pal") { - args << "f=dvd" << "vcodec=mpeg2video" << "acodec=ac3" << "b=5000k" << "maxrate=8000k" << "minrate=0" << "bufsize=1835008" << "mux_packet_s=2048" << "mux_rate=10080000" << "ab=192k" << "ar=48000" << "s=720x576" << "g=15" << "me_range=63" << "trellis=1" << "profile=dv_pal"; - } else if (m_profile == "dv_ntsc") { - args << "f=dvd" << "vcodec=mpeg2video" << "acodec=ac3" << "b=6000k" << "maxrate=9000k" << "minrate=0" << "bufsize=1835008" << "mux_packet_s=2048" << "mux_rate=10080000" << "ab=192k" << "ar=48000" << "s=720x480" << "g=18" << "me_range=63" << "trellis=1" << "profile=dv_ntsc"; - } else if (m_profile == "dv_pal_wide") { - args << "f=dvd" << "vcodec=mpeg2video" << "acodec=ac3" << "b=5000k" << "maxrate=8000k" << "minrate=0" << "bufsize=1835008" << "mux_packet_s=2048" << "mux_rate=10080000" << "ab=192k" << "ar=48000" << "s=720x576" << "g=15" << "me_range=63" << "trellis=1" << "profile=dv_pal_wide"; - } else if (m_profile == "dv_ntsc_wide") { - args << "f=dvd" << "vcodec=mpeg2video" << "acodec=ac3" << "b=6000k" << "maxrate=9000k" << "minrate=0" << "bufsize=1835008" << "mux_packet_s=2048" << "mux_rate=10080000" << "ab=192k" << "ar=48000" << "s=720x480" << "g=18" << "me_range=63" << "trellis=1" << "profile=dv_ntsc_wide"; - } - - kDebug() << "MLT ARGS: " << args; - QProcess renderbg; - renderbg.start("inigo", args); - if (renderbg.waitForFinished()) { - if (renderbg.exitStatus() == QProcess::CrashExit) { - kDebug() << "/// RENDERING MENU vob crashed"; + kDebug() << "MLT ARGS: " << args; + QProcess renderbg; + renderbg.start("inigo", args); + if (renderbg.waitForFinished()) { + if (renderbg.exitStatus() == QProcess::CrashExit) { + kDebug() << "/// RENDERING MENU vob crashed"; + vobitem->setIcon(KIcon("dialog-close")); + return; + } + } else { + kDebug() << "/// RENDERING MENU vob timed out"; vobitem->setIcon(KIcon("dialog-close")); return; } - } else { - kDebug() << "/// RENDERING MENU vob timed out"; - vobitem->setIcon(KIcon("dialog-close")); - return; + vobitem->setIcon(KIcon("dialog-ok")); } - - vobitem->setIcon(KIcon("dialog-ok")); kDebug() << "/// STARTING SPUMUX"; // create xml spumux file @@ -328,9 +195,36 @@ void DvdWizard::generateDvd() { spu.setAttribute("image", temp1.fileName()); spu.setAttribute("select", temp2.fileName()); spu.setAttribute("highlight", temp3.fileName()); - spu.setAttribute("autooutline", "infer"); + /*spu.setAttribute("autooutline", "infer"); spu.setAttribute("outlinewidth", "12"); - spu.setAttribute("autoorder", "rows"); + spu.setAttribute("autoorder", "rows");*/ + + int max = buttons.count() - 1; + int i = 0; + QMapIterator it(buttons); + while (it.hasNext()) { + it.next(); + QDomElement but = doc.createElement("button"); + but.setAttribute("name", "b" + QString::number(i)); + if (i < max) but.setAttribute("down", "b" + QString::number(i + 1)); + else but.setAttribute("down", "b0"); + if (i > 0) but.setAttribute("up", "b" + QString::number(i - 1)); + else but.setAttribute("up", "b" + QString::number(max)); + QRect r = it.value(); + int target = it.key(); + // TODO: solve play all button + if (target == 0) target = 1; + buttonsTarget.append(QString::number(target)); + but.setAttribute("x0", QString::number(r.x())); + but.setAttribute("y0", QString::number(r.y())); + but.setAttribute("x1", QString::number(r.right())); + but.setAttribute("y1", QString::number(r.bottom())); + spu.appendChild(but); + i++; + } + + kDebug() << "///// SPU: "; + kDebug() << doc.toString(); QFile data(temp6.fileName()); if (data.open(QFile::WriteOnly)) { @@ -341,12 +235,14 @@ void DvdWizard::generateDvd() { kDebug() << " SPUMUX DATA: " << doc.toString(); - args.clear(); + QStringList args; args.append(temp6.fileName()); - kDebug() << "SPM ARGS: " << args; + kDebug() << "SPM ARGS: " << args << temp5.fileName() << m_menuFile.fileName(); QProcess spumux; - spumux.setStandardInputFile(temp5.fileName()); + + if (m_pageMenu->menuMovie()) spumux.setStandardInputFile(m_pageMenu->menuMoviePath()); + else spumux.setStandardInputFile(temp5.fileName()); spumux.setStandardOutputFile(m_menuFile.fileName()); spumux.start("spumux", args); spumux.setProcessChannelMode(QProcess::MergedChannels); @@ -379,34 +275,61 @@ void DvdWizard::generateDvd() { dvddoc.appendChild(auth); QDomElement vmgm = dvddoc.createElement("vmgm"); auth.appendChild(vmgm); - if (m_menu.create_menu->isChecked()) { + + if (m_pageMenu->createMenu() && !m_pageVob->introMovie().isEmpty()) { + // intro movie QDomElement menus = dvddoc.createElement("menus"); vmgm.appendChild(menus); QDomElement pgc = dvddoc.createElement("pgc"); + pgc.setAttribute("entry", "title"); menus.appendChild(pgc); - QDomElement button = dvddoc.createElement("button"); - QDomText nametext = dvddoc.createTextNode("jump title 1;"); - button.appendChild(nametext); - pgc.appendChild(button); QDomElement menuvob = dvddoc.createElement("vob"); - menuvob.setAttribute("file", m_menuFile.fileName()); - menuvob.setAttribute("pause", "inf"); + menuvob.setAttribute("file", m_pageVob->introMovie()); pgc.appendChild(menuvob); + QDomElement post = dvddoc.createElement("post"); + QDomText call = dvddoc.createTextNode("jump titleset 1 menu;"); + post.appendChild(call); + pgc.appendChild(post); } QDomElement titleset = dvddoc.createElement("titleset"); auth.appendChild(titleset); + + if (m_pageMenu->createMenu()) { + + // DVD main menu + QDomElement menus = dvddoc.createElement("menus"); + titleset.appendChild(menus); + QDomElement pgc = dvddoc.createElement("pgc"); + pgc.setAttribute("entry", "root"); + menus.appendChild(pgc); + for (int i = 0; i < buttons.count(); i++) { + QDomElement button = dvddoc.createElement("button"); + button.setAttribute("name", "b" + QString::number(i)); + QDomText nametext = dvddoc.createTextNode("jump title " + buttonsTarget.at(i) + ";"); + button.appendChild(nametext); + pgc.appendChild(button); + } + QDomElement menuvob = dvddoc.createElement("vob"); + menuvob.setAttribute("file", m_menuFile.fileName()); + menuvob.setAttribute("pause", "inf"); + pgc.appendChild(menuvob); + } + QDomElement titles = dvddoc.createElement("titles"); titleset.appendChild(titles); + + QStringList voburls = m_pageVob->selectedUrls(); + QDomElement pgc2 = dvddoc.createElement("pgc"); titles.appendChild(pgc2); - if (m_menu.create_menu->isChecked()) { + if (m_pageMenu->createMenu()) { QDomElement post = dvddoc.createElement("post"); - QDomText call = dvddoc.createTextNode("call vmgm menu 1;"); + QDomText call = dvddoc.createTextNode("call menu;"); post.appendChild(call); pgc2.appendChild(post); } - QStringList voburls = m_pageVob->selectedUrls(); + for (int i = 0; i < voburls.count(); i++) { if (!voburls.at(i).isEmpty()) { // Add vob entry @@ -416,6 +339,27 @@ void DvdWizard::generateDvd() { } } + /* + // create one pgc for each video + for (int i = 0; i < voburls.count(); i++) { + if (!voburls.at(i).isEmpty()) { + // Add vob entry + + QDomElement pgc2 = dvddoc.createElement("pgc"); + titles.appendChild(pgc2); + if (m_pageMenu->createMenu()) { + QDomElement post = dvddoc.createElement("post"); + QDomText call = dvddoc.createTextNode("call vmgm menu 1;"); + post.appendChild(call); + pgc2.appendChild(post); + } + + QDomElement vob = dvddoc.createElement("vob"); + vob.setAttribute("file", voburls.at(i)); + pgc2.appendChild(vob); + } + } + */ QFile data2(m_authorFile.fileName()); if (data2.open(QFile::WriteOnly)) { QTextStream out(&data2); @@ -457,8 +401,8 @@ void DvdWizard::slotRenderFinished(int exitCode, QProcess::ExitStatus status) { void DvdWizard::slotIsoFinished(int exitCode, QProcess::ExitStatus status) { QListWidgetItem *isoitem = m_status.job_progress->item(4); if (status == QProcess::CrashExit) { - m_authorFile.remove(); - m_menuFile.remove(); + //m_authorFile.remove(); + //m_menuFile.remove(); KIO::NetAccess::del(KUrl(m_iso.tmp_folder->url().path() + "/DVD"), this); kDebug() << "Iso process crashed"; isoitem->setIcon(KIcon("dialog-close")); @@ -466,8 +410,8 @@ void DvdWizard::slotIsoFinished(int exitCode, QProcess::ExitStatus status) { } isoitem->setIcon(KIcon("dialog-ok")); kDebug() << "ISO IMAGE " << m_iso.iso_image->url().path() << " Successfully created"; - m_authorFile.remove(); - m_menuFile.remove(); + //m_authorFile.remove(); + //m_menuFile.remove(); KIO::NetAccess::del(KUrl(m_iso.tmp_folder->url().path() + "/DVD"), this); KMessageBox::information(this, i18n("Dvd iso image %1 successfully created.", m_iso.iso_image->url().path())); diff --git a/src/dvdwizard.h b/src/dvdwizard.h index 931c6752..74070e91 100644 --- a/src/dvdwizard.h +++ b/src/dvdwizard.h @@ -25,10 +25,6 @@ #include #include #include -#include -#include -#include -#include #include @@ -36,7 +32,7 @@ #include #include "dvdwizardvob.h" -#include "ui_dvdwizardmenu_ui.h" +#include "dvdwizardmenu.h" #include "ui_dvdwizardiso_ui.h" #include "ui_dvdwizardstatus_ui.h" @@ -48,26 +44,14 @@ public: private: DvdWizardVob *m_pageVob; - Ui::DvdWizardMenu_UI m_menu; + DvdWizardMenu *m_pageMenu; Ui::DvdWizardIso_UI m_iso; Ui::DvdWizardStatus_UI m_status; - QString m_profile; - QGraphicsScene *m_scene; - QGraphicsTextItem *m_button; - QGraphicsPixmapItem *m_background; - QGraphicsRectItem *m_color; - QGraphicsRectItem *m_safeRect; - int m_width; - int m_height; KTemporaryFile m_menuFile; KTemporaryFile m_authorFile; private slots: - void buildButton(); - void buildColor(); - void buildImage(); - void checkBackground(); void slotPageChanged(int page); void slotRenderFinished(int exitCode, QProcess::ExitStatus status); void slotIsoFinished(int exitCode, QProcess::ExitStatus status); diff --git a/src/dvdwizardmenu.cpp b/src/dvdwizardmenu.cpp new file mode 100644 index 00000000..915aa7d1 --- /dev/null +++ b/src/dvdwizardmenu.cpp @@ -0,0 +1,438 @@ +/*************************************************************************** + * Copyright (C) 2009 by Jean-Baptiste Mardelle (jb@kdenlive.org) * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + + +#include + +#include "dvdwizardmenu.h" + +DvdWizardMenu::DvdWizardMenu(const QString &profile, QWidget *parent): QWizardPage(parent) { + m_view.setupUi(this); + m_view.play_text->setText(i18n("Play")); + m_scene = new DvdScene(this); + m_view.menu_preview->setScene(m_scene); + + connect(m_view.create_menu, SIGNAL(toggled(bool)), m_view.menu_box, SLOT(setEnabled(bool))); + connect(m_view.create_menu, SIGNAL(toggled(bool)), this, SIGNAL(completeChanged())); + + 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")); + + if (profile == "dv_ntsc" || profile == "dv_ntsc_wide") { + m_view.menu_profile->setCurrentIndex(1); + m_isPal = false; + } else m_isPal = true; + + // Create color background + m_color = new QGraphicsRectItem(0, 0, m_width, m_height); + m_color->setBrush(m_view.background_color->color()); + m_color->setZValue(2); + m_scene->addItem(m_color); + + + // create background image + m_background = new QGraphicsPixmapItem(); + m_background->setZValue(3); + //m_scene->addItem(m_background); + + // create safe zone rect + int safeW = m_width / 20; + int safeH = m_height / 20; + m_safeRect = new QGraphicsRectItem(safeW, safeH, m_width - 2 * safeW, m_height - 2 * safeH); + QPen pen(Qt::red); + pen.setStyle(Qt::DashLine); + pen.setWidth(3); + m_safeRect->setPen(pen); + 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()); + QFont font = m_view.font_family->currentFont(); + font.setPixelSize(m_view.font_size->value()); + font.setStyleStrategy(QFont::NoAntialias); + button->setFont(font); + 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((m_width - r.width()) / 2, (m_height - r.height()) / 2); + button->setSelected(true); + + + //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.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.background_list, SIGNAL(activated(int)), this, SLOT(checkBackgroundType(int))); + + connect(m_view.target_list, SIGNAL(activated(int)), this, SLOT(setButtonTarget(int))); + + connect(m_view.add_button, SIGNAL(pressed()), this, SLOT(addButton())); + connect(m_view.delete_button, SIGNAL(pressed()), this, SLOT(deleteButton())); + connect(m_scene, SIGNAL(selectionChanged()), this, SLOT(buttonChanged())); + connect(m_scene, SIGNAL(changed(const QList &)), this, SIGNAL(completeChanged())); + + m_view.menu_box->setEnabled(false); + +} + +DvdWizardMenu::~DvdWizardMenu() { + delete m_color; + delete m_safeRect; + delete m_background; + delete m_scene; +} + +// virtual + +bool DvdWizardMenu::isComplete() const { + if (!m_view.create_menu->isChecked()) return true; + QList targets; + 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) { + buttonCount++; + DvdButton *button = static_cast < DvdButton* >(list.at(i)); + QList collisions = button->collidingItems(); + if (!collisions.isEmpty()) { + for (int j = 0; j < collisions.count(); j++) { + if (list.at(j)->type() == button->type()) return false; + } + } + targets.append(button->target()); + } + } + if (buttonCount == 0) return false; + // 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--) { + if (!targets.contains(i)) return false; + } + return true; +} + +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) { + DvdButton *button = static_cast < DvdButton* >(list.at(i)); + button->setTarget(ix); + break; + } + } + emit completeChanged(); +} + +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) { + m_view.play_text->blockSignals(true); + m_view.font_size->blockSignals(true); + m_view.font_family->blockSignals(true); + m_view.target_list->blockSignals(true); + foundButton = true; + m_view.button_box->setEnabled(true); + DvdButton *button = static_cast < DvdButton* >(list.at(i)); + m_view.target_list->setCurrentIndex(button->target()); + m_view.play_text->setText(button->toPlainText()); + QFont font = button->font(); + m_view.font_size->setValue(font.pixelSize()); + m_view.font_family->setCurrentFont(font); + m_view.play_text->blockSignals(false); + m_view.font_size->blockSignals(false); + m_view.font_family->blockSignals(false); + m_view.target_list->blockSignals(false); + break; + } + } + if (!foundButton) m_view.button_box->setEnabled(false); +} + +void DvdWizardMenu::addButton() { + m_scene->clearSelection(); + 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); + button->setFont(font); + 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((m_width - r.width()) / 2, (m_height - r.height()) / 2); + button->setSelected(true); +} + +void DvdWizardMenu::deleteButton() { + QList list = m_scene->selectedItems(); + for (int i = 0; i < list.count(); i++) { + if (list.at(i)->type() == QGraphicsItem::UserType + 1) { + delete list.at(i); + break; + } + } +} + +void DvdWizardMenu::changeProfile(int ix) { + switch (ix) { + case 1: + m_width = 720; + m_height = 480; + m_isPal = false; + updatePreview(); + break; + default: + m_width = 720; + m_height = 576; + m_isPal = true; + updatePreview(); + break; + } +} + +void DvdWizardMenu::updatePreview() { + m_scene->setProfile(m_width, m_height); + QMatrix matrix; + matrix.scale(0.5, 0.5); + 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); + + int safeW = m_width / 20; + int safeH = m_height / 20; + m_safeRect->setRect(safeW, safeH, m_width - 2 * safeW, m_height - 2 * safeH); +} + +void DvdWizardMenu::setTargets(QStringList list) { + 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->addItems(m_targets); +} + +void DvdWizardMenu::checkBackgroundType(int ix) { + if (ix == 0) { + m_view.background_color->setVisible(true); + m_view.background_image->setVisible(false); + m_scene->removeItem(m_background); + } else { + m_view.background_color->setVisible(false); + m_view.background_image->setVisible(true); + if (ix == 1) { + m_view.background_image->setFilter("*"); + m_scene->addItem(m_background); + } else { + m_scene->removeItem(m_background); + m_view.background_image->setFilter("video/mpeg"); + } + } +} + +void DvdWizardMenu::buildColor() { + m_color->setBrush(m_view.background_color->color()); +} + +void DvdWizardMenu::buildImage() { + if (m_view.background_image->url().isEmpty()) { + m_scene->removeItem(m_background); + return; + } + QPixmap pix; + if (!pix.load(m_view.background_image->url().path())) { + m_scene->removeItem(m_background); + return; + } + pix = pix.scaled(m_width, m_height); + m_background->setPixmap(pix); + if (m_view.background_list->currentIndex() == 1) m_scene->addItem(m_background); +} + +void DvdWizardMenu::checkBackground() { + if (m_view.background_list->currentIndex() != 1) { + m_scene->removeItem(m_background); + } else { + m_scene->addItem(m_background); + } +} + +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) { + button = static_cast < DvdButton* >(list.at(i)); + break; + } + } + if (button == NULL) return; + 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); + button->setFont(font); + button->setDefaultTextColor(m_view.text_color->color()); +} + +void DvdWizardMenu::updateColor() { + updateColor(m_view.text_color->color()); + m_view.menu_preview->viewport()->update(); +} + +void DvdWizardMenu::updateColor(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) { + button = static_cast < DvdButton* >(list.at(i)); + button->setDefaultTextColor(c); + } + } +} + + +void DvdWizardMenu::createButtonImages(const QString &img1, const QString &img2, const QString &img3) { + if (m_view.create_menu->isChecked()) { + m_scene->clearSelection(); + QImage img(m_width, m_height, QImage::Format_ARGB32); + QPainter p(&img); + 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(); + img.setNumColors(4); + QImage saved; + if (m_view.menu_profile->currentIndex() < 2) + saved = img.scaled(720, 576); + else saved = img.scaled(720, 480); + saved.save(img1); + + updateColor(m_view.selected_color->color()); + p.begin(&img); + m_scene->render(&p, QRectF(0, 0, m_width, m_height)); + p.end(); + img.setNumColors(4); + if (m_view.menu_profile->currentIndex() < 2) + saved = img.scaled(720, 576); + else saved = img.scaled(720, 480); + saved.save(img2); + + + updateColor(m_view.highlighted_color->color()); + p.begin(&img); + m_scene->render(&p, QRectF(0, 0, m_width, m_height)); + p.end(); + img.setNumColors(4); + if (m_view.menu_profile->currentIndex() < 2) + saved = img.scaled(720, 576); + else saved = img.scaled(720, 480); + saved.save(img3); + + updateColor(); + + m_scene->addItem(m_safeRect); + m_scene->addItem(m_color); + if (m_view.background_list->currentIndex() == 1) m_scene->addItem(m_background); + } +} + + +void DvdWizardMenu::createBackgroundImage(const QString &img1) { + 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; + img.save(img1); +} + +bool DvdWizardMenu::createMenu() const { + return m_view.create_menu->isChecked(); +} + +bool DvdWizardMenu::menuMovie() const { + return m_view.background_list->currentIndex() == 2; +} + +QString DvdWizardMenu::menuMoviePath() const { + return m_view.background_image->url().path(); +} + + +QMap DvdWizardMenu::buttonsInfo() { + QMap info; + QList list = m_scene->items(); + for (int i = 0; i < list.count(); i++) { + if (list.at(i)->type() == QGraphicsItem::UserType + 1) { + DvdButton *button = static_cast < DvdButton* >(list.at(i)); + QRect r = list.at(i)->sceneBoundingRect().toRect(); + // 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); + } + } + return info; +} + +bool DvdWizardMenu::isPalMenu() const { + return m_isPal; +} diff --git a/src/dvdwizardmenu.h b/src/dvdwizardmenu.h new file mode 100644 index 00000000..b1841dbe --- /dev/null +++ b/src/dvdwizardmenu.h @@ -0,0 +1,147 @@ +/*************************************************************************** + * Copyright (C) 2009 by Jean-Baptiste Mardelle (jb@kdenlive.org) * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + + +#ifndef DVDWIZARDMENU_H +#define DVDWIZARDMENU_H + +#include +#include +#include +#include +#include + +#include + +#include "ui_dvdwizardmenu_ui.h" + +class DvdScene : public QGraphicsScene { + +public: + DvdScene(QObject * parent = 0): QGraphicsScene(parent) {} + void setProfile(int width, int height) { + m_width = width; + m_height = height; + setSceneRect(0, 0, m_width, m_height); + } + int sceneWidth() const { + return m_width; + } + int sceneHeight() const { + return m_height; + } +private: + int m_width; + int m_height; +}; + +class DvdButton : public QGraphicsTextItem { + +public: + DvdButton(const QString & text): QGraphicsTextItem(text), m_target(0) {} + enum { Type = UserType + 1 }; + void setTarget(int t) { + m_target = t; + } + int target() const { + return m_target; + } + int type() const { + // Enable the use of qgraphicsitem_cast with this item. + return Type; + } + +private: + int m_target; + + +protected: + + virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value) { + if (change == ItemPositionChange && scene()) { + + /* QList list = collidingItems(); + if (!list.isEmpty()) { + for (int i = 0; i < list.count(); i++) { + if (list.at(i)->type() == Type) return pos(); + } + } + */ + DvdScene *sc = static_cast < DvdScene * >(scene()); + QRectF rect = QRectF(0, 0, sc->width(), sc->height()); + QPointF newPos = value.toPointF(); + if (!rect.contains(newPos)) { + // Keep the item inside the scene rect. + newPos.setX(qMin(rect.right(), qMax(newPos.x(), rect.left()))); + newPos.setY(qMin(rect.bottom(), qMax(newPos.y(), rect.top()))); + return newPos; + } + } + return QGraphicsItem::itemChange(change, value); + } + +}; + + +class DvdWizardMenu : public QWizardPage { + Q_OBJECT + +public: + DvdWizardMenu(const QString &profile, QWidget * parent = 0); + virtual ~DvdWizardMenu(); + virtual bool isComplete() const; + bool createMenu() const; + void createBackgroundImage(const QString &img1); + void createButtonImages(const QString &img1, const QString &img2, const QString &img3); + void setTargets(QStringList list); + QMap buttonsInfo(); + bool menuMovie() const; + QString menuMoviePath() const; + bool isPalMenu() const; + +private: + Ui::DvdWizardMenu_UI m_view; + bool m_isPal; + DvdScene *m_scene; + DvdButton *m_button; + QGraphicsPixmapItem *m_background; + QGraphicsRectItem *m_color; + QGraphicsRectItem *m_safeRect; + int m_width; + int m_height; + QStringList m_targets; + +private slots: + void buildButton(); + void buildColor(); + void buildImage(); + void checkBackground(); + void checkBackgroundType(int ix); + void changeProfile(int ix); + void updatePreview(); + void buttonChanged(); + void addButton(); + void setButtonTarget(int ix); + void deleteButton(); + void updateColor(); + void updateColor(QColor c); +}; + +#endif + diff --git a/src/dvdwizardvob.cpp b/src/dvdwizardvob.cpp index 2e8797ad..d127c804 100644 --- a/src/dvdwizardvob.cpp +++ b/src/dvdwizardvob.cpp @@ -57,6 +57,12 @@ QStringList DvdWizardVob::selectedUrls() const { result.append(allUrls.at(i)->url().path()); } } + return result; +} + +QString DvdWizardVob::introMovie() const { + if (!m_view.use_intro->isChecked()) return QString(); + return m_view.intro_vob->url().path(); } void DvdWizardVob::slotCheckVobList(const QString &text) { diff --git a/src/dvdwizardvob.h b/src/dvdwizardvob.h index f8b560c5..a8f68ea7 100644 --- a/src/dvdwizardvob.h +++ b/src/dvdwizardvob.h @@ -34,6 +34,7 @@ public: virtual bool isComplete() const; QStringList selectedUrls() const; void setUrl(const QString &url); + QString introMovie() const; private: Ui::DvdWizardVob_UI m_view; diff --git a/src/widgets/dvdwizardmenu_ui.ui b/src/widgets/dvdwizardmenu_ui.ui index 1559fed1..210a31c4 100644 --- a/src/widgets/dvdwizardmenu_ui.ui +++ b/src/widgets/dvdwizardmenu_ui.ui @@ -5,14 +5,14 @@ 0 0 - 377 - 365 + 421 + 454 Form - + @@ -20,976 +20,151 @@ - + - - - - - Play button - - - - - - - Text - - - - - - - - - - Font - - - - - - - 10 - - - 900 - - - 35 - - - - - - - - Sans Serif - - - - - Serif - - - - - Monospace - - - - - aakar - - - - - Aksharyogini - - - - - AlArabiya - - - - - AlBattar - - - - - AlHor - - - - - AlManzomah - - - - - AlMateen - - - - - AlMohanad - - - - - AlMothnna - - - - - AlYarmook - - - - - Andale Mono - - - - - Ani - - - - - AnjaliOldLipi - - - - - Arab - - - - - Arev Sans - - - - - Arial - - - - - Arial Black - - - - - AR PL UKai CN - - - - - AR PL UKai HK - - - - - AR PL UKai TW - - - - - AR PL UKai TW MBE - - - - - AR PL UMing CN - - - - - AR PL UMing HK - - - - - AR PL UMing TW - - - - - AR PL UMing TW MBE - - - - - Baekmuk Batang - - - - - Baekmuk Dotum - - - - - Baekmuk Gulim - - - - - Baekmuk Headline - - - - - Balker - - - - - Bitstream Charter - - - - - Bitstream Vera Sans - - - - - Bitstream Vera Sans Mono - - - - - Bitstream Vera Serif - - - - - Century Schoolbook L - - - - - Chandas - - - - - cmex10 - - - - - cmmi10 - - - - - cmr10 - - - - - cmsy10 - - - - - Comic Sans MS - - - - - Cortoba - - - - - Courier 10 Pitch - - - - - Courier New - - - - - DejaVu Sans - - - - - DejaVu Sans Mono - - - - - DejaVu Serif - - - - - Dimnah - - - - - Dingbats - - - - - Domestic Manners - - - - - Dustismo - - - - - Dustismo Roman - - - - - Dyuthi - - - - - El Abogado Loco - - - - - Electron - - - - - flatline - - - - - FreeMono - - - - - FreeSans - - - - - FreeSerif - - - - - Furat - - - - - gargi - - - - - Garuda - - - - - Gentium - - - - - GentiumAlt - - - - - Georgia - - - - - Granada - - - - - Graph - - - - - Hani - - - - - Haramain - - - - - Hor - - - - - Impact - - - - - It wasn't me - - - - - Jamrul - - - - - Japan - - - - - Jet - - - - - Junkyard - - - - - Kalimati - - - - - Kalyani - - - - - Kayrawan - - - - - Kedage - - - - - Khalid - - - - - Kinnari - - - - - Kochi Gothic - - - - - Kochi Mincho - - - - - Liberation Mono - - - - - Liberation Sans - - - - - Liberation Serif - - - - - Likhan - - - - - Lohit Bengali - - - - - Lohit Gujarati - - - - - Lohit Hindi - - - - - Lohit Kannada - - - - - Lohit Oriya - - - - - Lohit Punjabi - - - - - Lohit Tamil - - - - - Lohit Telugu - - - - - Loma - - - - - Mallige - - - - - Marked Fool - - - - - Mashq - - - - - Meera - - - - - Metal - - - - - MgOpen Canonica - - - - - MgOpen Cosmetica - - - - - MgOpen Modata - - - - - MgOpen Moderna - - - - - Mitra Mono - - - - - msam10 - - - - - msbm10 - - - - - Mukti Narrow - - - - - Nada - - - - - Nagham - - - - - Nakula - - - - - Nice - - - - - Nimbus Mono L - - - - - Nimbus Roman No9 L - - - - - Nimbus Sans L - - - - - Norasi - - - - - OpenSymbol - - - - - ori1Uni - - - - - Ostorah - - - - - Ouhod - - - - - padmaa - - - - - padmaa-Bold.1.1 - - - - - Penguin Attack - - - - - Petra - - - - - Phetsarath OT - - - - - Pothana2000 - - - - - progenisis - - - - - Purisa - - - - - Rachana - - - - - RaghuMalayalam - - - - - Rasheeq - - - - - Rehan - - - - - Rekha - - - - - Saab - - - - - Sahadeva - - - - - Salem - - - - - Samanata - - - - - Samyak Devanagari - - - - - Samyak Gujarati - - - - - Samyak Oriya - - - - - Sarai - - - - - Sawasdee - - - - - Shado - - - - - Sharjah - - - - - Sindbad - - - - - Standard Symbols L - - - - - suruma - - - - - Swift - - - - - TAMu_Kadambri - - - - - TAMu_Kalyani - - - - - TAMu_Maduram - - - - - Tarablus - - - - - Tholoth - - - - - Times New Roman - - - - - TlwgMono - - - - - TlwgTypewriter - - - - - Tlwg Typist - - - - - Tlwg Typo - - - - - Trebuchet MS - - - - - TSCu_Comic - - - - - TSCu_Paranar [macromedia] - - - - - TSCu_Paranar [unknown] - - - - - TSCu_Times - - - - - Umpush - - - - - UnBatang - - - - - UnDotum - - - - - URW Bookman L - - - - - URW Chancery L - - - - - URW Gothic L - - - - - URW Palladio L - - - - - Vemana2000 - - + + + + + Background + + + + + - Verdana + Color - Waree + Image - Wargames + Video - - - wasy10 - + + + + + + + + + + + + Button + + + + + + Text + + + + + + + + + + Target + + + + + + + + 0 + 0 + + + + + + + + Font + + + + + + + 10 + + + 900 + + + 35 + + + + + + + + + + + + + + + A + + + QToolButton::InstantPopup + + - - - Webdings - + + + + D + + + QToolButton::InstantPopup + + - - - WenQuanYi Zen Hei - + + + + Qt::Vertical + + + + 20 + 40 + + + - - - Winks - + + - + - + - Colors + Button colors - + @@ -1029,49 +204,21 @@ - - - - Background - - - - - - - Color - - - true - - - - - - - - - - Image - - - - - - - - - - Qt::Horizontal - - - - - - + label + background_list + background_color + background_image + button_box + scale_image + label_5 + text_color + + + + @@ -1081,9 +228,9 @@
kcolorbutton.h
- KFontComboBox - KComboBox -
kfontcombobox.h
+ KComboBox + QComboBox +
kcombobox.h
KIntSpinBox -- 2.39.2