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#ifndef MAINWINDOW_H
2#define MAINWINDOW_H
3
4#include <QMainWindow>
5#include <QSettings>
6#include "backend/grammar.hpp"
8#include "lltutorwindow.h"
9#include "slrtutorwindow.h"
10#include "tutorialmanager.h"
11
12static const QVector<QString> levelColors = {
13 "#2C3E50", // 1: Navy oscuro
14 "#2980B9", // 2: Azul brillante
15 "#16A085", // 3: Teal
16 "#27AE60", // 4: Verde esmeralda
17 "#8E44AD", // 5: Púrpura medio
18 "#9B59B6", // 6: Púrpura claro
19 "#E67E22", // 7: Naranja
20 "#D35400", // 8: Naranja oscuro
21 "#CD7F32", // 9: Bronce
22 "#FFD700" // 10: Oro puro
23};
24
25QT_BEGIN_NAMESPACE
26namespace Ui {
27class MainWindow;
28}
29QT_END_NAMESPACE
30
40class MainWindow : public QMainWindow
41{
42 Q_OBJECT
43 Q_PROPERTY(unsigned userLevel READ userLevel WRITE setUserLevel NOTIFY userLevelChanged)
44
45public:
50 MainWindow(QWidget *parent = nullptr);
51
54
60 unsigned thresholdFor(unsigned level) { return BASE_THRESHOLD * level; }
61
65 unsigned userLevel() const { return m_userLevel; };
66
71 void setUserLevel(unsigned lvl)
72 {
73 unsigned clamped = qMin(lvl, MAX_LEVEL);
74 if (m_userLevel == clamped)
75 return;
76 m_userLevel = clamped;
77 emit userLevelChanged(clamped);
78 }
79
80private slots:
84 void on_lv1Button_clicked(bool checked);
85 void on_lv2Button_clicked(bool checked);
86 void on_lv3Button_clicked(bool checked);
87
91 void on_pushButton_clicked();
92
96 void on_pushButton_2_clicked();
97
101 void on_tutorial_clicked();
102
106 void on_actionSobre_la_aplicaci_n_triggered();
107
111 void on_actionReferencia_LL_1_triggered();
112
116 void on_actionReferencia_SLR_1_triggered();
117
121 void on_idiom_clicked();
122
123signals:
128 void userLevelChanged(unsigned lvl);
129
134 void userLevelUp(unsigned newLevel);
135
136private:
140 void setupTutorial();
141
145 void restartTutorial();
146
152 void handleTutorFinished(int cntRight, int cntWrong);
153
157 void saveSettings();
158
162 void loadSettings();
163
164 Ui::MainWindow *ui;
165 GrammarFactory factory;
166 int level = 1;
167 TutorialManager *tm = nullptr;
168
169 static constexpr unsigned MAX_LEVEL = 10;
170 static constexpr unsigned MAX_SCORE = 999;
171
172 unsigned m_userLevel = 1;
173 unsigned userScore = 0;
174 QSettings settings;
175
176 const unsigned BASE_THRESHOLD = 10;
177};
178#endif // MAINWINDOW_H
unsigned userLevel() const
Returns the current user level.
Definition mainwindow.h:65
void setUserLevel(unsigned lvl)
Sets the user level, clamping it to the allowed maximum.
Definition mainwindow.h:71
unsigned thresholdFor(unsigned level)
Returns the required score threshold to unlock a level.
Definition mainwindow.h:60
void userLevelUp(unsigned newLevel)
Emitted when the user levels up.
unsigned userLevel
Definition mainwindow.h:43
MainWindow(QWidget *parent=nullptr)
Constructs the main window.
Definition mainwindow.cpp:5
void userLevelChanged(unsigned lvl)
Emitted when the user's level changes.
~MainWindow()
Destructor.
Definition mainwindow.cpp:228
Manages interactive tutorials by highlighting UI elements and guiding the user.
Definition tutorialmanager.h:35
Responsible for creating and managing grammar items and performing checks on grammars.
Definition grammar_factory.hpp:14