Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build/module.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ set(QML_IMPORT_PATH "${QML_IMPORT_PATH};${CMAKE_CURRENT_LIST_DIR}"
)

target_link_libraries(${MODULE} PRIVATE ${QT_LIBS})
target_include_directories(${MODULE} PRIVATE ${PROJECT_SOURCE_DIR}/src)
target_include_directories(${MODULE} PRIVATE ${PROJECT_SOURCE_DIR}/src/global)

list(APPEND QML_IMPORT_PATH ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
list(REMOVE_DUPLICATES QML_IMPORT_PATH)
Expand Down
3 changes: 2 additions & 1 deletion res/icons/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ qt_add_resources(
PREFIX "/icons/scratchcpp/32x32"
FILES
green_flag.svg
stop.svg
stop.svg
turbo.svg
)
12 changes: 12 additions & 0 deletions res/icons/turbo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ add_subdirectory(app)

add_subdirectory(global)
add_subdirectory(uicomponents)
add_subdirectory(keyboard)
28 changes: 27 additions & 1 deletion src/app/appmenubar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ AppMenuBar::AppMenuBar(QObject *parent) :

// File menu
m_fileMenu = new MenuModel(m_model);
m_fileMenu->setTitle(tr("File"));
m_fileMenu->setTitle(tr("&File"));
m_model->addMenu(m_fileMenu);

// File -> Open
Expand All @@ -33,6 +33,19 @@ AppMenuBar::AppMenuBar(QObject *parent) :
#ifdef Q_OS_WASM
connect(m_openFileDialog, &FileDialog::fileContentReady, this, &AppMenuBar::loadOpenedFile);
#endif

// Edit menu
m_editMenu = new MenuModel(m_model);
m_editMenu->setTitle(tr("&Edit"));
m_model->addMenu(m_editMenu);

// Edit -> Turbo mode
m_turboModeItem = new MenuItemModel(m_editMenu);
m_turboModeItem->setText(tr("Turbo Mode"));
m_turboModeItem->setCheckable(true);
m_turboModeItem->setChecked(false);
m_editMenu->addItem(m_turboModeItem);
connect(m_turboModeItem, &MenuItemModel::checkedChanged, this, &AppMenuBar::turboModeChanged);
}

MenuBarModel *AppMenuBar::model() const
Expand Down Expand Up @@ -68,3 +81,16 @@ void AppMenuBar::loadOpenedFile(const QByteArray &content)
qWarning("Failed to create temporary file.");
}
#endif

bool AppMenuBar::turboMode() const
{
return m_turboModeItem->checked();
}

void AppMenuBar::setTurboMode(bool newTurboMode)
{
if (m_turboModeItem->checked() == newTurboMode)
return;

m_turboModeItem->setChecked(newTurboMode);
}
9 changes: 9 additions & 0 deletions src/app/appmenubar.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,20 @@ class AppMenuBar : public QObject
QML_ELEMENT
QML_SINGLETON
Q_PROPERTY(uicomponents::MenuBarModel *model READ model NOTIFY modelChanged)
Q_PROPERTY(bool turboMode READ turboMode WRITE setTurboMode NOTIFY turboModeChanged)

public:
explicit AppMenuBar(QObject *parent = nullptr);

uicomponents::MenuBarModel *model() const;

bool turboMode() const;
void setTurboMode(bool newTurboMode);

signals:
void modelChanged();
void fileOpened(const QString &fileName);
void turboModeChanged();

private:
void openFile();
Expand All @@ -44,10 +49,14 @@ class AppMenuBar : public QObject
#endif

uicomponents::MenuBarModel *m_model = nullptr;

uicomponents::MenuModel *m_fileMenu = nullptr;
uicomponents::MenuItemModel *m_openFileItem = nullptr;
uicomponents::FileDialog *m_openFileDialog = nullptr;
QTemporaryFile *m_tmpFile = nullptr;

uicomponents::MenuModel *m_editMenu = nullptr;
uicomponents::MenuItemModel *m_turboModeItem = nullptr;
};

} // namespace scratchcpp
4 changes: 4 additions & 0 deletions src/app/main.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
// SPDX-License-Identifier: GPL-3.0-or-later

#include "app.h"
#include "globalmodule.h"
#include "keyboard/keyboardmodule.h"

using namespace scratchcpp;

int main(int argc, char *argv[])
{
App app;
app.addModule(new GlobalModule);
app.addModule(new keyboard::KeyboardModule);

return app.run(argc, argv);
}
29 changes: 26 additions & 3 deletions src/app/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import QtQuick.Layouts
import ScratchCPP
import ScratchCPP.UiComponents
import ScratchCPP.Render
import ScratchCPP.Keyboard

