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