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 <QStyledItemDelegate>
28 #include "definitions.h"
29 #include "ui_renderwidget_ui.h"
34 // RenderViewDelegate is used to draw the progress bars.
35 class RenderViewDelegate : public QStyledItemDelegate
39 RenderViewDelegate(QWidget *parent) : QStyledItemDelegate(parent) {}
41 void paint(QPainter *painter, const QStyleOptionViewItem &option,
42 const QModelIndex &index) const {
43 if (index.column() == 1) {
46 QStyleOptionViewItemV4 opt(option);
47 QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
48 const int textMargin = style->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
49 style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);
51 if (option.state & QStyle::State_Selected) {
52 painter->setPen(option.palette.highlightedText().color());
54 }// else painter->setPen(option.palette.color(QPalette::Text));
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() / factor));
61 r1.setBottom(r1.y() + mid);
62 painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data().toString());
63 r1.setBottom(r1.bottom() + mid);
64 r1.setTop(r1.bottom() - mid);
66 painter->setFont(font);
67 painter->drawText(r1, Qt::AlignLeft | Qt::AlignVCenter , index.data(Qt::UserRole).toString());
69 r1.setBottom(r1.bottom() + mid);
70 r1.setTop(r1.bottom() - mid);
71 painter->drawText(r1, Qt::AlignLeft | Qt::AlignVCenter , index.data(Qt::UserRole + 5).toString());
74 } else if (index.column() == 2) {
75 // Set up a QStyleOptionProgressBar to precisely mimic the
76 // environment of a progress bar.
77 QStyleOptionViewItemV4 opt(option);
78 QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
79 style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);
81 QStyleOptionProgressBar progressBarOption;
82 progressBarOption.state = option.state;
83 progressBarOption.direction = QApplication::layoutDirection();
84 QRect rect = option.rect;
85 int mid = rect.height() / 2;
86 rect.setTop(rect.top() + mid / 2);
88 progressBarOption.rect = rect;
89 progressBarOption.fontMetrics = QApplication::fontMetrics();
90 progressBarOption.minimum = 0;
91 progressBarOption.maximum = 100;
92 progressBarOption.textAlignment = Qt::AlignCenter;
93 progressBarOption.textVisible = true;
95 // Set the progress and text values of the style option.
96 int progress = index.data(Qt::UserRole).toInt();
97 progressBarOption.progress = progress < 0 ? 0 : progress;
98 progressBarOption.text = QString().sprintf("%d%%", progressBarOption.progress);
100 // Draw the progress bar onto the view.
101 QApplication::style()->drawControl(QStyle::CE_ProgressBar, &progressBarOption, painter);
102 } else QStyledItemDelegate::paint(painter, option, index);
107 class RenderWidget : public QDialog
112 explicit RenderWidget(const QString &projectfolder, bool enableProxy, QWidget * parent = 0);
113 virtual ~RenderWidget();
114 void setGuides(QDomElement guidesxml, double duration);
115 void focusFirstVisibleItem();
116 void setProfile(MltVideoProfile profile);
117 void setRenderJob(const QString &dest, int progress = 0);
118 void setRenderStatus(const QString &dest, int status, const QString &error);
119 void setDocumentPath(const QString path);
120 void reloadProfiles();
121 void setRenderProfile(QMap <QString, QString> props);
122 int waitingJobsCount() const;
123 QString getFreeScriptName(const QString &prefix = QString());
124 bool startWaitingRenderJobs();
125 void missingClips(bool hasMissing);
126 /** @brief Returns true if the export audio checkbox is set to automatic. */
127 bool automaticAudioExport() const;
128 /** @brief Returns true if user wants audio export. */
129 bool selectedAudioExport() const;
130 /** @brief Show / hide proxy settings. */
131 void updateProxyConfig(bool enable);
132 /** @brief Should we render using proxy clips. */
133 bool proxyRendering();
136 void slotExport(bool scriptExport, int zoneIn, int zoneOut, const QString &playlistPath, const QString &scriptPath, bool exportAudio);
139 void slotUpdateButtons(KUrl url);
140 void slotUpdateButtons();
142 void refreshCategory();
144 /** @brief Updates available options when a new format has been selected. */
145 void refreshParams();
146 void slotSaveProfile();
147 void slotEditProfile();
148 void slotDeleteProfile(bool refresh = true);
149 void slotUpdateGuideBox();
150 void slotCheckStartGuidePosition();
151 void slotCheckEndGuidePosition();
152 void showInfoPanel();
153 void slotAbortCurrentJob();
154 void slotStartScript();
155 void slotDeleteScript();
156 void slotGenerateScript();
157 void parseScriptFiles();
158 void slotCheckScript();
160 void slotEditItem(QListWidgetItem *item);
161 void slotCLeanUpJobs();
163 void slotPrepareExport(bool scriptExport = false);
164 void slotPlayRendering(QTreeWidgetItem *item, int);
165 void slotStartCurrentJob();
166 void slotCopyToFavorites();
167 void slotUpdateEncodeThreads(int);
168 void slotUpdateRescaleHeight(int);
169 void slotUpdateRescaleWidth(int);
170 void slotSwitchAspectRatio();
171 /** @brief Update export audio label depending on current settings. */
172 void slotUpdateAudioLabel(int ix);
175 Ui::RenderWidget_UI m_view;
176 MltVideoProfile m_profile;
177 QString m_projectFolder;
178 RenderViewDelegate *m_scriptsDelegate;
179 RenderViewDelegate *m_jobsDelegate;
180 bool m_blockProcessing;
182 void parseProfiles(QString meta = QString(), QString group = QString(), QString profile = QString());
183 void parseFile(QString exportFile, bool editable);
184 void updateButtons();
185 KUrl filenameWithExtension(KUrl url, QString extension);
186 void checkRenderStatus();
187 void startRendering(QTreeWidgetItem *item);
188 void saveProfile(QDomElement newprofile);
189 QList <QListWidgetItem *> m_renderItems;
190 QList <QListWidgetItem *> m_renderCategory;
193 void abortProcess(const QString &url);
194 void openDvdWizard(const QString &url, const QString &profile);
195 /** Send the infos about rendering that will be saved in the document:
196 (profile destination, profile name and url of rendered file */
197 void selectedRenderProfile(QMap <QString, QString> renderProps);
198 void prepareRenderingData(bool scriptExport, bool zoneOnly, const QString &chapterFile);