]> git.sesse.net Git - kdenlive/blob - src/dvdwizardmenu.h
Hopefully fix compile problem on armel, where there is no double type
[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
33 #include "ui_dvdwizardmenu_ui.h"
34
35 class DvdScene : public QGraphicsScene
36 {
37
38 public:
39     DvdScene(QObject * parent = 0): QGraphicsScene(parent) {}
40     void setProfile(int width, int height) {
41         m_width = width;
42         m_height = height;
43         setSceneRect(0, 0, m_width, m_height);
44     }
45     int sceneWidth() const {
46         return m_width;
47     }
48     int sceneHeight() const {
49         return m_height;
50     }
51 private:
52     int m_width;
53     int m_height;
54 };
55
56 class DvdButton : public QGraphicsTextItem
57 {
58
59 public:
60     DvdButton(const QString & text): QGraphicsTextItem(text), m_target(0), m_command(QString("jump title 1")), m_backToMenu(false) {}
61     enum { Type = UserType + 1 };
62     void setTarget(int t, QString c) {
63         m_target = t;
64         m_command = c;
65     }
66     int target() const {
67         return m_target;
68     }
69     QString command() const {
70         return m_command;
71     }
72     bool backMenu() const {
73         return m_backToMenu;
74     }
75     int type() const {
76         // Enable the use of qgraphicsitem_cast with this item.
77         return Type;
78     }
79     void setBackMenu(bool back) {
80         m_backToMenu = back;
81     }
82
83 private:
84     int m_target;
85     QString m_command;
86     bool m_backToMenu;
87
88 protected:
89
90     virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value) {
91         if (change == ItemPositionChange && scene()) {
92
93             QPointF newPos = value.toPointF();
94             QRectF sceneShape = sceneBoundingRect();
95             DvdScene *sc = static_cast < DvdScene * >(scene());
96             newPos.setX(qMax(newPos.x(), (qreal)0));
97             newPos.setY(qMax(newPos.y(), (qreal)0));
98             if (newPos.x() + sceneShape.width() > sc->width()) newPos.setX(sc->width() - sceneShape.width());
99             if (newPos.y() + sceneShape.height() > sc->height()) newPos.setY(sc->height() - sceneShape.height());
100
101             sceneShape.translate(newPos - pos());
102             QList<QGraphicsItem*> list = scene()->items(sceneShape, Qt::IntersectsItemShape);
103             list.removeAll(this);
104             if (!list.isEmpty()) {
105                 for (int i = 0; i < list.count(); i++) {
106                     if (list.at(i)->type() == Type) return pos();
107                 }
108             }
109             return newPos;
110         }
111         return QGraphicsItem::itemChange(change, value);
112     }
113
114 };
115
116
117 class DvdWizardMenu : public QWizardPage
118 {
119     Q_OBJECT
120
121 public:
122     explicit DvdWizardMenu(const QString &profile, QWidget * parent = 0);
123     virtual ~DvdWizardMenu();
124     virtual bool isComplete() const;
125     bool createMenu() const;
126     void createBackgroundImage(const QString &img1);
127     void createButtonImages(const QString &img1, const QString &img2, const QString &img3);
128     void setTargets(QStringList list, QStringList targetlist);
129     QMap <QString, QRect> buttonsInfo();
130     bool menuMovie() const;
131     QString menuMoviePath() const;
132     bool isPalMenu() const;
133     void changeProfile(bool isPal);
134     QDomElement toXml() const;
135     void loadXml(QDomElement xml);
136
137 private:
138     Ui::DvdWizardMenu_UI m_view;
139     bool m_isPal;
140     DvdScene *m_scene;
141     QGraphicsPixmapItem *m_background;
142     QGraphicsRectItem *m_color;
143     QGraphicsRectItem *m_safeRect;
144     int m_width;
145     int m_height;
146
147 private slots:
148     void buildButton();
149     void buildColor();
150     void buildImage();
151     void checkBackground();
152     void checkBackgroundType(int ix);
153     void updatePreview();
154     void buttonChanged();
155     void addButton();
156     void setButtonTarget(int ix);
157     void deleteButton();
158     void updateColor();
159     void updateColor(QColor c);
160     void setBackToMenu(bool backToMenu);
161     void slotZoom();
162     void slotUnZoom();
163 };
164
165 #endif
166