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, 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;
132 void slotExport(bool scriptExport, int zoneIn, int zoneOut, const QString &playlistPath, const QString &scriptPath, bool exportAudio);
135 void slotUpdateButtons(KUrl url);
136 void slotUpdateButtons();
138 void refreshCategory();
140 /** @brief Updates available options when a new format has been selected. */
141 void refreshParams();
142 void slotSaveProfile();
143 void slotEditProfile();
144 void slotDeleteProfile(bool refresh = true);
145 void slotUpdateGuideBox();
146 void slotCheckStartGuidePosition();
147 void slotCheckEndGuidePosition();
148 void showInfoPanel();
149 void slotAbortCurrentJob();
150 void slotStartScript();
151 void slotDeleteScript();
152 void slotGenerateScript();
153 void parseScriptFiles();
154 void slotCheckScript();
156 void slotEditItem(QListWidgetItem *item);
157 void slotCLeanUpJobs();
159 void slotPrepareExport(bool scriptExport = false);
160 void slotPlayRendering(QTreeWidgetItem *item, int);
161 void slotStartCurrentJob();
162 void slotCopyToFavorites();
163 void slotUpdateRescaleHeight(int);
164 void slotUpdateRescaleWidth(int);
165 void slotSwitchAspectRatio();
166 /** @brief Update export audio label depending on current settings. */
167 void slotUpdateAudioLabel(int ix);
170 Ui::RenderWidget_UI m_view;
171 MltVideoProfile m_profile;
172 QString m_projectFolder;
173 RenderViewDelegate *m_scriptsDelegate;
174 RenderViewDelegate *m_jobsDelegate;
175 bool m_blockProcessing;
177 void parseProfiles(QString meta = QString(), QString group = QString(), QString profile = QString());
178 void parseFile(QString exportFile, bool editable);
179 void updateButtons();
180 KUrl filenameWithExtension(KUrl url, QString extension);
181 void checkRenderStatus();
182 void startRendering(QTreeWidgetItem *item);
183 void saveProfile(QDomElement newprofile);
184 QList <QListWidgetItem *> m_renderItems;
185 QList <QListWidgetItem *> m_renderCategory;
188 void abortProcess(const QString &url);
189 void openDvdWizard(const QString &url, const QString &profile);
190 /** Send the infos about rendering that will be saved in the document:
191 (profile destination, profile name and url of rendered file */
192 void selectedRenderProfile(QMap <QString, QString> renderProps);
193 void prepareRenderingData(bool scriptExport, bool zoneOnly, const QString &chapterFile);