From 89f798631d913c8797aae93c55d0d5567d98e0a1 Mon Sep 17 00:00:00 2001
From: amassies <alexandre.massies@etu.ec-lyon.fr>
Date: Fri, 28 Mar 2025 15:26:01 +0100
Subject: [PATCH] =?UTF-8?q?Orga=20relative=20fenetre=20r=C3=A9gl=C3=A9e=20?=
 =?UTF-8?q?et=20=C3=A7a=20ercit=20dans=20les=20cases?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 Motus/CMakeLists.txt        |   1 +
 Motus/Main.qml              | 165 ++++++++++++++++--------------------
 Motus/qtquickcontrols2.conf |   2 +
 3 files changed, 78 insertions(+), 90 deletions(-)
 create mode 100644 Motus/qtquickcontrols2.conf

diff --git a/Motus/CMakeLists.txt b/Motus/CMakeLists.txt
index d1b3570..3a1b4da 100644
--- a/Motus/CMakeLists.txt
+++ b/Motus/CMakeLists.txt
@@ -47,6 +47,7 @@ qt_add_qml_module(appMotus
         QML_FILES
         QML_FILES MotusTimer.qml
         QML_FILES NumberLetterButton.qml
+        RESOURCES qtquickcontrols2.conf
 )
 
 # Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
