]> git.sesse.net Git - kdenlive/blob - src/dvdwizardmenu.h
Make sure DVD buttons have integer positions
[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 DvdButtonUnderline : public QGraphicsRectItem
65 {
66
67 public:
68     DvdButtonUnderline( const QRectF & rect, QGraphicsItem * parent = 0 ) : QGraphicsRectItem(rect, parent) {}
69
70     int type() const {
71         // Enable the use of qgraphicsitem_cast with this item.
72         return UserType + 2;
73     }
74 };
75
76 class DvdButton : public QGraphicsTextItem
77 {
78
79 public:
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);
84 #endif
85     }
86     void setTarget(int t, QString c) {
87         m_target = t;
88         m_command = c;
89     }
90     int target() const {
91         return m_target;
92     }
93     QString command() const {
94         return m_command;
95     }
96     bool backMenu() const {
97         return m_backToMenu;
98     }
99     int type() const {
100         // Enable the use of qgraphicsitem_cast with this item.
101         return UserType + 1;
102     }
103     void setBackMenu(bool back) {
104         m_backToMenu = back;
105     }
106
107 private:
108     int m_target;
109     QString m_command;
110     bool m_backToMenu;
111
112 protected:
113
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());
123
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();
130                 }
131             }
132             return newPos;
133         }
134         return QGraphicsItem::itemChange(change, value);
135     }
136
137 };
138
139
140 class DvdWizardMenu : public QWizardPage
141 {
142     Q_OBJECT
143
144 public:
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();
162
163 private:
164     Ui::DvdWizardMenu_UI m_view;
165     DVDFORMAT m_format;
166     DvdScene *m_scene;
167     QGraphicsPixmapItem *m_background;
168     QGraphicsRectItem *m_color;
169     QGraphicsRectItem *m_safeRect;
170     int m_width;
171     int m_height;
172     QSize m_finalSize;
173     int m_movieLength;
174 #if KDE_IS_VERSION(4,7,0)
175     KMessageWidget *m_menuMessage;
176 #endif
177
178 private slots:
179     void buildButton();
180     void buildColor();
181     void buildImage();
182     void checkBackground();
183     void checkBackgroundType(int ix);
184     void updatePreview();
185     void buttonChanged();
186     void addButton();
187     void setButtonTarget(int ix);
188     void deleteButton();
189     void updateColor();
190     void updateColor(QColor c);
191     void updateUnderlineColor(QColor c);
192     void setBackToMenu(bool backToMenu);
193     void slotZoom();
194     void slotUnZoom();
195     void slotEnableShadows(int enable);
196 };
197
198 #endif
199