]> git.sesse.net Git - kdenlive/blob - src/renderwidget.h
4c4f0a4b5e935a2ce967d1368a1b9ab024df0043
[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             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);
54
55             QFont font = painter->font();
56             font.setBold(true);
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);
62             QRect bounding;
63             painter->drawText(r1, Qt::AlignLeft | Qt::AlignTop ,index.data().toString(), &bounding);
64             r1.moveTop(r1.bottom() - textMargin);
65             font.setBold(false);
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                 // draw progress bar
71                 QColor color = option.palette.alternateBase().color();
72                 QColor fgColor = option.palette.text().color();
73                 color.setAlpha(150);
74                 fgColor.setAlpha(150);
75                 painter->setBrush(QBrush(color));
76                 painter->setPen(QPen(fgColor));
77                 int width = qMin(200, r1.width() - 4);
78                 QRect bgrect(r1.left() + 2, option.rect.bottom() - 6 - textMargin, width, 6);
79                 painter->drawRoundedRect(bgrect, 3, 3);
80                 painter->setBrush(QBrush(fgColor));
81                 bgrect.adjust(2, 2, 0, -1);
82                 painter->setPen(Qt::NoPen);
83                 bgrect.setWidth((width - 2) * progress / 100);
84                 painter->drawRect(bgrect);
85             } else {
86                 r1.setBottom(opt.rect.bottom());
87                 r1.setTop(r1.bottom() - mid);
88                 painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data(Qt::UserRole + 5).toString());
89             }
90             painter->restore();
91         } else QStyledItemDelegate::paint(painter, option, index);
92     }
93 };
94
95
96 class RenderJobItem: public QTreeWidgetItem
97 {
98 public:
99     explicit RenderJobItem(QTreeWidget * parent, const QStringList & strings, int type = QTreeWidgetItem::Type);
100     void setStatus(int status);
101     int status() const;
102     void setMetadata(const QString &data);
103     const QString metadata() const;
104     void render();
105
106 private:
107     int m_status;
108     QString m_data;    
109 };
110
111 class RenderWidget : public QDialog
112 {
113     Q_OBJECT
114
115 public:
116     explicit RenderWidget(const QString &projectfolder, bool enableProxy, MltVideoProfile profile, QWidget * parent = 0);
117     virtual ~RenderWidget();
118     void setGuides(QDomElement guidesxml, double duration);
119     void focusFirstVisibleItem();
120     void setProfile(MltVideoProfile profile);
121     void setRenderJob(const QString &dest, int progress = 0);
122     void setRenderStatus(const QString &dest, int status, const QString &error);
123     void setDocumentPath(const QString &path);
124     void reloadProfiles();
125     void setRenderProfile(QMap <QString, QString> props);
126     int waitingJobsCount() const;
127     QString getFreeScriptName(const QString &prefix = QString());
128     bool startWaitingRenderJobs();
129     void missingClips(bool hasMissing);
130     /** @brief Returns true if the export audio checkbox is set to automatic. */
131     bool automaticAudioExport() const;
132     /** @brief Returns true if user wants audio export. */
133     bool selectedAudioExport() const;
134     /** @brief Show / hide proxy settings. */
135     void updateProxyConfig(bool enable);
136     /** @brief Should we render using proxy clips. */
137     bool proxyRendering();
138
139 protected:
140     virtual QSize sizeHint() const;
141
142 public slots:
143     void slotExport(bool scriptExport, int zoneIn, int zoneOut, const QString &playlistPath, const QString &scriptPath, bool exportAudio);
144
145 private slots:
146     void slotUpdateButtons(KUrl url);
147     void slotUpdateButtons();
148     void refreshView();
149     void refreshCategory();
150
151     /** @brief Updates available options when a new format has been selected. */
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();
166     void slotCheckJob();
167     void slotEditItem(QListWidgetItem *item);
168     void slotCLeanUpJobs();
169     void slotHideLog();
170     void slotPrepareExport(bool scriptExport = false);
171     void slotPlayRendering(QTreeWidgetItem *item, int);
172     void slotStartCurrentJob();
173     void slotCopyToFavorites();
174     void slotUpdateEncodeThreads(int);
175     void slotUpdateRescaleHeight(int);
176     void slotUpdateRescaleWidth(int);
177     void slotSwitchAspectRatio();
178     /** @brief Update export audio label depending on current settings. */
179     void slotUpdateAudioLabel(int ix);
180     /** @brief Enable / disable the rescale options. */
181     void setRescaleEnabled(bool enable);
182
183 private:
184     Ui::RenderWidget_UI m_view;
185     QString m_projectFolder;
186     MltVideoProfile m_profile;
187     RenderViewDelegate *m_scriptsDelegate;
188     RenderViewDelegate *m_jobsDelegate;
189     bool m_blockProcessing;
190     QString m_renderer;
191
192 #if KDE_IS_VERSION(4,7,0)
193     KMessageWidget *m_infoMessage;
194 #endif
195
196     void parseProfiles(QString meta = QString(), QString group = QString(), QString profile = QString());
197     void parseFile(QString exportFile, bool editable);
198     void updateButtons();
199     KUrl filenameWithExtension(KUrl url, QString extension);
200     /** @brief Check if a job needs to be started. */
201     void checkRenderStatus();
202     void startRendering(RenderJobItem *item);
203     void saveProfile(QDomElement newprofile);
204     QList <QListWidgetItem *> m_renderItems;
205     QList <QListWidgetItem *> m_renderCategory;
206     void errorMessage(const QString &message);
207
208 signals:
209     void abortProcess(const QString &url);
210     void openDvdWizard(const QString &url, const QString &profile);
211     /** Send the infos about rendering that will be saved in the document:
212     (profile destination, profile name and url of rendered file */
213     void selectedRenderProfile(QMap <QString, QString> renderProps);
214     void prepareRenderingData(bool scriptExport, bool zoneOnly, const QString &chapterFile);
215     void shutdown();
216 };
217
218
219 #endif
220