]> git.sesse.net Git - kdenlive/blob - src/dvdwizardmenu.h
2ecdcae18b9c41153d5b40bf8680cfd7fe19eb20
[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 "ui_dvdwizardmenu_ui.h"
39
40 class DvdScene : public QGraphicsScene
41 {
42
43 public:
44     DvdScene(QObject * parent = 0): QGraphicsScene(parent) {
45         m_width = 0; m_height = 0;
46     }
47     void setProfile(int width, int height) {
48         m_width = width;
49         m_height = height;
50         setSceneRect(0, 0, m_width, m_height);
51     }
52     int sceneWidth() const {
53         return m_width;
54     }
55     int sceneHeight() const {
56         return m_height;
57     }
58 private:
59     int m_width;
60     int m_height;
61 };
62
63 class DvdButton : public QGraphicsTextItem
64 {
65
66 public:
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);
71 #endif
72     }
73     void setTarget(int t, QString c) {
74         m_target = t;
75         m_command = c;
76     }
77     int target() const {
78         return m_target;
79     }
80     QString command() const {
81         return m_command;
82     }
83     bool backMenu() const {
84         return m_backToMenu;
85     }
86     int type() const {
87         // Enable the use of qgraphicsitem_cast with this item.
88         return UserType + 1;
89     }
90     void setBackMenu(bool back) {
91         m_backToMenu = back;
92     }
93
94 private:
95     int m_target;
96     QString m_command;
97     bool m_backToMenu;
98
99 protected:
100
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());
110
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();
117                 }
118             }
119             return newPos;
120         }
121         return QGraphicsItem::itemChange(change, value);
122     }
123
124 };
125
126
127 class DvdWizardMenu : public QWizardPage
128 {
129     Q_OBJECT
130
131 public:
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 &overlayMenu, 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     int menuMovieLength() const;
144     bool isPalMenu() const;
145     void changeProfile(bool isPal);
146     QDomElement toXml() const;
147     void loadXml(QDomElement xml);
148     void prepareUnderLines();
149     void resetUnderLines();
150
151 private:
152     Ui::DvdWizardMenu_UI m_view;
153     bool m_isPal;
154     DvdScene *m_scene;
155     QGraphicsPixmapItem *m_background;
156     QGraphicsRectItem *m_color;
157     QGraphicsRectItem *m_safeRect;
158     int m_width;
159     int m_height;
160     QSize m_finalSize;
161     int m_movieLength;
162 #if KDE_IS_VERSION(4,7,0)
163     KMessageWidget *m_menuMessage;
164 #endif
165
166 private slots:
167     void buildButton();
168     void buildColor();
169     void buildImage();
170     void checkBackground();
171     void checkBackgroundType(int ix);
172     void updatePreview();
173     void buttonChanged();
174     void addButton();
175     void setButtonTarget(int ix);
176     void deleteButton();
177     void updateColor();
178     void updateColor(QColor c);
179     void updateUnderlineColor(QColor c);
180     void setBackToMenu(bool backToMenu);
181     void slotZoom();
182     void slotUnZoom();
183     void slotEnableShadows(int enable);
184 };
185
186 #endif
187