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 class DvdButtonUnderline : public QGraphicsRectItem
68 DvdButtonUnderline( const QRectF & rect, QGraphicsItem * parent = 0 ) : QGraphicsRectItem(rect, parent) {}
71 // Enable the use of qgraphicsitem_cast with this item.
76 class DvdButton : public QGraphicsTextItem
80 DvdButton(const QString & text): QGraphicsTextItem(text), m_target(0), m_command(QString("jump title 1")), m_backToMenu(false) {
81 setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
82 #if QT_VERSION >= 0x040600
83 setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
86 void setTarget(int t, QString c) {
93 QString command() const {
96 bool backMenu() const {
100 // Enable the use of qgraphicsitem_cast with this item.
103 void setBackMenu(bool back) {
114 virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value) {
115 if (change == ItemPositionChange && scene()) {
116 QPoint newPos = value.toPoint();
117 QRectF sceneShape = sceneBoundingRect();
118 DvdScene *sc = static_cast < DvdScene * >(scene());
119 newPos.setX(qMax(newPos.x(), 0));
120 newPos.setY(qMax(newPos.y(), 0));
121 if (newPos.x() + sceneShape.width() > sc->width()) newPos.setX(sc->width() - sceneShape.width());
122 if (newPos.y() + sceneShape.height() > sc->height()) newPos.setY(sc->height() - sceneShape.height());
124 sceneShape.translate(newPos - pos());
125 QList<QGraphicsItem*> list = scene()->items(sceneShape, Qt::IntersectsItemShape);
126 list.removeAll(this);
127 if (!list.isEmpty()) {
128 for (int i = 0; i < list.count(); i++) {
129 if (list.at(i)->type() == Type) return pos();
134 return QGraphicsItem::itemChange(change, value);
140 class DvdWizardMenu : public QWizardPage
145 explicit DvdWizardMenu(DVDFORMAT format, QWidget * parent = 0);
146 virtual ~DvdWizardMenu();
147 virtual bool isComplete() const;
148 bool createMenu() const;
149 void createBackgroundImage(const QString &img1, bool letterbox);
150 void createButtonImages(const QString &selected_image, const QString &highlighted_image, bool letterbox);
151 void setTargets(QStringList list, QStringList targetlist);
152 QMap <QString, QRect> buttonsInfo(bool letterbox = false);
153 bool loopMovie() const;
154 bool menuMovie() const;
155 QString menuMoviePath() const;
156 int menuMovieLength() const;
157 void changeProfile(DVDFORMAT format);
158 QDomElement toXml() const;
159 void loadXml(DVDFORMAT format, QDomElement xml);
160 void prepareUnderLines();
161 void resetUnderLines();
164 Ui::DvdWizardMenu_UI m_view;
167 QGraphicsPixmapItem *m_background;
168 QGraphicsRectItem *m_color;
169 QGraphicsRectItem *m_safeRect;
174 #if KDE_IS_VERSION(4,7,0)
175 KMessageWidget *m_menuMessage;
182 void checkBackground();
183 void checkBackgroundType(int ix);
184 void updatePreview();
185 void buttonChanged();
187 void setButtonTarget(int ix);
190 void updateColor(QColor c);
191 void updateUnderlineColor(QColor c);
192 void setBackToMenu(bool backToMenu);
195 void slotEnableShadows(int enable);