[games/chessament] src: Refactor results footer

Manuel Alcaraz Zambrano <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit f03b5c48858140b2d4dbd2586a95e84228f94d07 by Manuel Alcaraz Zambrano.
Committed on 07/08/2026 at 11:30.
Pushed by manuelal into branch 'master'.

Refactor results footer

M  +1    -0    src/CMakeLists.txt
M  +42   -47   src/qml/ResultsFooter.qml
A  +25   -0    src/qml/components/ResultButton.qml     [License: GPL(v3.0+)]

https://invent.kde.org/games/chessament/-/commit/f03b5c48858140b2d4dbd2586a95e84228f94d07

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 3ebac99..dc7d30d 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -16,6 +16,7 @@ ecm_add_qml_module(chessament_static
         qml/components/HeaderDelegate.qml
         qml/components/MenuBar.qml
         qml/components/RatingField.qml
+        qml/components/ResultButton.qml
         qml/components/StartingRankField.qml
         qml/components/TiebreakDelegate.qml
         qml/components/TimeControlDelegate.qml
diff --git a/src/qml/ResultsFooter.qml b/src/qml/ResultsFooter.qml
index c3d97f1..cc38213 100644
--- a/src/qml/ResultsFooter.qml
+++ b/src/qml/ResultsFooter.qml
@@ -33,81 +33,76 @@ QQC2.ToolBar {
 
     QQC2.ButtonGroup {
         id: results
-        buttons: row.children.filter(item => item instanceof QQC2.ToolButton)
+        buttons: row.children.filter(item => item instanceof QQC2.ToolButton && item !== otherResults)
     }
 
     Layouts.RowLayout {
         id: row
-
-        QQC2.ToolButton {
-            text: Controller.resultToString(Pairing.PartialResult.Unknown, Pairing.PartialResult.Unknown)
-            checkable: true
-            enabled: root.pairing !== null && root.pairing.blackPlayer !== null
-            checked: root.pairing?.whiteResult === Pairing.PartialResult.Unknown && root.pairing?.blackResult === Pairing.PartialResult.Unknown
-            onClicked: root.setResult(Pairing.PartialResult.Unknown, Pairing.PartialResult.Unknown)
+        enabled: root.pairing?.blackPlayer ?? false
+
+        ResultButton {
+            id: unknown
+            whiteResult: Pairing.PartialResult.Unknown
+            blackResult: Pairing.PartialResult.Unknown
+            pairing: root.pairing
+            onSetResult: root.setResult(whiteResult, blackResult)
         }
         Kirigami.Separator {
             Layouts.Layout.fillHeight: true
         }
-        QQC2.ToolButton {
+        ResultButton {
             id: whiteWins
-            text: Controller.resultToString(Pairing.PartialResult.Win, Pairing.PartialResult.Lost)
-            checkable: true
-            enabled: root.pairing !== null && root.pairing.blackPlayer !== null
-            checked: root.pairing?.whiteResult === Pairing.PartialResult.Win && root.pairing?.blackResult === Pairing.PartialResult.Lost
-            onClicked: root.setResult(Pairing.PartialResult.Win, Pairing.PartialResult.Lost)
+            whiteResult: Pairing.PartialResult.Win
+            blackResult: Pairing.PartialResult.Lost
+            pairing: root.pairing
+            onSetResult: root.setResult(whiteResult, blackResult)
         }
-        QQC2.ToolButton {
+        ResultButton {
             id: draw
-            text: Controller.resultToString(Pairing.PartialResult.Draw, Pairing.PartialResult.Draw)
-            checkable: true
-            enabled: root.pairing !== null && root.pairing.blackPlayer !== null
-            checked: root.pairing?.whiteResult === Pairing.PartialResult.Draw && root.pairing?.blackResult === Pairing.PartialResult.Draw
-            onClicked: root.setResult(Pairing.PartialResult.Draw, Pairing.PartialResult.Draw)
+            whiteResult: Pairing.PartialResult.Draw
+            blackResult: Pairing.PartialResult.Draw
+            pairing: root.pairing
+            onSetResult: root.setResult(whiteResult, blackResult)
         }
-        QQC2.ToolButton {
+        ResultButton {
             id: blackWins
-            text: Controller.resultToString(Pairing.PartialResult.Lost, Pairing.PartialResult.Win)
-            checkable: true
-            enabled: root.pairing !== null && root.pairing.blackPlayer !== null
-            checked: root.pairing?.whiteResult === Pairing.PartialResult.Lost && root.pairing?.blackResult === Pairing.PartialResult.Win
-            onClicked: root.setResult(Pairing.PartialResult.Lost, Pairing.PartialResult.Win)
+            whiteResult: Pairing.PartialResult.Lost
+            blackResult: Pairing.PartialResult.Win
+            pairing: root.pairing
+            onSetResult: root.setResult(whiteResult, blackResult)
         }
         Kirigami.Separator {
             Layouts.Layout.fillHeight: true
         }
-        QQC2.ToolButton {
+        ResultButton {
             id: whiteWinsForfeit
-            text: Controller.resultToString(Pairing.PartialResult.WinForfeit, Pairing.PartialResult.LostForfeit)
-            checkable: true
-            enabled: root.pairing !== null && root.pairing.blackPlayer !== null
-            checked: root.pairing?.whiteResult === Pairing.PartialResult.WinForfeit && root.pairing?.blackResult === Pairing.PartialResult.LostForfeit
-            onClicked: root.setResult(Pairing.PartialResult.WinForfeit, Pairing.PartialResult.LostForfeit)
+            whiteResult: Pairing.PartialResult.WinForfeit
+            blackResult: Pairing.PartialResult.LostForfeit
+            pairing: root.pairing
+            onSetResult: root.setResult(whiteResult, blackResult)
         }
-        QQC2.ToolButton {
+        ResultButton {
             id: blackWinsForfeit
-            text: Controller.resultToString(Pairing.PartialResult.LostForfeit, Pairing.PartialResult.WinForfeit)
-            checkable: true
-            enabled: root.pairing !== null && root.pairing.blackPlayer !== null
-            checked: root.pairing?.whiteResult === Pairing.PartialResult.LostForfeit && root.pairing?.blackResult === Pairing.PartialResult.WinForfeit
-            onClicked: root.setResult(Pairing.PartialResult.LostForfeit, Pairing.PartialResult.WinForfeit)
+            whiteResult: Pairing.PartialResult.LostForfeit
+            blackResult: Pairing.PartialResult.WinForfeit
+            pairing: root.pairing
+            onSetResult: root.setResult(whiteResult, blackResult)
         }
-        QQC2.ToolButton {
+        ResultButton {
             id: bothForfeit
-            text: Controller.resultToString(Pairing.PartialResult.LostForfeit, Pairing.PartialResult.LostForfeit)
-            checkable: true
-            enabled: root.pairing !== null && root.pairing.blackPlayer !== null
-            checked: root.pairing?.whiteResult === Pairing.PartialResult.LostForfeit && root.pairing?.blackResult === Pairing.PartialResult.LostForfeit
-            onClicked: root.setResult(Pairing.PartialResult.LostForfeit, Pairing.PartialResult.LostForfeit)
+            whiteResult: Pairing.PartialResult.LostForfeit
+            blackResult: Pairing.PartialResult.LostForfeit
+            pairing: root.pairing
+            onSetResult: root.setResult(whiteResult, blackResult)
         }
         Kirigami.Separator {
             Layouts.Layout.fillHeight: true
         }
         QQC2.ToolButton {
+            id: otherResults
             text: KI18n.i18nc("@action:intoolbar Other game results", "Other")
-            enabled: root.pairing !== null && root.pairing.blackPlayer !== null
-            checkable: true
-            checked: root.pairing && !whiteWins.checked && !draw.checked && !blackWins.checked && !whiteWinsForfeit.checked && !blackWinsForfeit.checked && !bothForfeit.checked
+            checkable: checked
+            checked: root.pairing && root.pairing.blackPlayer !== null && !(unknown.checked || whiteWins.checked || draw.checked || blackWins.checked || whiteWinsForfeit.checked || blackWinsForfeit.checked || bothForfeit.checked)
             down: pressed || otherMenu.opened
             onClicked: otherMenu.open()
 
diff --git a/src/qml/components/ResultButton.qml b/src/qml/components/ResultButton.qml
new file mode 100644
index 0000000..c29d2a2
--- /dev/null
+++ b/src/qml/components/ResultButton.qml
@@ -0,0 +1,25 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+// SPDX-FileCopyrightText: 2026 Manuel Alcaraz Zambrano <[email protected]>
+
+pragma ComponentBehavior: Bound
+
+import QtQuick
+import QtQuick.Controls as Controls
+
+import org.kde.chessament
+
+Controls.ToolButton {
+    id: root
+
+    required property int whiteResult
+    required property int blackResult
+
+    required property Pairing pairing
+
+    signal setResult
+
+    text: Controller.resultToString(root.whiteResult, root.blackResult)
+    checkable: true
+    checked: root.pairing?.whiteResult === root.whiteResult && root.pairing?.blackResult === root.blackResult
+    onClicked: root.setResult()
+}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.