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