# HG changeset patch # User Matti Hamalainen # Date 1350653286 -10800 # Node ID 2fdf440ea66ae0dbd9cc071d5308df6c559f343b # Parent f44a89a25c97c905606a1acbd0a9ef568c61373c Fix some segfaults, etc. diff -r f44a89a25c97 -r 2fdf440ea66a edgui.cpp --- a/edgui.cpp Fri Oct 19 15:56:59 2012 +0300 +++ b/edgui.cpp Fri Oct 19 16:28:06 2012 +0300 @@ -26,15 +26,14 @@ else name = currTimeline->filename; - if (changed) + if (currTimeline && currTimeline->touched()) name = "*" + name; setWindowTitle(name + " - " + QCoreApplication::applicationName()); // Enable menu items based on states - menuActSave->setEnabled(currTimeline->changed || changed); - menuActSaveAs->setEnabled(currTimeline->changed || changed); - + menuActSave->setEnabled(currTimeline != NULL&& currTimeline->touched()); + menuActSaveAs->setEnabled(currTimeline != NULL); // Enable undo/redo items and set their texts based on history status int historyLevels = undoHistory.size(); @@ -43,7 +42,7 @@ if (undoHistoryPos >= 0 && undoHistoryPos < historyLevels) { - itemText = " " + undoHistory.at(undoHistoryPos)->state; + itemText = " " + undoHistory.at(undoHistoryPos)->state(); itemEnabled = true; } else @@ -57,7 +56,7 @@ if (undoHistoryPos > 0 && historyLevels > 0) { - itemText = " " + undoHistory.at(undoHistoryPos - 1)->state; + itemText = " " + undoHistory.at(undoHistoryPos - 1)->state(); itemEnabled = true; } else @@ -121,7 +120,7 @@ { bool okToCreate = true; - if (changed) + if (currTimeline != NULL && currTimeline->touched()) { okToCreate = false; switch (showDocumentModifiedDialog()) @@ -132,7 +131,7 @@ case QMessageBox::Save: actionFileSave(); - if (!changed) + if (!currTimeline->touched()) { QMessageBox::information(this, "Document saved", @@ -156,7 +155,7 @@ { bool okToOpen = true; - if (changed) + if (currTimeline != NULL && currTimeline->touched()) { okToOpen = false; @@ -168,7 +167,7 @@ case QMessageBox::Save: actionFileSave(); - if (!changed) + if (!currTimeline->touched()) { QMessageBox::information(this, "Document saved", @@ -241,7 +240,7 @@ { bool okToClose = true; - if (changed) + if (currTimeline && currTimeline->touched()) { okToClose = false; switch (showDocumentModifiedDialog()) @@ -252,7 +251,7 @@ case QMessageBox::Save: actionFileSave(); - if (!changed) + if (!currTimeline->touched()) okToClose = true; break; diff -r f44a89a25c97 -r 2fdf440ea66a edmain.cpp --- a/edmain.cpp Fri Oct 19 15:56:59 2012 +0300 +++ b/edmain.cpp Fri Oct 19 16:28:06 2012 +0300 @@ -100,7 +100,6 @@ setWindowTitle(QCoreApplication::applicationName()); memset(&engine, 0, sizeof(engine)); - changed = FALSE; initSDL = FALSE; currTimeline = NULL; @@ -207,17 +206,9 @@ // Setup GUI elements createMainGUI(); - createNewFile(); - DMTimelineTrack *tr = NULL; - dmTimelineAddTrack(currTimeline->tl, &tr, "Penis"); - dmTimelineAddTrack(currTimeline->tl, &tr, "Cyrbe"); - dmTimelineAddTrack(currTimeline->tl, &tr, "Pasci"); - dmTimelineAddTrack(currTimeline->tl, &tr, "Lol"); - +// createNewFile(); timelineView->setTimeline(currTimeline); - settingsRestore(); - initEffectsAndResources(); statusMsg("Application started."); } @@ -377,7 +368,6 @@ update(); historyReset(); - changed = false; updateMenuStates(); } @@ -402,7 +392,6 @@ update(); historyReset(); - changed = false; updateMenuStates(); } } @@ -445,7 +434,9 @@ // void DemoEditor::historyReset() { - changed = false; + if (currTimeline != NULL) + currTimeline->scrub(); + undoHistoryPos = -1; undoHistoryMax = DOC_UNDO_MAX; undoHistory.clear(); @@ -454,7 +445,10 @@ void DemoEditor::historyPush(QString description) { - if (!undoHistory.isEmpty() && undoHistory.last()->state == "-") + if (currTimeline == NULL) + return; + + if (!undoHistory.isEmpty() && undoHistory.last()->state() == "-") { delete undoHistory.takeLast(); } @@ -465,19 +459,22 @@ } TimelineObject *copy = new TimelineObject(currTimeline); - copy->state = description; + copy->setState(description); undoHistory.append(copy); } void DemoEditor::historyTop() { + if (currTimeline == NULL) + return; + TimelineObject *copy = new TimelineObject(currTimeline); - copy->state = "-"; + copy->setState("-"); undoHistory.append(copy); undoHistoryPos = undoHistory.size() - 1; - changed = true; + currTimeline->touch(); updateMenuStates(); update(); } @@ -499,7 +496,7 @@ undoHistoryPos++; delete currTimeline; currTimeline = new TimelineObject(undoHistory.at(undoHistoryPos)); - changed = true; + currTimeline->touch(); updateMenuStates(); update(); @@ -514,7 +511,7 @@ undoHistoryPos--; delete currTimeline; currTimeline = new TimelineObject(undoHistory.at(undoHistoryPos)); - changed = true; + currTimeline->touch(); updateMenuStates(); update(); diff -r f44a89a25c97 -r 2fdf440ea66a edmain.h --- a/edmain.h Fri Oct 19 15:56:59 2012 +0300 +++ b/edmain.h Fri Oct 19 16:28:06 2012 +0300 @@ -107,7 +107,7 @@ void saveToFile(QString filename); - bool changed, initSDL; + bool initSDL; float currViewScale; int currViewOffset; int currFrameTime; diff -r f44a89a25c97 -r 2fdf440ea66a edtimeline.cpp --- a/edtimeline.cpp Fri Oct 19 15:56:59 2012 +0300 +++ b/edtimeline.cpp Fri Oct 19 16:28:06 2012 +0300 @@ -230,7 +230,7 @@ { if (tl != NULL) { - tl->changed++; + tl->touch(); emit timelineChanged(); } } diff -r f44a89a25c97 -r 2fdf440ea66a edtlobj.cpp --- a/edtlobj.cpp Fri Oct 19 15:56:59 2012 +0300 +++ b/edtlobj.cpp Fri Oct 19 16:28:06 2012 +0300 @@ -9,13 +9,13 @@ TimelineObject::TimelineObject() { dmTimelineNew(&tl, "Demo"); - changed = 0; + scrub(); } TimelineObject::TimelineObject(TimelineObject *obj) { - changed = 0; + scrub(); filename = obj->filename; dmCopyTimeline(obj->tl, &tl); } @@ -36,7 +36,8 @@ dmFreeTimeline(tl); int err = dmLoadTimeline(res, &tl); - changed = 0; + + scrub(); dmf_close(res); filename = mfilename; @@ -52,8 +53,38 @@ return DMERR_FOPEN; int err = dmSaveTimeline(res, tl); - changed = 0; + scrub(); dmf_close(res); return err; } + + +void TimelineObject::touch() +{ + ntouches++; +} + + +void TimelineObject::scrub() +{ + ntouches = 0; +} + + +bool TimelineObject::touched() +{ + return ntouches; +} + + +void TimelineObject::setState(const QString &mstate) +{ + cstate = mstate; +} + + +QString TimelineObject::state() const +{ + return cstate; +} diff -r f44a89a25c97 -r 2fdf440ea66a edtlobj.h --- a/edtlobj.h Fri Oct 19 15:56:59 2012 +0300 +++ b/edtlobj.h Fri Oct 19 16:28:06 2012 +0300 @@ -10,10 +10,12 @@ class TimelineObject { +private: + QString cstate; + int ntouches; + public: - QString state; QString filename; - int changed; DMTimeline *tl; TimelineObject(); @@ -22,6 +24,13 @@ int load(QString filename); int save(QString filename); + + void scrub(); + void touch(); + bool touched(); + + void setState(const QString &mstate); + QString state() const; };