Skip to content

Commit 68513bd

Browse files
committed
ProjectLoader: Add eventLoopEnabled property
1 parent 4cb00fa commit 68513bd

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

ScratchCPPGui/projectloader.cpp

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,10 @@ void ProjectLoader::load()
198198

199199
// Run event loop
200200
m_engine->setSpriteFencingEnabled(false);
201-
m_eventLoop = QtConcurrent::run(&runEventLoop, m_engine);
201+
202+
if (m_eventLoopEnabled)
203+
m_eventLoop = QtConcurrent::run(&runEventLoop, m_engine);
204+
202205
m_engineMutex.unlock();
203206

204207
emit loadStatusChanged();
@@ -353,3 +356,29 @@ void ProjectLoader::setSpriteFencing(bool newSpriteFencing)
353356
m_engineMutex.unlock();
354357
emit spriteFencingChanged();
355358
}
359+
360+
bool ProjectLoader::eventLoopEnabled() const
361+
{
362+
return m_eventLoopEnabled;
363+
}
364+
365+
void ProjectLoader::setEventLoopEnabled(bool newEventLoopEnabled)
366+
{
367+
if (m_eventLoopEnabled == newEventLoopEnabled)
368+
return;
369+
370+
m_eventLoopEnabled = newEventLoopEnabled;
371+
m_engineMutex.lock();
372+
373+
if (m_engine) {
374+
if (m_eventLoopEnabled)
375+
m_eventLoop = QtConcurrent::run(&runEventLoop, m_engine);
376+
else {
377+
m_engine->stopEventLoop();
378+
m_eventLoop.waitForFinished();
379+
}
380+
}
381+
382+
m_engineMutex.unlock();
383+
emit eventLoopEnabledChanged();
384+
}

ScratchCPPGui/projectloader.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class ProjectLoader : public QObject
2929
Q_PROPERTY(unsigned int stageHeight READ stageHeight WRITE setStageHeight NOTIFY stageHeightChanged)
3030
Q_PROPERTY(int cloneLimit READ cloneLimit WRITE setCloneLimit NOTIFY cloneLimitChanged)
3131
Q_PROPERTY(bool spriteFencing READ spriteFencing WRITE setSpriteFencing NOTIFY spriteFencingChanged)
32+
Q_PROPERTY(bool eventLoopEnabled READ eventLoopEnabled WRITE setEventLoopEnabled NOTIFY eventLoopEnabledChanged)
3233

3334
public:
3435
explicit ProjectLoader(QObject *parent = nullptr);
@@ -69,6 +70,9 @@ class ProjectLoader : public QObject
6970
bool spriteFencing() const;
7071
void setSpriteFencing(bool newSpriteFencing);
7172

73+
bool eventLoopEnabled() const;
74+
void setEventLoopEnabled(bool newEventLoopEnabled);
75+
7276
signals:
7377
void fileNameChanged();
7478
void loadStatusChanged();
@@ -82,6 +86,7 @@ class ProjectLoader : public QObject
8286
void stageHeightChanged();
8387
void cloneLimitChanged();
8488
void spriteFencingChanged();
89+
void eventLoopEnabledChanged();
8590

8691
protected:
8792
void timerEvent(QTimerEvent *event) override;
@@ -108,6 +113,7 @@ class ProjectLoader : public QObject
108113
unsigned int m_stageHeight = 360;
109114
int m_cloneLimit = 300;
110115
bool m_spriteFencing = true;
116+
bool m_eventLoopEnabled = true;
111117
};
112118

113119
} // namespace scratchcppgui

0 commit comments

Comments
 (0)