1 /***************************************************************************
2 * Copyright (C) 2009 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
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. *
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. *
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 ***************************************************************************/
21 #ifndef DVDWIZARDMENU_H
22 #define DVDWIZARDMENU_H
24 #include <QWizardPage>
25 #include <QGraphicsScene>
26 #include <QGraphicsTextItem>
27 #include <QGraphicsPixmapItem>
28 #include <QGraphicsRectItem>
29 #include <QDomElement>
32 #include <kdeversion.h>
34 #if KDE_IS_VERSION(4,7,0)
35 #include <KMessageWidget>
38 #include "dvdwizardvob.h"
39 #include "ui_dvdwizardmenu_ui.h"
41 class DvdScene : public QGraphicsScene
45 DvdScene(QObject * parent = 0): QGraphicsScene(parent) {
46 m_width = 0; m_height = 0;
48 void setProfile(int width, int height) {
51 setSceneRect(0, 0, m_width, m_height);
53 int sceneWidth() const {
56 int sceneHeight() const {
64 void mouseReleaseEvent( QGraphicsSceneMouseEvent * mouseEvent ) {
65 QGraphicsScene::mouseReleaseEvent(mouseEvent);
72 class DvdButtonUnderline : public QGraphicsRectItem
76 DvdButtonUnderline( const QRectF & rect, QGraphicsItem * parent = 0 ) : QGraphicsRectItem(rect, parent) {}
79 // Enable the use of qgraphicsitem_cast with this item.
84 class DvdButton : public QGraphicsTextItem
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);
94 void setTarget(int t, const QString &c) {
101 QString command() const {
104 bool backMenu() const {
108 // Enable the use of qgraphicsitem_cast with this item.
111 void setBackMenu(bool back) {
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()) newPos.setX(sc->width() - sceneShape.width());
130 if (newPos.y() + sceneShape.height() > sc->height()) newPos.setY(sc->height() - sceneShape.height());
132 sceneShape.translate(newPos - pos());
133 QList<QGraphicsItem*> list = scene()->items(sceneShape, Qt::IntersectsItemShape);
134 list.removeAll(this);
135 if (!list.isEmpty()) {
136 for (int i = 0; i < list.count(); ++i) {
137 if (list.at(i)->type() == Type) return pos();
142 return QGraphicsItem::itemChange(change, value);
148 class DvdWizardMenu : public QWizardPage
153 explicit DvdWizardMenu(DVDFORMAT format, QWidget * parent = 0);
154 virtual ~DvdWizardMenu();
155 virtual bool isComplete() const;
156 bool createMenu() const;
157 void createBackgroundImage(const QString &img1, bool letterbox);
158 void createButtonImages(const QString &selected_image, const QString &highlighted_image, bool letterbox);
159 void setTargets(const QStringList &list, const QStringList &targetlist);
160 QMap <QString, QRect> buttonsInfo(bool letterbox = false);
161 bool loopMovie() const;
162 bool menuMovie() const;
163 QString menuMoviePath() const;
164 int menuMovieLength() const;
165 void changeProfile(DVDFORMAT format);
166 QDomElement toXml() const;
167 void loadXml(DVDFORMAT format, const QDomElement &xml);
168 void prepareUnderLines();
169 void resetUnderLines();
172 Ui::DvdWizardMenu_UI m_view;
175 QGraphicsPixmapItem *m_background;
176 QGraphicsRectItem *m_color;
177 QGraphicsRectItem *m_safeRect;
182 #if KDE_IS_VERSION(4,7,0)
183 KMessageWidget *m_menuMessage;
190 void checkBackground();
191 void checkBackgroundType(int ix);
192 void updatePreview();
193 void buttonChanged();
195 void setButtonTarget(int ix);
198 void updateColor(const QColor &c);
199 void updateUnderlineColor(QColor c);
200 void setBackToMenu(bool backToMenu);
203 void slotEnableShadows(int enable);