]> git.sesse.net Git - kdenlive/blob - src/renderwidget.h
Fix detection of missing codecs in render dialog, use kmessagewidget to inform user
[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 RenderWidget : public QDialog
113 {
114     Q_OBJECT
115
116 public:
117     explicit RenderWidget(const QString &projectfolder, bool enableProxy, 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();
139
140 protected:
141     virtual QSize sizeHint() const;
142
143 public slots:
144     void slotExport(bool scriptExport, int zoneIn, int zoneOut, const QString &playlistPath, const QString &scriptPath, bool exportAudio);
145
146 private slots:
147     void slotUpdateButtons(KUrl url);
148     void slotUpdateButtons();
149     void refreshView();
150     void refreshCategory();
151
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();
167     void slotCheckJob();
168     void slotEditItem(QListWidgetItem *item);
169     void slotCLeanUpJobs();
170     void slotHideLog();
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
182 private:
183     Ui::RenderWidget_UI m_view;
184     MltVideoProfile m_profile;
185     QString m_projectFolder;
186     RenderViewDelegate *m_scriptsDelegate;
187     RenderViewDelegate *m_jobsDelegate;
188     bool m_blockProcessing;
189     QString m_renderer;
190
191 #if KDE_IS_VERSION(4,7,0)
192     KMessageWidget *m_infoMessage;
193 #endif
194
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     void checkRenderStatus();
200     void startRendering(QTreeWidgetItem *item);
201     void saveProfile(QDomElement newprofile);
202     QList <QListWidgetItem *> m_renderItems;
203     QList <QListWidgetItem *> m_renderCategory;
204     void errorMessage(const QString &message);
205
206 signals:
207     void abortProcess(const QString &url);
208     void openDvdWizard(const QString &url, const QString &profile);
209     /** Send the infos about rendering that will be saved in the document:
210     (profile destination, profile name and url of rendered file */
211     void selectedRenderProfile(QMap <QString, QString> renderProps);
212     void prepareRenderingData(bool scriptExport, bool zoneOnly, const QString &chapterFile);
213     void shutdown();
214 };
215
216
217 #endif
218