From e007747d5b02a12d64366d614a3df3fbe5df4bf4 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mardelle Date: Sun, 4 Nov 2012 17:01:43 +0100 Subject: [PATCH] Small fixes to clip job progress bar --- src/dvdwizardvob.cpp | 6 ++- src/projectitem.cpp | 40 ++++++++++++++---- src/projectitem.h | 11 +++-- src/projectlist.cpp | 99 ++++++++++++++++++++++++++------------------ src/projectlist.h | 36 ++++++++-------- 5 files changed, 122 insertions(+), 70 deletions(-) diff --git a/src/dvdwizardvob.cpp b/src/dvdwizardvob.cpp index 0d99f697..9cdfd8d0 100644 --- a/src/dvdwizardvob.cpp +++ b/src/dvdwizardvob.cpp @@ -34,6 +34,7 @@ #include #include #include +#include DvdTreeWidget::DvdTreeWidget(QWidget *parent) : QTreeWidget(parent) @@ -201,11 +202,11 @@ void DvdWizardVob::slotAddVobFile(KUrl url, const QString &chapters, bool checkF item->setData(1, Qt::UserRole, playTime); int standard = -1; int aspect = profile.dar() * 100; - if (profile.height() == 576) { + if (profile.height() == 576 && profile.fps() == 25.0) { if (aspect > 150) standard = 1; else standard = 0; } - else if (profile.height() == 480) { + else if (profile.height() == 480 && qAbs(profile.fps() - 30000.0 / 1001) < 0.2) { if (aspect > 150) standard = 3; else standard = 2; } @@ -226,6 +227,7 @@ void DvdWizardVob::slotAddVobFile(KUrl url, const QString &chapters, bool checkF default: standardName = i18n("Unknown"); } + standardName.append(QString(" | %1x%2, %3fps").arg(profile.width()).arg(profile.height()).arg(profile.fps())); item->setData(0, Qt::UserRole, standardName); item->setData(0, Qt::UserRole + 1, standard); item->setData(0, Qt::UserRole + 2, QSize(profile.dar() * profile.height(), profile.height())); diff --git a/src/projectitem.cpp b/src/projectitem.cpp index 711865cb..c26f5ce9 100644 --- a/src/projectitem.cpp +++ b/src/projectitem.cpp @@ -35,24 +35,26 @@ const int JobTypeRole = Qt::UserRole + 6; const int JobStatusMessage = Qt::UserRole + 7; const int itemHeight = 38; -ProjectItem::ProjectItem(QTreeWidget * parent, DocClipBase *clip) : +ProjectItem::ProjectItem(QTreeWidget * parent, DocClipBase *clip, QSize pixmapSize) : QTreeWidgetItem(parent, PROJECTCLIPTYPE), m_clip(clip), - m_clipId(clip->getId()) + m_clipId(clip->getId()), + m_pixmapSet(false) { - buildItem(); + buildItem(pixmapSize); } -ProjectItem::ProjectItem(QTreeWidgetItem * parent, DocClipBase *clip) : +ProjectItem::ProjectItem(QTreeWidgetItem * parent, DocClipBase *clip, QSize pixmapSize) : QTreeWidgetItem(parent, PROJECTCLIPTYPE), m_clip(clip), - m_clipId(clip->getId()) + m_clipId(clip->getId()), + m_pixmapSet(false) { - buildItem(); + buildItem(pixmapSize); } -void ProjectItem::buildItem() +void ProjectItem::buildItem(QSize pixmapSize) { setSizeHint(0, QSize(itemHeight * 3, itemHeight)); if (m_clip->isPlaceHolder()) setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled); @@ -60,6 +62,19 @@ void ProjectItem::buildItem() QString name = m_clip->getProperty("name"); if (name.isEmpty()) name = KUrl(m_clip->getProperty("resource")).fileName(); m_clipType = (CLIPTYPE) m_clip->getProperty("type").toInt(); + switch(m_clipType) { + case AUDIO: + setData(0, Qt::DecorationRole, KIcon("audio-x-generic").pixmap(pixmapSize)); + m_pixmapSet = true; + break; + case IMAGE: + case SLIDESHOW: + setData(0, Qt::DecorationRole, KIcon("image-x-generic").pixmap(pixmapSize)); + break; + default: + setData(0, Qt::DecorationRole, KIcon("video-x-generic").pixmap(pixmapSize)); + } + setText(0, name); setText(1, m_clip->description()); GenTime duration = m_clip->duration(); @@ -80,6 +95,17 @@ ProjectItem::~ProjectItem() { } +bool ProjectItem::hasPixmap() const +{ + return m_pixmapSet; +} + +void ProjectItem::setPixmap(const QPixmap p) +{ + m_pixmapSet = true; + setData(0, Qt::DecorationRole, p); +} + //static int ProjectItem::itemDefaultHeight() { diff --git a/src/projectitem.h b/src/projectitem.h index c6fd3b4a..6d07b1b8 100644 --- a/src/projectitem.h +++ b/src/projectitem.h @@ -41,8 +41,8 @@ class DocClipBase; class ProjectItem : public QTreeWidgetItem { public: - ProjectItem(QTreeWidget * parent, DocClipBase *clip); - ProjectItem(QTreeWidgetItem * parent, DocClipBase *clip); + ProjectItem(QTreeWidget * parent, DocClipBase *clip, QSize pixmapSize); + ProjectItem(QTreeWidgetItem * parent, DocClipBase *clip, QSize pixmapSize); virtual ~ProjectItem(); QDomElement toXml() const; int numReferences() const; @@ -76,6 +76,10 @@ public: bool isJobRunning() const; /** \brief Returns true if we are currently creating the proxy for this clip. */ bool isProxyRunning() const; + /** \brief Returns true if the thumbnail for this clip has been loaded. */ + bool hasPixmap() const; + /** \brief Sets the thumbnail for this clip. */ + void setPixmap(const QPixmap p); virtual bool operator<(const QTreeWidgetItem &other)const { int column = treeWidget()->sortColumn(); @@ -88,8 +92,9 @@ private: CLIPTYPE m_clipType; DocClipBase *m_clip; QString m_clipId; + bool m_pixmapSet; /** @brief Setup basic properties */ - void buildItem(); + void buildItem(QSize pixmapSize); /** @brief Check if an xml project file has proxies */ bool playlistHasProxies(const QString path); }; diff --git a/src/projectlist.cpp b/src/projectlist.cpp index 5db34b1a..5f532320 100644 --- a/src/projectlist.cpp +++ b/src/projectlist.cpp @@ -739,7 +739,7 @@ void ProjectList::slotModifiedClip(const QString &id) } else { pixmap = KIcon("view-refresh").pixmap(m_listView->iconSize()); } - item->setData(0, Qt::DecorationRole, pixmap); + item->setPixmap(pixmap); } } @@ -763,7 +763,7 @@ void ProjectList::slotMissingClip(const QString &id) QPainter p(&pixmap); p.drawPixmap(3, 3, icon.pixmap(width - 6, height - 6)); p.end(); - item->setData(0, Qt::DecorationRole, pixmap); + item->setPixmap(pixmap); if (item->referencedClip()) { item->referencedClip()->setPlaceHolder(true); Mlt::Producer *newProd = m_render->invalidProducer(id); @@ -1295,6 +1295,7 @@ void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties) //m_listView->setEnabled(false); const QString parent = clip->getProperty("groupid"); QString groupName = clip->getProperty("groupname"); + QSize pixelSize((int)(m_listView->iconSize().height() * m_render->dar()), m_listView->iconSize().height()); ProjectItem *item = NULL; monitorItemEditing(false); if (!parent.isEmpty()) { @@ -1308,19 +1309,16 @@ void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties) } if (parentitem) - item = new ProjectItem(parentitem, clip); + item = new ProjectItem(parentitem, clip, pixelSize); } if (item == NULL) { - item = new ProjectItem(m_listView, clip); + item = new ProjectItem(m_listView, clip, pixelSize); } if (item->data(0, DurationRole).isNull()) item->setData(0, DurationRole, i18n("Loading")); connect(clip, SIGNAL(createProxy(const QString &)), this, SLOT(slotCreateProxy(const QString &))); connect(clip, SIGNAL(abortProxy(const QString &, const QString &)), this, SLOT(slotAbortProxy(const QString, const QString))); + if (getProperties) { - int height = m_listView->iconSize().height(); - int width = (int)(height * m_render->dar()); - QPixmap pix = KIcon("video-x-generic").pixmap(QSize(width, height)); - item->setData(0, Qt::DecorationRole, pix); //item->setFlags(Qt::ItemIsSelectable); m_listView->processLayout(); QDomElement e = clip->toXML().cloneNode().toElement(); @@ -1469,8 +1467,9 @@ void ProjectList::getCachedThumbnail(ProjectItem *item) requestClipThumbnail(item->clipId()); } else { - processThumbOverlays(item, pix); - item->setData(0, Qt::DecorationRole, pix); + QPixmap result = roundedPixmap(pix); + processThumbOverlays(item, result); + item->setPixmap(result); } } else { @@ -1478,6 +1477,34 @@ void ProjectList::getCachedThumbnail(ProjectItem *item) } } +QPixmap ProjectList::roundedPixmap(QImage img) +{ + QPixmap pix(img.width(), img.height()); + pix.fill(Qt::transparent); + QPainter p(&pix); + p.setRenderHint(QPainter::Antialiasing, true); + QPainterPath path; + path.addRoundedRect(0.5, 0.5, pix.width() - 1, pix.height() - 1, 2, 2); + p.setClipPath(path); + p.drawImage(0, 0, img); + p.end(); + return pix; +} + +QPixmap ProjectList::roundedPixmap(QPixmap source) +{ + QPixmap pix(source.width(), source.height()); + pix.fill(Qt::transparent); + QPainter p(&pix); + p.setRenderHint(QPainter::Antialiasing, true); + QPainterPath path; + path.addRoundedRect(0.5, 0.5, pix.width() - 1, pix.height() - 1, 2, 2); + p.setClipPath(path); + p.drawPixmap(0, 0, source); + p.end(); + return pix; +} + void ProjectList::getCachedThumbnail(SubProjectItem *item) { if (!item) return; @@ -1565,22 +1592,22 @@ void ProjectList::updateAllClips(bool displayRatioChanged, bool fpsChanged, QStr } else if (clip->isPlaceHolder()) { item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled); - if (item->data(0, Qt::DecorationRole).isNull()) { - item->setData(0, Qt::DecorationRole, missingPixmap); + if (!item->hasPixmap()) { + item->setPixmap(missingPixmap); } else { QPixmap pixmap = qVariantValue(item->data(0, Qt::DecorationRole)); QPainter p(&pixmap); p.drawPixmap(3, 3, KIcon("dialog-close").pixmap(pixmap.width() - 6, pixmap.height() - 6)); p.end(); - item->setData(0, Qt::DecorationRole, pixmap); + item->setPixmap(pixmap); } } } else { if (displayRatioChanged) { requestClipThumbnail(clip->getId()); } - else if (item->data(0, Qt::DecorationRole).isNull()) { + else if (!item->hasPixmap()) { getCachedThumbnail(item); } if (item->data(0, DurationRole).toString().isEmpty()) { @@ -1595,7 +1622,7 @@ void ProjectList::updateAllClips(bool displayRatioChanged, bool fpsChanged, QStr QPainter p(&pixmap); p.drawPixmap(3, 3, KIcon("dialog-close").pixmap(pixmap.width() - 6, pixmap.height() - 6)); p.end(); - item->setData(0, Qt::DecorationRole, pixmap); + item->setPixmap(pixmap); } else if (clip->getProperty("_replaceproxy") == "1") { clip->setProperty("_replaceproxy", QString()); @@ -2013,8 +2040,11 @@ void ProjectList::slotSetThumbnail(const QString &id, int framePos, QImage img) if (item && item->parent()) pItem = static_cast (item->parent()); if (!item && framePos == 0) pItem = getItemById(id); if (!item && !pItem) return; - if (item) item->setData(0, Qt::DecorationRole, QPixmap::fromImage(img)); - else if (pItem) pItem->setData(0, Qt::DecorationRole, QPixmap::fromImage(img)); + if (item) { + if (item->type() == PROJECTCLIPTYPE) static_cast(item)->setPixmap(QPixmap::fromImage(img)); + else item->setData(0, Qt::DecorationRole, QPixmap::fromImage(img)); + } + else if (pItem) pItem->setPixmap(QPixmap::fromImage(img)); if (pItem) { QString hash = pItem->getClipHash(); if (!hash.isEmpty()) m_doc->cacheImage(hash + '#' + QString::number(framePos), img); @@ -2124,26 +2154,22 @@ void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update) slotProcessNextThumbnail(); return; } - QPixmap pix; QImage img; int height = m_listView->iconSize().height(); int swidth = (int)(height * m_render->frameRenderWidth() / m_render->renderHeight()+ 0.5); int dwidth = (int)(height * m_render->dar() + 0.5); - if (clip->clipType() == AUDIO) - pix = KIcon("audio-x-generic").pixmap(QSize(dwidth, height)); - else if (clip->clipType() == IMAGE) { + if (clip->clipType() == IMAGE) { img = KThumb::getFrame(item->referencedClip()->getProducer(), 0, swidth, dwidth, height); } - else { + else if (clip->clipType() != AUDIO) { img = item->referencedClip()->extractImage(frame, dwidth, height); } - if (!pix.isNull() || !img.isNull()) { + if (!img.isNull()) { monitorItemEditing(false); - if (!img.isNull()) { - pix = QPixmap::fromImage(img); - processThumbOverlays(item, pix); - } - it->setData(0, Qt::DecorationRole, pix); + QPixmap pix = roundedPixmap(img); + processThumbOverlays(item, pix); + if (isSubItem) it->setData(0, Qt::DecorationRole, pix); + else item->setPixmap(pix); monitorItemEditing(true); QString hash = item->getClipHash(); @@ -2212,7 +2238,7 @@ void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Produce } } - if (!replace && m_allClipsProcessed && item->data(0, Qt::DecorationRole).isNull()) { + if (!replace && m_allClipsProcessed && !item->hasPixmap()) { getCachedThumbnail(item); } if (!toReload.isEmpty()) @@ -2335,18 +2361,10 @@ void ProjectList::slotReplyGetImage(const QString &clipId, const QImage &img) { ProjectItem *item = getItemById(clipId); if (item && !img.isNull()) { - QPixmap pix(img.width(), img.height()); - pix.fill(Qt::transparent); - QPainter p(&pix); - p.setRenderHint(QPainter::Antialiasing, true); - QPainterPath path; - path.addRoundedRect(0.5, 0.5, pix.width() - 1, pix.height() - 1, 2, 2); - p.setClipPath(path); - p.drawImage(0, 0, img); - p.end(); + QPixmap pix = roundedPixmap(img); processThumbOverlays(item, pix); monitorItemEditing(false); - item->setData(0, Qt::DecorationRole, pix); + item->setPixmap(pix); monitorItemEditing(true); QString hash = item->getClipHash(); if (!hash.isEmpty()) m_doc->cacheImage(hash, img); @@ -3496,7 +3514,8 @@ void ProjectList::startClipFilterJob(const QString &filterName, const QString &c QMap extraParams; extraParams.insert("key", "shot_change_list"); extraParams.insert("projecttreefilter", "1"); - extraParams.insert("resultmessage", i18n("Found %1 scenes.", "%count")); + QString keyword("%count"); + extraParams.insert("resultmessage", i18n("Found %1 scenes.", keyword)); if (ui.add_markers->isChecked()) { // We want to create markers extraParams.insert("addmarkers", QString::number(ui.marker_type->currentIndex())); diff --git a/src/projectlist.h b/src/projectlist.h index af8605b1..8c5cd95c 100644 --- a/src/projectlist.h +++ b/src/projectlist.h @@ -168,31 +168,28 @@ public: QString subText = index.data(DurationRole).toString(); int usage = index.data(UsageRole).toInt(); if (usage != 0) subText.append(QString(" (%1)").arg(usage)); - if (option.state & (QStyle::State_Selected)) painter->setPen(option.palette.color(QPalette::Mid)); QRectF bounding; painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , subText, &bounding); - int jobProgress = index.data(Qt::UserRole + 5).toInt(); if (jobProgress != 0 && jobProgress != JOBDONE && jobProgress != JOBABORTED) { if (jobProgress != JOBCRASHED) { // Draw job progress bar QColor color = option.palette.alternateBase().color(); - painter->setPen(Qt::NoPen); - color.setAlpha(180); - painter->setBrush(QBrush(color)); - QRect progress(pixmapPoint.x() + 1, pixmapPoint.y() + pixmap.height() - 9, pixmap.width() - 2, 8); - painter->drawRect(progress); - painter->setBrush(option.palette.text()); - if (jobProgress > 0) { - progress.adjust(1, 1, 0, -1); - progress.setWidth((pixmap.width() - 4) * jobProgress / 100); - painter->drawRect(progress); - } else if (jobProgress == JOBWAITING) { - // Draw kind of a pause icon - progress.adjust(1, 1, 0, -1); - progress.setWidth(2); - painter->drawRect(progress); - progress.moveLeft(progress.right() + 2); + color.setAlpha(150); + painter->setPen(option.palette.link().color()); + QRect progress(pixmapPoint.x() + 2, pixmapPoint.y() + pixmap.height() - 9, pixmap.width() - 4, 7); + painter->setBrush(QBrush(color)); + painter->drawRect(progress); + painter->setBrush(option.palette.link()); + progress.adjust(2, 2, -2, -2); + if (jobProgress == JOBWAITING) { + progress.setLeft(progress.right() - 2); + painter->drawRect(progress); + progress.moveLeft(progress.left() - 5); + painter->drawRect(progress); + } + else if (jobProgress > 0) { + progress.setWidth(progress.width() * jobProgress / 100); painter->drawRect(progress); } } else if (jobProgress == JOBCRASHED) { @@ -426,6 +423,9 @@ private: QStringList getPendingJobs(const QString &id); /** @brief Start an MLT process job. */ void processClipJob(QStringList ids, const QString&destination, bool autoAdd, QStringList jobParams, const QString &description, QMap extraParams = QMap ()); + /** @brief Create rounded shape pixmap for project tree thumb. */ + QPixmap roundedPixmap(QImage img); + QPixmap roundedPixmap(QPixmap source); private slots: void slotClipSelected(); -- 2.39.5