renderwidget.h 9.59 KB
Newer Older
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/***************************************************************************
 *   Copyright (C) 2008 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
 ***************************************************************************/

#ifndef RENDERWIDGET_H
#define RENDERWIDGET_H

23 24
#include <KMessageWidget>

25
#include <QPainter>
Nicolas Carion's avatar
Nicolas Carion committed
26
#include <QPushButton>
27
#include <QStyledItemDelegate>
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
28

29 30 31 32
#ifdef KF5_USE_PURPOSE
namespace Purpose { class Menu; }
#endif

33
#include "definitions.h"
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
34 35
#include "ui_renderwidget_ui.h"

36
class QDomElement;
37
class QKeyEvent;
38

39
// RenderViewDelegate is used to draw the progress bars.
40
class RenderViewDelegate : public QStyledItemDelegate
41
{
42 43
    Q_OBJECT
public:
44 45 46 47
    explicit RenderViewDelegate(QWidget *parent)
        : QStyledItemDelegate(parent)
    {
    }
48

Nicolas Carion's avatar
Nicolas Carion committed
49
    void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
50
    {
51
        if (index.column() == 1) {
52
            painter->save();
53
            QStyleOptionViewItem opt(option);
54 55 56 57
            QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
            const int textMargin = style->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
            style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);

58 59 60
            QFont font = painter->font();
            font.setBold(true);
            painter->setFont(font);
61
            QRect r1 = option.rect;
Nicolas Carion's avatar
Nicolas Carion committed
62
            r1.adjust(0, textMargin, 0, -textMargin);
63
            int mid = (int)((r1.height() / 2));
64
            r1.setBottom(r1.y() + mid);
65
            QRect bounding;
66
            painter->drawText(r1, Qt::AlignLeft | Qt::AlignTop, index.data().toString(), &bounding);
67
            r1.moveTop(r1.bottom() - textMargin);
68 69
            font.setBold(false);
            painter->setFont(font);
70
            painter->drawText(r1, Qt::AlignLeft | Qt::AlignTop, index.data(Qt::UserRole).toString());
71 72
            int progress = index.data(Qt::UserRole + 3).toInt();
            if (progress > 0 && progress < 100) {
73
                // draw progress bar
74 75 76 77 78 79 80 81
                QColor color = option.palette.alternateBase().color();
                QColor fgColor = option.palette.text().color();
                color.setAlpha(150);
                fgColor.setAlpha(150);
                painter->setBrush(QBrush(color));
                painter->setPen(QPen(fgColor));
                int width = qMin(200, r1.width() - 4);
                QRect bgrect(r1.left() + 2, option.rect.bottom() - 6 - textMargin, width, 6);
82
                painter->drawRoundedRect(bgrect, 3, 3);
83 84 85 86 87 88 89
                painter->setBrush(QBrush(fgColor));
                bgrect.adjust(2, 2, 0, -1);
                painter->setPen(Qt::NoPen);
                bgrect.setWidth((width - 2) * progress / 100);
                painter->drawRect(bgrect);
            } else {
                r1.setBottom(opt.rect.bottom());
90
                r1.setTop(r1.bottom() - mid);
91
                painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom, index.data(Qt::UserRole + 5).toString());
92
            }
93
            painter->restore();
94 95 96
        } else {
            QStyledItemDelegate::paint(painter, option, index);
        }
97 98 99
    }
};

Nicolas Carion's avatar
Nicolas Carion committed
100
class RenderJobItem : public QTreeWidgetItem
101 102
{
public:
103
    explicit RenderJobItem(QTreeWidget *parent, const QStringList &strings, int type = QTreeWidgetItem::Type);
104 105 106 107 108 109 110 111
    void setStatus(int status);
    int status() const;
    void setMetadata(const QString &data);
    const QString metadata() const;
    void render();

private:
    int m_status;
112
    QString m_data;
113 114
};

