Display timing info in rendering jog widget

svn path=/branches/KDE4/; revision=3001
parent 433ca07e
......@@ -101,15 +101,18 @@ RenderWidget::RenderWidget(QWidget * parent): QDialog(parent) {
m_view.out_file->setMode(KFile::File);
m_view.running_jobs->setHeaderLabels(QStringList() << QString() << i18n("File") << i18n("Progress"));
m_view.running_jobs->setItemDelegate(new RenderViewDelegate(this));
QHeaderView *header = m_view.running_jobs->header();
QFontMetrics fm = fontMetrics();
//header->resizeSection(0, fm.width("typical-name-for-a-torrent.torrent"));
header->setResizeMode(0, QHeaderView::Interactive);
header->resizeSection(0, fm.width("typical-name-for-a-file.torrent"));
header->setResizeMode(1, QHeaderView::Fixed);
header->resizeSection(0, width() * 2 / 3);
header->setResizeMode(0, QHeaderView::Fixed);
header->resizeSection(0, 30);
header->setResizeMode(1, QHeaderView::Interactive);
header->resizeSection(1, fm.width("typical-name-for-a-file.torrent"));
header->setResizeMode(2, QHeaderView::Fixed);
header->resizeSection(1, width() * 2 / 3);
header->setResizeMode(2, QHeaderView::Interactive);
//header->setResizeMode(1, QHeaderView::Fixed);
focusFirstVisibleItem();
......@@ -472,9 +475,14 @@ void RenderWidget::slotExport() {
// insert item in running jobs list
QTreeWidgetItem *renderItem;
QList<QTreeWidgetItem *> existing = m_view.running_jobs->findItems(dest, Qt::MatchExactly);
QList<QTreeWidgetItem *> existing = m_view.running_jobs->findItems(dest, Qt::MatchExactly, 1);
if (!existing.isEmpty()) renderItem = existing.at(0);
else renderItem = new QTreeWidgetItem(m_view.running_jobs, QStringList() << dest << QString());
else renderItem = new QTreeWidgetItem(m_view.running_jobs, QStringList() << QString() << dest << QString());
renderItem->setSizeHint(1, QSize(m_view.running_jobs->columnWidth(1), fontMetrics().height() * 2));
QTime startTime;
startTime.start();
renderItem->setData(1, Qt::UserRole + 2, startTime);
// Set rendering type
QString group = m_view.size_list->currentItem()->data(MetaGroupRole).toString();
if (group == "dvd" && m_view.open_dvd->isChecked()) {
......@@ -768,25 +776,39 @@ void RenderWidget::parseFile(QString exportFile, bool editable) {
void RenderWidget::setRenderJob(const QString &dest, int progress) {
QTreeWidgetItem *item;
QList<QTreeWidgetItem *> existing = m_view.running_jobs->findItems(dest, Qt::MatchExactly);
QList<QTreeWidgetItem *> existing = m_view.running_jobs->findItems(dest, Qt::MatchExactly, 1);
if (!existing.isEmpty()) item = existing.at(0);
else item = new QTreeWidgetItem(m_view.running_jobs, QStringList() << dest << QString());
item->setData(1, Qt::UserRole, progress);
if (progress == 0) item->setIcon(0, KIcon("system-run"));
else item = new QTreeWidgetItem(m_view.running_jobs, QStringList() << QString() << dest << QString());
item->setData(2, Qt::UserRole, progress);
if (progress == 0) {
item->setIcon(0, KIcon("system-run"));
item->setSizeHint(1, QSize(m_view.running_jobs->columnWidth(1), fontMetrics().height() * 2));
QTime startTime;
startTime.start();
item->setData(1, Qt::UserRole + 2, startTime);
} else {
QTime startTime = item->data(1, Qt::UserRole + 2).toTime();
int seconds = startTime.secsTo(QTime::currentTime());
seconds = seconds * (100 - progress) / progress;
item->setData(1, Qt::UserRole + 3, i18n("Estimated time %1", QTime(0, 0, seconds).toString("hh:mm:ss")));
}
}
void RenderWidget::setRenderStatus(const QString &dest, int status, const QString &error) {
QTreeWidgetItem *item;
QList<QTreeWidgetItem *> existing = m_view.running_jobs->findItems(dest, Qt::MatchExactly);
QList<QTreeWidgetItem *> existing = m_view.running_jobs->findItems(dest, Qt::MatchExactly, 1);
if (!existing.isEmpty()) item = existing.at(0);
else item = new QTreeWidgetItem(m_view.running_jobs, QStringList() << dest << QString());
else item = new QTreeWidgetItem(m_view.running_jobs, QStringList() << QString() << dest << QString());
if (status == -1) {
// Job finished successfully
item->setIcon(0, KIcon("dialog-ok"));
item->setData(1, Qt::UserRole, 100);
item->setData(2, Qt::UserRole, 100);
QTime startTime = item->data(1, Qt::UserRole + 2).toTime();
int seconds = startTime.secsTo(QTime::currentTime());
item->setData(1, Qt::UserRole + 3, i18n("Rendering finished in %1", QTime(0, 0, seconds).toString("hh:mm:ss")));
QString itemGroup = item->data(0, Qt::UserRole).toString();
if (itemGroup == "dvd") {
emit openDvdWizard(item->text(0), item->data(0, Qt::UserRole + 1).toString());
emit openDvdWizard(item->text(1), item->data(0, Qt::UserRole + 1).toString());
} else if (itemGroup == "websites") {
QString url = item->data(0, Qt::UserRole + 1).toString();
if (!url.isEmpty()) KRun *openBrowser = new KRun(url, this);
......@@ -794,7 +816,7 @@ void RenderWidget::setRenderStatus(const QString &dest, int status, const QStrin
} else if (status == -2) {
// Rendering crashed
item->setIcon(0, KIcon("dialog-close"));
item->setData(1, Qt::UserRole, 0);
item->setData(2, Qt::UserRole, 0);
m_view.error_log->append(i18n("<strong>Rendering of %1 crashed</strong><br />", dest));
m_view.error_log->append(error);
m_view.error_log->append("<hr />");
......@@ -802,14 +824,14 @@ void RenderWidget::setRenderStatus(const QString &dest, int status, const QStrin
} else if (status == -3) {
// User aborted job
item->setIcon(0, KIcon("dialog-cancel"));
item->setData(1, Qt::UserRole, 100);
item->setData(1, Qt::UserRole + 1, i18n("Aborted by user"));
item->setData(2, Qt::UserRole, 100);
item->setData(2, Qt::UserRole + 1, i18n("Aborted by user"));
}
}
void RenderWidget::slotAbortCurrentJob() {
QTreeWidgetItem *current = m_view.running_jobs->currentItem();
if (current) emit abortProcess(current->text(0));
if (current) emit abortProcess(current->text(1));
}
#include "renderwidget.moc"
......@@ -23,6 +23,7 @@
#include <QDialog>
#include <QPushButton>
#include <QPainter>
#include "definitions.h"
#include "ui_renderwidget_ui.h"
......@@ -36,17 +37,52 @@ public:
void paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const {
if (index.column() != 1) {
if (index.column() == 0) {
QItemDelegate::paint(painter, option, index);
return;
} else if (index.column() == 1) {
const bool hover = option.state & (QStyle::State_Selected);
QRect r1 = option.rect;
painter->save();
if (hover) {
painter->setPen(option.palette.color(QPalette::HighlightedText));
QColor backgroundColor = option.palette.color(QPalette::Highlight);
painter->setBrush(QBrush(backgroundColor));
painter->fillRect(r1, QBrush(backgroundColor));
} else painter->setPen(option.palette.color(QPalette::Text));
QFont font = painter->font();
font.setBold(true);
painter->setFont(font);
int mid = (int)((r1.height() / 2));
r1.setBottom(r1.y() + mid);
QRect r2 = option.rect;
r2.setTop(r2.y() + mid);
painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data().toString());
font.setBold(false);
painter->setFont(font);
painter->setPen(option.palette.color(QPalette::Mid));
painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , index.data(Qt::UserRole + 3).toString());
painter->restore();
return;
}
// Set up a QStyleOptionProgressBar to precisely mimic the
// environment of a progress bar.
QStyleOptionProgressBar progressBarOption;
progressBarOption.state = QStyle::State_Enabled;
progressBarOption.state = option.state;
progressBarOption.direction = QApplication::layoutDirection();
progressBarOption.rect = option.rect;
QRect rect = option.rect;
const bool hover = option.state & (QStyle::State_Selected);
if (hover) {
painter->setPen(option.palette.color(QPalette::HighlightedText));
QColor backgroundColor = option.palette.color(QPalette::Highlight);
painter->setBrush(QBrush(backgroundColor));
painter->fillRect(rect, QBrush(backgroundColor));
}
int mid = rect.height() / 2;
rect.setTop(rect.top() + mid / 2);
rect.setHeight(mid);
progressBarOption.rect = rect;
progressBarOption.fontMetrics = QApplication::fontMetrics();
progressBarOption.minimum = 0;
progressBarOption.maximum = 100;
......
......@@ -5,8 +5,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>415</width>
<height>512</height>
<width>474</width>
<height>504</height>
</rect>
</property>
<property name="windowTitle" >
......@@ -26,6 +26,60 @@
<string>Render Project</string>
</attribute>
<layout class="QGridLayout" name="gridLayout" >
<item row="2" column="2" colspan="3" >
<spacer name="horizontalSpacer_2" >
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0" >
<size>
<width>124</width>
<height>23</height>
</size>
</property>
</spacer>
</item>
<item row="9" column="0" colspan="10" >
<layout class="QHBoxLayout" name="horizontalLayout" >
<item>
<widget class="QRadioButton" name="render_full" >
<property name="text" >
<string>Full project</string>
</property>
<property name="checked" >
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="render_zone" >
<property name="text" >
<string>Selected zone</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="render_guide" >
<property name="text" >
<string>Guide zone</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="11" column="4" colspan="4" >
<spacer name="horizontalSpacer" >
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0" >
<size>
<width>221</width>
<height>24</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0" colspan="2" >
<widget class="QLabel" name="label_6" >
<property name="text" >
......@@ -60,19 +114,6 @@
</property>
</widget>
</item>
<item row="2" column="2" colspan="3" >
<spacer name="horizontalSpacer_2" >
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0" >
<size>
<width>124</width>
<height>23</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="5" colspan="2" >
<widget class="KComboBox" name="format_selection" >
<item>
......@@ -108,42 +149,6 @@
</property>
</widget>
</item>
<item row="3" column="0" colspan="10" >
<widget class="QSplitter" name="splitter_3" >
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<widget class="QSplitter" name="splitter" >
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<widget class="KListWidget" name="format_list" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Expanding" hsizetype="Preferred" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
<widget class="KListWidget" name="size_list" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</widget>
<widget class="KTextEdit" name="advanced_params" >
<property name="readOnly" >
<bool>true</bool>
</property>
<property name="acceptRichText" >
<bool>false</bool>
</property>
</widget>
</widget>
</item>
<item row="4" column="0" colspan="2" >
<widget class="QLabel" name="label_5" >
<property name="text" >
......@@ -190,10 +195,10 @@
<item row="5" column="2" colspan="4" >
<widget class="KRestrictedLine" name="rescale_size" >
<property name="inputMask" >
<string>0099\&#x00d7;0099; </string>
<string>0099\×0099; </string>
</property>
<property name="text" >
<string> 320&#x00d7; 240</string>
<string>320×240</string>
</property>
<property name="validChars" >
<string/>
......@@ -228,34 +233,6 @@
</property>
</widget>
</item>
<item row="9" column="0" colspan="10" >
<layout class="QHBoxLayout" name="horizontalLayout" >
<item>
<widget class="QRadioButton" name="render_full" >
<property name="text" >
<string>Full project</string>
</property>
<property name="checked" >
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="render_zone" >
<property name="text" >
<string>Selected zone</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="render_guide" >
<property name="text" >
<string>Guide zone</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="10" column="0" colspan="10" >
<widget class="QGroupBox" name="guides_box" >
<property name="title" >
......@@ -306,19 +283,6 @@
</property>
</widget>
</item>
<item row="11" column="4" colspan="4" >
<spacer name="horizontalSpacer" >
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0" >
<size>
<width>221</width>
<height>24</height>
</size>
</property>
</spacer>
</item>
<item row="11" column="8" colspan="2" >
<widget class="KPushButton" name="buttonClose" >
<property name="text" >
......@@ -326,6 +290,42 @@
</property>
</widget>
</item>
<item row="3" column="0" colspan="10" >
<widget class="QSplitter" name="splitter_3" >
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<widget class="QSplitter" name="splitter" >
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<widget class="KListWidget" name="format_list" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Expanding" hsizetype="Preferred" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
<widget class="KListWidget" name="size_list" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</widget>
<widget class="KTextEdit" name="advanced_params" >
<property name="readOnly" >
<bool>true</bool>
</property>
<property name="acceptRichText" >
<bool>false</bool>
</property>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2" >
......@@ -333,6 +333,33 @@
<string>Current jobs</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_5" >
<item row="1" column="1" >
<spacer name="horizontalSpacer_3" >
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0" >
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0" >
<widget class="QPushButton" name="abort_job" >
<property name="text" >
<string>Abort Job</string>
</property>
</widget>
</item>
<item row="1" column="2" >
<widget class="KPushButton" name="buttonClose2" >
<property name="text" >
<string>Close</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="3" >
<widget class="QSplitter" name="splitter_2" >
<property name="orientation" >
......@@ -351,22 +378,9 @@
<property name="allColumnsShowFocus" >
<bool>true</bool>
</property>
<property name="headerHidden" >
<bool>false</bool>
</property>
<property name="columnCount" >
<number>2</number>
<number>0</number>
</property>
<column>
<property name="text" >
<string>File</string>
</property>
</column>
<column>
<property name="text" >
<string>Progress</string>
</property>
</column>
</widget>
<widget class="QGroupBox" name="error_box" >
<property name="sizePolicy" >
......@@ -397,39 +411,7 @@
</widget>
</widget>
</item>
<item row="1" column="0" >
<widget class="QPushButton" name="abort_job" >
<property name="text" >
<string>Abort Job</string>
</property>
</widget>
</item>
<item row="1" column="1" >
<spacer name="horizontalSpacer_3" >
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0" >
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="2" >
<widget class="KPushButton" name="buttonClose2" >
<property name="text" >
<string>Close</string>
</property>
</widget>
</item>
</layout>
<zorder>running_jobs</zorder>
<zorder>abort_job</zorder>
<zorder>buttonClose2</zorder>
<zorder>error_box</zorder>
<zorder>splitter_2</zorder>
</widget>
</widget>
</item>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment