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 QStyledItemDelegate::paint(painter, option, index);
95 class RenderJobItem: public QTreeWidgetItem
98 explicit RenderJobItem(QTreeWidget * parent, const QStringList & strings, int type = QTreeWidgetItem::Type);
99 void setStatus(int status);
101 void setMetadata(const QString &data);
102 const QString metadata() const;
110 class RenderWidget : public QDialog
115 explicit RenderWidget(const QString &projectfolder, bool enableProxy, MltVideoProfile profile, QWidget * parent = 0);
116 virtual ~RenderWidget();
117 void setGuides(QDomElement guidesxml, double duration);
118 void focusFirstVisibleItem();
119 void setProfile(MltVideoProfile profile);
120 void setRenderJob(const QString &dest, int progress = 0);
121 void setRenderStatus(const QString &dest, int status, const QString &error);
122 void setDocumentPath(const QString &path);
123 void reloadProfiles();
124 void setRenderProfile(QMap <QString, QString> props);
125 int waitingJobsCount() const;
126 QString getFreeScriptName(const QString &prefix = QString());
127 bool startWaitingRenderJobs();
128 void missingClips(bool hasMissing);
129 /** @brief Returns true if the export audio checkbox is set to automatic. */
130 bool automaticAudioExport() const;
131 /** @brief Returns true if user wants audio export. */
132 bool selectedAudioExport() const;
133 /** @brief Show / hide proxy settings. */
134 void updateProxyConfig(bool enable);
135 /** @brief Should we render using proxy clips. */
136 bool proxyRendering();
139 virtual QSize sizeHint() const;
142 void slotExport(bool scriptExport, int zoneIn, int zoneOut, const QString &playlistPath, const QString &scriptPath, bool exportAudio);
145 void slotUpdateButtons(KUrl url);
146 void slotUpdateButtons();
148 void refreshCategory();
150 /** @brief Updates available options when a new format has been selected. */
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);
167 void slotCLeanUpJobs();
169 void slotPrepareExport(bool scriptExport = false);
170 void slotPlayRendering(QTreeWidgetItem *item, int);
171 void slotStartCurrentJob();
172 void slotCopyToFavorites();
173 void slotUpdateEncodeThreads(int);
174 void slotUpdateRescaleHeight(int);
175 void slotUpdateRescaleWidth(int);
176 void slotSwitchAspectRatio();
177 /** @brief Update export audio label depending on current settings. */
178 void slotUpdateAudioLabel(int ix);
179 /** @brief Enable / disable the rescale options. */
180 void setRescaleEnabled(bool enable);
183 Ui::RenderWidget_UI m_view;
184 QString m_projectFolder;
185 MltVideoProfile m_profile;
186 RenderViewDelegate *m_scriptsDelegate;
187 RenderViewDelegate *m_jobsDelegate;
188 bool m_blockProcessing;
191 #if KDE_IS_VERSION(4,7,0)
192 KMessageWidget *m_infoMessage;
195 void parseProfiles(QString meta = QString(), QString group = QString(), QString profile = QString());
196 void parseFile(QString exportFile, bool editable);
197 void updateButtons();
198 KUrl filenameWithExtension(KUrl url, QString extension);
199 /** @brief Check if a job needs to be started. */
200 void checkRenderStatus();
201 void startRendering(RenderJobItem *item);
202 void saveProfile(QDomElement newprofile);
203 QList <QListWidgetItem *> m_renderItems;
204 QList <QListWidgetItem *> m_renderCategory;
205 void errorMessage(const QString &message);
208 void abortProcess(const QString &url);
209 void openDvdWizard(const QString &url, const QString &profile);
210 /** Send the infos about rendering that will be saved in the document:
211 (profile destination, profile name and url of rendered file */
212 void selectedRenderProfile(QMap <QString, QString> renderProps);
213 void prepareRenderingData(bool scriptExport, bool zoneOnly, const QString &chapterFile);