115 116
class RenderWidget : public QDialog
{
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
117 118 119
    Q_OBJECT

public:
120
    explicit RenderWidget(const QString &projectfolder, bool enableProxy, QWidget *parent = nullptr);
121
    virtual ~RenderWidget();
122
    void setGuides(const QList<CommentedTime> &guidesList, double duration);
Vincent Pinon's avatar
Vincent Pinon committed
123
    void focusFirstVisibleItem(const QString &profile = QString());
124
    void setRenderJob(const QString &dest, int progress = 0);
125
    void setRenderStatus(const QString &dest, int status, const QString &error);
126
    void setDocumentPath(const QString &path);
127
    void reloadProfiles();
Laurent Montel's avatar
Laurent Montel committed
128
    void setRenderProfile(const QMap<QString, QString> &props);
129
    int waitingJobsCount() const;
130
    QString getFreeScriptName(const QUrl &projectName = QUrl(), const QString &prefix = QString());
131
    bool startWaitingRenderJobs();
132 133 134 135
    /** @brief Returns true if the export audio checkbox is set to automatic. */
    bool automaticAudioExport() const;
    /** @brief Returns true if user wants audio export. */
    bool selectedAudioExport() const;
136
    /** @brief Show / hide proxy settings. */
137
    void updateProxyConfig(bool enable);
138 139
    /** @brief Should we render using proxy clips. */
    bool proxyRendering();
Ed Rogalsky's avatar
Ed Rogalsky committed
140 141
    /** @brief Returns true if the stem audio export checkbox is set. */
    bool isStemAudioExportEnabled() const;
142
    enum RenderError { CompositeError = 0, ProfileError = 1, ProxyWarning = 2, PlaybackError = 3 };
143

144
    /** @brief Display warning message in render widget. */
145
    void errorMessage(RenderError type, const QString &message);
146

147
protected:
148 149
    QSize sizeHint() const override;
    void keyPressEvent(QKeyEvent *e) override;
150

151
public slots:
Nicolas Carion's avatar
Nicolas Carion committed
152 153
    void slotExport(bool scriptExport, int zoneIn, int zoneOut, const QMap<QString, QString> &metadata, const QList<QString> &playlistPaths,
                    const QList<QString> &trackNames, const QString &scriptPath, bool exportAudio);
154
    void slotAbortCurrentJob();
Laurent Montel's avatar
Laurent Montel committed
155
    void slotPrepareExport(bool scriptExport = false, const QString &scriptPath = QString());
156
    void adjustViewToProfile();
157

Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
158
private slots:
159
    void slotUpdateButtons(const QUrl &url);
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
160
    void slotUpdateButtons();
161
    void refreshView();
162 163

    /** @brief Updates available options when a new format has been selected. */
164
    void refreshParams();
165
    void slotSaveProfile();
166
    void slotEditProfile();
167
    void slotDeleteProfile(bool dontRefresh = false);
168 169 170
    void slotUpdateGuideBox();
    void slotCheckStartGuidePosition();
    void slotCheckEndGuidePosition();
171
    void showInfoPanel();
172 173 174 175 176 177
    void slotStartScript();
    void slotDeleteScript();
    void slotGenerateScript();
    void parseScriptFiles();
    void slotCheckScript();
    void slotCheckJob();
178
    void slotEditItem(QTreeWidgetItem *item);
179 180
    void slotCLeanUpJobs();
    void slotHideLog();
181
    void slotPlayRendering(QTreeWidgetItem *item, int);
182
    void slotStartCurrentJob();
183
    void slotCopyToFavorites();
184
    void slotUpdateEncodeThreads(int);
185 186 187
    void slotUpdateRescaleHeight(int);
    void slotUpdateRescaleWidth(int);
    void slotSwitchAspectRatio();
188 189
    /** @brief Update export audio label depending on current settings. */
    void slotUpdateAudioLabel(int ix);
190 191
    /** @brief Enable / disable the rescale options. */
    void setRescaleEnabled(bool enable);
192 193
    /** @brief Adjust video/audio quality spinboxes from quality slider. */
    void adjustAVQualities(int quality);
194
    /** @brief Adjust quality slider from video spinbox. */
195
    void adjustQuality(int videoQuality);
196 197
    /** @brief Show updated command parameter in tooltip. */
    void adjustSpeed(int videoQuality);
198 199
    /** @brief Display warning on proxy rendering. */
    void slotProxyWarn(bool enableProxy);
200

Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
201 202
private:
    Ui::RenderWidget_UI m_view;
203
    QString m_projectFolder;
204 205
    RenderViewDelegate *m_scriptsDelegate;
    RenderViewDelegate *m_jobsDelegate;
206
    bool m_blockProcessing;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
207
    QString m_renderer;
208
    KMessageWidget *m_infoMessage;
Nicolas Carion's avatar
Nicolas Carion committed
209
    QMap<int, QString> m_errorMessages;
210

211 212 213
#ifdef KF5_USE_PURPOSE
    Purpose::Menu *m_shareMenu;
#endif
214
    void parseMltPresets();
215
    void parseProfiles(const QString &selectedProfile = QString());
Laurent Montel's avatar
Laurent Montel committed
216
    void parseFile(const QString &exportFile, bool editable);
217
    void updateButtons();
218
    QUrl filenameWithExtension(QUrl url, const QString &extension);
219
    /** @brief Check if a job needs to be started. */
220
    void checkRenderStatus();
221
    void startRendering(RenderJobItem *item);
222
    bool saveProfile(QDomElement newprofile);
223
    /** @brief Create a rendering profile from MLT preset. */
Laurent Montel's avatar
Laurent Montel committed
224
    QTreeWidgetItem *loadFromMltPreset(const QString &groupName, const QString &path, const QString &profileName);
225
    void checkCodecs();
226

Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
227
signals:
228
    void abortProcess(const QString &url);
229
    void openDvdWizard(const QString &url);
Vincent Pinon's avatar
Vincent Pinon committed
230
    /** Send the info about rendering that will be saved in the document:
231
    (profile destination, profile name and url of rendered file */
Laurent Montel's avatar
Laurent Montel committed
232
    void selectedRenderProfile(const QMap<QString, QString> &renderProps);
233
    void prepareRenderingData(bool scriptExport, bool zoneOnly, const QString &chapterFile, const QString scriptPath);
234
    void shutdown();
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
235 236 237
};

#endif