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