1 /***************************************************************************
2 * Copyright (C) 2008 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
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. *
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. *
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 ***************************************************************************/
21 #ifndef RENDERWIDGET_H
22 #define RENDERWIDGET_H
25 #include <QPushButton>
27 #include <QItemDelegate>
29 #include "definitions.h"
30 #include "ui_renderwidget_ui.h"
33 // RenderViewDelegate is used to draw the progress bars.
34 class RenderViewDelegate : public QItemDelegate {
37 RenderViewDelegate(QWidget *parent) : QItemDelegate(parent) {}
39 void paint(QPainter *painter, const QStyleOptionViewItem &option,
40 const QModelIndex &index) const {
41 if (index.column() == 0) {
42 QItemDelegate::paint(painter, option, index);
44 } else if (index.column() == 1) {
45 QRect r1 = option.rect;
47 if (option.state & (QStyle::State_Selected)) {
48 painter->setPen(option.palette.color(QPalette::HighlightedText));
49 painter->fillRect(r1, option.palette.highlight());
50 } else painter->setPen(option.palette.color(QPalette::Text));
51 QFont font = painter->font();
53 painter->setFont(font);
54 int mid = (int)((r1.height() / 2));
55 r1.setBottom(r1.y() + mid);
56 QRect r2 = option.rect;
57 r2.setTop(r2.y() + mid);
58 painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data().toString());
60 painter->setFont(font);
61 painter->setPen(option.palette.color(QPalette::Mid));
62 painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , index.data(Qt::UserRole).toString());
66 // Set up a QStyleOptionProgressBar to precisely mimic the
67 // environment of a progress bar.
68 QStyleOptionProgressBar progressBarOption;
69 progressBarOption.state = option.state;
70 progressBarOption.direction = QApplication::layoutDirection();
71 QRect rect = option.rect;
72 if (option.state & (QStyle::State_Selected)) {
73 painter->setPen(option.palette.color(QPalette::HighlightedText));
74 painter->fillRect(rect, option.palette.highlight());
77 int mid = rect.height() / 2;
78 rect.setTop(rect.top() + mid / 2);
80 progressBarOption.rect = rect;
81 progressBarOption.fontMetrics = QApplication::fontMetrics();
82 progressBarOption.minimum = 0;
83 progressBarOption.maximum = 100;
84 progressBarOption.textAlignment = Qt::AlignCenter;
85 progressBarOption.textVisible = true;
87 // Set the progress and text values of the style option.
88 int progress = index.data(Qt::UserRole).toInt();
89 progressBarOption.progress = progress < 0 ? 0 : progress;
90 progressBarOption.text = QString().sprintf("%d%%", progressBarOption.progress);
92 // Draw the progress bar onto the view.
93 QApplication::style()->drawControl(QStyle::CE_ProgressBar, &progressBarOption, painter);
98 // RenderScriptDelegate is used to draw the script items.
99 class RenderScriptDelegate : public QItemDelegate {
102 RenderScriptDelegate(QWidget *parent) : QItemDelegate(parent) {}
104 void paint(QPainter *painter, const QStyleOptionViewItem &option,
105 const QModelIndex &index) const {
106 if (index.column() == 0) {
107 QRect r1 = option.rect;
109 if (option.state & (QStyle::State_Selected)) {
110 painter->setPen(option.palette.color(QPalette::HighlightedText));
111 painter->fillRect(r1, option.palette.highlight());
112 } else painter->setPen(option.palette.color(QPalette::Text));
113 QFont font = painter->font();
115 painter->setFont(font);
116 int mid = (int)((r1.height() / 2));
117 r1.setBottom(r1.y() + mid);
118 r1.setLeft(r1.left() + 3);
119 QRect r2 = option.rect;
120 r2.setTop(r2.y() + mid);
121 r2.setLeft(r2.left() + 3);
122 painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data().toString());
124 painter->setFont(font);
125 painter->setPen(option.palette.color(QPalette::Mid));
126 painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , index.data(Qt::UserRole).toString());
129 } else QItemDelegate::paint(painter, option, index);
133 class RenderWidget : public QDialog {
137 explicit RenderWidget(const QString &projectfolder, QWidget * parent = 0);
138 void setGuides(QDomElement guidesxml, double duration);
139 void focusFirstVisibleItem();
140 void setProfile(MltVideoProfile profile);
141 void setRenderJob(const QString &dest, int progress = 0);
142 void setRenderStatus(const QString &dest, int status, const QString &error);
143 void setDocumentPath(const QString path);
144 void reloadProfiles();
147 void slotUpdateButtons(KUrl url);
148 void slotUpdateButtons();
149 void slotExport(bool scriptExport = false);
151 void refreshParams();
152 void slotSaveProfile();
153 void slotEditProfile();
154 void slotDeleteProfile(bool refresh = true);
155 void slotUpdateGuideBox();
156 void slotCheckStartGuidePosition();
157 void slotCheckEndGuidePosition();
158 void showInfoPanel();
159 void slotAbortCurrentJob();
160 void slotStartScript();
161 void slotDeleteScript();
162 void slotGenerateScript();
163 void parseScriptFiles();
164 void slotCheckScript();
166 void slotEditItem(QListWidgetItem *item);
169 Ui::RenderWidget_UI m_view;
170 MltVideoProfile m_profile;
171 QString m_projectFolder;
172 void parseProfiles(QString meta = QString(), QString group = QString(), QString profile = QString());
173 void parseFile(QString exportFile, bool editable);
174 void updateButtons();
175 KUrl filenameWithExtension(KUrl url, QString extension);
178 void doRender(const QString&, const QString&, const QStringList &, const QStringList &, bool, bool, double, double, bool, const QString &);
179 void abortProcess(const QString &url);
180 void openDvdWizard(const QString &url, const QString &profile);