]> git.sesse.net Git - kdenlive/blob - src/renderwidget.h
Rendering scripts can now be generated from the render dialog:
[kdenlive] / src / renderwidget.h
1 /***************************************************************************
2  *   Copyright (C) 2008 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 RENDERWIDGET_H
22 #define RENDERWIDGET_H
23
24 #include <QDialog>
25 #include <QPushButton>
26 #include <QPainter>
27
28 #include "definitions.h"
29 #include "ui_renderwidget_ui.h"
30
31
32 // RenderViewDelegate is used to draw the progress bars.
33 class RenderViewDelegate : public QItemDelegate {
34     Q_OBJECT
35 public:
36     RenderViewDelegate(QWidget *parent) : QItemDelegate(parent) {}
37
38     void paint(QPainter *painter, const QStyleOptionViewItem &option,
39                const QModelIndex &index) const {
40         if (index.column() == 0) {
41             QItemDelegate::paint(painter, option, index);
42             return;
43         } else if (index.column() == 1) {
44             QRect r1 = option.rect;
45             painter->save();
46             if (option.state & (QStyle::State_Selected)) {
47                 painter->setPen(option.palette.color(QPalette::HighlightedText));
48                 painter->fillRect(r1, option.palette.highlight());
49             } else painter->setPen(option.palette.color(QPalette::Text));
50             QFont font = painter->font();
51             font.setBold(true);
52             painter->setFont(font);
53             int mid = (int)((r1.height() / 2));
54             r1.setBottom(r1.y() + mid);
55             QRect r2 = option.rect;
56             r2.setTop(r2.y() + mid);
57             painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data().toString());
58             font.setBold(false);
59             painter->setFont(font);
60             painter->setPen(option.palette.color(QPalette::Mid));
61             painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , index.data(Qt::UserRole).toString());
62             painter->restore();
63             return;
64         }
65         // Set up a QStyleOptionProgressBar to precisely mimic the
66         // environment of a progress bar.
67         QStyleOptionProgressBar progressBarOption;
68         progressBarOption.state = option.state;
69         progressBarOption.direction = QApplication::layoutDirection();
70         QRect rect = option.rect;
71         if (option.state & (QStyle::State_Selected)) {
72             painter->setPen(option.palette.color(QPalette::HighlightedText));
73             painter->fillRect(rect, option.palette.highlight());
74         }
75
76         int mid = rect.height() / 2;
77         rect.setTop(rect.top() + mid / 2);
78         rect.setHeight(mid);
79         progressBarOption.rect = rect;
80         progressBarOption.fontMetrics = QApplication::fontMetrics();
81         progressBarOption.minimum = 0;
82         progressBarOption.maximum = 100;
83         progressBarOption.textAlignment = Qt::AlignCenter;
84         progressBarOption.textVisible = true;
85
86         // Set the progress and text values of the style option.
87         int progress = index.data(Qt::UserRole).toInt();
88         progressBarOption.progress = progress < 0 ? 0 : progress;
89         progressBarOption.text = QString().sprintf("%d%%", progressBarOption.progress);
90
91         // Draw the progress bar onto the view.
92         QApplication::style()->drawControl(QStyle::CE_ProgressBar, &progressBarOption, painter);
93     }
94 };
95
96
97 // RenderScriptDelegate is used to draw the script items.
98 class RenderScriptDelegate : public QItemDelegate {
99     Q_OBJECT
100 public:
101     RenderScriptDelegate(QWidget *parent) : QItemDelegate(parent) {}
102
103     void paint(QPainter *painter, const QStyleOptionViewItem &option,
104                const QModelIndex &index) const {
105         if (index.column() == 0) {
106             QRect r1 = option.rect;
107             painter->save();
108             if (option.state & (QStyle::State_Selected)) {
109                 painter->setPen(option.palette.color(QPalette::HighlightedText));
110                 painter->fillRect(r1, option.palette.highlight());
111             } else painter->setPen(option.palette.color(QPalette::Text));
112             QFont font = painter->font();
113             font.setBold(true);
114             painter->setFont(font);
115             int mid = (int)((r1.height() / 2));
116             r1.setBottom(r1.y() + mid);
117             r1.setLeft(r1.left() + 3);
118             QRect r2 = option.rect;
119             r2.setTop(r2.y() + mid);
120             r2.setLeft(r2.left() + 3);
121             painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data().toString());
122             font.setBold(false);
123             painter->setFont(font);
124             painter->setPen(option.palette.color(QPalette::Mid));
125             painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , index.data(Qt::UserRole).toString());
126             painter->restore();
127             return;
128         } else QItemDelegate::paint(painter, option, index);
129     }
130 };
131
132 class RenderWidget : public QDialog {
133     Q_OBJECT
134
135 public:
136     RenderWidget(const QString &projectfolder, QWidget * parent = 0);
137     void setGuides(QDomElement guidesxml, double duration);
138     void focusFirstVisibleItem();
139     void setProfile(MltVideoProfile profile);
140     void setRenderJob(const QString &dest, int progress = 0);
141     void setRenderStatus(const QString &dest, int status, const QString &error);
142     void setDocumentPath(const QString path);
143
144 private slots:
145     void slotUpdateButtons(KUrl url);
146     void slotUpdateButtons();
147     void slotExport(bool scriptExport = false);
148     void refreshView();
149     void refreshParams();
150     void slotSaveProfile();
151     void slotEditProfile();
152     void slotDeleteProfile();
153     void slotUpdateGuideBox();
154     void slotCheckStartGuidePosition();
155     void slotCheckEndGuidePosition();
156     void showInfoPanel();
157     void slotAbortCurrentJob();
158     void slotStartScript();
159     void slotDeleteScript();
160     void slotGenerateScript();
161     void parseScriptFiles();
162     void slotCheckScript();
163     void slotCheckJob();
164
165 private:
166     Ui::RenderWidget_UI m_view;
167     MltVideoProfile m_profile;
168     QString m_projectFolder;
169     void parseProfiles(QString group = QString(), QString profile = QString());
170     void parseFile(QString exportFile, bool editable);
171     void updateButtons();
172     KUrl filenameWithExtension(KUrl url, QString extension);
173
174 signals:
175     void doRender(const QString&, const QString&, const QStringList &, const QStringList &, bool, bool, double, double, bool, const QString &);
176     void abortProcess(const QString &url);
177     void openDvdWizard(const QString &url, const QString &profile);
178 };
179
180
181 #endif
182