]> git.sesse.net Git - kdenlive/blob - src/renderwidget.h
5cadb060996427e23f54cc9513b75211c17c5494
[kdenlive] / src / renderwidget.h
1 /***************************************************************************
2  *   Copyright (C) 2008 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3  *                                                                         *
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.                                   *
8  *                                                                         *
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.                          *
13  *                                                                         *
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  ***************************************************************************/
19
20
21 #ifndef RENDERWIDGET_H
22 #define RENDERWIDGET_H
23
24 #include <kdeversion.h>
25 #if KDE_IS_VERSION(4,7,0)
26 #include <KMessageWidget>
27 #endif
28
29 #include <QPushButton>
30 #include <QPainter>
31 #include <QStyledItemDelegate>
32
33 #include "definitions.h"
34 #include "ui_renderwidget_ui.h"
35
36 class QDomElement;
37
38
39 // RenderViewDelegate is used to draw the progress bars.
40 class RenderViewDelegate : public QStyledItemDelegate
41 {
42     Q_OBJECT
43 public:
44     RenderViewDelegate(QWidget *parent) : QStyledItemDelegate(parent) {}
45
46     void paint(QPainter *painter, const QStyleOptionViewItem &option,
47                const QModelIndex &index) const {
48         if (index.column() == 1) {
49             painter->save();
50             int factor = 2;
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);
55
56             if (option.state & QStyle::State_Selected) {
57                 painter->setPen(option.palette.highlightedText().color());
58                 factor = 3;
59             }// else painter->setPen(option.palette.color(QPalette::Text));
60             QFont font = painter->font();
61             font.setBold(true);
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);
70             font.setBold(false);
71             painter->setFont(font);
72             painter->drawText(r1, Qt::AlignLeft | Qt::AlignVCenter , index.data(Qt::UserRole).toString());
73             if (factor > 2) {
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());
77             }
78             painter->restore();
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);
85
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);
92             rect.setHeight(mid);
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;
99
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);
104
105             // Draw the progress bar onto the view.
106             QApplication::style()->drawControl(QStyle::CE_ProgressBar, &progressBarOption, painter);
107         } else QStyledItemDelegate::paint(painter, option, index);
108     }
109 };
110
111
112 class RenderJobItem: public QTreeWidgetItem
113 {
114 public:
115     explicit RenderJobItem(QTreeWidget * parent, const QStringList & strings, int type = QTreeWidgetItem::Type);
116     void setStatus(int status);
117     int status() const;
118     void setMetadata(const QString &data);
119     const QString metadata() const;
120     void render();
121
122 private:
123     int m_status;
124     QString m_data;    
125 };
126
127 class RenderWidget : public QDialog
128 {
129     Q_OBJECT
130
131 public:
132     explicit RenderWidget(const QString &projectfolder, bool enableProxy, MltVideoProfile profile, QWidget * parent = 0);
133     virtual ~RenderWidget();
134     void setGuides(QDomElement guidesxml, double duration);
135     void focusFirstVisibleItem();
136     void setProfile(MltVideoProfile profile);
137     void setRenderJob(const QString &dest, int progress = 0);
138     void setRenderStatus(const QString &dest, int status, const QString &error);
139     void setDocumentPath(const QString &path);
140     void reloadProfiles();
141     void setRenderProfile(QMap <QString, QString> props);
142     int waitingJobsCount() const;
143     QString getFreeScriptName(const QString &prefix = QString());
144     bool startWaitingRenderJobs();
145     void missingClips(bool hasMissing);
146     /** @brief Returns true if the export audio checkbox is set to automatic. */
147     bool automaticAudioExport() const;
148     /** @brief Returns true if user wants audio export. */
149     bool selectedAudioExport() const;
150     /** @brief Show / hide proxy settings. */
151     void updateProxyConfig(bool enable);
152     /** @brief Should we render using proxy clips. */
153     bool proxyRendering();
154
155 protected:
156     virtual QSize sizeHint() const;
157
158 public slots:
159     void slotExport(bool scriptExport, int zoneIn, int zoneOut, const QString &playlistPath, const QString &scriptPath, bool exportAudio);
160
161 private slots:
162     void slotUpdateButtons(KUrl url);
163     void slotUpdateButtons();
164     void refreshView();
165     void refreshCategory();
166
167     /** @brief Updates available options when a new format has been selected. */
168     void refreshParams();
169     void slotSaveProfile();
170     void slotEditProfile();
171     void slotDeleteProfile(bool refresh = true);
172     void slotUpdateGuideBox();
173     void slotCheckStartGuidePosition();
174     void slotCheckEndGuidePosition();
175     void showInfoPanel();
176     void slotAbortCurrentJob();
177     void slotStartScript();
178     void slotDeleteScript();
179     void slotGenerateScript();
180     void parseScriptFiles();
181     void slotCheckScript();
182     void slotCheckJob();
183     void slotEditItem(QListWidgetItem *item);
184     void slotCLeanUpJobs();
185     void slotHideLog();
186     void slotPrepareExport(bool scriptExport = false);
187     void slotPlayRendering(QTreeWidgetItem *item, int);
188     void slotStartCurrentJob();
189     void slotCopyToFavorites();
190     void slotUpdateEncodeThreads(int);
191     void slotUpdateRescaleHeight(int);
192     void slotUpdateRescaleWidth(int);
193     void slotSwitchAspectRatio();
194     /** @brief Update export audio label depending on current settings. */
195     void slotUpdateAudioLabel(int ix);
196     /** @brief Enable / disable the rescale options. */
197     void setRescaleEnabled(bool enable);
198
199 private:
200     Ui::RenderWidget_UI m_view;
201     QString m_projectFolder;
202     MltVideoProfile m_profile;
203     RenderViewDelegate *m_scriptsDelegate;
204     RenderViewDelegate *m_jobsDelegate;
205     bool m_blockProcessing;
206     QString m_renderer;
207
208 #if KDE_IS_VERSION(4,7,0)
209     KMessageWidget *m_infoMessage;
210 #endif
211
212     void parseProfiles(QString meta = QString(), QString group = QString(), QString profile = QString());
213     void parseFile(QString exportFile, bool editable);
214     void updateButtons();
215     KUrl filenameWithExtension(KUrl url, QString extension);
216     /** @brief Check if a job needs to be started. */
217     void checkRenderStatus();
218     void startRendering(RenderJobItem *item);
219     void saveProfile(QDomElement newprofile);
220     QList <QListWidgetItem *> m_renderItems;
221     QList <QListWidgetItem *> m_renderCategory;
222     void errorMessage(const QString &message);
223
224 signals:
225     void abortProcess(const QString &url);
226     void openDvdWizard(const QString &url, const QString &profile);
227     /** Send the infos about rendering that will be saved in the document:
228     (profile destination, profile name and url of rendered file */
229     void selectedRenderProfile(QMap <QString, QString> renderProps);
230     void prepareRenderingData(bool scriptExport, bool zoneOnly, const QString &chapterFile);
231     void shutdown();
232 };
233
234
235 #endif
236