ApplicationWindow {
id: root
Expand Down Expand Up @@ -40,12 +41,17 @@ ApplicationWindow {
Layout.fillWidth: true

CustomToolButton {
id: greenFlagButton
icon.name: "green_flag"
icon.color: "transparent"
onClicked: {
player.stop()
player.start()
player.forceActiveFocus(Qt.TabFocusReason);
if (KeyboardInfo.keyboardModifiers() === Qt.ShiftModifier)
AppMenuBar.turboMode = !AppMenuBar.turboMode
else {
player.stop()
player.start()
player.forceActiveFocus(Qt.TabFocusReason);
}
}
}

Expand All @@ -57,6 +63,22 @@ ApplicationWindow {
}
}

IconLabel {
icon.name: "turbo"
icon.color: "transparent"
text: qsTr("Turbo Mode")
color: Qt.rgba(1, 0.67, 0.1, 1)
visible: AppMenuBar.turboMode

font {
// Reuse the font from the green flag button
family: greenFlagButton.font.family
capitalization: Font.MixedCase
pointSize: 8
bold: true
}
}

TextField {
id: urlField
Layout.fillWidth: true
Expand All @@ -78,6 +100,7 @@ ApplicationWindow {
activeFocusOnTab: true
focus: true
spriteFencing: false
turboMode: AppMenuBar.turboMode
stageRect.border.color: Material.theme == Material.Dark ? Qt.rgba(1, 1, 1, 0.15) : Qt.rgba(0, 0, 0, 0.15)
stageRect.border.width: 5
}
Expand Down
11 changes: 11 additions & 0 deletions src/keyboard/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
set(MODULE keyboard)
set(MODULE_URI Keyboard)
set(MODULE_SRC
keyboardmodule.cpp
keyboardmodule.h
ikeyboardinfo.h
internal/keyboardinfo.cpp
internal/keyboardinfo.h
)

include(${PROJECT_SOURCE_DIR}/build/module.cmake)
19 changes: 19 additions & 0 deletions src/keyboard/ikeyboardinfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: GPL-3.0-or-later

#pragma once

#include <modularity/ioc.h>
#include <Qt>

namespace scratchcpp::keyboard
{

class IKeyboardInfo : MODULE_EXPORT_INTERFACE
{
public:
virtual ~IKeyboardInfo() { }

virtual Qt::KeyboardModifiers keyboardModifiers() const = 0;
};

} // namespace scratchcpp::keyboard
17 changes: 17 additions & 0 deletions src/keyboard/internal/keyboardinfo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-License-Identifier: GPL-3.0-or-later

#include <QGuiApplication>

#include "keyboardinfo.h"

using namespace scratchcpp::keyboard;

KeyboardInfo::KeyboardInfo(QObject *parent) :
QObject(parent)
{
}

Qt::KeyboardModifiers KeyboardInfo::keyboardModifiers() const
{
return QGuiApplication::keyboardModifiers();
}
24 changes: 24 additions & 0 deletions src/keyboard/internal/keyboardinfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: GPL-3.0-or-later

#pragma once

#include <QObject>

#include "ikeyboardinfo.h"

namespace scratchcpp::keyboard
{

class KeyboardInfo
: public QObject
, public IKeyboardInfo
{
Q_OBJECT

public:
explicit KeyboardInfo(QObject *parent = nullptr);

Q_INVOKABLE Qt::KeyboardModifiers keyboardModifiers() const override;
};

} // namespace scratchcpp::keyboard
23 changes: 23 additions & 0 deletions src/keyboard/keyboardmodule.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: GPL-3.0-or-later

#include <QQmlEngine>

#include "modularity/ioc.h"
#include "keyboardmodule.h"
#include "internal/keyboardinfo.h"

using namespace scratchcpp::keyboard;

std::string KeyboardModule::moduleName() const
{
return "keyboard";
}

void KeyboardModule::registerExports()
{
m_keyboardInfo = std::make_shared<KeyboardInfo>();

QQmlEngine::setObjectOwnership(m_keyboardInfo.get(), QQmlEngine::CppOwnership);
qmlRegisterSingletonInstance<KeyboardInfo>("ScratchCPP.Keyboard", 1, 0, "KeyboardInfo", m_keyboardInfo.get());
modularity::ioc()->registerExport<IKeyboardInfo>(m_keyboardInfo);
}
25 changes: 25 additions & 0 deletions src/keyboard/keyboardmodule.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SPDX-License-Identifier: GPL-3.0-or-later

#pragma once

#include <memory>

#include "modularity/imodulesetup.h"

namespace scratchcpp::keyboard
{

class KeyboardInfo;

class KeyboardModule : public modularity::IModuleSetup
{
public:
std::string moduleName() const override;

void registerExports() override;

private:
std::shared_ptr<KeyboardInfo> m_keyboardInfo;
};

} // namespace scratchcpp::keyboard