prime_numbers/qml/Main.qml

146 lines
4.4 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 {
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)
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 {
text: "Pause"
Layout.fillWidth: true
enabled: factorizationController.isRunning
onClicked: factorizationController.stop()
}
}
2025-02-25 18:59:49 +01:00
}
}
GroupBox {
title: "Settings"
2025-02-25 18:59:49 +01:00
Layout.fillWidth: true
ColumnLayout {
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
}
}
CheckBox {
text: "Stop at sqrt(n)"
checked: true
onCheckedChanged: factorizationController.useSqrtOptimization = checked
}
2025-02-25 18:59:49 +01:00
}
}
ProgressBar {
Layout.fillWidth: true
from: 0
to: 100
value: factorizationController.progress
}
GroupBox {
title: "Current Status"
Layout.fillWidth: true
ColumnLayout {
spacing: 5
2025-02-25 18:59:49 +01:00
Text {
text: "Current Factor: " + factorizationController.currentFactor
font.pixelSize: 14
Layout.alignment: Qt.AlignHCenter
}
Text {
text: "Current Number (being factorized): " + factorizationController.curFactNumber
font.pixelSize: 14
Layout.alignment: Qt.AlignHCenter
}
}
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 {
text: factorizationController.useSqrtOptimization ? "Note: Only factors up to sqrt(n) are searched." : "Note: Searching all factors (slower)."
2025-02-25 18:59:49 +01:00
font.pixelSize: 12
Layout.alignment: Qt.AlignHCenter
}
}
2025-02-25 12:12:56 +01:00
}