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