]> git.sesse.net Git - kdenlive/blobdiff - src/vectorscope.cpp
Add animation feature to Slideshow Clip.
[kdenlive] / src / vectorscope.cpp
index 897d9cf7388b8e1bdc39027449998f03c5d5aed3..ab90ced0fb7eddf2f8039e42a05d3f3d7ab51631 100644 (file)
@@ -26,7 +26,6 @@
 
 const float P75 = .75;
 const unsigned char DEFAULT_Y = 255;
-//const unsigned int REALTIME_FPS = 15; // in fps.
 
 const QPointF YUV_R(-.147,  .615);
 const QPointF YUV_G(-.289, -.515);
@@ -49,8 +48,6 @@ Vectorscope::Vectorscope(Monitor *projMonitor, Monitor *clipMonitor, QWidget *pa
     ui = new Ui::Vectorscope_UI();
     ui->setupUi(this);
 
-    //TODO don't draw circle when mouseLeaved
-
     m_colorTools = new ColorTools();
     m_colorPlaneExport = new ColorPlaneExport(this);
     m_vectorscopeGenerator = new VectorscopeGenerator();
@@ -86,13 +83,11 @@ Vectorscope::Vectorscope(Monitor *projMonitor, Monitor *clipMonitor, QWidget *pa
 
     m_a75PBox = new QAction(i18n("75% box"), this);
     m_a75PBox->setCheckable(true);
-    m_a75PBox->setChecked(false);
     m_menu->addAction(m_a75PBox);
     b &= connect(m_a75PBox, SIGNAL(changed()), this, SLOT(forceUpdateBackground()));
 
     m_aAxisEnabled = new QAction(i18n("Draw axis"), this);
     m_aAxisEnabled->setCheckable(true);
-    m_aAxisEnabled->setChecked(false);
     m_menu->addAction(m_aAxisEnabled);
     b &= connect(m_aAxisEnabled, SIGNAL(changed()), this, SLOT(forceUpdateBackground()));
 
@@ -101,10 +96,14 @@ Vectorscope::Vectorscope(Monitor *projMonitor, Monitor *clipMonitor, QWidget *pa
 
     this->setMouseTracking(true);
     slotGainChanged(ui->sliderGain->value());
+
+    init();
 }
 
 Vectorscope::~Vectorscope()
 {
+    writeConfig();
+
     delete m_colorTools;
     delete m_colorPlaneExport;
     delete m_vectorscopeGenerator;
@@ -114,28 +113,49 @@ Vectorscope::~Vectorscope()
     delete m_a75PBox;
 }
 
-QString Vectorscope::widgetName() const {
-    return QString("Vectorscope");
+QString Vectorscope::widgetName() const { return QString("Vectorscope"); }
+
+void Vectorscope::readConfig()
+{
+    AbstractScopeWidget::readConfig();
+
+    KSharedConfigPtr config = KGlobal::config();
+    KConfigGroup scopeConfig(config, configName());
+    m_a75PBox->setChecked(scopeConfig.readEntry("75PBox", false));
+    m_aAxisEnabled->setChecked(scopeConfig.readEntry("axis", false));
+    ui->backgroundMode->setCurrentIndex(scopeConfig.readEntry("backgroundmode").toInt());
+    ui->paintMode->setCurrentIndex(scopeConfig.readEntry("paintmode").toInt());
+    ui->sliderGain->setValue(scopeConfig.readEntry("gain", 1));
 }
 
-QRect Vectorscope::scopeRect()
+void Vectorscope::writeConfig()
 {
-    // Widget width/height
-    int ww = this->size().width();
-    int wh = this->size().height();
+    KSharedConfigPtr config = KGlobal::config();
+    KConfigGroup scopeConfig(config, configName());
+    scopeConfig.writeEntry("75PBox", m_a75PBox->isChecked());
+    scopeConfig.writeEntry("axis", m_aAxisEnabled->isChecked());
+    scopeConfig.writeEntry("backgroundmode", ui->backgroundMode->currentIndex());
+    scopeConfig.writeEntry("paintmode", ui->paintMode->currentIndex());
+    scopeConfig.writeEntry("gain", ui->sliderGain->value());
+    scopeConfig.sync();
+}
 
+QRect Vectorscope::scopeRect()
+{
     // Distance from top/left/right
     int offset = 6;
 
     // We want to paint below the controls area. The line is the lowest element.
-    QPoint topleft(offset, ui->line->y()+offset);
+    QPoint topleft(offset, ui->verticalSpacer->geometry().y()+offset);
+    QPoint bottomright(ui->horizontalSpacer->geometry().right()-offset, this->size().height()-offset);
+
+    QRect scopeRect(topleft, bottomright);
 
     // Circle Width: min of width and height
-    cw = wh - topleft.y();
-    if (ww < cw) { cw = ww; }
-    cw -= 2*offset;
+    cw = (scopeRect.height() < scopeRect.width()) ? scopeRect.height() : scopeRect.width();
+    scopeRect.setWidth(cw);
+    scopeRect.setHeight(cw);
 
-    QRect scopeRect(topleft, QPoint(cw, cw) + topleft);
 
     m_centerPoint = m_vectorscopeGenerator->mapToCircle(scopeRect.size(), QPointF(0,0));
     pR75 = m_vectorscopeGenerator->mapToCircle(scopeRect.size(), P75*VectorscopeGenerator::scaling*YUV_R);
@@ -179,7 +199,11 @@ QImage Vectorscope::renderHUD(uint)
             davinci.setPen(penLight);
             break;
         default:
-            davinci.setPen(penDark);
+            if (r > cw/2) {
+                davinci.setPen(penLight);
+            } else {
+                davinci.setPen(penDark);
+            }
             break;
         }
         davinci.drawEllipse(m_centerPoint, (int)r, (int)r);
@@ -197,7 +221,7 @@ QImage Vectorscope::renderHUD(uint)
     return hud;
 }
 
-QImage Vectorscope::renderScope(uint accelerationFactor)
+QImage Vectorscope::renderScope(uint accelerationFactor, QImage qimage)
 {
     QTime start = QTime::currentTime();
     QImage scope;
@@ -207,17 +231,14 @@ QImage Vectorscope::renderScope(uint accelerationFactor)
     } else {
 
         scope = m_vectorscopeGenerator->calculateVectorscope(m_scopeRect.size(),
-                                                             m_activeRender->extractFrame(m_activeRender->seekFramePosition()),
+                                                             qimage,
                                                              m_gain, (VectorscopeGenerator::PaintMode) ui->paintMode->itemData(ui->paintMode->currentIndex()).toInt(),
                                                              m_aAxisEnabled->isChecked(), accelerationFactor);
 
     }
 
     unsigned int mseconds = start.msecsTo(QTime::currentTime());
-//    qDebug() << "Scope rendered in " << mseconds << " ms. Sending finished signal.";
-//    emit signalScopeCalculationFinished(mseconds, skipPixels);
     emit signalScopeRenderingFinished(mseconds, accelerationFactor);
-//    qDebug() << "xxScope: Signal finished sent.";
     return scope;
 }
 
@@ -388,3 +409,12 @@ void Vectorscope::mouseMoveEvent(QMouseEvent *event)
     m_mousePos = event->pos();
     forceUpdateHUD();
 }
+
+void Vectorscope::leaveEvent(QEvent *event)
+{
+    // Repaint the HUD without the circle
+
+    m_circleEnabled = false;
+    QWidget::leaveEvent(event);
+    forceUpdateHUD();
+}