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