Mercurial > hg > dmlib
annotate editor/edtlobj.cpp @ 2306:e798a41f27a5
Clean up some code duplication.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 08 Jul 2019 12:25:46 +0300 |
parents | b4992d9f72fe |
children |
rev | line source |
---|---|
376
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1 // |
403
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
401
diff
changeset
|
2 // Demo Editor -- Timeline state object |
397 | 3 // Wrapper class for DMTimeline data |
376
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
4 // (C) Copyright 2012 Matti 'ccr' Hämäläinen <ccr@tnsp.org> |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
5 // |
379
05e85401480a
Rename eddemoobj to edtlobj, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
6 #include "edtlobj.h" |
376
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
7 #include "dmres.h" |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
8 |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
9 |
403
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
401
diff
changeset
|
10 EDTimelineObject::EDTimelineObject() |
376
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
11 { |
397 | 12 dmTimelineNew(&tl, "Demo"); |
401 | 13 scrub(); |
376
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
14 } |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
15 |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
16 |
403
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
401
diff
changeset
|
17 EDTimelineObject::EDTimelineObject(EDTimelineObject *obj) |
376
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
18 { |
401 | 19 scrub(); |
376
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
20 filename = obj->filename; |
397 | 21 dmCopyTimeline(obj->tl, &tl); |
376
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
22 } |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
23 |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
24 |
403
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
401
diff
changeset
|
25 EDTimelineObject::~EDTimelineObject() |
376
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
26 { |
379
05e85401480a
Rename eddemoobj to edtlobj, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
27 dmFreeTimeline(tl); |
376
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
28 } |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
29 |
379
05e85401480a
Rename eddemoobj to edtlobj, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
30 |
403
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
401
diff
changeset
|
31 int EDTimelineObject::load(QString mfilename) |
376
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
32 { |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
33 DMResource *res; |
403
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
401
diff
changeset
|
34 DMTimeline *tmp; |
1738 | 35 int err; |
376
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
36 |
1738 | 37 if ((err = dmf_open_stdio(mfilename.toUtf8().constData(), "rb", &res)) != DMERR_OK) |
38 return err; | |
39 | |
40 err = dmLoadTimeline(res, &tmp); | |
403
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
401
diff
changeset
|
41 dmf_close(res); |
401 | 42 |
403
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
401
diff
changeset
|
43 if (err == DMERR_OK) |
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
401
diff
changeset
|
44 { |
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
401
diff
changeset
|
45 dmFreeTimeline(tl); |
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
401
diff
changeset
|
46 tl = tmp; |
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
401
diff
changeset
|
47 scrub(); |
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
401
diff
changeset
|
48 if (tl->name != NULL) |
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
401
diff
changeset
|
49 filename = QString(tl->name); |
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
401
diff
changeset
|
50 else |
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
401
diff
changeset
|
51 filename = mfilename; |
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
401
diff
changeset
|
52 } |
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
401
diff
changeset
|
53 else |
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
401
diff
changeset
|
54 { |
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
401
diff
changeset
|
55 dmFreeTimeline(tmp); |
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
401
diff
changeset
|
56 } |
376
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
57 return err; |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
58 } |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
59 |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
60 |
403
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
401
diff
changeset
|
61 int EDTimelineObject::save(QString mfilename) |
376
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
62 { |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
63 DMResource *res; |
1738 | 64 int err; |
376
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
65 |
1738 | 66 if ((err = dmf_open_stdio(mfilename.toUtf8().constData(), "wb", &res)) != DMERR_OK) |
67 return err; | |
68 | |
69 err = dmSaveTimeline(res, tl); | |
401 | 70 scrub(); |
376
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
71 |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
72 dmf_close(res); |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
73 return err; |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
74 } |
401 | 75 |
76 | |
403
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
401
diff
changeset
|
77 void EDTimelineObject::touch() |
401 | 78 { |
79 ntouches++; | |
80 } | |
81 | |
82 | |
403
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
401
diff
changeset
|
83 void EDTimelineObject::scrub() |
401 | 84 { |
85 ntouches = 0; | |
86 } | |
87 | |
88 | |
403
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
401
diff
changeset
|
89 bool EDTimelineObject::touched() |
401 | 90 { |
91 return ntouches; | |
92 } | |
93 | |
94 | |
403
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
401
diff
changeset
|
95 void EDTimelineObject::setState(const QString &mstate) |
401 | 96 { |
97 cstate = mstate; | |
98 } | |
99 | |
100 | |
403
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
401
diff
changeset
|
101 QString EDTimelineObject::state() const |
401 | 102 { |
103 return cstate; | |
104 } |