# HG changeset patch # User Matti Hamalainen # Date 1356188190 -7200 # Node ID a4666c9e1336e7dfb3b90c87f4f1333ac8bf7dd3 # Parent 2dbe70d404814e127b987a30953c2b454160dd3d Moar work on the editor (broken). diff -r 2dbe70d40481 -r a4666c9e1336 edtimeline.cpp --- a/edtimeline.cpp Thu Dec 20 01:44:01 2012 +0200 +++ b/edtimeline.cpp Sat Dec 22 16:56:30 2012 +0200 @@ -30,25 +30,6 @@ } -void QEDTimelineTrackDisplay::setTime(const int mtime) -{ - time = mtime; -} - - -void QEDTimelineTrackDisplay::setOffset(const int moffs) -{ - offs = moffs; -} - - -void QEDTimelineTrackDisplay::setScale(const float mscale) -{ - if (mscale > 0.05) - scale = mscale; -} - - float QEDTimelineTrackDisplay::getTimeScale(float value) { return value * scale; @@ -61,17 +42,115 @@ } +void QEDTimelineTrackDisplay::setTime(const float mtime) +{ + if (time != mtime && mtime >= 0) + { + time = mtime; + emit timeChanged(time); + } +} + + +void QEDTimelineTrackDisplay::setOffset(const float moffs) +{ + if (offs != moffs && moffs >= 0) + { + offs = moffs; + emit offsetChanged(offs); + } +} + + +void QEDTimelineTrackDisplay::setScale(const float mscale) +{ + if (mscale > 0.05) + scale = mscale; +} + + +void QEDTimelineTrackDisplay::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 QEDTimelineTrackDisplay::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; +} + + +QList QEDTimelineTrackDisplay::getEventsAt(const int time) +{ + QList list; + + for (int event = 0; event < track->nevents; event++) + { + DMTimelineEvent *ev = track->events[event]; + if (time >= ev->start && time <= ev->start + ev->duration) + list.append(ev); + } + + return list; +} + + + +QList QEDTimelineTrackDisplay::getEventsForRange(const int start, const int duration) +{ + QList list; + + for (int event = 0; event < track->nevents; event++) + { + DMTimelineEvent *ev = track->events[event]; + } + + return list; +} + + void QEDTimelineTrackDisplay::paintEvent(QPaintEvent *) { if (track == NULL) return; - QColor eventColor(150, 150, 150); - QColor invalidEventColor(250, 150, 150); - QColor eventBorder(200, 250, 200); + QColor eventColor(150, 150, 150, 128); + QColor invalidEventColor(250, 150, 150, 128); + QColor eventBorder(200, 250, 200, 200); QColor eventParam(200, 150, 100); QColor eventText(255, 255, 255); QColor markerColor(255,255,255); + QColor selectionColor(0,255,0, 150); + QColor selectionEnd(0,255,0, 200); QFont fantti; fantti.setFamily("Arial"); @@ -102,22 +181,44 @@ x1 = ev->duration; painter.fillRect(x0, 0, x1, height(), eventColor); + QPainterPath path; + path.addText(QPointF(x0 + 2, 10), fantti, ev->effect != NULL ? QString(ev->effect->name) : "INVALID"); + + painter.save(); + painter.translate(1,1); + painter.setPen(Qt::black); + painter.setBrush(Qt::black); + painter.drawPath(path); + painter.restore(); + + painter.setPen(eventText); painter.setBrush(eventText); - if (ev->effect != NULL) - { - QString name(ev->effect->name); - painter.drawText(QPointF(x0 + 2, 10), name); - } - else - { - painter.drawText(QPointF(x0 + 2, 10), "INVALID"); - } + painter.drawPath(path); } } painter.restore(); + if (selectionValid) + { + float x0 = getTimeScale(selectionStart - offs), + x1 = getTimeScale(selectionStart + selectionDuration - offs); + + if ((x0 >= 0 && x0 < wd) || (x0 < 0 && x1 >= 0)) + { + painter.setBrush(selectionColor); + painter.setPen(selectionEnd); + x0 = selectionStart - offs; + x1 = selectionDuration; + painter.fillRect(x0, 0, x1, height(), eventColor); + + painter.drawLine(x0, 0, x0, height()); + painter.drawLine(x1, 0, x1, height()); + } + } + + if (time >= offs * scale && time - offs <= width() * scale) { int xc = time - offs; @@ -132,34 +233,59 @@ void QEDTimelineTrackDisplay::mousePressEvent(QMouseEvent *ev) { -/* - if (ev->button() == Qt::LeftButton) + switch (ev->button()) { - lastPoint = ev->pos(); - scribbling = true; + case Qt::LeftButton: + if (parent->getActiveTrack() != this) + emit trackActivated(this); + + selectionPoint = ev->pos(); + selectionOffs = offs / scale; + selecting = false; + break; + + case Qt::RightButton: + dragPoint = ev->pos(); + dragOffs = offs / scale; + dragging = false; + break; + + default: + break; } -*/ } void QEDTimelineTrackDisplay::mouseMoveEvent(QMouseEvent *ev) { -/* - if ((ev->buttons() & Qt::LeftButton) && scribbling) - drawLineTo(ev->pos()); -*/ + if ((ev->buttons() & Qt::LeftButton) && ev->pos().x() != selectionPoint.x()) + { + selecting = true; + setSelection(selectionOffs, offs + (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); + } } void QEDTimelineTrackDisplay::mouseReleaseEvent(QMouseEvent *ev) { -/* - if (ev->button() == Qt::LeftButton && scribbling) + if (ev->button() == Qt::LeftButton) { - drawLineTo(ev->pos()); - scribbling = false; + if (selecting) + { + selecting = false; + setSelection(selectionOffs + (ev->pos().x() - selectionPoint.x()) / scale); + } } -*/ + else + if (ev->button() == Qt::RightButton && !dragging) + { + setTime(offs + getTimeFromCoord(ev->pos().x())); + } } @@ -177,7 +303,6 @@ QVBoxLayout *infoLayout = new QVBoxLayout(infoLayoutContainer); infoLayout->setMargin(0); -// QVBoxLayout *infoLayout = new QVBoxLayout(); infoName = new QLineEdit(); infoName->setFrame(false); infoName->setMaxLength(DT_MAX_NAME_LENGTH); @@ -195,7 +320,6 @@ infoLayout->addWidget(infoData); mainLayout->addWidget(infoLayoutContainer); -// mainLayout->addLayout(infoLayout); mainLayout->addWidget(track); } @@ -268,6 +392,9 @@ tracks.append(vtr); layout->addWidget(vtr); connect(vtr, SIGNAL(trackChanged()), this, SLOT(slotTimelineChanged())); + connect(vtr, SIGNAL(timeChanged(float)), this, SLOT(slotTimeChanged(float))); + connect(vtr, SIGNAL(offsetChanged(float)), this, SLOT(slotOffsetChanged(float))); + connect(vtr, SIGNAL(selectionChanged(float,float)), this, SLOT(slotSelectionChanged(float,float))); } } update(); @@ -324,3 +451,21 @@ update(); } } + + +QList QEDTimelineView::getEventsAt(const int time) +{ + if (tl != NULL && tl->tl != NULL && + activeTrack >= 0 && activeTrack < tl->tl->ntracks) + { + return tracks[activeTrack]->tl->getEventsAt(time); + } + else + return QList(); +} + + +QList QEDTimelineView::getEventsForRange(const int start, const int duration) +{ +} + diff -r 2dbe70d40481 -r a4666c9e1336 edtimeline.h --- a/edtimeline.h Thu Dec 20 01:44:01 2012 +0200 +++ b/edtimeline.h Sat Dec 22 16:56:30 2012 +0200 @@ -23,13 +23,26 @@ float getTimeScale(float value); float getTimeFromCoord(float value); - void setTime(const int mtime); - void setOffset(const int moffs); void setScale(const float mscale); + bool getSelection(float *mstart, float *mduration); + QList getEventsAt(const int time); + QList getEventsForRange(const int start, const int duration); + QSize minimumSizeHint() const; QSize sizeHint() const; +public slots: + void setTime(const float mtime); + void setOffset(const float moffs); + void setSelection(const float mstart, const float mend); + void clearSelection(); + +signals: + void selectionChanged(float mstart, float mduration); + void timeChanged(float value); + void offsetChanged(float value); + protected: void mousePressEvent(QMouseEvent *event); void mouseMoveEvent(QMouseEvent *event); @@ -38,12 +51,14 @@ void paintEvent(QPaintEvent *event); private: - bool dragging; - QPoint dragPoint; - int dragOffs; // milliseconds + float scale, time, offs; - float scale; - int time, offs; + bool selectionValid; + float selectionStart, selectionDuration; + + QPoint selectionPoint, dragPoint; + bool selecting, dragging; + float selectionOffs, dragOffs; }; @@ -69,6 +84,9 @@ signals: void trackChanged(); + void selectionChanged(float mstart, float mduration); + void timeChanged(float value); + void offsetChanged(float value); }; @@ -81,13 +99,14 @@ EDTimelineObject *tl; QList tracks; + int activeTrack; public: QEDTimelineView(QWidget *parent = 0); void setTimeline(EDTimelineObject *mtl); - void setTime(const int mtime); - void setOffset(const int moffs); + void setTime(const float mtime); + void setOffset(const float moffs); void setScale(const float mscale); private slots: @@ -95,6 +114,8 @@ signals: void timelineChanged(); + void timeChanged(float value); + void offsetChanged(float value); }; #endif diff -r 2dbe70d40481 -r a4666c9e1336 edwaveform.cpp --- 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))); } diff -r 2dbe70d40481 -r a4666c9e1336 edwaveform.h --- a/edwaveform.h Thu Dec 20 01:44:01 2012 +0200 +++ b/edwaveform.h Sat Dec 22 16:56:30 2012 +0200 @@ -35,8 +35,11 @@ public slots: void setTime(const float mtime); void setOffset(const float moffs); + void setSelection(const float mstart, const float mend); + void clearSelection(); signals: + void selectionChanged(float mstart, float mduration); void timeChanged(float value); void offsetChanged(float value); @@ -48,15 +51,16 @@ void paintEvent(QPaintEvent *event); private: - bool dragging; - QPoint dragPoint; - float dragOffs; // milliseconds - - float scale; - float time, offs, duration; // in milliseconds - + float scale, time, offs, duration; // in milliseconds int size, channels, format, freq, sduration; void *data; + + bool selectionValid; + float selectionStart, selectionDuration; + + QPoint selectionPoint, dragPoint; + bool selecting, dragging; + float selectionOffs, dragOffs; };