]> git.sesse.net Git - kdenlive/blob - src/renderwidget.h
Moving choosecolorwidget and colorpickerwidget in the widget folder.
[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 class QKeyEvent;
38
39
40 // RenderViewDelegate is used to draw the progress bars.
41 class RenderViewDelegate : public QStyledItemDelegate
42 {
43     Q_OBJECT
44 public:
45     RenderViewDelegate(QWidget *parent) : QStyledItemDelegate(parent) {}
46
47     void paint(QPainter *painter, const QStyleOptionViewItem &option,
48                const QModelIndex &index) const {
49         if (index.column() == 1) {
50             painter->save();
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             QFont font = painter->font();
57             font.setBold(true);
58             painter->setFont(font);
59             QRect r1 = option.rect;
60             r1.adjust(0, textMargin, 0, - textMargin);
61             int mid = (int)((r1.height() / 2));
62             r1.setBottom(r1.y() + mid);
63             QRect bounding;
64             painter->drawText(r1, Qt::AlignLeft | Qt::AlignTop ,index.data().toString(), &bounding);
65             r1.moveTop(r1.bottom() - textMargin);
66             font.setBold(false);
67             painter->setFont(font);
68             painter->drawText(r1, Qt::AlignLeft | Qt::AlignTop , index.data(Qt::UserRole).toString());
69             int progress = index.data(Qt::UserRole + 3).toInt();
70             if (progress > 0 && progress < 100) {
71                 // draw progress bar
72                 QColor color = option.palette.alternateBase().color();
73                 QColor fgColor = option.palette.text().color();
74                 color.setAlpha(150);
75                 fgColor.setAlpha(150);
76                 painter->setBrush(QBrush(color));
77                 painter->setPen(QPen(fgColor));
78                 int width = qMin(200, r1.width() - 4);
79                 QRect bgrect(r1.left() + 2, option.rect.bottom() - 6 - textMargin, width, 6);
80                 painter->drawRoundedRect(bgrect, 3, 3);
81                 painter->setBrush(QBrush(fgColor));
82                 bgrect.adjust(2, 2, 0, -1);
83                 painter->setPen(Qt::NoPen);
84                 bgrect.setWidth((width - 2) * progress / 100);
85                 painter->drawRect(bgrect);
86             } else {
87                 r1.setBottom(opt.rect.bottom());
88                 r1.setTop(r1.bottom() - mid);
89                 painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data(Qt::UserRole + 5).toString());
90             }
91             painter->restore();
92         } else QStyledItemDelegate::paint(painter, option, index);
93     }
94 };
95
96
97 class RenderJobItem: public QTreeWidgetItem
98 {
99 public:
100     explicit RenderJobItem(QTreeWidget * parent, const QStringList & strings, int type = QTreeWidgetItem::Type);
101     void setStatus(int status);
102     int status() const;
103     void setMetadata(const QString &data);
104     const QString metadata() const;
105     void render();
106
107 private:
108     int m_status;
109     QString m_data;    
110 };
111
112 class RenderWidget : public QDialog
113 {
114     Q_OBJECT
115
116 public:
117     explicit RenderWidget(const QString &projectfolder, bool enableProxy, const MltVideoProfile &profile, QWidget * parent = 0);
118     virtual ~RenderWidget();
119     void setGuides(QDomElement guidesxml, double duration);
120     void focusFirstVisibleItem(const QString &profile = QString());
121     void setProfile(const 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(const QMap <QString, QString>& props);
127     int waitingJobsCount() const;
128     QString getFreeScriptName(const KUrl &projectName = KUrl(), 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     virtual void keyPressEvent(QKeyEvent *e);
143
144 public slots:
145     void slotExport(bool scriptExport, int zoneIn, int zoneOut, const QMap <QString, QString> &metadata, const QString &playlistPath, const QString &scriptPath, bool exportAudio);
146
147 private slots:
148     void slotUpdateButtons(const KUrl &url);
149     void slotUpdateButtons();
150     void refreshView(const QString &profile = QString());
151     void refreshCategory(const QString &group = QString(), const QString &profile = QString());
152
153     /** @brief Updates available options when a new format has been selected. */
154     void refreshParams();
155     void slotSaveProfile();
156     void slotEditProfile();
157     void slotDeleteProfile(bool refresh = true);
158     void slotUpdateGuideBox();
159     void slotCheckStartGuidePosition();
160     void slotCheckEndGuidePosition();
161     void showInfoPanel();
162     void slotAbortCurrentJob();
163     void slotStartScript();
164     void slotDeleteScript();
165     void slotGenerateScript();
166     void parseScriptFiles();
167     void slotCheckScript();
168     void slotCheckJob();
169     void slotEditItem(QListWidgetItem *item);
170     void slotCLeanUpJobs();
171     void slotHideLog();
172     void slotPrepareExport(bool scriptExport = false);
173     void slotPlayRendering(QTreeWidgetItem *item, int);
174     void slotStartCurrentJob();
175     void slotCopyToFavorites();
176     void slotUpdateEncodeThreads(int);
177     void slotUpdateRescaleHeight(int);
178     void slotUpdateRescaleWidth(int);
179     void slotSwitchAspectRatio();
180     /** @brief Update export audio label depending on current settings. */
181     void slotUpdateAudioLabel(int ix);
182     /** @brief Enable / disable the rescale options. */
183     void setRescaleEnabled(bool enable);
184
185 private:
186     Ui::RenderWidget_UI m_view;
187     QString m_projectFolder;
188     MltVideoProfile m_profile;
189     RenderViewDelegate *m_scriptsDelegate;
190     RenderViewDelegate *m_jobsDelegate;
191     bool m_blockProcessing;
192     QString m_renderer;
193
194 #if KDE_IS_VERSION(4,7,0)
195     KMessageWidget *m_infoMessage;
196 #endif
197
198     void parseProfiles(const QString &meta = QString(), const QString &group = QString(), const QString &profile = QString());
199     void parseFile(const QString &exportFile, bool editable);
200     void updateButtons();
201     KUrl filenameWithExtension(KUrl url, const QString &extension);
202     /** @brief Check if a job needs to be started. */
203     void checkRenderStatus();
204     void startRendering(RenderJobItem *item);
205     void saveProfile(const QDomElement &newprofile);
206     QList <QListWidgetItem *> m_renderItems;
207     QList <QListWidgetItem *> m_renderCategory;
208     void errorMessage(const QString &message);
209
210 signals:
211     void abortProcess(const QString &url);
212     void openDvdWizard(const QString &url);
213     /** Send the infos about rendering that will be saved in the document:
214     (profile destination, profile name and url of rendered file */
215     void selectedRenderProfile(const QMap <QString, QString> &renderProps);
216     void prepareRenderingData(bool scriptExport, bool zoneOnly, const QString &chapterFile);
217     void shutdown();
218 };
219
220
221 #endif
222