Skip to content

Commit e7bd6c8

Browse files
authored
Merge pull request #34 from scratchcpp/turbo_mode_option
Add turbo mode option
2 parents 450b921 + 14d7e40 commit e7bd6c8

File tree

14 files changed

+202
-5
lines changed

14 files changed

+202
-5
lines changed

build/module.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ set(QML_IMPORT_PATH "${QML_IMPORT_PATH};${CMAKE_CURRENT_LIST_DIR}"
2020
)
2121

2222
target_link_libraries(${MODULE} PRIVATE ${QT_LIBS})
23+
target_include_directories(${MODULE} PRIVATE ${PROJECT_SOURCE_DIR}/src)
24+
target_include_directories(${MODULE} PRIVATE ${PROJECT_SOURCE_DIR}/src/global)
2325

2426
list(APPEND QML_IMPORT_PATH ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
2527
list(REMOVE_DUPLICATES QML_IMPORT_PATH)

res/icons/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ qt_add_resources(
1010
PREFIX "/icons/scratchcpp/32x32"
1111
FILES
1212
green_flag.svg
13-
stop.svg
13+
stop.svg
14+
turbo.svg
1415
)

res/icons/turbo.svg

Lines changed: 12 additions & 0 deletions
Loading

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ add_subdirectory(app)
22

33
add_subdirectory(global)
44
add_subdirectory(uicomponents)
5+
add_subdirectory(keyboard)

src/app/appmenubar.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ AppMenuBar::AppMenuBar(QObject *parent) :
2121

2222
// File menu
2323
m_fileMenu = new MenuModel(m_model);
24-
m_fileMenu->setTitle(tr("File"));
24+
m_fileMenu->setTitle(tr("&File"));
2525
m_model->addMenu(m_fileMenu);
2626

2727
// File -> Open
@@ -33,6 +33,19 @@ AppMenuBar::AppMenuBar(QObject *parent) :
3333
#ifdef Q_OS_WASM
3434
connect(m_openFileDialog, &FileDialog::fileContentReady, this, &AppMenuBar::loadOpenedFile);
3535
#endif
36+
37+
// Edit menu
38+
m_editMenu = new MenuModel(m_model);
39+
m_editMenu->setTitle(tr("&Edit"));
40+
m_model->addMenu(m_editMenu);
41+
42+
// Edit -> Turbo mode
43+
m_turboModeItem = new MenuItemModel(m_editMenu);
44+
m_turboModeItem->setText(tr("Turbo Mode"));
45+
m_turboModeItem->setCheckable(true);
46+
m_turboModeItem->setChecked(false);
47+
m_editMenu->addItem(m_turboModeItem);
48+
connect(m_turboModeItem, &MenuItemModel::checkedChanged, this, &AppMenuBar::turboModeChanged);
3649
}
3750

3851
MenuBarModel *AppMenuBar::model() const
@@ -68,3 +81,16 @@ void AppMenuBar::loadOpenedFile(const QByteArray &content)
6881
qWarning("Failed to create temporary file.");
6982
}
7083
#endif
84+
85+
bool AppMenuBar::turboMode() const
86+
{
87+
return m_turboModeItem->checked();
88+
}
89+
90+
void AppMenuBar::setTurboMode(bool newTurboMode)
91+
{
92+
if (m_turboModeItem->checked() == newTurboMode)
93+
return;
94+
95+
m_turboModeItem->setChecked(newTurboMode);
96+
}

src/app/appmenubar.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,20 @@ class AppMenuBar : public QObject
2727
QML_ELEMENT
2828
QML_SINGLETON
2929
Q_PROPERTY(uicomponents::MenuBarModel *model READ model NOTIFY modelChanged)
30+
Q_PROPERTY(bool turboMode READ turboMode WRITE setTurboMode NOTIFY turboModeChanged)
3031

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

3435
uicomponents::MenuBarModel *model() const;
3536

37+
bool turboMode() const;
38+
void setTurboMode(bool newTurboMode);
39+
3640
signals:
3741
void modelChanged();
3842
void fileOpened(const QString &fileName);
43+
void turboModeChanged();
3944

4045
private:
4146
void openFile();
@@ -44,10 +49,14 @@ class AppMenuBar : public QObject
4449
#endif
4550

