prime_numbers/qml/Main.qml

183 lines
5.9 KiB
QML
Raw Normal View History

2025-02-25 12:12:56 +01:00
import QtQuick
2025-02-25 18:59:49 +01:00
import QtQuick.Controls
import QtQuick.Layouts
import PrimeNumbers
2025-02-25 12:12:56 +01:00
2025-02-25 18:59:49 +01:00
ApplicationWindow {
2025-02-25 12:12:56 +01:00
visible: true
2025-02-25 18:59:49 +01:00
width: 400
height: 500
title: "Factorization"
FactorizationController {
id: factorizationController
}
ColumnLayout {
anchors.fill: parent
spacing: 15
2025-02-25 18:59:49 +01:00
GroupBox {
title: "Input"
2025-02-25 18:59:49 +01:00
Layout.fillWidth: true
ColumnLayout {
2025-02-26 14:18:41 +01:00
anchors.fill: parent
spacing: 10
TextField {
id: numberInput
placeholderText: "Enter a number"
// NOTE: We can't use the IntValidator here, since it doesn't support 64-bit values (long long)
2025-02-26 14:18:41 +01:00
// Entering invalid numbers might cause unexpected behavior (will be fed to parseInt).
Layout.fillWidth: true
font.pixelSize: 16
onTextChanged: factorizationController.reset()
}
RowLayout {
Layout.fillWidth: true
Button {
text: factorizationController.isPaused ? "Resume" : factorizationController.isRunning ? "..." : "Start"
Layout.fillWidth: true
enabled: !factorizationController.isRunning
onClicked: {
if (factorizationController.isPaused) {
factorizationController.resume();
} else {
factorizationController.start(parseInt(numberInput.text, 10));
}
}
}
Button {
2025-02-26 15:03:34 +01:00
text: factorizationController.isPaused ? "Reset" : factorizationController.isRunning ? "Pause" : "Reset"
Layout.fillWidth: true
2025-02-26 15:03:34 +01:00
enabled: factorizationController.isRunning || factorizationController.isPaused
onClicked: {
if (factorizationController.isPaused) {
factorizationController.reset();
} else {
factorizationController.stop();
}
}
}
}
2025-02-25 18:59:49 +01:00
}
}
GroupBox {
title: "Settings"
2025-02-25 18:59:49 +01:00
Layout.fillWidth: true
2025-02-26 14:18:41 +01:00
ColumnLayout {
2025-02-26 14:18:41 +01:00
anchors.fill: parent
spacing: 10
RowLayout {
Layout.fillWidth: true
Text {
text: "Iterations per cycle:"
Layout.alignment: Qt.AlignLeft
2025-02-25 18:59:49 +01:00
}
Slider {
id: iterationSlider
Layout.fillWidth: true
from: 1
to: 100000
stepSize: 1
value: 1
onValueChanged: factorizationController.iterationsPerCycle = value
}
Text {
text: iterationSlider.value.toFixed(0)
font.bold: true
Layout.alignment: Qt.AlignRight
2025-02-25 18:59:49 +01:00
}
}
RowLayout {
Layout.fillWidth: true
CheckBox {
text: "Stop at sqrt(n)"
checked: factorizationController.useSqrtOptimization
onCheckedChanged: factorizationController.useSqrtOptimization = checked
}
CheckBox {
text: "Pause when factor found"
checked: factorizationController.pauseOnFound
onCheckedChanged: factorizationController.pauseOnFound = checked
}
}
2025-02-25 18:59:49 +01:00
}
}
GroupBox {
title: "Current Status"
Layout.fillWidth: true
2025-02-26 14:18:41 +01:00
ColumnLayout {
2025-02-26 14:18:41 +01:00
anchors.fill: parent
spacing: 5
2025-02-25 18:59:49 +01:00
Text {
2025-02-26 14:18:41 +01:00
text: "Current Number (being factorized): " + factorizationController.curFactNumber
font.pixelSize: 14
}
Text {
2025-02-26 14:18:41 +01:00
text: "Current Factor: " + factorizationController.currentFactor
font.pixelSize: 14
2025-02-26 14:18:41 +01:00
}
2025-02-26 14:36:24 +01:00
Text {
text: "Stop Factor: " + factorizationController.stopFactor
font.pixelSize: 14
}
2025-02-26 15:24:58 +01:00
Item {
2025-02-26 14:18:41 +01:00
Layout.fillWidth: true
2025-02-26 15:24:58 +01:00
Layout.preferredHeight: 25
ProgressBar {
anchors.fill: parent
to: 100
value: factorizationController.progress
}
Text {
text: factorizationController.progress.toFixed(0) + "%"
anchors.centerIn: parent
font.pixelSize: 16
color: "black"
font.bold: true
}
}
}
2025-02-25 18:59:49 +01:00
}
GroupBox {
title: "Factors Found"
2025-02-25 18:59:49 +01:00
Layout.fillWidth: true
Layout.fillHeight: true
Text {
text: factorizationController.factors.join(", ")
2025-02-25 18:59:49 +01:00
font.pixelSize: 14
color: "black"
2025-02-25 18:59:49 +01:00
}
}
Text {
2025-02-26 14:18:41 +01:00
text: factorizationController.useSqrtOptimization ? "Note: Only factors up to sqrt(n) are searched." : "Warning: Searching all factors (inefficient)."
2025-02-25 18:59:49 +01:00
font.pixelSize: 12
Layout.alignment: Qt.AlignHCenter
}
}
2025-02-25 12:12:56 +01:00
}