From d2c65ec06ade4d3cb26e649989a5b5a164637e59 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mardelle Date: Mon, 14 Jan 2013 16:59:45 +0100 Subject: [PATCH] * Cleanup transode stabilize GUI: http://kdenlive.org/mantis/view.php?id=2930 * Show thumbnail in marker tooltip in monitor ruler --- src/abstractmonitor.cpp | 2 +- src/clipstabilize.cpp | 14 +++++++----- src/clipstabilize.h | 1 + src/definitions.h | 2 ++ src/kthumb.cpp | 2 +- src/mainwindow.cpp | 9 +++++++- src/markerdialog.cpp | 15 +++++++++---- src/markerdialog.h | 2 ++ src/monitor.cpp | 22 ++++++++++++++++++- src/monitor.h | 6 +++++ src/monitormanager.cpp | 17 +++++++++++++++ src/monitormanager.h | 6 +++++ src/smallruler.cpp | 46 +++++++++++++++++++++++++++++---------- src/smallruler.h | 4 ++-- src/widgets/monitor_ui.ui | 2 +- 15 files changed, 121 insertions(+), 29 deletions(-) diff --git a/src/abstractmonitor.cpp b/src/abstractmonitor.cpp index 9f108832..b1b3875c 100644 --- a/src/abstractmonitor.cpp +++ b/src/abstractmonitor.cpp @@ -71,7 +71,7 @@ VideoContainer::VideoContainer(AbstractMonitor* monitor, QWidget *parent) : setFrameShape(QFrame::NoFrame); setFocusPolicy(Qt::ClickFocus); //setEnabled(false); - setContentsMargins(2, 2, 2, 2); + setContentsMargins(0, 0, 0, 0); setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); } diff --git a/src/clipstabilize.cpp b/src/clipstabilize.cpp index 85085521..dcfd55c4 100644 --- a/src/clipstabilize.cpp +++ b/src/clipstabilize.cpp @@ -80,19 +80,21 @@ ClipStabilize::ClipStabilize(const QString &dest, int count, const QString &filt ls << "shutterangle,type,int,value,0,min,0,max,180,tooltip,Angle that Images could be maximum rotated"; fillParameters(ls); }else if (m_filtername=="videostab2"){ + // Some default params have to be set: + m_fixedParams << "algo=1" << "relative=1"; QStringList ls; - ls << "accuracy,type,int,value,4,min,1,max,10,tooltip,Accuracy of Shakiness detection"; + ls << "accuracy,type,int,value,8,min,1,max,10,tooltip,Accuracy of Shakiness detection"; ls << "shakiness,type,int,value,4,min,1,max,10,tooltip,How shaky is the Video"; ls << "stepsize,type,int,value,6,min,0,max,100,tooltip,Stepsize of Detection process minimum around"; - ls << "algo,type,bool,value,1,min,0,max,1,tooltip,0 = Bruteforce 1 = small measurement fields"; + //ls << "algo,type,bool,value,1,min,0,max,1,tooltip,0 = Bruteforce 1 = small measurement fields"; ls << "mincontrast,type,double,value,0.3,min,0,max,1,factor,1,decimals,2,tooltip,Below this Contrast Field is discarded"; - ls << "show,type,int,value,0,min,0,max,2,tooltip,0 = draw nothing. 1 or 2 show fields and transforms"; + //ls << "show,type,int,value,0,min,0,max,2,tooltip,0 = draw nothing. 1 or 2 show fields and transforms"; ls << "smoothing,type,int,value,10,min,0,max,100,tooltip,number of frames for lowpass filtering"; ls << "maxshift,type,int,value,-1,min,-1,max,1000,tooltip,max number of pixels to shift"; ls << "maxangle,type,int,value,-1,min,-1,max,1000,tooltip,max anglen to rotate (in rad)"; ls << "crop,type,bool,value,0,min,0,max,1,tooltip,0 = keep border 1 = black background"; - ls << "invert,type,bool,value,0,min,0,max,1,tooltip,invert transform"; - ls << "relative,type,bool,value,1,min,0,max,1,tooltip,0 = absolute transform 1= relative"; + //ls << "invert,type,bool,value,0,min,0,max,1,tooltip,invert transform"; + //ls << "relative,type,bool,value,1,min,0,max,1,tooltip,0 = absolute transform 1= relative"; ls << "zoom,type,int,value,0,min,-500,max,500,tooltip,additional zoom during transform"; ls << "optzoom,type,bool,value,1,min,0,max,1,tooltip,use optimal zoom (calulated from transforms)"; ls << "sharpen,type,double,value,0.8,min,0,max,1,decimals,1,tooltip,sharpen transformed image"; @@ -145,7 +147,7 @@ QStringList ClipStabilize::params() params << QString(); // filter params << m_filtername; - QStringList filterparamsList; + QStringList filterparamsList = m_fixedParams; QHashIterator > it(m_ui_params); while (it.hasNext()){ it.next(); diff --git a/src/clipstabilize.h b/src/clipstabilize.h index 269c0c4b..b09969ae 100644 --- a/src/clipstabilize.h +++ b/src/clipstabilize.h @@ -64,6 +64,7 @@ private: QHash > m_ui_params; QVBoxLayout *vbox; void fillParameters(QStringList); + QStringList m_fixedParams; signals: void addClip(KUrl url); diff --git a/src/definitions.h b/src/definitions.h index b525a77f..738e133d 100644 --- a/src/definitions.h +++ b/src/definitions.h @@ -32,8 +32,10 @@ const int MAXCLIPDURATION = 15000; + namespace Kdenlive { enum MONITORID { noMonitor, clipMonitor, projectMonitor, recordMonitor, stopmotionMonitor, dvdMonitor }; + const int DefaultThumbHeight = 100; /*const QString clipMonitor("clipMonitor"); const QString recordMonitor("recordMonitor"); const QString projectMonitor("projectMonitor"); diff --git a/src/kthumb.cpp b/src/kthumb.cpp index 4dc0a294..ef9e98ca 100644 --- a/src/kthumb.cpp +++ b/src/kthumb.cpp @@ -114,7 +114,7 @@ void KThumb::extractImage(QList frames) void KThumb::getThumb(int frame) { - const int theight = 120;//KdenliveSettings::trackheight(); + const int theight = Kdenlive::DefaultThumbHeight; const int swidth = (int)(theight * m_ratio + 0.5); const int dwidth = (int)(theight * m_dar + 0.5); QImage img = getProducerFrame(frame, swidth, dwidth, theight); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index e273a984..693ba5f2 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -2012,6 +2012,7 @@ bool MainWindow::closeCurrentDocument(bool saveChanges) if (docToClose == m_activeDocument) { delete m_activeDocument; m_activeDocument = NULL; + m_monitorManager->setDocument(m_activeDocument); m_effectStack->clear(); m_transitionConfig->slotTransitionItemSelected(NULL, 0, QPoint(), false); } else { @@ -2694,6 +2695,7 @@ void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) //cha m_saveAction->setEnabled(doc->isModified()); m_normalEditTool->setChecked(true); m_activeDocument = doc; + m_monitorManager->setDocument(m_activeDocument); m_activeTimeline->updateProjectFps(); m_activeDocument->checkProjectClips(); #ifndef Q_WS_MAC @@ -2890,8 +2892,11 @@ void MainWindow::slotAddClipMarker() CommentedTime marker(pos, i18n("Marker"), KdenliveSettings::default_marker_type()); QPointer d = new MarkerDialog(clip, marker, m_activeDocument->timecode(), i18n("Add Marker"), this); - if (d->exec() == QDialog::Accepted) + if (d->exec() == QDialog::Accepted) { m_activeTimeline->projectView()->slotAddClipMarker(id, QList () << d->newMarker()); + QString hash = clip->getClipHash(); + if (!hash.isEmpty()) m_activeDocument->cacheImage(hash + '#' + QString::number(d->newMarker().time().frames(m_activeDocument->fps())), d->markerImage()); + } delete d; } @@ -2977,6 +2982,8 @@ void MainWindow::slotEditClipMarker() m_activeDocument->timecode(), i18n("Edit Marker"), this); if (d->exec() == QDialog::Accepted) { m_activeTimeline->projectView()->slotAddClipMarker(id, QList () <newMarker()); + QString hash = clip->getClipHash(); + if (!hash.isEmpty()) m_activeDocument->cacheImage(hash + '#' + QString::number(d->newMarker().time().frames(m_activeDocument->fps())), d->markerImage()); if (d->newMarker().time() != pos) { // remove old marker oldMarker.setMarkerType(-1); diff --git a/src/markerdialog.cpp b/src/markerdialog.cpp index e1e8283d..bf0a7578 100644 --- a/src/markerdialog.cpp +++ b/src/markerdialog.cpp @@ -64,11 +64,11 @@ MarkerDialog::MarkerDialog(DocClipBase *clip, CommentedTime t, Timecode tc, cons //char *tmp = doc.toString().toUtf8().data(); m_producer = new Mlt::Producer(*m_profile, "xml-string", doc.toString().toUtf8().data()); //delete[] tmp; - int width = 100.0 * m_dar; + int width = Kdenlive::DefaultThumbHeight * m_dar; if (width % 2 == 1) width++; QPixmap p(width, 100); QString colour = clip->getProperty("colour"); - int swidth = (int) (100.0 * m_profile->width() / m_profile->height() + 0.5); + int swidth = (int) (Kdenlive::DefaultThumbHeight * m_profile->width() / m_profile->height() + 0.5); switch (m_clip->clipType()) { case VIDEO: @@ -78,7 +78,8 @@ MarkerDialog::MarkerDialog(DocClipBase *clip, CommentedTime t, Timecode tc, cons connect(this, SIGNAL(updateThumb()), m_previewTimer, SLOT(start())); case IMAGE: case TEXT: - p = QPixmap::fromImage(KThumb::getFrame(m_producer, m_in->getValue(), swidth, width, 100)); + m_image = KThumb::getFrame(m_producer, m_in->getValue(), swidth, width, Kdenlive::DefaultThumbHeight); + p = QPixmap::fromImage(m_image); break; case COLOR: colour = colour.replace(0, 2, "#"); @@ -121,13 +122,19 @@ void MarkerDialog::slotUpdateThumb() int width = 100.0 * m_dar; int swidth = (int) (100.0 * m_profile->width() / m_profile->height() + 0.5); if (width % 2 == 1) width++; - QPixmap p = QPixmap::fromImage(KThumb::getFrame(m_producer, pos, swidth, width, 100)); + m_image = KThumb::getFrame(m_producer, pos, swidth, width, 100); + QPixmap p = QPixmap::fromImage(m_image); if (!p.isNull()) clip_thumb->setPixmap(p); else kDebug() << "!!!!!!!!!!! ERROR CREATING THUMB"; } +QImage MarkerDialog::markerImage() const +{ + return m_image; +} + CommentedTime MarkerDialog::newMarker() { KdenliveSettings::setDefault_marker_type(marker_type->currentIndex()); diff --git a/src/markerdialog.h b/src/markerdialog.h index 88960ca4..6a78e468 100644 --- a/src/markerdialog.h +++ b/src/markerdialog.h @@ -47,6 +47,7 @@ public: MarkerDialog(DocClipBase *clip, CommentedTime t, Timecode tc, const QString &caption, QWidget * parent = 0); ~MarkerDialog(); CommentedTime newMarker(); + QImage markerImage() const; private slots: void slotUpdateThumb(); @@ -55,6 +56,7 @@ private: Mlt::Producer *m_producer; Mlt::Profile *m_profile; DocClipBase *m_clip; + QImage m_image; TimecodeDisplay *m_in; double m_dar; QTimer *m_previewTimer; diff --git a/src/monitor.cpp b/src/monitor.cpp index 1c74137f..12093fb8 100644 --- a/src/monitor.cpp +++ b/src/monitor.cpp @@ -173,7 +173,7 @@ Monitor::Monitor(Kdenlive::MONITORID id, MonitorManager *manager, QString profil #endif // Monitor ruler - m_ruler = new SmallRuler(m_monitorManager, render); + m_ruler = new SmallRuler(this, render); if (id == Kdenlive::dvdMonitor) m_ruler->setZone(-3, -2); layout->addWidget(m_ruler); @@ -350,6 +350,16 @@ void Monitor::resetSize() videoBox->setMinimumSize(0, 0); } +QString Monitor::getTimecodeFromFrames(int pos) +{ + return m_monitorManager->timecode().getTimecodeFromFrames(pos); +} + +double Monitor::fps() const +{ + return m_monitorManager->timecode().fps(); +} + DocClipBase *Monitor::activeClip() { return m_currentClip; @@ -1128,6 +1138,16 @@ void Monitor::reloadProducer(const QString &id) slotSetClipProducer(m_currentClip, m_currentClip->zone(), true); } +QString Monitor::getMarkerThumb(GenTime pos) +{ + if (!m_currentClip) return QString(); + if (!m_currentClip->getClipHash().isEmpty()) { + QString url = m_monitorManager->getProjectFolder() + "thumbs/" + m_currentClip->getClipHash() + '#' + QString::number(pos.frames(m_monitorManager->timecode().fps())) + ".png"; + if (QFile::exists(url)) return url; + } + return QString(); +} + void Monitor::setPalette ( const QPalette & p) { QWidget::setPalette(p); diff --git a/src/monitor.h b/src/monitor.h index 84a8b9b3..d6bc5b60 100644 --- a/src/monitor.h +++ b/src/monitor.h @@ -92,6 +92,12 @@ public: QFrame *m_volumePopup; /** @brief Reimplemented from QWidget, updates the palette colors. */ void setPalette ( const QPalette & p); + /** @brief Returns a hh:mm:ss timecode from a frame number. */ + QString getTimecodeFromFrames(int pos); + /** @brief Returns current project's fps. */ + double fps() const; + /** @brief Get url for the clip's thumbnail */ + QString getMarkerThumb(GenTime pos); protected: virtual void mousePressEvent(QMouseEvent * event); diff --git a/src/monitormanager.cpp b/src/monitormanager.cpp index a871bb51..8a065bf0 100644 --- a/src/monitormanager.cpp +++ b/src/monitormanager.cpp @@ -21,6 +21,7 @@ #include "monitormanager.h" #include "renderer.h" #include "kdenlivesettings.h" +#include "kdenlivedoc.h" #include @@ -31,6 +32,7 @@ MonitorManager::MonitorManager(QWidget *parent) : QObject(parent), + m_document(NULL), m_clipMonitor(NULL), m_projectMonitor(NULL), m_activeMonitor(NULL) @@ -42,6 +44,11 @@ Timecode MonitorManager::timecode() return m_timecode; } +void MonitorManager::setDocument(KdenliveDoc *doc) +{ + m_document = doc; +} + void MonitorManager::initMonitors(Monitor *clipMonitor, Monitor *projectMonitor, RecMonitor *recMonitor) { m_clipMonitor = clipMonitor; @@ -255,4 +262,14 @@ void MonitorManager::slotSwitchFullscreen() if (m_activeMonitor) m_activeMonitor->slotSwitchFullScreen(); } +QString MonitorManager::getProjectFolder() const +{ + if (m_document == NULL) { + kDebug()<<" + + +NULL DOC!!"; + return QString(); + } + return m_document->projectFolder().path(KUrl::AddTrailingSlash); +} + + #include "monitormanager.moc" diff --git a/src/monitormanager.h b/src/monitormanager.h index 8ce0e3f3..91ba7021 100644 --- a/src/monitormanager.h +++ b/src/monitormanager.h @@ -25,6 +25,7 @@ #include "recmonitor.h" #include "timecode.h" +class KdenliveDoc; class MonitorManager : public QObject { @@ -45,6 +46,10 @@ public: AbstractMonitor *monitor(Kdenlive::MONITORID monitorName); void updateScopeSource(); void clearScopeSource(); + /** @brief Returns current project's folder. */ + QString getProjectFolder() const; + /** @brief Sets current document for later reference. */ + void setDocument(KdenliveDoc *doc); public slots: @@ -79,6 +84,7 @@ private slots: void slotRefreshCurrentMonitor(const QString &id); private: + KdenliveDoc *m_document; Monitor *m_clipMonitor; Monitor *m_projectMonitor; Timecode m_timecode; diff --git a/src/smallruler.cpp b/src/smallruler.cpp index 3673cbb1..74c7692b 100644 --- a/src/smallruler.cpp +++ b/src/smallruler.cpp @@ -31,11 +31,11 @@ #define SEEK_INACTIVE (-1) -SmallRuler::SmallRuler(MonitorManager *manager, Render *render, QWidget *parent) : +SmallRuler::SmallRuler(Monitor *monitor, Render *render, QWidget *parent) : QWidget(parent) ,m_cursorFramePosition(0) ,m_maxval(2) - ,m_manager(manager) + ,m_monitor(monitor) ,m_render(render) ,m_lastSeekPosition(SEEK_INACTIVE) ,m_cursorColor(palette().text()) @@ -46,7 +46,7 @@ SmallRuler::SmallRuler(MonitorManager *manager, Render *render, QWidget *parent) m_zoneBrush = KStatefulBrush(KColorScheme::View, KColorScheme::PositiveBackground, config); setMouseTracking(true); - setMinimumHeight(10); + setMinimumHeight(8); adjustScale(m_maxval); } @@ -176,12 +176,28 @@ void SmallRuler::mouseMoveEvent(QMouseEvent * event) update(); } if (qAbs((pos - m_zoneStart) * m_scale) < 4) { - setToolTip(i18n("Zone start: %1", m_manager->timecode().getTimecodeFromFrames(m_zoneStart))); + setToolTip(i18n("Zone start: %1", m_monitor->getTimecodeFromFrames(m_zoneStart))); } else if (qAbs((pos - m_zoneEnd) * m_scale) < 4) { - setToolTip(i18n("Zone end: %1", m_manager->timecode().getTimecodeFromFrames(m_zoneEnd))); - } else if (pos > m_zoneStart && pos < m_zoneEnd) { - setToolTip(i18n("Zone duration: %1", m_manager->timecode().getTimecodeFromFrames(m_zoneEnd - m_zoneStart))); - } else setToolTip(i18n("Position: %1", m_manager->timecode().getTimecodeFromFrames(pos))); + setToolTip(i18n("Zone end: %1", m_monitor->getTimecodeFromFrames(m_zoneEnd))); + } + for (int i = 0; i < m_markers.count(); i++) { + if (qAbs((pos - m_markers.at(i).time().frames(m_monitor->fps())) * m_scale) < 4) { + // We are on a marker + QString markerxt = m_monitor->getMarkerThumb(m_markers.at(i).time()); + if (!markerxt.isEmpty()) { + markerxt.prepend("

