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: factorizationController.isPaused ? "Reset" : factorizationController.isRunning ? "Pause" : "Reset" Layout.fillWidth: true enabled: factorizationController.isRunning || factorizationController.isPaused onClicked: { if (factorizationController.isPaused) { factorizationController.reset(); } else { 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 } } 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 } } } } 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 } Text { text: "Stop Factor: " + factorizationController.stopFactor font.pixelSize: 14 } Item { Layout.fillWidth: true Layout.preferredHeight: 25 ProgressBar { anchors.fill: parent to: 100 value: factorizationController.progress } Text { text: factorizationController.progress.toFixed(1) + "%" anchors.centerIn: parent font.pixelSize: 16 color: "black" font.bold: true } } } } 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 } } }