diff edwaveform.cpp @ 565:a4666c9e1336

Moar work on the editor (broken).
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 22 Dec 2012 16:56:30 +0200
parents d34922e6a244
children
line wrap: on
line diff
--- a/edwaveform.cpp	Thu Dec 20 01:44:01 2012 +0200
+++ b/edwaveform.cpp	Sat Dec 22 16:56:30 2012 +0200
@@ -87,7 +87,6 @@
     if (time != mtime && mtime >= 0 && mtime < duration)
     {
         time = mtime;
-        update();
         emit timeChanged(time);
     }
 }
@@ -98,7 +97,6 @@
     if (offs != moffs && moffs >= 0 && moffs < getDuration())
     {
         offs = moffs;
-        update();
         emit offsetChanged(offs);
     }
 }
@@ -108,7 +106,47 @@
 {
     if (mscale > 0.05)
         scale = mscale;
-    update();
+    emit scaleChanged(scale);
+}
+
+
+void QEDWaveTrackDisplay::setSelection(const float mstart, const float mend)
+{
+    if (mstart >= 0 && mend >= 0 && fabs(mend - mstart) > 0)
+    {
+        selectionValid = true;
+        if (mend > mstart)
+        {
+            selectionStart    = mstart;
+            selectionDuration = mend - mstart + 1;
+        }
+        else
+        {
+            selectionStart    = mend;
+            selectionDuration = mstart - mend + 1;
+        }
+        emit selectionChanged(selectionStart, selectionDuration);
+    }
+}
+
+
+void QEDWaveTrackDisplay::clearSelection()
+{
+    selectionValid    = false;
+    selectionStart    = 0;
+    selectionDuration = 0;
+    emit selectionChanged(selectionStart, selectionDuration);
+}
+
+
+bool QEDTimelineTrackDisplay::getSelection(float *mstart, float *mduration)
+{
+    if (selectionValid)
+    {
+        *mstart = selectionStart;
+        *mduration = selectionDuration;
+    }
+    return selectionValid;
 }
 
 
@@ -219,18 +257,34 @@
 
 void QEDWaveTrackDisplay::mousePressEvent(QMouseEvent *ev)
 {
-    if (ev->button() == Qt::LeftButton)
+    switch (ev->button())
     {
-        dragPoint = ev->pos();
-        dragOffs = offs;
-        dragging = false;
+        case Qt::LeftButton:
+            selectionPoint = ev->pos();
+            selectionOffs = offs;
+            selecting = false;
+            break;
+
+        case Qt::RightButton:
+            dragPoint = ev->pos();
+            dragOffs = offs;
+            dragging = false;
+            break;
+
+        default:
+            break;
     }
 }
 
 
 void QEDWaveTrackDisplay::mouseMoveEvent(QMouseEvent *ev)
 {
-    if ((ev->buttons() & Qt::LeftButton) && ev->pos().x() != dragPoint.x())
+    if ((ev->buttons() & Qt::LeftButton) && ev->pos().x() != selPoint.x())
+    {
+        selecting = true;
+        setSelection(selectionOffs + (ev->pos().x() - selectionPoint.x()) / scale);
+    }
+    if ((ev->buttons() & Qt::RightButton) && ev->pos().x() != dragPoint.x())
     {
         dragging = true;
         setOffset(dragOffs - (ev->pos().x() - dragPoint.x()) / scale);
@@ -242,7 +296,11 @@
 {
     if (ev->button() == Qt::LeftButton)
     {
-        dragging = false;
+        if (selecting)
+        {
+            selecting = false;
+            setSelection(selOffs + (ev->pos().x() - selPoint.x()) / scale);
+        }
     }
     else
     if (ev->button() == Qt::RightButton && !dragging)
@@ -265,7 +323,6 @@
 
     QVBoxLayout *infoLayout = new QVBoxLayout(infoLayoutContainer);
     infoLayout->setMargin(0);
-//    QVBoxLayout *infoLayout = new QVBoxLayout();
     infoName = new QLabel("Audio");
     infoName->setStyleSheet("QLabel { background-color: black; color: white; padding: 2px; }");
     infoLayout->addWidget(infoName);
@@ -275,11 +332,11 @@
     infoLayout->addWidget(infoData);
 
     mainLayout->addWidget(infoLayoutContainer);
-//    mainLayout->addLayout(infoLayout);
     mainLayout->addWidget(wave);
 
     connect(wave, SIGNAL(timeChanged(float)), this, SLOT(slotTimeChanged(float)));
     connect(wave, SIGNAL(offsetChanged(float)), this, SLOT(slotOffsetChanged(float)));
+    connect(wave, SIGNAL(selectionChanged(float,float)), this, SLOT(slotSelectionChanged(float,float)));
 }