"); + } + markerxt.append(m_markers.at(i).comment()); + setToolTip(markerxt); + event->accept(); + return; + } + } + if (pos > m_zoneStart && pos < m_zoneEnd) { + setToolTip(i18n("Zone duration: %1", m_monitor->getTimecodeFromFrames(m_zoneEnd - m_zoneStart))); + } + else setToolTip(i18n("Position: %1", m_monitor->getTimecodeFromFrames(pos))); } event->accept(); } @@ -226,10 +242,13 @@ void SmallRuler::updatePixmap() const int zoneEnd = (int)(m_zoneEnd * m_scale); p.setPen(Qt::NoPen); p.setBrush(m_zoneBrush.brush(this)); - p.drawRect(zoneStart, height() / 2 - 1, zoneEnd - zoneStart, height() / 2); + p.drawRect(zoneStart, 0, zoneEnd - zoneStart, height()); // draw ruler - p.setPen(palette().text().color()); + p.setPen(palette().midlight().color()); + //p.drawLine(0, 0, width(), 0); + p.drawLine(0, height() - 1, width(), height() - 1); + p.setPen(palette().dark().color()); // draw the little marks fend = m_scale * m_small; if (fend > 2) for (f = 0; f < width(); f += fend) { @@ -244,7 +263,7 @@ void SmallRuler::updatePixmap() // draw markers if (!m_markers.isEmpty()) { for (int i = 0; i < m_markers.count(); i++) { - int pos = m_markers.at(i).time().frames(m_manager->timecode().fps()) * m_scale; + int pos = m_markers.at(i).time().frames(m_monitor->fps()) * m_scale; p.setPen(CommentedTime::markerColor(m_markers.at(i).markerType())); p.drawLine(pos, 0, pos, 9); } @@ -261,11 +280,14 @@ void SmallRuler::paintEvent(QPaintEvent *e) QRect r = e->rect(); p.setClipRect(r); p.drawPixmap(QPointF(), m_pixmap); + p.setPen(palette().shadow().color()); + //p.setRenderHint(QPainter::Antialiasing, true); + //p.drawRoundedRect(rect().adjusted(1,1,-2,-2), 3, 3); int cursorPos = m_cursorFramePosition * m_scale; // draw pointer QPolygon pa(3); - pa.setPoints(3, cursorPos - 6, 10, cursorPos + 6, 10, cursorPos/*+0*/, 4); + pa.setPoints(3, cursorPos - 6, 7, cursorPos + 6, 7, cursorPos/*+0*/, 0); p.setBrush(m_cursorColor); p.setPen(Qt::NoPen); p.drawPolygon(pa); diff --git a/src/smallruler.h b/src/smallruler.h index ac7217e2..30b09413 100644 --- a/src/smallruler.h +++ b/src/smallruler.h @@ -32,7 +32,7 @@ class SmallRuler : public QWidget Q_OBJECT public: - explicit SmallRuler(MonitorManager *manager, Render *render, QWidget *parent = 0); + explicit SmallRuler(Monitor *manager, Render *render, QWidget *parent = 0); virtual void mousePressEvent(QMouseEvent * event); virtual void mouseMoveEvent(QMouseEvent * event); virtual void mouseReleaseEvent(QMouseEvent * event); @@ -62,7 +62,7 @@ private: KStatefulBrush m_zoneBrush; QList m_markers; QPixmap m_pixmap; - MonitorManager *m_manager; + Monitor *m_monitor; Render *m_render; int m_lastSeekPosition; QBrush m_cursorColor; diff --git a/src/widgets/monitor_ui.ui b/src/widgets/monitor_ui.ui index e43077ee..da42b948 100644 --- a/src/widgets/monitor_ui.ui +++ b/src/widgets/monitor_ui.ui @@ -28,7 +28,7 @@ 16 - 10 + 8 -- 2.39.2