]> git.sesse.net Git - kdenlive/blob - src/renderwidget.h
Fix compilation
[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 <QDialog>
25 #include <QPushButton>
26 #include <QPainter>
27 #include <QItemDelegate>
28
29 #include "definitions.h"
30 #include "ui_renderwidget_ui.h"
31
32
33 // RenderViewDelegate is used to draw the progress bars.
34 class RenderViewDelegate : public QItemDelegate {
35     Q_OBJECT
36 public:
37     RenderViewDelegate(QWidget *parent) : QItemDelegate(parent) {}
38
39     void paint(QPainter *painter, const QStyleOptionViewItem &option,
40                const QModelIndex &index) const {
41         if (index.column() == 0) {
42             QItemDelegate::paint(painter, option, index);
43             return;
44         } else if (index.column() == 1) {
45             QRect r1 = option.rect;
46             painter->save();
47             if (option.state & (QStyle::State_Selected)) {
48                 painter->setPen(option.palette.color(QPalette::HighlightedText));
49                 painter->fillRect(r1, option.palette.highlight());
50             } else painter->setPen(option.palette.color(QPalette::Text));
51             QFont font = painter->font();
52             font.setBold(true);
53             painter->setFont(font);
54             int mid = (int)((r1.height() / 2));
55             r1.setBottom(r1.y() + mid);
56             QRect r2 = option.rect;
57             r2.setTop(r2.y() + mid);
58             painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data().toString());
59             font.setBold(false);
60             painter->setFont(font);
61             painter->setPen(option.palette.color(QPalette::Mid));
62             painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , index.data(Qt::UserRole).toString());
63             painter->restore();
64             return;
65         }
66         // Set up a QStyleOptionProgressBar to precisely mimic the
67         // environment of a progress bar.
68         QStyleOptionProgressBar progressBarOption;
69         progressBarOption.state = option.state;
70         progressBarOption.direction = QApplication::layoutDirection();
71         QRect rect = option.rect;
72         if (option.state & (QStyle::State_Selected)) {
73             painter->setPen(option.palette.color(QPalette::HighlightedText));
74             painter->fillRect(rect, option.palette.highlight());
75         }
76
77         int mid = rect.height() / 2;
78         rect.setTop(rect.top() + mid / 2);
79         rect.setHeight(mid);
80         progressBarOption.rect = rect;
81         progressBarOption.fontMetrics = QApplication::fontMetrics();
82         progressBarOption.minimum = 0;
83         progressBarOption.maximum = 100;
84         progressBarOption.textAlignment = Qt::AlignCenter;
85         progressBarOption.textVisible = true;
86
87         // Set the progress and text values of the style option.
88         int progress = index.data(Qt::UserRole).toInt();
89         progressBarOption.progress = progress < 0 ? 0 : progress;
90         progressBarOption.text = QString().sprintf("%d%%", progressBarOption.progress);
91
92         // Draw the progress bar onto the view.
93         QApplication::style()->drawControl(QStyle::CE_ProgressBar, &progressBarOption, painter);
94     }
95 };
96
97
98 // RenderScriptDelegate is used to draw the script items.
99 class RenderScriptDelegate : public QItemDelegate {
100     Q_OBJECT
101 public:
102     RenderScriptDelegate(QWidget *parent) : QItemDelegate(parent) {}
103
104     void paint(QPainter *painter, const QStyleOptionViewItem &option,
105                const QModelIndex &index) const {
106         if (index.column() == 0) {
107             QRect r1 = option.rect;
108             painter->save();
109             if (option.state & (QStyle::State_Selected)) {
110                 painter->setPen(option.palette.color(QPalette::HighlightedText));
111                 painter->fillRect(r1, option.palette.highlight());
112             } else painter->setPen(option.palette.color(QPalette::Text));
113             QFont font = painter->font();
114             font.setBold(true);
115             painter->setFont(font);
116             int mid = (int)((r1.height() / 2));
117             r1.setBottom(r1.y() + mid);
118             r1.setLeft(r1.left() + 3);
119             QRect r2 = option.rect;
120             r2.setTop(r2.y() + mid);
121             r2.setLeft(r2.left() + 3);
122             painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data().toString());
123             font.setBold(false);
124             painter->setFont(font);
125             painter->setPen(option.palette.color(QPalette::Mid));
126             painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , index.data(Qt::UserRole).toString());
127             painter->restore();
128             return;
129         } else QItemDelegate::paint(painter, option, index);
130     }
131 };
132
133 class RenderWidget : public QDialog {
134     Q_OBJECT
135
136 public:
137     RenderWidget(const QString &projectfolder, QWidget * parent = 0);
138     void setGuides(QDomElement guidesxml, double duration);
139     void focusFirstVisibleItem();
140     void setProfile(MltVideoProfile profile);
141     void setRenderJob(const QString &dest, int progress = 0);
142     void setRenderStatus(const QString &dest, int status, const QString &error);
143     void setDocumentPath(const QString path);
144
145 private slots:
146     void slotUpdateButtons(KUrl url);
147     void slotUpdateButtons();
148     void slotExport(bool scriptExport = false);
149     void refreshView();
150     void refreshParams();
151     void slotSaveProfile();
152     void slotEditProfile();
153     void slotDeleteProfile();
154     void slotUpdateGuideBox();
155     void slotCheckStartGuidePosition();
156     void slotCheckEndGuidePosition();
157     void showInfoPanel();
158     void slotAbortCurrentJob();
159     void slotStartScript();
160     void slotDeleteScript();
161     void slotGenerateScript();
162     void parseScriptFiles();
163     void slotCheckScript();
164     void slotCheckJob();
165
166 private:
167     Ui::RenderWidget_UI m_view;
168     MltVideoProfile m_profile;
169     QString m_projectFolder;
170     void parseProfiles(QString group = QString(), QString profile = QString());
171     void parseFile(QString exportFile, bool editable);
172     void updateButtons();
173     KUrl filenameWithExtension(KUrl url, QString extension);
174
175 signals:
176     void doRender(const QString&, const QString&, const QStringList &, const QStringList &, bool, bool, double, double, bool, const QString &);
177     void abortProcess(const QString &url);
178     void openDvdWizard(const QString &url, const QString &profile);
179 };
180
181
182 #endif
183