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 <QItemDelegate>
28 #include "definitions.h"
29 #include "ui_renderwidget_ui.h"
34 // RenderViewDelegate is used to draw the progress bars.
35 class RenderViewDelegate : public QItemDelegate {
38 RenderViewDelegate(QWidget *parent) : QItemDelegate(parent) {}
40 void paint(QPainter *painter, const QStyleOptionViewItem &option,
41 const QModelIndex &index) const {
42 if (index.column() == 0) {
43 QItemDelegate::paint(painter, option, index);
45 } else if (index.column() == 1) {
46 QRect r1 = option.rect;
48 if (option.state & (QStyle::State_Selected)) {
49 painter->setPen(option.palette.color(QPalette::HighlightedText));
50 painter->fillRect(r1, option.palette.highlight());
51 } else painter->setPen(option.palette.color(QPalette::Text));
52 QFont font = painter->font();
54 painter->setFont(font);
55 int mid = (int)((r1.height() / 2));
56 r1.setBottom(r1.y() + mid);
57 QRect r2 = option.rect;
58 r2.setTop(r2.y() + mid);
59 painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data().toString());
61 painter->setFont(font);
62 painter->setPen(option.palette.color(QPalette::Mid));
63 painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , index.data(Qt::UserRole).toString());
67 // Set up a QStyleOptionProgressBar to precisely mimic the
68 // environment of a progress bar.
69 QStyleOptionProgressBar progressBarOption;
70 progressBarOption.state = option.state;
71 progressBarOption.direction = QApplication::layoutDirection();
72 QRect rect = option.rect;
73 if (option.state & (QStyle::State_Selected)) {
74 painter->setPen(option.palette.color(QPalette::HighlightedText));
75 painter->fillRect(rect, option.palette.highlight());
78 int mid = rect.height() / 2;
79 rect.setTop(rect.top() + mid / 2);
81 progressBarOption.rect = rect;
82 progressBarOption.fontMetrics = QApplication::fontMetrics();
83 progressBarOption.minimum = 0;
84 progressBarOption.maximum = 100;
85 progressBarOption.textAlignment = Qt::AlignCenter;
86 progressBarOption.textVisible = true;
88 // Set the progress and text values of the style option.
89 int progress = index.data(Qt::UserRole).toInt();
90 progressBarOption.progress = progress < 0 ? 0 : progress;
91 progressBarOption.text = QString().sprintf("%d%%", progressBarOption.progress);
93 // Draw the progress bar onto the view.
94 QApplication::style()->drawControl(QStyle::CE_ProgressBar, &progressBarOption, painter);
99 // RenderScriptDelegate is used to draw the script items.
100 class RenderScriptDelegate : public QItemDelegate {
103 RenderScriptDelegate(QWidget *parent) : QItemDelegate(parent) {}
105 void paint(QPainter *painter, const QStyleOptionViewItem &option,
106 const QModelIndex &index) const {
107 if (index.column() == 0) {
108 QRect r1 = option.rect;
110 if (option.state & (QStyle::State_Selected)) {
111 painter->setPen(option.palette.color(QPalette::HighlightedText));
112 painter->fillRect(r1, option.palette.highlight());
113 } else painter->setPen(option.palette.color(QPalette::Text));
114 QFont font = painter->font();
116 painter->setFont(font);
117 int mid = (int)((r1.height() / 2));
118 r1.setBottom(r1.y() + mid);
119 r1.setLeft(r1.left() + 3);
120 QRect r2 = option.rect;
121 r2.setTop(r2.y() + mid);
122 r2.setLeft(r2.left() + 3);
123 painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data().toString());
125 painter->setFont(font);
126 painter->setPen(option.palette.color(QPalette::Mid));
127 painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , index.data(Qt::UserRole).toString());
130 } else QItemDelegate::paint(painter, option, index);
134 class RenderWidget : public QDialog {
138 explicit RenderWidget(const QString &projectfolder, QWidget * parent = 0);
139 void setGuides(QDomElement guidesxml, double duration);
140 void focusFirstVisibleItem();
141 void setProfile(MltVideoProfile profile);
142 void setRenderJob(const QString &dest, int progress = 0);
143 void setRenderStatus(const QString &dest, int status, const QString &error);
144 void setDocumentPath(const QString path);
145 void reloadProfiles();
148 void slotUpdateButtons(KUrl url);
149 void slotUpdateButtons();
150 void slotExport(bool scriptExport = false);
152 void refreshParams();
153 void slotSaveProfile();
154 void slotEditProfile();
155 void slotDeleteProfile(bool refresh = true);
156 void slotUpdateGuideBox();
157 void slotCheckStartGuidePosition();
158 void slotCheckEndGuidePosition();
159 void showInfoPanel();
160 void slotAbortCurrentJob();
161 void slotStartScript();
162 void slotDeleteScript();
163 void slotGenerateScript();
164 void parseScriptFiles();
165 void slotCheckScript();
167 void slotEditItem(QListWidgetItem *item);
170 Ui::RenderWidget_UI m_view;
171 MltVideoProfile m_profile;
172 QString m_projectFolder;
173 void parseProfiles(QString meta = QString(), QString group = QString(), QString profile = QString());
174 void parseFile(QString exportFile, bool editable);
175 void updateButtons();
176 KUrl filenameWithExtension(KUrl url, QString extension);
179 void doRender(const QString&, const QString&, const QStringList &, const QStringList &, bool, bool, double, double, bool, const QString &);
180 void abortProcess(const QString &url);
181 void openDvdWizard(const QString &url, const QString &profile);