]> git.sesse.net Git - kdenlive/blob - src/dvdwizardmenu.h
Updated DVD wizard (added load/save dvd projects)
[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     enum { Type = UserType + 1 };
62     void setTarget(int t, QString c) {
63         m_target = t;
64         m_command = c;
65     }
66     int target() const {
67         return m_target;
68     }
69     QString command() const {
70         return m_command;
71     }
72     bool backMenu() const {
73         return m_backToMenu;
74     }
75     int type() const {
76         // Enable the use of qgraphicsitem_cast with this item.
77         return Type;
78     }
79     void setBackMenu(bool back) {
80         m_backToMenu = back;
81     }
82
83 private:
84     int m_target;
85     QString m_command;
86     bool m_backToMenu;
87
88 protected:
89
90     virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value) {
91         if (change == ItemPositionChange && scene()) {
92
93             /*   QList<QGraphicsItem *> list = collidingItems();
94                if (!list.isEmpty()) {
95                    for (int i = 0; i < list.count(); i++) {
96                 if (list.at(i)->type() == Type) return pos();
97                    }
98                }
99             */
100             DvdScene *sc = static_cast < DvdScene * >(scene());
101             QRectF rect = QRectF(0, 0, sc->width(), sc->height());
102             QPointF newPos = value.toPointF();
103             if (!rect.contains(newPos)) {
104                 // Keep the item inside the scene rect.
105                 newPos.setX(qMin(rect.right(), qMax(newPos.x(), rect.left())));
106                 newPos.setY(qMin(rect.bottom(), qMax(newPos.y(), rect.top())));
107                 return newPos;
108             }
109         }
110         return QGraphicsItem::itemChange(change, value);
111     }
112
113 };
114
115
116 class DvdWizardMenu : public QWizardPage
117 {
118     Q_OBJECT
119
120 public:
121     explicit DvdWizardMenu(const QString &profile, QWidget * parent = 0);
122     virtual ~DvdWizardMenu();
123     virtual bool isComplete() const;
124     bool createMenu() const;
125     void createBackgroundImage(const QString &img1);
126     void createButtonImages(const QString &img1, const QString &img2, const QString &img3);
127     void setTargets(QStringList list, QStringList targetlist);
128     QMap <QString, QRect> buttonsInfo();
129     bool menuMovie() const;
130     QString menuMoviePath() const;
131     bool isPalMenu() const;
132     void changeProfile(bool isPal);
133     QDomElement toXml() const;
134     void loadXml(QDomElement xml);
135
136 private:
137     Ui::DvdWizardMenu_UI m_view;
138     bool m_isPal;
139     DvdScene *m_scene;
140     QGraphicsPixmapItem *m_background;
141     QGraphicsRectItem *m_color;
142     QGraphicsRectItem *m_safeRect;
143     int m_width;
144     int m_height;
145
146 private slots:
147     void buildButton();
148     void buildColor();
149     void buildImage();
150     void checkBackground();
151     void checkBackgroundType(int ix);
152     void updatePreview();
153     void buttonChanged();
154     void addButton();
155     void setButtonTarget(int ix);
156     void deleteButton();
157     void updateColor();
158     void updateColor(QColor c);
159     void setBackToMenu(bool backToMenu);
160 };
161
162 #endif
163