]> git.sesse.net Git - kdenlive/blob - src/dvdwizardmenu.h
Fix issues with DVD wizard, allow to loop menu movie
[kdenlive] / src / dvdwizardmenu.h
1 /***************************************************************************
2  *   Copyright (C) 2009 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3  *                                                                         *
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.                                   *
8  *                                                                         *
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.                          *
13  *                                                                         *
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  ***************************************************************************/
19
20
21 #ifndef DVDWIZARDMENU_H
22 #define DVDWIZARDMENU_H
23
24 #include <QWizardPage>
25 #include <QGraphicsScene>
26 #include <QGraphicsTextItem>
27 #include <QGraphicsPixmapItem>
28 #include <QGraphicsRectItem>
29 #include <QDomElement>
30
31 #include <KDebug>
32
33 #include "ui_dvdwizardmenu_ui.h"
34
35 class DvdScene : public QGraphicsScene
36 {
37
38 public:
39     DvdScene(QObject * parent = 0): QGraphicsScene(parent) {}
40     void setProfile(int width, int height) {
41         m_width = width;
42         m_height = height;
43         setSceneRect(0, 0, m_width, m_height);
44     }
45     int sceneWidth() const {
46         return m_width;
47     }
48     int sceneHeight() const {
49         return m_height;
50     }
51 private:
52     int m_width;
53     int m_height;
54 };
55
56 class DvdButton : public QGraphicsTextItem
57 {
58
59 public:
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);
64 #endif
65     }
66     void setTarget(int t, QString c) {
67         m_target = t;
68         m_command = c;
69     }
70     int target() const {
71         return m_target;
72     }
73     QString command() const {
74         return m_command;
75     }
76     bool backMenu() const {
77         return m_backToMenu;
78     }
79     int type() const {
80         // Enable the use of qgraphicsitem_cast with this item.
81         return UserType + 1;
82     }
83     void setBackMenu(bool back) {
84         m_backToMenu = back;
85     }
86
87 private:
88     int m_target;
89     QString m_command;
90     bool m_backToMenu;
91
92 protected:
93
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());
103
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();
110                 }
111             }
112             return newPos;
113         }
114         return QGraphicsItem::itemChange(change, value);
115     }
116
117 };
118
119
120 class DvdWizardMenu : public QWizardPage
121 {
122     Q_OBJECT
123
124 public:
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);
140
141 private:
142     Ui::DvdWizardMenu_UI m_view;
143     bool m_isPal;
144     DvdScene *m_scene;
145     QGraphicsPixmapItem *m_background;
146     QGraphicsRectItem *m_color;
147     QGraphicsRectItem *m_safeRect;
148     int m_width;
149     int m_height;
150
151 private slots:
152     void buildButton();
153     void buildColor();
154     void buildImage();
155     void checkBackground();
156     void checkBackgroundType(int ix);
157     void updatePreview();
158     void buttonChanged();
159     void addButton();
160     void setButtonTarget(int ix);
161     void deleteButton();
162     void updateColor();
163     void updateColor(QColor c);
164     void setBackToMenu(bool backToMenu);
165     void slotZoom();
166     void slotUnZoom();
167 };
168
169 #endif
170