Mercurial > hg > dmlib
annotate edtimeline.cpp @ 401:2fdf440ea66a
Fix some segfaults, etc.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 19 Oct 2012 16:28:06 +0300 |
parents | 8660c6005032 |
children | 0f290af63fc1 |
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); |
398 | 127 infoLayoutContainer->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum); |
128 infoLayoutContainer->setFixedWidth(200); | |
393
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(); |
398 | 133 infoName = new QLineEdit(); |
134 infoName->setFrame(false); | |
135 infoName->setMaxLength(DT_MAX_NAME_LENGTH); | |
136 infoName->setStyleSheet("QLineEdit { background-color: black; color: white; padding: 2px; }"); | |
137 connect(infoName, SIGNAL(textEdited(const QString&)), this, SLOT(slotTrackNameChanged(const QString&))); | |
393
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
138 infoLayout->addWidget(infoName); |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
139 |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
140 |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
141 enabledCheck = new QCheckBox("Enabled"); |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
142 infoLayout->addWidget(enabledCheck); |
398 | 143 connect(enabledCheck, SIGNAL(toggled(bool)), this, SLOT(slotTrackEnabledChanged(bool))); |
393
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
144 |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
145 infoData = new QLabel(); |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
146 infoData->setStyleSheet("QLabel { padding: 2px; }"); |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
147 infoLayout->addWidget(infoData); |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
148 |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
149 mainLayout->addWidget(infoLayoutContainer); |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
150 // mainLayout->addLayout(infoLayout); |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
151 mainLayout->addWidget(track); |
398 | 152 } |
393
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
153 |
398 | 154 |
155 void QTimelineTrackView::update() | |
156 { | |
157 if (track != NULL && track->track) | |
158 { | |
159 infoName->setText(QString(track->track->name)); | |
160 enabledCheck->setChecked(track->track->enabled); | |
161 infoData->setText(QString("<b>%1</b> events").arg(track->track->nevents)); | |
162 } | |
163 else | |
164 { | |
165 infoName->setText(""); | |
166 infoData->setText("-"); | |
167 enabledCheck->setChecked(false); | |
168 } | |
169 | |
170 QWidget::update(); | |
393
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
171 } |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
172 |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
173 |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
174 void QTimelineTrackView::setTrack(DMTimelineTrack *mtrack) |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
175 { |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
176 track->setTrack(mtrack); |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
177 update(); |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
178 } |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
179 |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
180 |
398 | 181 void QTimelineTrackView::slotTrackEnabledChanged(bool value) |
393
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
182 { |
397 | 183 track->track->enabled = value; |
398 | 184 emit trackChanged(); |
185 } | |
186 | |
187 | |
188 void QTimelineTrackView::slotTrackNameChanged(const QString & text) | |
189 { | |
190 QByteArray ba = text.toUtf8(); | |
191 track->track->name = dm_strdup(ba.constData()); | |
192 emit trackChanged(); | |
397 | 193 } |
194 | |
195 | |
196 | |
197 QTimelineView::QTimelineView(QWidget *parent) : QWidget(parent) | |
198 { | |
199 layout = new QVBoxLayout(this); | |
200 tl = NULL; | |
393
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
201 } |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
202 |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
203 |
397 | 204 void QTimelineView::setTimeline(TimelineObject *mtl) |
393
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
205 { |
397 | 206 tl = mtl; |
207 | |
208 delete layout; | |
209 layout = new QVBoxLayout(this); | |
398 | 210 layout->setMargin(0); |
211 | |
397 | 212 tracks.clear(); |
213 | |
214 if (tl != NULL && tl->tl != NULL) | |
215 { | |
216 for (int track = 0; track < tl->tl->ntracks; track++) | |
217 { | |
218 QTimelineTrackView *vtr = new QTimelineTrackView(this); | |
219 vtr->setTrack(tl->tl->tracks[track]); | |
220 tracks.append(vtr); | |
221 layout->addWidget(vtr); | |
398 | 222 connect(vtr, SIGNAL(trackChanged()), this, SLOT(slotTimelineChanged())); |
397 | 223 } |
224 } | |
225 update(); | |
393
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
226 } |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
227 |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
228 |
397 | 229 void QTimelineView::slotTimelineChanged() |
393
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
230 { |
397 | 231 if (tl != NULL) |
232 { | |
401 | 233 tl->touch(); |
397 | 234 emit timelineChanged(); |
235 } | |
236 } | |
237 | |
398 | 238 |
397 | 239 void QTimelineView::setTime(const int mtime) |
240 { | |
241 if (tl != NULL && tl->tl != NULL) | |
242 { | |
243 QList<QTimelineTrackView *>::iterator track; | |
244 for (track = tracks.begin(); track != tracks.end(); track++) | |
245 { | |
246 (*track)->track->setTime(mtime); | |
247 } | |
248 update(); | |
249 } | |
393
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
250 } |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
251 |
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
252 |
397 | 253 void QTimelineView::setOffset(const int moffs) |
393
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
254 { |
397 | 255 if (tl != NULL && tl->tl != NULL) |
256 { | |
257 QList<QTimelineTrackView *>::iterator track; | |
258 for (track = tracks.begin(); track != tracks.end(); track++) | |
259 { | |
260 (*track)->track->setOffset(moffs); | |
261 } | |
262 update(); | |
263 } | |
393
5137db55f00b
More work towards the editor ..
Matti Hamalainen <ccr@tnsp.org>
parents:
386
diff
changeset
|
264 } |
397 | 265 |
266 | |
267 void QTimelineView::setScale(const float mscale) | |
268 { | |
269 if (tl != NULL && tl->tl != NULL) | |
270 { | |
271 QList<QTimelineTrackView *>::iterator track; | |
272 for (track = tracks.begin(); track != tracks.end(); track++) | |
273 { | |
274 (*track)->track->setScale(mscale); | |
275 } | |
276 update(); | |
277 } | |
278 } |