]> git.sesse.net Git - kdenlive/blobdiff - src/dvdwizardmenu.h
const'ref. Fix coding style. Minor optimization
[kdenlive] / src / dvdwizardmenu.h
index 01a0c73ba25a9846e6ce101bdbb8c499f38bfd9c..d5daa98964c699b99d8c08a06b92e6db63cfa4da 100644 (file)
 #include <QGraphicsTextItem>
 #include <QGraphicsPixmapItem>
 #include <QGraphicsRectItem>
+#include <QDomElement>
 
 #include <KDebug>
+#include <kdeversion.h>
 
+#if KDE_IS_VERSION(4,7,0)
+#include <KMessageWidget>
+#endif
+
+#include "dvdwizardvob.h"
 #include "ui_dvdwizardmenu_ui.h"
 
 class DvdScene : public QGraphicsScene
 {
-
+    Q_OBJECT
 public:
-    DvdScene(QObject * parent = 0): QGraphicsScene(parent) {}
+    DvdScene(QObject * parent = 0): QGraphicsScene(parent) {
+        m_width = 0; m_height = 0;
+    }
     void setProfile(int width, int height) {
         m_width = width;
         m_height = height;
@@ -50,50 +59,88 @@ public:
 private:
     int m_width;
     int m_height;
+    
+protected:
+    void mouseReleaseEvent( QGraphicsSceneMouseEvent * mouseEvent ) {
+        QGraphicsScene::mouseReleaseEvent(mouseEvent);
+        emit sceneChanged();
+    }
+signals:
+    void sceneChanged();
+};
+
+class DvdButtonUnderline : public QGraphicsRectItem
+{
+
+public:
+    DvdButtonUnderline( const QRectF & rect, QGraphicsItem * parent = 0 ) : QGraphicsRectItem(rect, parent) {}
+
+    int type() const {
+        // Enable the use of qgraphicsitem_cast with this item.
+        return UserType + 2;
+    }
 };
 
 class DvdButton : public QGraphicsTextItem
 {
 
 public:
-    DvdButton(const QString & text): QGraphicsTextItem(text), m_target(0) {}
-    enum { Type = UserType + 1 };
-    void setTarget(int t) {
+    DvdButton(const QString & text): QGraphicsTextItem(text), m_target(0), m_command(QString("jump title 1")), m_backToMenu(false) {
+        setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
+#if QT_VERSION >= 0x040600
+        setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
+#endif
+    }
+    void setTarget(int t, const QString &c) {
         m_target = t;
+        m_command = c;
     }
     int target() const {
         return m_target;
     }
+    QString command() const {
+        return m_command;
+    }
+    bool backMenu() const {
+        return m_backToMenu;
+    }
     int type() const {
         // Enable the use of qgraphicsitem_cast with this item.
-        return Type;
+        return UserType + 1;
+    }
+    void setBackMenu(bool back) {
+        m_backToMenu = back;
     }
 
 private:
     int m_target;
-
+    QString m_command;
+    bool m_backToMenu;
 
 protected:
 
     virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value) {
         if (change == ItemPositionChange && scene()) {
-
-            /*   QList<QGraphicsItem *> list = collidingItems();
-               if (!list.isEmpty()) {
-                   for (int i = 0; i < list.count(); i++) {
-                if (list.at(i)->type() == Type) return pos();
-                   }
-               }
-            */
+            QPoint newPos = value.toPoint();
+            QRectF sceneShape = sceneBoundingRect();
             DvdScene *sc = static_cast < DvdScene * >(scene());
-            QRectF rect = QRectF(0, 0, sc->width(), sc->height());
-            QPointF newPos = value.toPointF();
-            if (!rect.contains(newPos)) {
-                // Keep the item inside the scene rect.
-                newPos.setX(qMin(rect.right(), qMax(newPos.x(), rect.left())));
-                newPos.setY(qMin(rect.bottom(), qMax(newPos.y(), rect.top())));
-                return newPos;
+            newPos.setX(qMax(newPos.x(), 0));
+            newPos.setY(qMax(newPos.y(), 0));
+            if (newPos.x() + sceneShape.width() > sc->width())
+                newPos.setX(sc->width() - sceneShape.width());
+            if (newPos.y() + sceneShape.height() > sc->height())
+                newPos.setY(sc->height() - sceneShape.height());
+
+            sceneShape.translate(newPos - pos());
+            QList<QGraphicsItem*> list = scene()->items(sceneShape, Qt::IntersectsItemShape);
+            list.removeAll(this);
+            if (!list.isEmpty()) {
+                for (int i = 0; i < list.count(); ++i) {
+                    if (list.at(i)->type() == Type)
+                        return pos();
+                }
             }
+            return newPos;
         }
         return QGraphicsItem::itemChange(change, value);
     }
@@ -106,28 +153,38 @@ class DvdWizardMenu : public QWizardPage
     Q_OBJECT
 
 public:
-    explicit DvdWizardMenu(const QString &profile, QWidget * parent = 0);
+    explicit DvdWizardMenu(DVDFORMAT format, QWidget * parent = 0);
     virtual ~DvdWizardMenu();
     virtual bool isComplete() const;
     bool createMenu() const;
-    void createBackgroundImage(const QString &img1);
-    void createButtonImages(const QString &img1, const QString &img2, const QString &img3);
-    void setTargets(QStringList list);
-    QMap <int, QRect> buttonsInfo();
+    void createBackgroundImage(const QString &img1, bool letterbox);
+    void createButtonImages(const QString &selected_image, const QString &highlighted_image, bool letterbox);
+    void setTargets(const QStringList &list, const QStringList &targetlist);
+    QMap <QString, QRect> buttonsInfo(bool letterbox = false);
+    bool loopMovie() const;
     bool menuMovie() const;
     QString menuMoviePath() const;
-    bool isPalMenu() const;
+    int menuMovieLength() const;
+    void changeProfile(DVDFORMAT format);
+    QDomElement toXml() const;
+    void loadXml(DVDFORMAT format, const QDomElement &xml);
+    void prepareUnderLines();
+    void resetUnderLines();
 
 private:
     Ui::DvdWizardMenu_UI m_view;
-    bool m_isPal;
+    DVDFORMAT m_format;
     DvdScene *m_scene;
     QGraphicsPixmapItem *m_background;
     QGraphicsRectItem *m_color;
     QGraphicsRectItem *m_safeRect;
     int m_width;
     int m_height;
-    QStringList m_targets;
+    QSize m_finalSize;
+    int m_movieLength;
+#if KDE_IS_VERSION(4,7,0)
+    KMessageWidget *m_menuMessage;
+#endif
 
 private slots:
     void buildButton();
@@ -135,14 +192,18 @@ private slots:
     void buildImage();
     void checkBackground();
     void checkBackgroundType(int ix);
-    void changeProfile(int ix);
     void updatePreview();
     void buttonChanged();
     void addButton();
     void setButtonTarget(int ix);
     void deleteButton();
     void updateColor();
-    void updateColor(QColor c);
+    void updateColor(const QColor &c);
+    void updateUnderlineColor(QColor c);
+    void setBackToMenu(bool backToMenu);
+    void slotZoom();
+    void slotUnZoom();
+    void slotEnableShadows(int enable);
 };
 
 #endif