]> git.sesse.net Git - kdenlive/blob - src/dvdwizardmenu.h
const'ref. Fix coding style. Minor optimization
[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     Q_OBJECT
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 protected:
64     void mouseReleaseEvent( QGraphicsSceneMouseEvent * mouseEvent ) {
65         QGraphicsScene::mouseReleaseEvent(mouseEvent);
66         emit sceneChanged();
67     }
68 signals:
69     void sceneChanged();
70 };
71
72 class DvdButtonUnderline : public QGraphicsRectItem
73 {
74
75 public:
76     DvdButtonUnderline( const QRectF & rect, QGraphicsItem * parent = 0 ) : QGraphicsRectItem(rect, parent) {}
77
78     int type() const {
79         // Enable the use of qgraphicsitem_cast with this item.
80         return UserType + 2;
81     }
82 };
83
84 class DvdButton : public QGraphicsTextItem
85 {
86
87 public:
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);
92 #endif
93     }
94     void setTarget(int t, const QString &c) {
95         m_target = t;
96         m_command = c;
97     }
98     int target() const {
99         return m_target;
100     }
101     QString command() const {
102         return m_command;
103     }
104     bool backMenu() const {
105         return m_backToMenu;
106     }
107     int type() const {
108         // Enable the use of qgraphicsitem_cast with this item.
109         return UserType + 1;
110     }
111     void setBackMenu(bool back) {
112         m_backToMenu = back;
113     }
114
115 private:
116     int m_target;
117     QString m_command;
118     bool m_backToMenu;
119
120 protected:
121
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())
130                 newPos.setX(sc->width() - sceneShape.width());
131             if (newPos.y() + sceneShape.height() > sc->height())
132                 newPos.setY(sc->height() - sceneShape.height());
133
134             sceneShape.translate(newPos - pos());
135             QList<QGraphicsItem*> list = scene()->items(sceneShape, Qt::IntersectsItemShape);
136             list.removeAll(this);
137             if (!list.isEmpty()) {
138                 for (int i = 0; i < list.count(); ++i) {
139                     if (list.at(i)->type() == Type)
140                         return pos();
141                 }
142             }
143             return newPos;
144         }
145         return QGraphicsItem::itemChange(change, value);
146     }
147
148 };
149
150
151 class DvdWizardMenu : public QWizardPage
152 {
153     Q_OBJECT
154
155 public:
156     explicit DvdWizardMenu(DVDFORMAT format, QWidget * parent = 0);
157     virtual ~DvdWizardMenu();
158     virtual bool isComplete() const;
159     bool createMenu() const;
160     void createBackgroundImage(const QString &img1, bool letterbox);
161     void createButtonImages(const QString &selected_image, const QString &highlighted_image, bool letterbox);
162     void setTargets(const QStringList &list, const QStringList &targetlist);
163     QMap <QString, QRect> buttonsInfo(bool letterbox = false);
164     bool loopMovie() const;
165     bool menuMovie() const;
166     QString menuMoviePath() const;
167     int menuMovieLength() const;
168     void changeProfile(DVDFORMAT format);
169     QDomElement toXml() const;
170     void loadXml(DVDFORMAT format, const QDomElement &xml);
171     void prepareUnderLines();
172     void resetUnderLines();
173
174 private:
175     Ui::DvdWizardMenu_UI m_view;
176     DVDFORMAT m_format;
177     DvdScene *m_scene;
178     QGraphicsPixmapItem *m_background;
179     QGraphicsRectItem *m_color;
180     QGraphicsRectItem *m_safeRect;
181     int m_width;
182     int m_height;
183     QSize m_finalSize;
184     int m_movieLength;
185 #if KDE_IS_VERSION(4,7,0)
186     KMessageWidget *m_menuMessage;
187 #endif
188
189 private slots:
190     void buildButton();
191     void buildColor();
192     void buildImage();
193     void checkBackground();
194     void checkBackgroundType(int ix);
195     void updatePreview();
196     void buttonChanged();
197     void addButton();
198     void setButtonTarget(int ix);
199     void deleteButton();
200     void updateColor();
201     void updateColor(const QColor &c);
202     void updateUnderlineColor(QColor c);
203     void setBackToMenu(bool backToMenu);
204     void slotZoom();
205     void slotUnZoom();
206     void slotEnableShadows(int enable);
207 };
208
209 #endif
210