]> git.sesse.net Git - kdenlive/blob - src/renderwidget.h
automatically select if we should export audio or not:
[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 <QPushButton>
25 #include <QPainter>
26 #include <QItemDelegate>
27
28 #include "definitions.h"
29 #include "ui_renderwidget_ui.h"
30
31 class QDomElement;
32
33
34 // RenderViewDelegate is used to draw the progress bars.
35 class RenderViewDelegate : public QItemDelegate
36 {
37     Q_OBJECT
38 public:
39     RenderViewDelegate(QWidget *parent) : QItemDelegate(parent) {}
40
41     void paint(QPainter *painter, const QStyleOptionViewItem &option,
42                const QModelIndex &index) const {
43         if (index.column() == 1) {
44             QRect r1 = option.rect;
45             painter->save();
46             if (option.state & (QStyle::State_Selected)) {
47                 painter->setPen(option.palette.color(QPalette::HighlightedText));
48                 painter->fillRect(r1, option.palette.highlight());
49             } else painter->setPen(option.palette.color(QPalette::Text));
50             QFont font = painter->font();
51             font.setBold(true);
52             painter->setFont(font);
53             int mid = (int)((r1.height() / 2));
54             r1.setBottom(r1.y() + mid);
55             QRect r2 = option.rect;
56             r2.setTop(r2.y() + mid);
57             painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data().toString());
58             font.setBold(false);
59             painter->setFont(font);
60             painter->setPen(option.palette.color(QPalette::Mid));
61             painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , index.data(Qt::UserRole).toString());
62             painter->restore();
63         } else if (index.column() == 2) {
64             // Set up a QStyleOptionProgressBar to precisely mimic the
65             // environment of a progress bar.
66             QStyleOptionProgressBar progressBarOption;
67             progressBarOption.state = option.state;
68             progressBarOption.direction = QApplication::layoutDirection();
69             QRect rect = option.rect;
70             if (option.state & (QStyle::State_Selected)) {
71                 painter->setPen(option.palette.color(QPalette::HighlightedText));
72                 painter->fillRect(rect, option.palette.highlight());
73             }
74
75             int mid = rect.height() / 2;
76             rect.setTop(rect.top() + mid / 2);
77             rect.setHeight(mid);
78             progressBarOption.rect = rect;
79             progressBarOption.fontMetrics = QApplication::fontMetrics();
80             progressBarOption.minimum = 0;
81             progressBarOption.maximum = 100;
82             progressBarOption.textAlignment = Qt::AlignCenter;
83             progressBarOption.textVisible = true;
84
85             // Set the progress and text values of the style option.
86             int progress = index.data(Qt::UserRole).toInt();
87             progressBarOption.progress = progress < 0 ? 0 : progress;
88             progressBarOption.text = QString().sprintf("%d%%", progressBarOption.progress);
89
90             // Draw the progress bar onto the view.
91             QApplication::style()->drawControl(QStyle::CE_ProgressBar, &progressBarOption, painter);
92         } else QItemDelegate::paint(painter, option, index);
93     }
94 };
95
96
97 class RenderWidget : public QDialog
98 {
99     Q_OBJECT
100
101 public:
102     explicit RenderWidget(const QString &projectfolder, QWidget * parent = 0);
103     virtual ~RenderWidget();
104     void setGuides(QDomElement guidesxml, double duration);
105     void focusFirstVisibleItem();
106     void setProfile(MltVideoProfile profile);
107     void setRenderJob(const QString &dest, int progress = 0);
108     void setRenderStatus(const QString &dest, int status, const QString &error);
109     void setDocumentPath(const QString path);
110     void reloadProfiles();
111     void setRenderProfile(const QString &dest, const QString &group, const QString &name, const QString &url);
112     int waitingJobsCount() const;
113     QString getFreeScriptName(const QString &prefix = QString());
114     bool startWaitingRenderJobs();
115     void missingClips(bool hasMissing);
116
117 public slots:
118     void slotExport(bool scriptExport, int zoneIn, int zoneOut, const QString &playlistPath, const QString &scriptPath);
119     /** @brief Enable / disable audio export if audio export checkbox is in auto mode. */
120     void slotEnableAudio(bool enable);
121
122 private slots:
123     void slotUpdateButtons(KUrl url);
124     void slotUpdateButtons();
125     void refreshView();
126     void refreshCategory();
127
128     /** @brief Updates available options when a new format has been selected. */
129     void refreshParams();
130     void slotSaveProfile();
131     void slotEditProfile();
132     void slotDeleteProfile(bool refresh = true);
133     void slotUpdateGuideBox();
134     void slotCheckStartGuidePosition();
135     void slotCheckEndGuidePosition();
136     void showInfoPanel();
137     void slotAbortCurrentJob();
138     void slotStartScript();
139     void slotDeleteScript();
140     void slotGenerateScript();
141     void parseScriptFiles();
142     void slotCheckScript();
143     void slotCheckJob();
144     void slotEditItem(QListWidgetItem *item);
145     void slotCLeanUpJobs();
146     void slotHideLog();
147     void slotPrepareExport(bool scriptExport = false);
148     void slotPlayRendering(QTreeWidgetItem *item, int);
149     void slotStartCurrentJob();
150     void slotCopyToFavorites();
151     void slotUpdateRescaleHeight(int);
152     void slotUpdateRescaleWidth(int);
153     void slotSwitchAspectRatio();
154     /** @brief Update export audio label depending on current settings. */
155     void slotUpdateAudioLabel(int ix);
156
157 private:
158     Ui::RenderWidget_UI m_view;
159     MltVideoProfile m_profile;
160     QString m_projectFolder;
161     RenderViewDelegate *m_scriptsDelegate;
162     RenderViewDelegate *m_jobsDelegate;
163     bool m_blockProcessing;
164     QString m_renderer;
165     void parseProfiles(QString meta = QString(), QString group = QString(), QString profile = QString());
166     void parseFile(QString exportFile, bool editable);
167     void updateButtons();
168     KUrl filenameWithExtension(KUrl url, QString extension);
169     void checkRenderStatus();
170     void startRendering(QTreeWidgetItem *item);
171     void saveProfile(QDomElement newprofile);
172     QList <QListWidgetItem *> m_renderItems;
173     QList <QListWidgetItem *> m_renderCategory;
174     /** @brief True if current project has audio, false otherwise. */
175     bool m_autoAudio;
176
177 signals:
178     void abortProcess(const QString &url);
179     void openDvdWizard(const QString &url, const QString &profile);
180     /** Send the infos about rendering that will be saved in the document:
181     (profile destination, profile name and url of rendered file */
182     void selectedRenderProfile(const QString &, const QString &, const QString &, const QString &);
183     void prepareRenderingData(bool scriptExport, bool zoneOnly, const QString &chapterFile);
184     void shutdown();
185 };
186
187
188 #endif
189