]> git.sesse.net Git - kdenlive/blob - src/dvdwizardmenu.h
Merge branch 'feature/pkey' of git://anongit.kde.org/kdenlive into pkey
[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
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
64 class DvdButton : public QGraphicsTextItem
65 {
66
67 public:
68     DvdButton(const QString & text): QGraphicsTextItem(text), m_target(0), m_command(QString("jump title 1")), m_backToMenu(false) {
69         setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
70 #if QT_VERSION >= 0x040600
71         setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
72 #endif
73     }
74     void setTarget(int t, QString c) {
75         m_target = t;
76         m_command = c;
77     }
78     int target() const {
79         return m_target;
80     }
81     QString command() const {
82         return m_command;
83     }
84     bool backMenu() const {
85         return m_backToMenu;
86     }
87     int type() const {
88         // Enable the use of qgraphicsitem_cast with this item.
89         return UserType + 1;
90     }
91     void setBackMenu(bool back) {
92         m_backToMenu = back;
93     }
94
95 private:
96     int m_target;
97     QString m_command;
98     bool m_backToMenu;
99
100 protected:
101
102     virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value) {
103         if (change == ItemPositionChange && scene()) {
104             QPointF newPos = value.toPointF();
105             QRectF sceneShape = sceneBoundingRect();
106             DvdScene *sc = static_cast < DvdScene * >(scene());
107             newPos.setX(qMax(newPos.x(), (qreal)0));
108             newPos.setY(qMax(newPos.y(), (qreal)0));
109             if (newPos.x() + sceneShape.width() > sc->width()) newPos.setX(sc->width() - sceneShape.width());
110             if (newPos.y() + sceneShape.height() > sc->height()) newPos.setY(sc->height() - sceneShape.height());
111
112             sceneShape.translate(newPos - pos());
113             QList<QGraphicsItem*> list = scene()->items(sceneShape, Qt::IntersectsItemShape);
114             list.removeAll(this);
115             if (!list.isEmpty()) {
116                 for (int i = 0; i < list.count(); i++) {
117                     if (list.at(i)->type() == Type) return pos();
118                 }
119             }
120             return newPos;
121         }
122         return QGraphicsItem::itemChange(change, value);
123     }
124
125 };
126
127
128 class DvdWizardMenu : public QWizardPage
129 {
130     Q_OBJECT
131
132 public:
133     explicit DvdWizardMenu(DVDFORMAT format, QWidget * parent = 0);
134     virtual ~DvdWizardMenu();
135     virtual bool isComplete() const;
136     bool createMenu() const;
137     void createBackgroundImage(const QString &overlayMenu, const QString &img1);
138     void createButtonImages(const QString &img1, const QString &img2, const QString &img3, bool letterbox = false);
139     void setTargets(QStringList list, QStringList targetlist);
140     QMap <QString, QRect> buttonsInfo(bool letterbox = false);
141     bool loopMovie() const;
142     bool menuMovie() const;
143     QString menuMoviePath() const;
144     int menuMovieLength() const;
145     void changeProfile(DVDFORMAT format);
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     DVDFORMAT m_format;
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