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>
32 #include <kdeversion.h>
34 #if KDE_IS_VERSION(4,7,0)
35 #include <KMessageWidget>
38 #include "ui_dvdwizardmenu_ui.h"
40 class DvdScene : public QGraphicsScene
44 DvdScene(QObject * parent = 0): QGraphicsScene(parent) {
45 m_width = 0; m_height = 0;
47 void setProfile(int width, int height) {
50 setSceneRect(0, 0, m_width, m_height);
52 int sceneWidth() const {
55 int sceneHeight() const {
63 class DvdButton : public QGraphicsTextItem
67 DvdButton(const QString & text): QGraphicsTextItem(text), m_target(0), m_command(QString("jump title 1")), m_backToMenu(false) {
68 setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
69 #if QT_VERSION >= 0x040600
70 setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
73 void setTarget(int t, QString c) {
80 QString command() const {
83 bool backMenu() const {
87 // Enable the use of qgraphicsitem_cast with this item.
90 void setBackMenu(bool back) {
101 virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value) {
102 if (change == ItemPositionChange && scene()) {
103 QPointF newPos = value.toPointF();
104 QRectF sceneShape = sceneBoundingRect();
105 DvdScene *sc = static_cast < DvdScene * >(scene());
106 newPos.setX(qMax(newPos.x(), (qreal)0));
107 newPos.setY(qMax(newPos.y(), (qreal)0));
108 if (newPos.x() + sceneShape.width() > sc->width()) newPos.setX(sc->width() - sceneShape.width());
109 if (newPos.y() + sceneShape.height() > sc->height()) newPos.setY(sc->height() - sceneShape.height());
111 sceneShape.translate(newPos - pos());
112 QList<QGraphicsItem*> list = scene()->items(sceneShape, Qt::IntersectsItemShape);
113 list.removeAll(this);
114 if (!list.isEmpty()) {
115 for (int i = 0; i < list.count(); i++) {
116 if (list.at(i)->type() == Type) return pos();
121 return QGraphicsItem::itemChange(change, value);
127 class DvdWizardMenu : public QWizardPage
132 explicit DvdWizardMenu(const QString &profile, QWidget * parent = 0);
133 virtual ~DvdWizardMenu();
134 virtual bool isComplete() const;
135 bool createMenu() const;
136 void createBackgroundImage(const QString &img1);
137 void createButtonImages(const QString &img1, const QString &img2, const QString &img3);
138 void setTargets(QStringList list, QStringList targetlist);
139 QMap <QString, QRect> buttonsInfo();
140 bool loopMovie() const;
141 bool menuMovie() const;
142 QString menuMoviePath() const;
143 bool isPalMenu() const;
144 void changeProfile(bool isPal);
145 QDomElement toXml() const;
146 void loadXml(QDomElement xml);
149 Ui::DvdWizardMenu_UI m_view;
152 QGraphicsPixmapItem *m_background;
153 QGraphicsRectItem *m_color;
154 QGraphicsRectItem *m_safeRect;
157 #if KDE_IS_VERSION(4,7,0)
158 KMessageWidget *m_menuMessage;
165 void checkBackground();
166 void checkBackgroundType(int ix);
167 void updatePreview();
168 void buttonChanged();
170 void setButtonTarget(int ix);
173 void updateColor(QColor c);
174 void setBackToMenu(bool backToMenu);