]> git.sesse.net Git - kdenlive/blob - src/dvdwizardvob.h
const'ref. Fix coding style. Minor optimization
[kdenlive] / src / dvdwizardvob.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 DVDWIZARDVOB_H
22 #define DVDWIZARDVOB_H
23
24 #include "ui_dvdwizardvob_ui.h"
25
26 #include <kdeversion.h>
27 #include <kcapacitybar.h>
28 #include <KUrl>
29
30 #if KDE_IS_VERSION(4,7,0)
31 #include <KMessageWidget>
32 #endif
33
34 #include <QWizardPage>
35 #include <QStyledItemDelegate>
36 #include <QPainter>
37 #include <QTreeWidget>
38 #include <QDragEnterEvent>
39 #include <QDropEvent>
40
41 enum DVDFORMAT { PAL, PAL_WIDE, NTSC, NTSC_WIDE };
42
43 class DvdTreeWidget : public QTreeWidget
44 {
45     Q_OBJECT
46 public:
47     explicit DvdTreeWidget(QWidget *parent);
48
49 protected:
50     void dragEnterEvent(QDragEnterEvent * event );
51     void dropEvent(QDropEvent * event );
52     void mouseDoubleClickEvent( QMouseEvent * );
53     void dragMoveEvent(QDragMoveEvent * event);
54
55 signals:
56     void addNewClip();
57     void addClips(const QList<QUrl>&);
58 };
59
60 class DvdViewDelegate : public QStyledItemDelegate
61 {
62     Q_OBJECT
63 public:
64     DvdViewDelegate(QWidget *parent) : QStyledItemDelegate(parent) {}
65
66     void paint(QPainter *painter, const QStyleOptionViewItem &option,
67                const QModelIndex &index) const {
68         if (index.column() == 0) {
69             painter->save();
70             QStyleOptionViewItemV4 opt(option);
71             QRect r1 = option.rect;
72             QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
73             const int textMargin = style->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
74             style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);
75
76             QPixmap pixmap = qVariantValue<QPixmap>(index.data(Qt::DecorationRole));
77             QPoint pixmapPoint(r1.left() + textMargin, r1.top() + (r1.height() - pixmap.height()) / 2);
78             painter->drawPixmap(pixmapPoint, pixmap);
79             int decoWidth = pixmap.width() + 2 * textMargin;
80
81             QFont font = painter->font();
82             font.setBold(true);
83             painter->setFont(font);
84             int mid = (int)((r1.height() / 2));
85             r1.adjust(decoWidth, 0, 0, -mid);
86             QRect r2 = option.rect;
87             r2.adjust(decoWidth, mid, 0, 0);
88             painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom, KUrl(index.data().toString()).fileName());
89             font.setBold(false);
90             painter->setFont(font);
91             QString subText = index.data(Qt::UserRole).toString();
92             QRectF bounding;
93             painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , subText, &bounding);
94             painter->restore();
95         } else {
96             QStyledItemDelegate::paint(painter, option, index);
97         }
98     }
99 };
100
101
102 class DvdWizardVob : public QWizardPage
103 {
104     Q_OBJECT
105
106 public:
107     explicit DvdWizardVob(QWidget * parent = 0);
108     virtual ~DvdWizardVob();
109     virtual bool isComplete() const;
110     QStringList selectedUrls() const;
111     void setUrl(const QString &url);
112     DVDFORMAT dvdFormat() const;
113     const QString dvdProfile() const;
114     int duration(int ix) const;
115     QStringList durations() const;
116     QStringList chapters() const;
117     void setProfile(const QString& profile);
118     void clear();
119     const QString introMovie() const;
120     void setUseIntroMovie(bool use);
121     void updateChapters(const QMap<QString, QString> &chaptersdata);
122     static QString getDvdProfile(DVDFORMAT format);
123
124 private:
125     Ui::DvdWizardVob_UI m_view;
126     DvdTreeWidget *m_vobList;
127     KCapacityBar *m_capacityBar;
128     QAction *m_transcodeAction;
129     bool m_installCheck;
130 #if KDE_IS_VERSION(4,7,0)
131     KMessageWidget *m_warnMessage;
132 #endif
133     void showProfileError();
134     void showError(const QString &error);
135
136 public slots:
137     void slotAddVobFile(KUrl url = KUrl(), const QString &chapters = QString(), bool checkFormats = true);
138     void slotAddVobList(const QList<QUrl> &list);
139     void slotCheckProfiles();
140
141 private slots:
142     void slotCheckVobList();
143     void slotDeleteVobFile();
144     void slotItemUp();
145     void slotItemDown();
146     void slotTranscodeFiles();
147     void slotTranscodedClip(KUrl, KUrl);
148     
149 signals:
150     void prepareMonitor();
151 };
152
153 #endif
154