SyntaxTutor
Educational app designed to help compiler students understand LL(1) and SLR(1) parsing algorithms.
Loading...
Searching...
No Matches
mainwindow.h
Go to the documentation of this file.
1/*
2 * SyntaxTutor - Interactive Tutorial About Syntax Analyzers
3 * Copyright (C) 2025 Jose R. (jose-rzm)
4 *
5 * This program is free software: you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
19#ifndef MAINWINDOW_H
20#define MAINWINDOW_H
21
22#include "backend/grammar.hpp"
24#include "lltutorwindow.h"
25#include "slrtutorwindow.h"
26#include "tutorialmanager.h"
27#include <QMainWindow>
28#include <QSettings>
29
30static const QVector<QString> levelColors = {
31 "#2C3E50", // 1: Navy oscuro
32 "#2980B9", // 2: Azul brillante
33 "#16A085", // 3: Teal
34 "#27AE60", // 4: Verde esmeralda
35 "#8E44AD", // 5: Púrpura medio
36 "#9B59B6", // 6: Púrpura claro
37 "#E67E22", // 7: Naranja
38 "#D35400", // 8: Naranja oscuro
39 "#CD7F32", // 9: Bronce
40 "#FFD700" // 10: Oro puro
41};
42
43QT_BEGIN_NAMESPACE
44namespace Ui {
45class MainWindow;
46}
47QT_END_NAMESPACE
48
59class MainWindow : public QMainWindow {
60 Q_OBJECT
61 Q_PROPERTY(unsigned userLevel READ userLevel WRITE setUserLevel NOTIFY
63
64 public:
69 MainWindow(QWidget* parent = nullptr);
70
73
79 unsigned thresholdFor(unsigned level) { return BASE_THRESHOLD * level; }
80
84 unsigned userLevel() const { return m_userLevel; };
85
90 void setUserLevel(unsigned lvl) {
91 unsigned clamped = qMin(lvl, MAX_LEVEL);
92 if (m_userLevel == clamped)
93 return;
94 m_userLevel = clamped;
95 emit userLevelChanged(clamped);
96 }
97
98 private slots:
102 void on_lv1Button_clicked(bool checked);
103 void on_lv2Button_clicked(bool checked);
104 void on_lv3Button_clicked(bool checked);
105
109 void on_pushButton_clicked();
110
114 void on_pushButton_2_clicked();
115
119 void on_tutorial_clicked();
120
124 void on_actionSobre_la_aplicaci_n_triggered();
125
129 void on_actionReferencia_LL_1_triggered();
130
134 void on_actionReferencia_SLR_1_triggered();
135
139 void on_idiom_clicked();
140
141 signals:
146 void userLevelChanged(unsigned lvl);
147
152 void userLevelUp(unsigned newLevel);
153
154 private:
158 void setupTutorial();
159
163 void restartTutorial();
164
170 void handleTutorFinished(int cntRight, int cntWrong);
171
175 void saveSettings();
176
180 void loadSettings();
181
182 Ui::MainWindow* ui;
183 GrammarFactory factory;
184 int level = 1;
185 TutorialManager* tm = nullptr;
186
187 static constexpr unsigned MAX_LEVEL = 10;
188 static constexpr unsigned MAX_SCORE = 999;
189
190 unsigned m_userLevel = 1;
191 unsigned userScore = 0;
192 QSettings settings;
193
194 const unsigned BASE_THRESHOLD = 10;
195};
196#endif // MAINWINDOW_H
unsigned userLevel() const
Returns the current user level.
Definition mainwindow.h:84
void setUserLevel(unsigned lvl)
Sets the user level, clamping it to the allowed maximum.
Definition mainwindow.h:90
unsigned thresholdFor(unsigned level)
Returns the required score threshold to unlock a level.
Definition mainwindow.h:79
void userLevelUp(unsigned newLevel)
Emitted when the user levels up.
unsigned userLevel
Definition mainwindow.h:62
MainWindow(QWidget *parent=nullptr)
Constructs the main window.
Definition mainwindow.cpp:25
void userLevelChanged(unsigned lvl)
Emitted when the user's level changes.
~MainWindow()
Destructor.
Definition mainwindow.cpp:152
Manages interactive tutorials by highlighting UI elements and guiding the user.
Definition tutorialmanager.h:53
Responsible for creating and managing grammar items and performing checks on grammars.
Definition grammar_factory.hpp:31