#include "kthumb.h"
+enum { DvdButtonItem = QGraphicsItem::UserType + 1, DvdButtonUnderlineItem = QGraphicsItem::UserType + 2 };
+
DvdWizardMenu::DvdWizardMenu(DVDFORMAT format, QWidget *parent) :
QWizardPage(parent),
m_color(NULL),
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.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)));
#if KDE_IS_VERSION(4,6,0)
QList<QGraphicsItem *> list = m_scene->items();
for (int i = 0; i < list.count(); i++) {
- if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
+ if (list.at(i)->type() == DvdButtonItem) {
if (enable) {
QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this);
shadow->setBlurRadius(7);
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) {
+ if (list.at(i)->type() == DvdButtonItem) {
buttonCount++;
DvdButton *button = static_cast < DvdButton* >(list.at(i));
QList<QGraphicsItem *> collisions = button->collidingItems();
{
QList<QGraphicsItem *> list = m_scene->selectedItems();
for (int i = 0; i < list.count(); i++) {
- if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
+ 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;
{
QList<QGraphicsItem *> list = m_scene->selectedItems();
for (int i = 0; i < list.count(); i++) {
- if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
+ if (list.at(i)->type() == DvdButtonItem) {
DvdButton *button = static_cast < DvdButton* >(list.at(i));
button->setBackMenu(backToMenu);
break;
QList<QGraphicsItem *> list = m_scene->selectedItems();
bool foundButton = false;
for (int i = 0; i < list.count(); i++) {
- if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
+ if (list.at(i)->type() == DvdButtonItem) {
m_view.play_text->blockSignals(true);
m_view.font_size->blockSignals(true);
m_view.font_family->blockSignals(true);
{
QList<QGraphicsItem *> list = m_scene->selectedItems();
for (int i = 0; i < list.count(); i++) {
- if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
+ if (list.at(i)->type() == DvdButtonItem) {
delete list.at(i);
break;
}
DvdButton *button = NULL;
QList<QGraphicsItem *> list = m_scene->selectedItems();
for (int i = 0; i < list.count(); i++) {
- if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
+ if (list.at(i)->type() == DvdButtonItem) {
button = static_cast < DvdButton* >(list.at(i));
break;
}
{
QList<QGraphicsItem *> list = m_scene->items();
for (int i = 0; i < list.count(); i++) {
- if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
+ if (list.at(i)->type() == DvdButtonItem) {
QRectF r = list.at(i)->sceneBoundingRect();
int bottom = r.bottom() - 1;
if (bottom % 2 == 1) bottom = bottom - 1;
underlineHeight = qMin(underlineHeight, 10);
underlineHeight = qMax(underlineHeight, 2);
r.setTop(bottom - underlineHeight);
+ r.setBottom(bottom);
r.adjust(2, 0, -2, 0);
- QGraphicsRectItem *underline = new QGraphicsRectItem(r);
- underline->setData(Qt::UserRole, QString("underline"));
+ DvdButtonUnderline *underline = new DvdButtonUnderline(r);
m_scene->addItem(underline);
list.at(i)->setVisible(false);
}
QList<QGraphicsItem *> list = m_scene->items();
QList<QGraphicsItem *> toDelete;
for (int i = 0; i < list.count(); i++) {
- if (list.at(i)->data(Qt::UserRole).toString() == "underline") {
+ if (list.at(i)->type() == DvdButtonUnderlineItem) {
toDelete.append(list.at(i));
}
- if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
+ if (list.at(i)->type() == DvdButtonItem) {
list.at(i)->setVisible(true);
}
}
{
QList<QGraphicsItem *> list = m_scene->items();
for (int i = 0; i < list.count(); i++) {
- if (list.at(i)->data(Qt::UserRole).toString() == "underline") {
- QGraphicsRectItem *underline = static_cast < QGraphicsRectItem* >(list.at(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);
DvdButton *button = NULL;
QList<QGraphicsItem *> list = m_scene->items();
for (int i = 0; i < list.count(); i++) {
- if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
+ if (list.at(i)->type() == DvdButtonItem) {
button = static_cast < DvdButton* >(list.at(i));
button->setDefaultTextColor(c);
}
}
-void DvdWizardMenu::createButtonImages(const QString &img1, const QString &img2, const QString &img3, bool letterbox)
+void DvdWizardMenu::createButtonImages(const QString &selected_image, const QString &highlighted_image, bool letterbox)
{
if (m_view.create_menu->isChecked()) {
m_scene->clearSelection();
#if QT_VERSION >= 0x040800
QImage img(m_finalSize.width(), m_finalSize.height(), QImage::Format_ARGB32);
img.fill(Qt::transparent);
- updateUnderlineColor(m_view.text_color->color());
+ updateUnderlineColor(m_view.highlighted_color->color());
#else
QImage img(m_finalSize.width(), m_finalSize.height(), QImage::Format_Mono);
img.fill(Qt::white);
updateUnderlineColor(Qt::black);
#endif
- QPainter p(&img);
- //p.setRenderHints(QPainter::Antialiasing, false);
- //p.setRenderHints(QPainter::TextAntialiasing, false);
- m_scene->render(&p, target, source, Qt::IgnoreAspectRatio);
- p.end();
-#if QT_VERSION >= 0x040800
-#elif QT_VERSION >= 0x040600
- img.setColor(0, m_view.text_color->color().rgb());
- img.setColor(1, qRgba(0,0,0,0));
-#else
- img.setNumColors(4);
-#endif
- img.save(img1);
-
-#if QT_VERSION >= 0x040800
- img.fill(Qt::transparent);
- updateUnderlineColor(m_view.highlighted_color->color());
-#else
- img.fill(Qt::white);
-#endif
+ QPainter p;
p.begin(&img);
//p.setRenderHints(QPainter::Antialiasing, false);
//p.setRenderHints(QPainter::TextAntialiasing, false);
#else
img.setNumColors(4);
#endif
- img.save(img3);
+ img.save(highlighted_image);
#if QT_VERSION >= 0x040800
img.fill(Qt::transparent);
#else
img.setNumColors(4);
#endif
- img.save(img2);
+ img.save(selected_image);
resetUnderLines();
m_scene->addItem(m_safeRect);
m_scene->addItem(m_color);
}
-void DvdWizardMenu::createBackgroundImage(const QString &overlayMenu, const QString &img1)
+void DvdWizardMenu::createBackgroundImage(const QString &img1, bool 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);
- if (menuMovie() && m_background->scene() != 0) {
+
+ //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;
- m_scene->removeItem(m_background);
+ if (m_background->scene() != 0) m_scene->removeItem(m_background);
if (m_color->scene() != 0) m_scene->removeItem(m_color);
- if (m_safeRect->scene() != 0) m_scene->removeItem(m_safeRect);
img.fill(Qt::transparent);
}
updateColor(m_view.text_color->color());
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);
m_scene->addItem(m_background);
m_scene->addItem(m_color);
}
- return;
-
-
- /*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;
- // Overlay Normal menu
- QImage menu(overlayMenu);
- QPainter p(&img);
- QRectF target(0, 0, img.width(), img.height());
- QRectF src(0, 0, menu.width(), menu.height());
- p.drawImage(target, menu, src);
- p.end();
- img.save(img1);*/
}
bool DvdWizardMenu::createMenu() const
offset = (m_finalSize.height() - letterboxHeight) / 2;
}
for (int i = 0; i < list.count(); i++) {
- if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
+ if (list.at(i)->type() == DvdButtonItem) {
DvdButton *button = static_cast < DvdButton* >(list.at(i));
QRectF r = button->sceneBoundingRect();
QRect adjustedRect(r.x() * ratiox, offset + r.y() * ratioy, r.width() * ratiox, r.height() * ratioy);
int buttonCount = 0;
for (int i = 0; i < list.count(); i++) {
- if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
+ 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());
}
-void DvdWizardMenu::loadXml(QDomElement xml)
+void DvdWizardMenu::loadXml(DVDFORMAT format, 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);
QList<QGraphicsItem *> list = m_scene->items();
for (int i = 0; i < list.count(); i++) {
- if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
+ if (list.at(i)->type() == DvdButtonItem) {
delete list.at(i);
i--;
}
button->setDefaultTextColor(m_view.text_color->color());
button->setZValue(4);
m_scene->addItem(button);
- button->setPos(e.attribute("posx").toDouble(), e.attribute("posy").toDouble());
+ button->setPos(e.attribute("posx").toInt(), e.attribute("posy").toInt());
}
}