-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
230 lines (207 loc) · 9.42 KB
/
Copy pathmainwindow.cpp
File metadata and controls
230 lines (207 loc) · 9.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFile>
#include <QTextStream>
#include <QApplication>
#include <QDateTime>
#include <QRandomGenerator>
#include <QThread>
// Use an enum to name categories instead of numbers (makes code easier to read)
enum InterestCategory {
Gaming = 0,
Fitness,
Learning,
Movies,
Productivity,
CategoryCount // This is 5, used for loops
};
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
// Close the app when the close button is clicked
void MainWindow::on_pushButton_3_clicked()
{
close();
}
// Main function: When submit is clicked, calculate and show a suggestion
void MainWindow::on_btnSubmit_clicked()
{
// Step 1: Lists of random suggestions for each category
QStringList gamingPool = {"Enjoy Minecraft", "Play some Valorant", "Try Stardew Valley"};
QStringList fitnessPool = {"15-min workout", "Go for a run", "Try some Yoga"};
QStringList learningPool = {"Practice C++", "Watch a TED Talk", "Read a Tech Blog"};
QStringList moviePool = {"Watch Sci-Fi", "Watch an Action Movie", "Classic Drama"};
QStringList productPool = {"Clear your inbox", "Organize desk", "Set weekly goals"};
// Step 2: Fake "AI thinking" with Language Support
bool isArabic = (ui->comboLang->currentIndex() == 1);
for(int i = 0; i <= 100; i += 25) {
if(i == 25) ui->lblStatus->setText(isArabic ? "الذكاء الاصطناعي يحلل الأولويات..." : "AI is analyzing priorities...");
else if(i == 50) ui->lblStatus->setText(isArabic ? "مقارنة النتائج..." : "Comparing weighted scores...");
else if(i == 75) ui->lblStatus->setText(isArabic ? "إنشاء مطابقة مخصصة..." : "Generating personalized match...");
ui->progressBar->setValue(i);
QCoreApplication::processEvents();
QThread::msleep(150);
}
// Step 3: Calculate scores based on checkboxes and spin boxes
int scores[CategoryCount]; // Array to hold scores for each category
scores[Gaming] = ui->chkGaming->isChecked() ? ui->spinGaming->value() * 10 : 0;
scores[Fitness] = ui->chkFitness->isChecked() ? ui->spinFitness->value() * 15 : 0;
scores[Learning] = ui->chkLearning->isChecked() ? ui->spinLearning->value() * 20 : 0;
scores[Movies] = ui->chkMovies->isChecked() ? ui->spinMovies->value() * 10 : 0;
scores[Productivity] = ui->chkProductivity->isChecked() ? ui->spinProductivity->value() * 18 : 0;
// Find the highest score
int highestScore = 0;
for(int i = 0; i < CategoryCount; i++) {
if(scores[i] > highestScore) highestScore = scores[i];
}
// Step 4: Pick a suggestion based on scores
QString finalRec; // This will hold the final message
if (highestScore == 0) {
finalRec = "Please select an interest first!";
}
// Check for ties (combinations of two categories)
else if (scores[Gaming] == highestScore && scores[Fitness] == highestScore) {
finalRec = "Combined Suggestion: Play 'Ring Fit Adventure' or 'Pokemon GO'!";
}
else if (scores[Learning] == highestScore && scores[Movies] == highestScore) {
finalRec = "Combined Suggestion: Watch an Educational Documentary on Netflix.";
}
else if (scores[Productivity] == highestScore && scores[Learning] == highestScore) {
finalRec = "Combined Suggestion: Research new time-management apps or tools.";
}
else if (scores[Gaming] == highestScore && scores[Movies] == highestScore) {
finalRec = "Combined Suggestion: Watch a movie based on a Video Game.";
}
else if (scores[Productivity] == highestScore && scores[Fitness] == highestScore) {
finalRec = "Combined Suggestion: Plan your gym schedule for the whole week.";
}
else {
// No tie: Pick a random suggestion from the winning category
if(scores[Gaming] == highestScore)
finalRec = gamingPool.at(QRandomGenerator::global()->bounded(gamingPool.size()));
else if(scores[Fitness] == highestScore)
finalRec = fitnessPool.at(QRandomGenerator::global()->bounded(fitnessPool.size()));
else if(scores[Learning] == highestScore)
finalRec = learningPool.at(QRandomGenerator::global()->bounded(learningPool.size()));
else if(scores[Movies] == highestScore)
finalRec = moviePool.at(QRandomGenerator::global()->bounded(moviePool.size()));
else
finalRec = productPool.at(QRandomGenerator::global()->bounded(productPool.size()));
}
// Step 5: Add to history table and save to file
int row = ui->txtHistory->rowCount();
ui->txtHistory->insertRow(row);
ui->txtHistory->setItem(row, 0, new QTableWidgetItem(finalRec));
ui->txtHistory->resizeColumnsToContents();
QFile file("history.txt");
if (file.open(QIODevice::Append | QIODevice::Text)) {
QTextStream out(&file);
out << "AI Suggestion: " << finalRec << " | Confidence: " << highestScore << "%\n";
file.close();
}
// Step 6: Update the dial and its color based on the category
ui->dial->setValue(highestScore);
if (finalRec.contains("Combined Suggestion")) {
ui->dial->setStyleSheet("QDial { background-color: #DDA0DD; }"); // Purple for combined
}
else if (scores[Gaming] == highestScore && highestScore > 0) {
ui->dial->setStyleSheet("QDial { background-color: #90EE90; }"); // Green for gaming
}
else if (scores[Learning] == highestScore) {
ui->dial->setStyleSheet("QDial { background-color: #ADD8E6; }"); // Blue for learning
}
else if (scores[Fitness] == highestScore) {
ui->dial->setStyleSheet("QDial { background-color: #FFD700; }"); // Gold for fitness
}
else if (scores[Movies] == highestScore) {
ui->dial->setStyleSheet("QDial { background-color: #E6E6FA; }"); // Lavender for movies
}
else if (scores[Productivity] == highestScore) {
ui->dial->setStyleSheet("QDial { background-color: #F08080; }"); // Coral for productivity
}
// Step 7: Show final message and make a beep sound
ui->lblStatus->setText("AI Suggests: " + finalRec + " (Confidence: " + QString::number(highestScore) + "%)");
QApplication::beep();
}
// Reset everything when reset button is clicked
void MainWindow::on_btnReset_clicked()
{
ui->chkGaming->setChecked(false);
ui->chkLearning->setChecked(false);
ui->chkFitness->setChecked(false);
ui->chkMovies->setChecked(false);
ui->chkProductivity->setChecked(false);
ui->spinGaming->setValue(0);
ui->spinFitness->setValue(0);
ui->spinLearning->setValue(0);
ui->spinMovies->setValue(0);
ui->spinProductivity->setValue(0);
ui->progressBar->setValue(0);
ui->dial->setValue(0);
ui->dial->setStyleSheet(""); // Reset color
ui->lblStatus->setText("System Reset. Standing by for new input...");
ui->txtHistory->setRowCount(0);
}
// Switch between light and dark mode
void MainWindow::on_comboBox_currentIndexChanged(int index)
{
if (index == 1) { // Dark mode
this->setStyleSheet("QMainWindow { background-color: #2d2d2d; }"
"QLabel { color: white; }"
"QCheckBox { color: white; }"
"QTableWidget { background-color: #3d3d3d; color: white; }");
}
else { // Light mode
this->setStyleSheet("");
}
}
// Export history to a file when export button is clicked
void MainWindow::on_btnExport_clicked()
{
QFile file("Final_Export.txt");
if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
QTextStream out(&file);
out << "=== PERSONALIZED AI HISTORY REPORT ===\n";
out << "Generated on: " << QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss") << "\n\n";
for (int i = 0; i < ui->txtHistory->rowCount(); ++i) {
QString itemText = ui->txtHistory->item(i, 0)->text();
out << i + 1 << ". " << itemText << "\n";
}
file.close();
ui->lblStatus->setText("History exported to Final_Export.txt!");
}
}
void MainWindow::updateLanguage(int index) {
if (index == 1) { // Arabic selected
ui->chkGaming->setText("الألعاب");
ui->chkFitness->setText("اللياقة البدنية");
ui->chkLearning->setText("التعلم");
ui->chkMovies->setText("الأفلام");
ui->chkProductivity->setText("الإنتاجية");
ui->btnSubmit->setText("إرسال");
ui->btnReset->setText("إعادة تعيين");
ui->btnExport->setText("تصدير التاريخ");
ui->lblStatus->setText("نظام مستعد...");
} else { // English selected
ui->chkGaming->setText("Gaming");
ui->chkFitness->setText("Fitness");
ui->chkLearning->setText("Learning");
ui->chkMovies->setText("Movies");
ui->chkProductivity->setText("Productivity");
ui->btnSubmit->setText("Submit Recommendation");
ui->btnReset->setText("Reset All");
ui->btnExport->setText("Export History");
ui->lblStatus->setText("System Standing by...");
}
}
void MainWindow::on_comboLang_currentIndexChanged(int index)
{
updateLanguage(index);
}