Skip to content

Commit 1c88726

Browse files
committed
Add turbo mode menu option
1 parent 07091f0 commit 1c88726

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

src/app/appmenubar.cpp

Lines changed: 28 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, [this]() { setTurboMode(m_turboModeItem->checked()); });
3649
}
3750

3851
MenuBarModel *AppMenuBar::model() const
@@ -68,3 +81,17 @@ 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_turboMode;
88+
}
89+
90+
void AppMenuBar::setTurboMode(bool newTurboMode)
91+
{
92+
if (m_turboMode == newTurboMode)
93+
return;
94+
95+
m_turboMode = newTurboMode;
96+
emit turboModeChanged();
97+
}

src/app/appmenubar.h

Lines changed: 10 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,15 @@ 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;
60+
bool m_turboMode = false;
5161
};
5262

5363
} // namespace scratchcpp

src/app/main.qml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ ApplicationWindow {
4040
Layout.fillWidth: true
4141

4242
CustomToolButton {
43+
id: greenFlagButton
4344
icon.name: "green_flag"
4445
icon.color: "transparent"
4546
onClicked: {
@@ -57,6 +58,22 @@ ApplicationWindow {
5758
}
5859
}
5960

61+
IconLabel {
62+
icon.name: "turbo"
63+
icon.color: "transparent"
64+
text: qsTr("Turbo Mode")
65+
color: Qt.rgba(1, 0.67, 0.1, 1)
66+
visible: AppMenuBar.turboMode
67+
68+
font {
69+
// Reuse the font from the green flag button
70+
family: greenFlagButton.font.family
71+
capitalization: Font.MixedCase
72+
pointSize: 8
73+
bold: true
74+
}
75+
}
76+
6077
TextField {
6178
id: urlField
6279
Layout.fillWidth: true
@@ -78,6 +95,7 @@ ApplicationWindow {
7895
activeFocusOnTab: true
7996
focus: true
8097
spriteFencing: false
98+
turboMode: AppMenuBar.turboMode
8199
stageRect.border.color: Material.theme == Material.Dark ? Qt.rgba(1, 1, 1, 0.15) : Qt.rgba(0, 0, 0, 0.15)
82100
stageRect.border.width: 5
83101
}

0 commit comments

Comments
 (0)