diff --git a/Motus/Main.qml b/Motus/Main.qml
index 6c4ae75..f24ac68 100644
--- a/Motus/Main.qml
+++ b/Motus/Main.qml
@@ -1,59 +1,57 @@
-import QtQuick
+import QtQuick 2.12
+import QtQuick.Window 2.12
+import QtQuick.Controls 2.12
+// Optionnel : utilisez un style non natif pour autoriser la personnalisation
+// import QtQuick.Controls.Material 2.12
 
 Window {
+    id: mainWindow
     width: Screen.width
     height: Screen.height
     visible: true
     visibility: Window.Maximized
     title: qsTr("Motus")
 
-    property var caseArray: [
-        _case_1_1, _case_1_2, _case_1_3, _case_1_4, _case_1_5,
-        _case_2_1, _case_2_2, _case_2_3, _case_2_4, _case_2_5,
-        _case_3_1, _case_3_2, _case_3_3, _case_3_4, _case_3_5,
-        _case_4_1, _case_4_2, _case_4_3, _case_4_4, _case_4_5,
-        _case_5_1, _case_5_2, _case_5_3, _case_5_4, _case_5_5,
-        _case_6_1, _case_6_2, _case_6_3, _case_6_4, _case_6_5
-    ]
-
+    // Suppression de la déclaration initiale de caseArray car _case_1_1 etc. ne sont pas définis.
     property int indice_case: 0
+    property var caseArray: []   // sera rempli après création de la grille
+    property var case_focus: null
 
-    property var case_focus: caseArray[0]
-
-    Keys.onPressed: {
-        // Vérifier que l'élément qui a le focus possède la propriété _textText
-        if (case_focus && case_focus._textText !== undefined && /^[a-zA-Z]$/.test(event.text)) {
-            case_focus._textText = event.text;
-            indice_case += 1;
-            case_focus = caseArray[indice_case]
-            console.log("Lettre pressée :", event.text);
-            event.accepted = true;
-        }
-        else if (event.key === Qt.Key_Backspace) {
-            console.log("Backspace a été pressée");
-            case_focus._textText = "";
-            if (indice_case != 0){
-                indice_case -= 1;
-                case_focus = caseArray[indice_case];
-            }
-
-            // Ajoutez ici le code pour effacer le contenu ou réaliser l'action souhaitée
-        }
-    }
-
+    // L'élément Rectangle ci-dessous couvre toute la fenêtre et gère les touches
     Rectangle {
-        id: rectangle
+        id: mainRect
         anchors.fill: parent
         color: "#323232"
         focus: true
 
+        // Gestion des touches (attachée à un Item, pas à Window)
+        Keys.onPressed: {
+            // Vérification que case_focus existe et possède la propriété _textText
+            if (case_focus && case_focus._textText !== undefined && /^[a-zA-Z]$/.test(event.text)) {
+                case_focus._textText = event.text;
+                indice_case++;
+                if (indice_case < caseArray.length) {
+                    case_focus = caseArray[indice_case];
+                }
+                event.accepted = true;
+            } else if (event.key === Qt.Key_Backspace) {
+                if (case_focus && case_focus._textText !== undefined)
+                    case_focus._textText = "";
+                if (indice_case > 0) {
+                    indice_case--;
+                    case_focus = caseArray[indice_case];
+                }
+                event.accepted = true;
+            }
+        }
+
         // Bouton "Générer un mot"
         Choosebutton {
             id: choosebutton
             anchors.top: parent.top
             anchors.left: parent.left
-            anchors.topMargin: height * 0.2
-            anchors.leftMargin: width * 0.2
+            anchors.topMargin: parent.height * 0.2
+            anchors.leftMargin: parent.width * 0.2
             _textText: "Générer un mot"
 
             Case {
@@ -72,8 +70,6 @@ Window {
             }
         }
 
-        // Choix du nombre de lettres (en haut à droite)
-
         // Fenêtre pour les langages (en dessous du bouton générer)
         Rectangle {
             id: big_rectangle_langue
@@ -81,7 +77,7 @@ Window {
             height: parent.height * 0.35
             anchors.top: choosebutton.bottom
             anchors.left: choosebutton.left
-            anchors.topMargin: height * 0.3
+            anchors.topMargin: parent.height * 0.3
             color: "#323232"
             radius: 10
             border.color: "#ffffff"
@@ -91,48 +87,37 @@ Window {
                 anchors.fill: parent
                 anchors.margins: 10
                 spacing: 10
-                anchors.horizontalCenter: parent.horizontalCenter
-
-
-
-
-
+                // Ne pas utiliser d'anchors conflictuels sur les enfants du Column
 
                 Text {
                     text: qsTr("Language/Langage")
                     font.pixelSize: 25
                     color: "white"
                     horizontalAlignment: Text.AlignHCenter
-                    anchors.horizontalCenter: parent.horizontalCenter
                 }
 
                 LangageButton {
                     _textText: "Français"
-
-                    anchors.top: parent.top
-                    anchors.right: parent.right
-                    anchors.horizontalCenter: parent.horizontalCenter
-                    anchors.topMargin: parent.height * 0.6
-
-
+                    // Utilisez par exemple Layout.alignment si nécessaire
 
                     MouseArea {
                         anchors.fill: parent
                         cursorShape: Qt.PointingHandCursor
-                        onClicked: motusGame.dictionnaryChoosed = "Motus\\mots_francais.txt"
+                        onClicked: {
+                            motusGame.dictionnaryChoosed = "Motus\\mots_francais.txt";
+                        }
                     }
                 }
 
                 LangageButton {
                     _textText: "English"
-                    anchors.horizontalCenter: parent.horizontalCenter
-                    anchors.top: parent.top
-                    anchors.topMargin: parent.height * 0.2
 
                     MouseArea {
                         anchors.fill: parent
                         cursorShape: Qt.PointingHandCursor
-                        onClicked: motusGame.dictionnaryChoosed = "Motus\\words_alpha.txt"
+                        onClicked: {
+                            motusGame.dictionnaryChoosed = "Motus\\words_alpha.txt";
+                        }
                     }
                 }
             }
@@ -149,14 +134,14 @@ Window {
             horizontalAlignment: Text.AlignHCenter
             anchors.horizontalCenter: parent.horizontalCenter
             anchors.top: parent.top
-            anchors.topMargin: height * 0.2
+            anchors.topMargin: parent.height * 0.2
         }
 
-        // Grille de jeu juste en dessous de MOTUS
+        // Grille de jeu (les cases seront créées dynamiquement)
         Grid {
             id: grid
             anchors.top: _text2.bottom
-            anchors.topMargin: height * 0.02
+            anchors.topMargin: parent.height * 0.02
             anchors.horizontalCenter: parent.horizontalCenter
             width: parent.width * 0.25
             height: parent.height * 0.3
@@ -165,8 +150,26 @@ Window {
             columns: 5
 
             Repeater {
+                id: caseRepeater
                 model: 30
-                delegate: Case {}
+                delegate: Case {
+                    // Afin d'identifier chaque instance, on peut donner un objectName
+                    objectName: "caseDelegate"
+                }
+            }
+        }
+
+        // Au chargement, remplir caseArray à partir des enfants de la grille
+        Component.onCompleted: {
+            caseArray = [];
+            for (var i = 0; i < grid.children.length; i++) {
+                // On ajoute uniquement les instances générées par le Repeater
+                if (grid.children[i].objectName === "caseDelegate") {
+                    caseArray.push(grid.children[i]);
+                }
+            }
+            if (caseArray.length > 0) {
+                case_focus = caseArray[0];
             }
         }
 
@@ -177,7 +180,7 @@ Window {
             height: parent.height * 0.28
             anchors.bottom: parent.bottom
             anchors.horizontalCenter: parent.horizontalCenter
-            anchors.bottomMargin: height * 0.2
+            anchors.bottomMargin: parent.height * 0.2
             color: "#323232"
             radius: 10
             border.color: "#ffffff"
@@ -186,17 +189,7 @@ Window {
             Column {
                 anchors.fill: parent
                 anchors.margins: 10
-
-                anchors.top: parent.top
-                anchors.right: parent.right
-                anchors.bottom: parent.bottom
-                anchors.left: parent.left
-                anchors.topMargin: 0
-                anchors.rightMargin: 0
-                anchors.leftMargin: 0
-                anchors.bottomMargin: 0
-
-                spacing: parent.width*0.04
+                spacing: parent.width * 0.04
 
                 Repeater {
                     model: [
@@ -205,7 +198,7 @@ Window {
                         ["↑", "W", "X", "C", "V", "B", "N", "M", "<"]
                     ]
                     delegate: Row {
-                        spacing: parent.width*0.005
+                        spacing: parent.width * 0.005
                         anchors.horizontalCenter: parent.horizontalCenter
 
                         Repeater {
@@ -220,22 +213,17 @@ Window {
                     }
                 }
             }
-
-            // Timer en bas à droite
-            // Timer à droite du mot MOTUS
-
         }
 
+        // Combobox pour le nombre de lettres
         Rectangle {
             id: rectangle_combobox
-            x: 1299
-            y: 4
-            width: parent.width * 0.2
-            height: parent.height * 0.2
             anchors.top: parent.top
             anchors.right: parent.right
-            anchors.topMargin: height * 1.3
-            anchors.rightMargin: width * 0.6
+            width: parent.width * 0.2
+            height: parent.height * 0.2
+            anchors.topMargin: parent.height * 0.13
+            anchors.rightMargin: parent.width * 0.6
             color: "#323232"
             radius: 10
             border.color: "#ffffff"
@@ -252,15 +240,14 @@ Window {
             NumberLetterButton {
                 y: 49
                 width: parent.width
-                height: parent.height *0.5
+                height: parent.height * 0.5
                 anchors.horizontalCenter: parent.horizontalCenter
                 anchors.bottom: parent.bottom
                 anchors.bottomMargin: 16
-                anchors.left: parent.left
             }
-
         }
 
+        // Timer
         MotusTimer {
             id: motusTimer
             anchors.top: parent.top
@@ -268,7 +255,5 @@ Window {
             anchors.topMargin: parent.height * 0.07
             anchors.rightMargin: parent.width * 0.25
         }
-
-
     }
 }
diff --git a/Motus/qtquickcontrols2.conf b/Motus/qtquickcontrols2.conf
new file mode 100644
index 0000000..b6c7c87
--- /dev/null
+++ b/Motus/qtquickcontrols2.conf
@@ -0,0 +1,2 @@
+[Controls]
+Style=Material
-- 
GitLab