diff --git a/Motus/CMakeLists.txt b/Motus/CMakeLists.txt index e9ddbc6e3417070c819e76873a3d8473051b49b9..5a9421c326146a777702d354629f2cee76611a72 100644 --- a/Motus/CMakeLists.txt +++ b/Motus/CMakeLists.txt @@ -15,14 +15,21 @@ qt_add_executable(appMotus qt_add_qml_module(appMotus URI Motus VERSION 1.0 + QML_FILES Main.qml - RESOURCES Ressources.qrc - QML_FILES Case.qml - QML_FILES Key.qml - QML_FILES BackKey.qml - QML_FILES Bouton.qml - SOURCES wordchooser.h wordchooser.cpp + Case.qml + Key.qml + BackKey.qml + Bouton.qml + Choosebutton.qml + + SOURCES + wordchooser.h + wordchooser.cpp + + RESOURCES + Ressources.qrc ) # Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1. diff --git a/Motus/Choosebutton.qml b/Motus/Choosebutton.qml new file mode 100644 index 0000000000000000000000000000000000000000..c5b0fb055ad33e3f30a9598fe20724abc7b94b82 --- /dev/null +++ b/Motus/Choosebutton.qml @@ -0,0 +1,28 @@ +import QtQuick +import QtQuick.Controls 2.15 + +Item { + property alias buttonText: button.text + width: 300 + height: 200 + Rectangle { + id: rectangle + x: 0 + y: 0 + width: 300 + height: 200 + color: "#ffffff" + + Button { + id: button + x: 2 + y: 0 + width: 298 + height: 200 + text: qsTr("Bouton") + } + } + + + +} diff --git a/Motus/Main.qml b/Motus/Main.qml index ac3f942014758c05524b0321bd985103d66c0848..5849c592972a07d7d8a976354928cde438671ed8 100644 --- a/Motus/Main.qml +++ b/Motus/Main.qml @@ -57,6 +57,27 @@ Window { } } + Choosebutton { + id: choosebutton + x: 663 + y: 249 + buttonText: "Générer un mot" + + MouseArea { + id: mouseArea1 + x: 0 + y: 0 + width: 400 + height: 200 + onClicked: { + let mot = wordChooser.getRandomWord(); + console.log("Mot choisi :", mot); + case3._textText = mot; + onClicked: case3._textColor="#51c3e1"; + } + } + + Image { id: testImage @@ -390,6 +411,8 @@ Window { } } + + Keys.onPressed: (event) => { if (event.key === Qt.Key_A) { case1._textText = qsTr("C"); @@ -399,3 +422,4 @@ Window { } } } +} diff --git a/Motus/Ressources.qrc b/Motus/Ressources.qrc index 6c7eb073031421e4ebd0a99ba5f60a2d1b15a0b0..10ea4bd56d51efeaee741beb607d68e743fc5220 100644 --- a/Motus/Ressources.qrc +++ b/Motus/Ressources.qrc @@ -6,5 +6,6 @@ <file>Key.qml</file> <file>words_alpha.txt</file> <file>back_key.png</file> + <file>Choosebutton.qml</file> </qresource> </RCC> diff --git a/Motus/wordchooser.cpp b/Motus/wordchooser.cpp index fe0abe66c595dc6668f2a0c187b61b5f137aad05..a0aedbdf3e840fa7767f8ed8ca35b31f130dca53 100644 --- a/Motus/wordchooser.cpp +++ b/Motus/wordchooser.cpp @@ -2,14 +2,17 @@ #include <QFile> #include <QTextStream> #include <QRandomGenerator> -QFile file("words_alpha.txt"); + + +#include <QDebug> + WordChooser::WordChooser(QObject *parent) : QObject(parent) { loadWords(); } void WordChooser::loadWords() { - QFile file("qrc:/words_alpha.txt"); + QFile file(":/words_alpha.txt"); // ✅ fonctionne avec le .qrc if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { QTextStream in(&file); while (!in.atEnd()) { @@ -18,13 +21,20 @@ void WordChooser::loadWords() { words.append(line); } file.close(); + qDebug() << "✅ Mots chargés :" << words.size(); + } else { + qDebug() << "❌ Erreur : impossible d'ouvrir words_alpha.txt"; } } QString WordChooser::getRandomWord() { - if (words.isEmpty()) + if (words.isEmpty()) { + qDebug() << "❌ Aucune donnée chargée dans words."; return ""; + } int index = QRandomGenerator::global()->bounded(words.size()); - return words[index]; + QString mot = words[index]; + qDebug() << "✅ Mot choisi :" << mot; + return mot; }