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 <kdeversion.h>
25 #if KDE_IS_VERSION(4,7,0)
26 #include <KMessageWidget>
29 #include <QPushButton>
31 #include <QStyledItemDelegate>
33 #include "definitions.h"
34 #include "ui_renderwidget_ui.h"
39 // RenderViewDelegate is used to draw the progress bars.
40 class RenderViewDelegate : public QStyledItemDelegate
44 RenderViewDelegate(QWidget *parent) : QStyledItemDelegate(parent) {}
46 void paint(QPainter *painter, const QStyleOptionViewItem &option,
47 const QModelIndex &index) const {
48 if (index.column() == 1) {
50 QStyleOptionViewItemV4 opt(option);
51 QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
52 const int textMargin = style->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
53 style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);
55 QFont font = painter->font();
57 painter->setFont(font);
58 QRect r1 = option.rect;
59 r1.adjust(0, textMargin, 0, - textMargin);
60 int mid = (int)((r1.height() / 2));
61 r1.setBottom(r1.y() + mid);
63 painter->drawText(r1, Qt::AlignLeft | Qt::AlignTop ,index.data().toString(), &bounding);
64 r1.moveTop(r1.bottom() - textMargin);
66 painter->setFont(font);
67 painter->drawText(r1, Qt::AlignLeft | Qt::AlignTop , index.data(Qt::UserRole).toString());
68 int progress = index.data(Qt::UserRole + 3).toInt();
69 if (progress > 0 && progress < 100) {
70 QColor color = option.palette.alternateBase().color();
71 QColor fgColor = option.palette.text().color();
73 fgColor.setAlpha(150);
74 painter->setBrush(QBrush(color));
75 painter->setPen(QPen(fgColor));
76 int width = qMin(200, r1.width() - 4);
77 QRect bgrect(r1.left() + 2, option.rect.bottom() - 6 - textMargin, width, 6);
78 painter->drawRect(bgrect);
79 painter->setBrush(QBrush(fgColor));
80 bgrect.adjust(2, 2, 0, -1);
81 painter->setPen(Qt::NoPen);
82 bgrect.setWidth((width - 2) * progress / 100);
83 painter->drawRect(bgrect);
85 r1.setBottom(opt.rect.bottom());
86 r1.setTop(r1.bottom() - mid);
87 painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data(Qt::UserRole + 5).toString());
90 } else if (index.column() == 2) {
91 // Set up a QStyleOptionProgressBar to precisely mimic the
92 // environment of a progress bar.
93 QStyleOptionViewItemV4 opt(option);
94 QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
95 style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);
97 QStyleOptionProgressBar progressBarOption;
98 progressBarOption.state = option.state;
99 progressBarOption.direction = QApplication::layoutDirection();
100 QRect rect = option.rect;
101 int mid = rect.height() / 2;
102 rect.setTop(rect.top() + mid / 2);
104 progressBarOption.rect = rect;
105 progressBarOption.fontMetrics = QApplication::fontMetrics();
106 progressBarOption.minimum = 0;
107 progressBarOption.maximum = 100;
108 progressBarOption.textAlignment = Qt::AlignCenter;
109 progressBarOption.textVisible = true;
111 // Set the progress and text values of the style option.
112 int progress = index.data(Qt::UserRole).toInt();
113 progressBarOption.progress = progress < 0 ? 0 : progress;
114 progressBarOption.text = QString().sprintf("%d%%", progressBarOption.progress);
116 // Draw the progress bar onto the view.
117 QApplication::style()->drawControl(QStyle::CE_ProgressBar, &progressBarOption, painter);
118 } else QStyledItemDelegate::paint(painter, option, index);
123 class RenderJobItem: public QTreeWidgetItem
126 explicit RenderJobItem(QTreeWidget * parent, const QStringList & strings, int type = QTreeWidgetItem::Type);
127 void setStatus(int status);
129 void setMetadata(const QString &data);
130 const QString metadata() const;
138 class RenderWidget : public QDialog
143 explicit RenderWidget(const QString &projectfolder, bool enableProxy, MltVideoProfile profile, QWidget * parent = 0);
144 virtual ~RenderWidget();
145 void setGuides(QDomElement guidesxml, double duration);
146 void focusFirstVisibleItem();
147 void setProfile(MltVideoProfile profile);
148 void setRenderJob(const QString &dest, int progress = 0);
149 void setRenderStatus(const QString &dest, int status, const QString &error);
150 void setDocumentPath(const QString &path);
151 void reloadProfiles();
152 void setRenderProfile(QMap <QString, QString> props);
153 int waitingJobsCount() const;
154 QString getFreeScriptName(const QString &prefix = QString());
155 bool startWaitingRenderJobs();
156 void missingClips(bool hasMissing);
157 /** @brief Returns true if the export audio checkbox is set to automatic. */
158 bool automaticAudioExport() const;
159 /** @brief Returns true if user wants audio export. */
160 bool selectedAudioExport() const;
161 /** @brief Show / hide proxy settings. */
162 void updateProxyConfig(bool enable);
163 /** @brief Should we render using proxy clips. */
164 bool proxyRendering();
167 virtual QSize sizeHint() const;
170 void slotExport(bool scriptExport, int zoneIn, int zoneOut, const QString &playlistPath, const QString &scriptPath, bool exportAudio);
173 void slotUpdateButtons(KUrl url);
174 void slotUpdateButtons();
176 void refreshCategory();
178 /** @brief Updates available options when a new format has been selected. */
179 void refreshParams();
180 void slotSaveProfile();
181 void slotEditProfile();
182 void slotDeleteProfile(bool refresh = true);
183 void slotUpdateGuideBox();
184 void slotCheckStartGuidePosition();
185 void slotCheckEndGuidePosition();
186 void showInfoPanel();
187 void slotAbortCurrentJob();
188 void slotStartScript();
189 void slotDeleteScript();
190 void slotGenerateScript();
191 void parseScriptFiles();
192 void slotCheckScript();
194 void slotEditItem(QListWidgetItem *item);
195 void slotCLeanUpJobs();
197 void slotPrepareExport(bool scriptExport = false);
198 void slotPlayRendering(QTreeWidgetItem *item, int);
199 void slotStartCurrentJob();
200 void slotCopyToFavorites();
201 void slotUpdateEncodeThreads(int);
202 void slotUpdateRescaleHeight(int);
203 void slotUpdateRescaleWidth(int);
204 void slotSwitchAspectRatio();
205 /** @brief Update export audio label depending on current settings. */
206 void slotUpdateAudioLabel(int ix);
207 /** @brief Enable / disable the rescale options. */
208 void setRescaleEnabled(bool enable);
211 Ui::RenderWidget_UI m_view;
212 QString m_projectFolder;
213 MltVideoProfile m_profile;
214 RenderViewDelegate *m_scriptsDelegate;
215 RenderViewDelegate *m_jobsDelegate;
216 bool m_blockProcessing;
219 #if KDE_IS_VERSION(4,7,0)
220 KMessageWidget *m_infoMessage;
223 void parseProfiles(QString meta = QString(), QString group = QString(), QString profile = QString());
224 void parseFile(QString exportFile, bool editable);
225 void updateButtons();
226 KUrl filenameWithExtension(KUrl url, QString extension);
227 /** @brief Check if a job needs to be started. */
228 void checkRenderStatus();
229 void startRendering(RenderJobItem *item);
230 void saveProfile(QDomElement newprofile);
231 QList <QListWidgetItem *> m_renderItems;
232 QList <QListWidgetItem *> m_renderCategory;
233 void errorMessage(const QString &message);
236 void abortProcess(const QString &url);
237 void openDvdWizard(const QString &url, const QString &profile);
238 /** Send the infos about rendering that will be saved in the document:
239 (profile destination, profile name and url of rendered file */
240 void selectedRenderProfile(QMap <QString, QString> renderProps);
241 void prepareRenderingData(bool scriptExport, bool zoneOnly, const QString &chapterFile);