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