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) {
51 QStyleOptionViewItemV4 opt(option);
52 QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
53 const int textMargin = style->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
54 style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);
56 if (option.state & QStyle::State_Selected) {
57 painter->setPen(option.palette.highlightedText().color());
59 }// else painter->setPen(option.palette.color(QPalette::Text));
60 QFont font = painter->font();
62 painter->setFont(font);
63 QRect r1 = option.rect;
64 r1.adjust(0, textMargin, 0, - textMargin);
65 int mid = (int)((r1.height() / factor));
66 r1.setBottom(r1.y() + mid);
67 painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data().toString());
68 r1.setBottom(r1.bottom() + mid);
69 r1.setTop(r1.bottom() - mid);
71 painter->setFont(font);
72 painter->drawText(r1, Qt::AlignLeft | Qt::AlignVCenter , index.data(Qt::UserRole).toString());
74 r1.setBottom(r1.bottom() + mid);
75 r1.setTop(r1.bottom() - mid);
76 painter->drawText(r1, Qt::AlignLeft | Qt::AlignVCenter , index.data(Qt::UserRole + 5).toString());
79 } else if (index.column() == 2) {
80 // Set up a QStyleOptionProgressBar to precisely mimic the
81 // environment of a progress bar.
82 QStyleOptionViewItemV4 opt(option);
83 QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
84 style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);
86 QStyleOptionProgressBar progressBarOption;
87 progressBarOption.state = option.state;
88 progressBarOption.direction = QApplication::layoutDirection();
89 QRect rect = option.rect;
90 int mid = rect.height() / 2;
91 rect.setTop(rect.top() + mid / 2);
93 progressBarOption.rect = rect;
94 progressBarOption.fontMetrics = QApplication::fontMetrics();
95 progressBarOption.minimum = 0;
96 progressBarOption.maximum = 100;
97 progressBarOption.textAlignment = Qt::AlignCenter;
98 progressBarOption.textVisible = true;
100 // Set the progress and text values of the style option.
101 int progress = index.data(Qt::UserRole).toInt();
102 progressBarOption.progress = progress < 0 ? 0 : progress;
103 progressBarOption.text = QString().sprintf("%d%%", progressBarOption.progress);
105 // Draw the progress bar onto the view.
106 QApplication::style()->drawControl(QStyle::CE_ProgressBar, &progressBarOption, painter);
107 } else QStyledItemDelegate::paint(painter, option, index);
112 class RenderWidget : public QDialog
117 explicit RenderWidget(const QString &projectfolder, bool enableProxy, MltVideoProfile profile, QWidget * parent = 0);
118 virtual ~RenderWidget();
119 void setGuides(QDomElement guidesxml, double duration);
120 void focusFirstVisibleItem();
121 void setProfile(MltVideoProfile profile);
122 void setRenderJob(const QString &dest, int progress = 0);
123 void setRenderStatus(const QString &dest, int status, const QString &error);
124 void setDocumentPath(const QString &path);
125 void reloadProfiles();
126 void setRenderProfile(QMap <QString, QString> props);
127 int waitingJobsCount() const;
128 QString getFreeScriptName(const QString &prefix = QString());
129 bool startWaitingRenderJobs();
130 void missingClips(bool hasMissing);
131 /** @brief Returns true if the export audio checkbox is set to automatic. */
132 bool automaticAudioExport() const;
133 /** @brief Returns true if user wants audio export. */
134 bool selectedAudioExport() const;
135 /** @brief Show / hide proxy settings. */
136 void updateProxyConfig(bool enable);
137 /** @brief Should we render using proxy clips. */
138 bool proxyRendering();
141 virtual QSize sizeHint() const;
144 void slotExport(bool scriptExport, int zoneIn, int zoneOut, const QString &playlistPath, const QString &scriptPath, bool exportAudio);
147 void slotUpdateButtons(KUrl url);
148 void slotUpdateButtons();
150 void refreshCategory();
152 /** @brief Updates available options when a new format has been selected. */
153 void refreshParams();
154 void slotSaveProfile();
155 void slotEditProfile();
156 void slotDeleteProfile(bool refresh = true);
157 void slotUpdateGuideBox();
158 void slotCheckStartGuidePosition();
159 void slotCheckEndGuidePosition();
160 void showInfoPanel();
161 void slotAbortCurrentJob();
162 void slotStartScript();
163 void slotDeleteScript();
164 void slotGenerateScript();
165 void parseScriptFiles();
166 void slotCheckScript();
168 void slotEditItem(QListWidgetItem *item);
169 void slotCLeanUpJobs();
171 void slotPrepareExport(bool scriptExport = false);
172 void slotPlayRendering(QTreeWidgetItem *item, int);
173 void slotStartCurrentJob();
174 void slotCopyToFavorites();
175 void slotUpdateEncodeThreads(int);
176 void slotUpdateRescaleHeight(int);
177 void slotUpdateRescaleWidth(int);
178 void slotSwitchAspectRatio();
179 /** @brief Update export audio label depending on current settings. */
180 void slotUpdateAudioLabel(int ix);
181 /** @brief Enable / disable the rescale options. */
182 void setRescaleEnabled(bool enable);
185 Ui::RenderWidget_UI m_view;
186 QString m_projectFolder;
187 MltVideoProfile m_profile;
188 RenderViewDelegate *m_scriptsDelegate;
189 RenderViewDelegate *m_jobsDelegate;
190 bool m_blockProcessing;
193 #if KDE_IS_VERSION(4,7,0)
194 KMessageWidget *m_infoMessage;
197 void parseProfiles(QString meta = QString(), QString group = QString(), QString profile = QString());
198 void parseFile(QString exportFile, bool editable);
199 void updateButtons();
200 KUrl filenameWithExtension(KUrl url, QString extension);
201 void checkRenderStatus();
202 void startRendering(QTreeWidgetItem *item);
203 void saveProfile(QDomElement newprofile);
204 QList <QListWidgetItem *> m_renderItems;
205 QList <QListWidgetItem *> m_renderCategory;
206 void errorMessage(const QString &message);
209 void abortProcess(const QString &url);
210 void openDvdWizard(const QString &url, const QString &profile);
211 /** Send the infos about rendering that will be saved in the document:
212 (profile destination, profile name and url of rendered file */
213 void selectedRenderProfile(QMap <QString, QString> renderProps);
214 void prepareRenderingData(bool scriptExport, bool zoneOnly, const QString &chapterFile);