Mercurial > hg > dmlib
annotate edtimeline.cpp @ 397:9993873ff655
More work towards editor.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 19 Oct 2012 07:22:09 +0300 |
parents | 5137db55f00b |
children | 8660c6005032 |
rev | line source |
---|---|
357 | 1 #include <QtGui> |
2 #include "edtimeline.h" | |
3 | |
4 | |
393
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
5 QTimelineTrackDisplay::QTimelineTrackDisplay(QWidget *parent) : QWidget(parent) |
357 | 6 { |
7 track = NULL; | |
8 time = offs = 0; | |
9 scale = 1.0f; | |
386 | 10 |
11 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); | |
12 } | |
13 | |
14 | |
393
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
15 QSize QTimelineTrackDisplay::minimumSizeHint() const |
386 | 16 { |
17 return QSize(100, 60); | |
18 } | |
19 | |
20 | |
393
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
21 QSize QTimelineTrackDisplay::sizeHint() const |
386 | 22 { |
23 return QSize(600, 60); | |
357 | 24 } |
25 | |
26 | |
393
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
27 void QTimelineTrackDisplay::setTrack(DMTimelineTrack *mtrack) |
357 | 28 { |
29 track = mtrack; | |
30 } | |
31 | |
32 | |
393
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
33 void QTimelineTrackDisplay::setTime(const int mtime) |
357 | 34 { |
35 time = mtime; | |
36 } | |
37 | |
38 | |
393
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
39 void QTimelineTrackDisplay::setOffset(const int moffs) |
357 | 40 { |
41 offs = moffs; | |
42 } | |
43 | |
44 | |
393
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
45 void QTimelineTrackDisplay::setScale(const float mscale) |
357 | 46 { |
47 if (mscale > 0.05) | |
48 scale = mscale; | |
49 } | |
50 | |
51 | |
393
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
52 void QTimelineTrackDisplay::paintEvent(QPaintEvent *) |
357 | 53 { |
393
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
54 if (track == NULL) |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
55 return; |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
56 |
357 | 57 QColor eventColor(150, 150, 150); |
58 QColor markerColor(255,255,255); | |
59 | |
60 QPainter painter(this); | |
61 painter.setRenderHint(QPainter::Antialiasing); | |
62 | |
63 painter.save(); | |
64 painter.scale(scale, 1); | |
65 | |
66 for (int event = 0; event < track->nevents; event++) | |
67 { | |
68 DMTimelineEvent *ev = track->events[event]; | |
69 } | |
70 | |
397 | 71 painter.restore(); |
72 | |
357 | 73 if (time >= offs * scale && time - offs <= width() * scale) |
74 { | |
75 int xc = time - offs; | |
397 | 76 painter.save(); |
357 | 77 painter.scale(scale, 1); |
78 painter.setPen(markerColor); | |
79 painter.drawLine(xc, 0, xc, height()); | |
397 | 80 painter.restore(); |
357 | 81 } |
82 } | |
83 | |
84 | |
393
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
85 void QTimelineTrackDisplay::mousePressEvent(QMouseEvent *ev) |
357 | 86 { |
87 /* | |
88 if (ev->button() == Qt::LeftButton) | |
89 { | |
90 lastPoint = ev->pos(); | |
91 scribbling = true; | |
92 } | |
93 */ | |
94 } | |
95 | |
96 | |
393
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
97 void QTimelineTrackDisplay::mouseMoveEvent(QMouseEvent *ev) |
357 | 98 { |
99 /* | |
100 if ((ev->buttons() & Qt::LeftButton) && scribbling) | |
101 drawLineTo(ev->pos()); | |
102 */ | |
103 } | |
104 | |
105 | |
393
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
106 void QTimelineTrackDisplay::mouseReleaseEvent(QMouseEvent *ev) |
357 | 107 { |
108 /* | |
109 if (ev->button() == Qt::LeftButton && scribbling) | |
110 { | |
111 drawLineTo(ev->pos()); | |
112 scribbling = false; | |
113 } | |
114 */ | |
115 } | |
393
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
116 |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
117 |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
118 QTimelineTrackView::QTimelineTrackView(QWidget *parent) : QWidget(parent) |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
119 { |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
120 QHBoxLayout *mainLayout = new QHBoxLayout(this); |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
121 mainLayout->setMargin(0); |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
122 track = new QTimelineTrackDisplay(this); |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
123 |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
124 QFrame *infoLayoutContainer = new QFrame(this); |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
125 infoLayoutContainer->setFrameStyle(QFrame::StyledPanel | QFrame::Plain); |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
126 infoLayoutContainer->setLineWidth(2); |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
127 // infoLayoutContainer->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Ignored); |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
128 // infoLayoutContainer->resize(250, 60); |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
129 |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
130 QVBoxLayout *infoLayout = new QVBoxLayout(infoLayoutContainer); |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
131 infoLayout->setMargin(0); |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
132 // QVBoxLayout *infoLayout = new QVBoxLayout(); |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
133 infoName = new QLabel("-"); |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
134 infoName->setStyleSheet("QLabel { background-color: black; color: white; padding: 2px; }"); |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
135 infoLayout->addWidget(infoName); |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
136 |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
137 |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
138 enabledCheck = new QCheckBox("Enabled"); |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
139 infoLayout->addWidget(enabledCheck); |
397 | 140 connect(enabledCheck, SIGNAL(toggled(bool)), this, SLOT(slotTrackChanged(bool))); |
393
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
141 |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
142 infoData = new QLabel(); |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
143 infoData->setStyleSheet("QLabel { padding: 2px; }"); |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
144 infoLayout->addWidget(infoData); |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
145 |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
146 mainLayout->addWidget(infoLayoutContainer); |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
147 // mainLayout->addLayout(infoLayout); |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
148 mainLayout->addWidget(track); |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
149 |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
150 } |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
151 |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
152 |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
153 void QTimelineTrackView::setTrack(DMTimelineTrack *mtrack) |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
154 { |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
155 if (mtrack != NULL) |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
156 { |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
157 infoName->setText(QString(mtrack->name)); |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
158 infoData->setText("-"); |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
159 // infoData->setText(QString("<b>%1</b>, <b>%2</b> ch, <b>%3</b> Hz").arg(fmt).arg(mchannels).arg(mfreq)); |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
160 } |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
161 else |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
162 { |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
163 infoData->setText("-"); |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
164 } |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
165 track->setTrack(mtrack); |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
166 update(); |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
167 } |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
168 |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
169 |
397 | 170 void QTimelineTrackView::slotTrackChanged(bool value) |
393
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
171 { |
397 | 172 track->track->enabled = value; |
173 emit trackChanged(value); | |
174 } | |
175 | |
176 | |
177 | |
178 QTimelineView::QTimelineView(QWidget *parent) : QWidget(parent) | |
179 { | |
180 layout = new QVBoxLayout(this); | |
181 tl = NULL; | |
393
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
182 } |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
183 |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
184 |
397 | 185 void QTimelineView::setTimeline(TimelineObject *mtl) |
393
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
186 { |
397 | 187 tl = mtl; |
188 | |
189 delete layout; | |
190 layout = new QVBoxLayout(this); | |
191 tracks.clear(); | |
192 | |
193 if (tl != NULL && tl->tl != NULL) | |
194 { | |
195 for (int track = 0; track < tl->tl->ntracks; track++) | |
196 { | |
197 QTimelineTrackView *vtr = new QTimelineTrackView(this); | |
198 vtr->setTrack(tl->tl->tracks[track]); | |
199 tracks.append(vtr); | |
200 layout->addWidget(vtr); | |
201 connect(vtr, SIGNAL(trackChanged(bool)), this, SLOT(slotTimelineChanged())); | |
202 } | |
203 } | |
204 update(); | |
393
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
205 } |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
206 |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
207 |
397 | 208 void QTimelineView::slotTimelineChanged() |
393
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
209 { |
397 | 210 if (tl != NULL) |
211 { | |
212 tl->changed++; | |
213 emit timelineChanged(); | |
214 } | |
215 } | |
216 | |
217 void QTimelineView::setTime(const int mtime) | |
218 { | |
219 if (tl != NULL && tl->tl != NULL) | |
220 { | |
221 QList<QTimelineTrackView *>::iterator track; | |
222 for (track = tracks.begin(); track != tracks.end(); track++) | |
223 { | |
224 (*track)->track->setTime(mtime); | |
225 } | |
226 update(); | |
227 } | |
393
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
228 } |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
229 |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
230 |
397 | 231 |
232 void QTimelineView::setOffset(const int moffs) | |
393
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
233 { |
397 | 234 if (tl != NULL && tl->tl != NULL) |
235 { | |
236 QList<QTimelineTrackView *>::iterator track; | |
237 for (track = tracks.begin(); track != tracks.end(); track++) | |
238 { | |
239 (*track)->track->setOffset(moffs); | |
240 } | |
241 update(); | |
242 } | |
393
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
243 } |
397 | 244 |
245 | |
246 void QTimelineView::setScale(const float mscale) | |
247 { | |
248 if (tl != NULL && tl->tl != NULL) | |
249 { | |
250 QList<QTimelineTrackView *>::iterator track; | |
251 for (track = tracks.begin(); track != tracks.end(); track++) | |
252 { | |
253 (*track)->track->setScale(mscale); | |
254 } | |
255 update(); | |
256 } | |
257 } |