4651
uicomponents::MenuBarModel *m_model = nullptr;
52+
4753
uicomponents::MenuModel *m_fileMenu = nullptr;
4854
uicomponents::MenuItemModel *m_openFileItem = nullptr;
4955
uicomponents::FileDialog *m_openFileDialog = nullptr;
5056
QTemporaryFile *m_tmpFile = nullptr;
57+
58+
uicomponents::MenuModel *m_editMenu = nullptr;
59+
uicomponents::MenuItemModel *m_turboModeItem = nullptr;
5160
};
5261

5362
} // namespace scratchcpp

src/app/main.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
// SPDX-License-Identifier: GPL-3.0-or-later
22

33
#include "app.h"
4+
#include "globalmodule.h"
5+
#include "keyboard/keyboardmodule.h"
46

57
using namespace scratchcpp;
68

79
int main(int argc, char *argv[])
810
{
911
App app;
12+
app.addModule(new GlobalModule);
13+
app.addModule(new keyboard::KeyboardModule);
1014

1115
return app.run(argc, argv);
1216
}

src/app/main.qml

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import QtQuick.Layouts
66
import ScratchCPP
77
import ScratchCPP.UiComponents
88
import ScratchCPP.Render
9+
import ScratchCPP.Keyboard
910

1011
ApplicationWindow {
1112
id: root
@@ -40,12 +41,17 @@ ApplicationWindow {
4041
Layout.fillWidth: true
4142

4243
CustomToolButton {
44+
id: greenFlagButton
4345
icon.name: "green_flag"
4446
icon.color: "transparent"
4547
onClicked: {
46-
player.stop()
47-
player.start()
48-
player.forceActiveFocus(Qt.TabFocusReason);
48+
if (KeyboardInfo.keyboardModifiers() === Qt.ShiftModifier)
49+
AppMenuBar.turboMode = !AppMenuBar.turboMode
50+
else {
51+
player.stop()
52+
player.start()
53+
player.forceActiveFocus(Qt.TabFocusReason);
54+
}
4955
}
5056
}
5157

@@ -57,6 +63,22 @@ ApplicationWindow {
5763
}
5864
}
5965

66+
IconLabel {
67+
icon.name: "turbo"
68+
icon.color: "transparent"
69+
text: qsTr("Turbo Mode")
70+
color: Qt.rgba(1, 0.67, 0.1, 1)
71+
visible: AppMenuBar.turboMode
72+
73+
font {
74+
// Reuse the font from the green flag button
75+
family: greenFlagButton.font.family
76+
capitalization: Font.MixedCase
77+
pointSize: 8
78+
bold: true
79+
}
80+
}
81+
6082
TextField {
6183
id: urlField
6284
Layout.fillWidth: true
@@ -78,6 +100,7 @@ ApplicationWindow {
78100
activeFocusOnTab: true
79101
focus: true
80102
spriteFencing: false
103+
turboMode: AppMenuBar.turboMode
81104
stageRect.border.color: Material.theme == Material.Dark ? Qt.rgba(1, 1, 1, 0.15) : Qt.rgba(0, 0, 0, 0.15)
82105
stageRect.border.width: 5
83106
}

src/keyboard/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
set(MODULE keyboard)
2+
set(MODULE_URI Keyboard)
3+
set(MODULE_SRC
4+
keyboardmodule.cpp
5+
keyboardmodule.h
6+
ikeyboardinfo.h
7+
internal/keyboardinfo.cpp
8+
internal/keyboardinfo.h
9+
)
10+
11+
include(${PROJECT_SOURCE_DIR}/build/module.cmake)

src/keyboard/ikeyboardinfo.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// SPDX-License-Identifier: GPL-3.0-or-later
2+
3+
#pragma once
4+
5+
#include <modularity/ioc.h>
6+
#include <Qt>
7+
8+
namespace scratchcpp::keyboard
9+
{
10+
11+
class IKeyboardInfo : MODULE_EXPORT_INTERFACE
12+
{
13+
public:
14+
virtual ~IKeyboardInfo() { }
15+
16+
virtual Qt::KeyboardModifiers keyboardModifiers() const = 0;
17+
};
18+
19+
} // namespace scratchcpp::keyboard

0 commit comments

Comments
 (0)