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
24 #include <QPushButton>
26 #include <QItemDelegate>
28 #include "definitions.h"
29 #include "ui_renderwidget_ui.h"
34 // RenderViewDelegate is used to draw the progress bars.
35 class RenderViewDelegate : public QItemDelegate
39 RenderViewDelegate(QWidget *parent) : QItemDelegate(parent) {}
41 void paint(QPainter *painter, const QStyleOptionViewItem &option,
42 const QModelIndex &index) const {
43 if (index.column() == 0) {
44 QItemDelegate::paint(painter, option, index);
46 } else if (index.column() == 1) {
47 QRect r1 = option.rect;
49 if (option.state & (QStyle::State_Selected)) {
50 painter->setPen(option.palette.color(QPalette::HighlightedText));
51 painter->fillRect(r1, option.palette.highlight());
52 } else painter->setPen(option.palette.color(QPalette::Text));
53 QFont font = painter->font();
55 painter->setFont(font);
56 int mid = (int)((r1.height() / 2));
57 r1.setBottom(r1.y() + mid);
58 QRect r2 = option.rect;
59 r2.setTop(r2.y() + mid);
60 painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data().toString());
62 painter->setFont(font);
63 painter->setPen(option.palette.color(QPalette::Mid));
64 painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , index.data(Qt::UserRole).toString());
68 // Set up a QStyleOptionProgressBar to precisely mimic the
69 // environment of a progress bar.
70 QStyleOptionProgressBar progressBarOption;
71 progressBarOption.state = option.state;
72 progressBarOption.direction = QApplication::layoutDirection();
73 QRect rect = option.rect;
74 if (option.state & (QStyle::State_Selected)) {
75 painter->setPen(option.palette.color(QPalette::HighlightedText));
76 painter->fillRect(rect, option.palette.highlight());
79 int mid = rect.height() / 2;
80 rect.setTop(rect.top() + mid / 2);
82 progressBarOption.rect = rect;
83 progressBarOption.fontMetrics = QApplication::fontMetrics();
84 progressBarOption.minimum = 0;
85 progressBarOption.maximum = 100;
86 progressBarOption.textAlignment = Qt::AlignCenter;
87 progressBarOption.textVisible = true;
89 // Set the progress and text values of the style option.
90 int progress = index.data(Qt::UserRole).toInt();
91 progressBarOption.progress = progress < 0 ? 0 : progress;
92 progressBarOption.text = QString().sprintf("%d%%", progressBarOption.progress);
94 // Draw the progress bar onto the view.
95 QApplication::style()->drawControl(QStyle::CE_ProgressBar, &progressBarOption, painter);
100 // RenderScriptDelegate is used to draw the script items.
101 class RenderScriptDelegate : public QItemDelegate
105 RenderScriptDelegate(QWidget *parent) : QItemDelegate(parent) {}
107 void paint(QPainter *painter, const QStyleOptionViewItem &option,
108 const QModelIndex &index) const {
109 if (index.column() == 0) {
110 QRect r1 = option.rect;
112 if (option.state & (QStyle::State_Selected)) {
113 painter->setPen(option.palette.color(QPalette::HighlightedText));
114 painter->fillRect(r1, option.palette.highlight());
115 } else painter->setPen(option.palette.color(QPalette::Text));
116 QFont font = painter->font();
118 painter->setFont(font);
119 int mid = (int)((r1.height() / 2));
120 r1.setBottom(r1.y() + mid);
121 r1.setLeft(r1.left() + 3);
122 QRect r2 = option.rect;
123 r2.setTop(r2.y() + mid);
124 r2.setLeft(r2.left() + 3);
125 painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data().toString());
127 painter->setFont(font);
128 painter->setPen(option.palette.color(QPalette::Mid));
129 painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , index.data(Qt::UserRole).toString());
132 } else QItemDelegate::paint(painter, option, index);
136 class RenderWidget : public QDialog
141 explicit RenderWidget(const QString &projectfolder, QWidget * parent = 0);
142 void setGuides(QDomElement guidesxml, double duration);
143 void focusFirstVisibleItem();
144 void setProfile(MltVideoProfile profile);
145 void setRenderJob(const QString &dest, int progress = 0);
146 void setRenderStatus(const QString &dest, int status, const QString &error);
147 void setDocumentPath(const QString path);
148 void reloadProfiles();
151 void slotUpdateButtons(KUrl url);
152 void slotUpdateButtons();
153 void slotExport(bool scriptExport = false);
155 void refreshParams();
156 void slotSaveProfile();
157 void slotEditProfile();
158 void slotDeleteProfile(bool refresh = true);
159 void slotUpdateGuideBox();
160 void slotCheckStartGuidePosition();
161 void slotCheckEndGuidePosition();
162 void showInfoPanel();
163 void slotAbortCurrentJob();
164 void slotStartScript();
165 void slotDeleteScript();
166 void slotGenerateScript();
167 void parseScriptFiles();
168 void slotCheckScript();
170 void slotEditItem(QListWidgetItem *item);
173 Ui::RenderWidget_UI m_view;
174 MltVideoProfile m_profile;
175 QString m_projectFolder;
176 void parseProfiles(QString meta = QString(), QString group = QString(), QString profile = QString());
177 void parseFile(QString exportFile, bool editable);
178 void updateButtons();
179 KUrl filenameWithExtension(KUrl url, QString extension);
182 void doRender(const QString&, const QString&, const QStringList &, const QStringList &, bool, bool, double, double, bool, const QString &);
183 void abortProcess(const QString &url);
184 void openDvdWizard(const QString &url, const QString &profile);