diff edtimeline.cpp @ 357:1b8362a26692

Work towards Qt based editor.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 16 Oct 2012 20:09:11 +0300
parents
children 40e33ad0d153
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/edtimeline.cpp	Tue Oct 16 20:09:11 2012 +0300
@@ -0,0 +1,116 @@
+#include <QtGui>
+#include "edtimeline.h"
+
+
+TimelineTrackView::TimelineTrackView(QWidget *parent) : QWidget(parent)
+{
+    track = NULL;
+    time = offs = 0;
+    scale = 1.0f;
+}
+
+
+void TimelineTrackView::setTrack(DMTimelineTrack *mtrack)
+{
+    track = mtrack;
+    update();
+}
+
+
+DMTimelineTrack * TimelineTrackView::getTrack()
+{
+    return track;
+}
+
+
+void TimelineTrackView::setTime(const int mtime)
+{
+    time = mtime;
+    update();
+}
+
+
+void TimelineTrackView::setOffset(const int moffs)
+{
+    offs = moffs;
+    update();
+}
+
+
+void TimelineTrackView::setScale(const float mscale)
+{
+    if (mscale > 0.05)
+        scale = mscale;
+    update();
+}
+
+
+void TimelineTrackView::paintEvent(QPaintEvent *)
+{
+    QColor eventColor(150, 150, 150);
+    QColor markerColor(255,255,255);
+
+    QPainter painter(this);
+    painter.setRenderHint(QPainter::Antialiasing);
+
+    painter.save();
+    painter.scale(scale, 1);
+
+    for (int event = 0; event < track->nevents; event++)
+    {
+        DMTimelineEvent *ev = track->events[event];
+
+        if (ev->startTime >= offs && ev->startTime < twidth ||
+            ev->startTime + ev->duration >= offs)
+        {
+            int ex0 = x0 + (ev->startTime - offs) * scale,
+                ew = ex0 + ev->duration * scale,
+                ex1 = ex0 + ew <= x1 ? ex0 + ew : x1;
+
+            painter.setPen(waveColor);
+            dmFillRect(screen, ex0, y0, ex1, y1, eventColor);
+            //dmDrawTTFText(screen, font, fontcol, ex0, y0, "'%s'", ev->effect->name);
+        }
+    }
+
+    if (time >= offs * scale && time - offs <= width() * scale)
+    {
+        int xc = time - offs;
+        painter.scale(scale, 1);
+        painter.setPen(markerColor);
+        painter.drawLine(xc, 0, xc, height());
+    }
+}
+
+
+void TimelineTrackView::mousePressEvent(QMouseEvent *ev)
+{
+/*
+    if (ev->button() == Qt::LeftButton)
+    {
+        lastPoint = ev->pos();
+        scribbling = true;
+    }
+*/
+}
+
+
+void TimelineTrackView::mouseMoveEvent(QMouseEvent *ev)
+{
+/*
+    if ((ev->buttons() & Qt::LeftButton) && scribbling)
+        drawLineTo(ev->pos());
+*/
+}
+
+
+void TimelineTrackView::mouseReleaseEvent(QMouseEvent *ev)
+{
+/*
+    if (ev->button() == Qt::LeftButton && scribbling)
+    {
+        drawLineTo(ev->pos());
+        scribbling = false;
+    }
+*/
+}