]> git.sesse.net Git - kdenlive/blob - src/dvdwizardmenu.h
c4496b2f2411296f175c311a84a2e137a473430d
[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 #include <kdeversion.h>
33
34 #if KDE_IS_VERSION(4,7,0)
35 #include <KMessageWidget>
36 #endif
37
38 #include "dvdwizardvob.h"
39 #include "ui_dvdwizardmenu_ui.h"
40
41 class DvdScene : public QGraphicsScene
42 {
43     Q_OBJECT
44 public:
45     DvdScene(QObject * parent = 0): QGraphicsScene(parent) {
46         m_width = 0; m_height = 0;
47     }
48     void setProfile(int width, int height) {
49         m_width = width;
50         m_height = height;
51         setSceneRect(0, 0, m_width, m_height);
52     }
53     int sceneWidth() const {
54         return m_width;
55     }
56     int sceneHeight() const {
57         return m_height;
58     }
59 private:
60     int m_width;
61     int m_height;
62     
63 protected:
64     void mouseReleaseEvent( QGraphicsSceneMouseEvent * mouseEvent ) {
65         QGraphicsScene::mouseReleaseEvent(mouseEvent);
66         emit sceneChanged();
67     }
68 signals:
69     void sceneChanged();
70 };
71
72 class DvdButtonUnderline : public QGraphicsRectItem
73 {
74
75 public:
76     DvdButtonUnderline( const QRectF & rect, QGraphicsItem * parent = 0 ) : QGraphicsRectItem(rect, parent) {}
77
78     int type() const {
79         // Enable the use of qgraphicsitem_cast with this item.
80         return UserType + 2;
81     }
82 };
83
84 class DvdButton : public QGraphicsTextItem
85 {
86
87 public:
88     DvdButton(const QString & text): QGraphicsTextItem(text), m_target(0), m_command(QString("jump title 1")), m_backToMenu(false) {
89         setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
90 #if QT_VERSION >= 0x040600
91         setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
92 #endif
93     }
94     void setTarget(int t, const QString &c) {
95         m_target = t;
96         m_command = c;
97     }
98     int target() const {
99         return m_target;
100     }
101     QString command() const {
102         return m_command;
103     }
104     bool backMenu() const {
105         return m_backToMenu;
106     }
107     int type() const {
108         // Enable the use of qgraphicsitem_cast with this item.
109         return UserType + 1;
110     }
111     void setBackMenu(bool back) {
112         m_backToMenu = back;
113     }
114
115 private:
116     int m_target;
117     QString m_command;
118     bool m_backToMenu;
119
120 protected:
121
122     virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value) {
123         if (change == ItemPositionChange && scene()) {
124             QPoint newPos = value.toPoint();
125             QRectF sceneShape = sceneBoundingRect();
126             DvdScene *sc = static_cast < DvdScene * >(scene());
127             newPos.setX(qMax(newPos.x(), 0));
128             newPos.setY(qMax(newPos.y(), 0));
129             if (newPos.x() + sceneShape.width() > sc->width())
130                 newPos.setX(sc->width() - sceneShape.width());
131             if (newPos.y() + sceneShape.height() > sc->height())
132                 newPos.setY(sc->height() - sceneShape.height());
133
134             sceneShape.translate(newPos - pos());
135             QList<QGraphicsItem*> list = scene()->items(sceneShape, Qt::IntersectsItemShape);
136             list.removeAll(this);
137             if (!list.isEmpty()) {
138                 for (int i = 0; i < list.count(); ++i) {
139                     if (list.at(i)->type() == Type) return pos();
140                 }
141             }
142             return newPos;
143         }
144         return QGraphicsItem::itemChange(change, value);
145     }
146
147 };
148
149
150 class DvdWizardMenu : public QWizardPage
151 {
152     Q_OBJECT
153
154 public:
155     explicit DvdWizardMenu(DVDFORMAT format, QWidget * parent = 0);
156     virtual ~DvdWizardMenu();
157     virtual bool isComplete() const;
158     bool createMenu() const;
159     void createBackgroundImage(const QString &img1, bool letterbox);
160     void createButtonImages(const QString &selected_image, const QString &highlighted_image, bool letterbox);
161     void setTargets(const QStringList &list, const QStringList &targetlist);
162     QMap <QString, QRect> buttonsInfo(bool letterbox = false);
163     bool loopMovie() const;
164     bool menuMovie() const;
165     QString menuMoviePath() const;
166     int menuMovieLength() const;
167     void changeProfile(DVDFORMAT format);
168     QDomElement toXml() const;
169     void loadXml(DVDFORMAT format, const QDomElement &xml);
170     void prepareUnderLines();
171     void resetUnderLines();
172
173 private:
174     Ui::DvdWizardMenu_UI m_view;
175     DVDFORMAT m_format;
176     DvdScene *m_scene;
177     QGraphicsPixmapItem *m_background;
178     QGraphicsRectItem *m_color;
179     QGraphicsRectItem *m_safeRect;
180     int m_width;
181     int m_height;
182     QSize m_finalSize;
183     int m_movieLength;
184 #if KDE_IS_VERSION(4,7,0)
185     KMessageWidget *m_menuMessage;
186 #endif
187
188 private slots:
189     void buildButton();
190     void buildColor();
191     void buildImage();
192     void checkBackground();
193     void checkBackgroundType(int ix);
194     void updatePreview();
195     void buttonChanged();
196     void addButton();
197     void setButtonTarget(int ix);
198     void deleteButton();
199     void updateColor();
200     void updateColor(const QColor &c);
201     void updateUnderlineColor(QColor c);
202     void setBackToMenu(bool backToMenu);
203     void slotZoom();
204     void slotUnZoom();
205     void slotEnableShadows(int enable);
206 };
207
208 #endif
209