1 /***************************************************************************
2 * Copyright (C) 2009 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
21 #ifndef DVDWIZARDMENU_H
22 #define DVDWIZARDMENU_H
24 #include <QWizardPage>
25 #include <QGraphicsScene>
26 #include <QGraphicsTextItem>
27 #include <QGraphicsPixmapItem>
28 #include <QGraphicsRectItem>
29 #include <QDomElement>
33 #include "ui_dvdwizardmenu_ui.h"
35 class DvdScene : public QGraphicsScene
39 DvdScene(QObject * parent = 0): QGraphicsScene(parent) {}
40 void setProfile(int width, int height) {
43 setSceneRect(0, 0, m_width, m_height);
45 int sceneWidth() const {
48 int sceneHeight() const {
56 class DvdButton : public QGraphicsTextItem
60 DvdButton(const QString & text): QGraphicsTextItem(text), m_target(0), m_command(QString("jump title 1")), m_backToMenu(false) {
61 setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
62 #if QT_VERSION >= 0x040600
63 setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
66 void setTarget(int t, QString c) {
73 QString command() const {
76 bool backMenu() const {
80 // Enable the use of qgraphicsitem_cast with this item.
83 void setBackMenu(bool back) {
94 virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value) {
95 if (change == ItemPositionChange && scene()) {
96 QPointF newPos = value.toPointF();
97 QRectF sceneShape = sceneBoundingRect();
98 DvdScene *sc = static_cast < DvdScene * >(scene());
99 newPos.setX(qMax(newPos.x(), (qreal)0));
100 newPos.setY(qMax(newPos.y(), (qreal)0));
101 if (newPos.x() + sceneShape.width() > sc->width()) newPos.setX(sc->width() - sceneShape.width());
102 if (newPos.y() + sceneShape.height() > sc->height()) newPos.setY(sc->height() - sceneShape.height());
104 sceneShape.translate(newPos - pos());
105 QList<QGraphicsItem*> list = scene()->items(sceneShape, Qt::IntersectsItemShape);
106 list.removeAll(this);
107 if (!list.isEmpty()) {
108 for (int i = 0; i < list.count(); i++) {
109 if (list.at(i)->type() == Type) return pos();
114 return QGraphicsItem::itemChange(change, value);
120 class DvdWizardMenu : public QWizardPage
125 explicit DvdWizardMenu(const QString &profile, QWidget * parent = 0);
126 virtual ~DvdWizardMenu();
127 virtual bool isComplete() const;
128 bool createMenu() const;
129 void createBackgroundImage(const QString &img1);
130 void createButtonImages(const QString &img1, const QString &img2, const QString &img3);
131 void setTargets(QStringList list, QStringList targetlist);
132 QMap <QString, QRect> buttonsInfo();
133 bool loopMovie() const;
134 bool menuMovie() const;
135 QString menuMoviePath() const;
136 bool isPalMenu() const;
137 void changeProfile(bool isPal);
138 QDomElement toXml() const;
139 void loadXml(QDomElement xml);
142 Ui::DvdWizardMenu_UI m_view;
145 QGraphicsPixmapItem *m_background;
146 QGraphicsRectItem *m_color;
147 QGraphicsRectItem *m_safeRect;
155 void checkBackground();
156 void checkBackgroundType(int ix);
157 void updatePreview();
158 void buttonChanged();
160 void setButtonTarget(int ix);
163 void updateColor(QColor c);
164 void setBackToMenu(bool backToMenu);