prime_numbers/qml/Main.qml
2025-02-26 14:18:41 +01:00

149 lines
4.5 KiB
QML

import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import PrimeNumbers
ApplicationWindow {
visible: true
width: 400
height: 500
title: "Factorization"
FactorizationController {
id: factorizationController
}
ColumnLayout {
anchors.fill: parent
spacing: 15
GroupBox {
title: "Input"
Layout.fillWidth: true
ColumnLayout {
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)
// 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 {
text: "Pause"
Layout.fillWidth: true
enabled: factorizationController.isRunning
onClicked: factorizationController.stop()
}
}
}
}
GroupBox {
title: "Settings"
Layout.fillWidth: true
ColumnLayout {
anchors.fill: parent
spacing: 10
RowLayout {
Layout.fillWidth: true
Text {
text: "Iterations per cycle:"
Layout.alignment: Qt.AlignLeft
}
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
}
}
CheckBox {
text: "Stop at sqrt(n)"
checked: true
onCheckedChanged: factorizationController.useSqrtOptimization = checked
}
}
}
GroupBox {
title: "Current Status"
Layout.fillWidth: true
ColumnLayout {
anchors.fill: parent
spacing: 5
Text {
text: "Current Number (being factorized): " + factorizationController.curFactNumber
font.pixelSize: 14
}
Text {
text: "Current Factor: " + factorizationController.currentFactor
font.pixelSize: 14
}
ProgressBar {
Layout.fillWidth: true
from: 0
to: 100
value: factorizationController.progress
}
}
}
GroupBox {
title: "Factors Found"
Layout.fillWidth: true
Layout.fillHeight: true
Text {
text: factorizationController.factors.join(", ")
font.pixelSize: 14
color: "black"
}
}
Text {
text: factorizationController.useSqrtOptimization ? "Note: Only factors up to sqrt(n) are searched." : "Warning: Searching all factors (inefficient)."
font.pixelSize: 12
Layout.alignment: Qt.AlignHCenter
}
}
}