/
aserger
/
cutcalcut
Обзор
Документация
Войти
/
aserger
/
cutcalcut
Код
Запросы
2
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
develop
Calcul/Main.qml
435 строк
14 KB
SergeyParkhachevIP-415
Resolve merge conflicts in Main.qml between feature/buttonsize and develop
15 дек 2025, 17:34
15 дек 2025, 17:34
db23543
Код
Авторство
О чём код?
import QtQuick import QtQuick.Layouts import QtQuick.Controls import QtQuick.Window import "CalculatorEngine.js" as CalcLogic Window { id: mainWindow width: 360 height: 720 visible: true title: qsTr("CuteCalCut") minimumWidth: 300 minimumHeight: 400 color: themeManager.currentTheme.background ThemeManager { id: themeManager onThemeChanged: mainWindow.color = currentTheme.background Component.onCompleted: mainWindow.color = currentTheme.background } // Данные дисплея property string displayText: "0" property string expressionText: "" // Инициализация Component.onCompleted: { CalcLogic.clearAll() } // Обработчик кнопок function handleButtonClick(btnText) { var result if (btnText >= "0" && btnText <= "9") { result = CalcLogic.handleDigit(btnText) } else { result = CalcLogic.handleOperator(btnText) } // Обновляем отображение if (result) { displayText = result.display expressionText = result.expression // Показываем ошибку, если есть if (result.error) { errorPopup.message = result.error errorPopup.open() } } } // Попап ошибки Popup { id: errorPopup width: 280 height: 120 x: (parent.width - width) / 2 y: (parent.height - height) / 2 modal: true focus: true property string message: "" Rectangle { anchors.fill: parent radius: 10 color: themeManager.currentTheme.menuBar Column { anchors.centerIn: parent spacing: 15 Text { text: "⚠️ Ошибка" font.bold: true font.pixelSize: 18 color: "#dc3545" } Text { text: errorPopup.message font.pixelSize: 14 color: themeManager.currentTheme.text horizontalAlignment: Text.AlignHCenter width: 240 wrapMode: Text.Wrap } Button { text: "OK" anchors.horizontalCenter: parent.horizontalCenter background: Rectangle { radius: 6 color: parent.down ? "#6c757d" : "#495057" } contentItem: Text { text: parent.text color: "white" horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter } onClicked: errorPopup.close() } } } } // Drawer настроек Drawer { id: settingsDrawer width: 280 height: parent.height edge: Qt.RightEdge modal: false dim: false Rectangle { anchors.fill: parent color: themeManager.currentTheme.menuBar border.color: "#dee2e6" border.width: 1 ColumnLayout { anchors.fill: parent anchors.margins: 15 spacing: 15 Text { text: "Настройки" font.bold: true font.pixelSize: 22 color: themeManager.currentTheme.text Layout.alignment: Qt.AlignHCenter } Rectangle { Layout.fillWidth: true height: 1 color: "#dee2e6" } Text { text: "Цветовая тема:" font.pixelSize: 16 color: themeManager.currentTheme.text } ListView { id: themeListView Layout.fillWidth: true Layout.fillHeight: true model: themeManager.themes spacing: 10 delegate: Rectangle { width: parent.width height: 70 radius: 8 border.color: modelData.id === themeManager.currentThemeId ? modelData.operation : "#dee2e6" border.width: modelData.id === themeManager.currentThemeId ? 2 : 1 color: modelData.background RowLayout { anchors.fill: parent anchors.margins: 10 spacing: 10 Column { spacing: 3 Row { spacing: 3 Rectangle { width: 15; height: 15; radius: 3; color: modelData.digit } Rectangle { width: 15; height: 15; radius: 3; color: modelData.operation } Rectangle { width: 15; height: 15; radius: 3; color: modelData.clear } } Text { text: modelData.name color: modelData.text font.pixelSize: 14 } } Item { Layout.fillWidth: true } Text { visible: modelData.id === themeManager.currentThemeId text: "✓" color: modelData.operation font.bold: true font.pixelSize: 18 } } MouseArea { anchors.fill: parent onClicked: { themeManager.setTheme(modelData.id); settingsDrawer.close(); } } } } Item { Layout.fillHeight: true } Button { text: "Закрыть" Layout.fillWidth: true background: Rectangle { radius: 8 color: parent.down ? Qt.darker(themeManager.currentTheme.operation, 1.2) : themeManager.currentTheme.operation } contentItem: Text { text: parent.text color: "white" horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter } onClicked: settingsDrawer.close() } } } } // Основной интерфейс ColumnLayout { anchors.fill: parent anchors.margins: 10 spacing: 0 // Панель меню Rectangle { Layout.fillWidth: true Layout.preferredHeight: 50 color: themeManager.currentTheme.menuBar border.color: "#dee2e6" border.width: 1 RowLayout { anchors.fill: parent anchors.margins: 10 Text { text: "CuteCalCut" Layout.fillWidth: true font.bold: true font.pixelSize: 18 color: themeManager.currentTheme.text } Button { text: "⚙️" Layout.alignment: Qt.AlignRight font.pixelSize: 20 background: Rectangle { radius: 6 color: parent.down ? Qt.darker(themeManager.currentTheme.operation, 1.2) : themeManager.currentTheme.operation } contentItem: Text { text: parent.text color: "white" horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter } onClicked: settingsDrawer.open() } } } // Дисплей Rectangle { Layout.fillWidth: true Layout.preferredHeight: 130 color: themeManager.currentTheme.display border.color: "#ced4da" border.width: 1 Column { anchors.fill: parent anchors.margins: 15 spacing: 5 // Выражение Text { id: expressionDisplay width: parent.width text: expressionText font.pixelSize: 16 color: themeManager.currentTheme.textSecondary horizontalAlignment: Text.AlignRight elide: Text.ElideLeft maximumLineCount: 1 } // Основной дисплей Text { id: mainDisplay width: parent.width text: displayText font.pixelSize: 42 font.bold: true color: themeManager.currentTheme.text horizontalAlignment: Text.AlignRight elide: Text.ElideLeft maximumLineCount: 1 } // Статус Text { text: "Готов к вычислениям" font.pixelSize: 14 color: themeManager.currentTheme.textSecondary width: parent.width horizontalAlignment: Text.AlignRight } } } // Кнопки калькулятора GridLayout { id: grid Layout.fillWidth: true Layout.fillHeight: true rows: 6 columns: 4 columnSpacing: 2 rowSpacing: 2 Repeater { model: ["!", "(", ")", "←", "x²", "√", "%", "/", "7", "8", "9", "+", "4", "5", "6", "-", "1", "2", "3", "×", "C", "0", ".", "="] Button { Layout.fillWidth: true Layout.fillHeight: true Layout.preferredWidth: grid.width / 4 - grid.columnSpacing Layout.preferredHeight: grid.height / 6 - grid.rowSpacing text: modelData font.pixelSize: 20 property string buttonType: { if (text === "←") return "delete"; else if (text === "C") return "clear"; else if (["+", "-", "×", "/", "%", "="].includes(text)) return "operation"; else if (["!", "(", ")", "x²", "√"].includes(text)) return "function"; else return "digit"; } property color buttonColor: themeManager.getButtonColor(buttonType) property color textColor: themeManager.getButtonTextColor(buttonType) background: Rectangle { color: parent.down ? Qt.darker(parent.buttonColor, 1.2) : parent.buttonColor radius: 8 border.color: Qt.darker(parent.buttonColor, 1.3) border.width: 2 } contentItem: Text { text: parent.text color: parent.textColor font: parent.font horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter } onClicked: mainWindow.handleButtonClick(text) } } } // Горячие клавиши Shortcut { sequence: "Escape" onActivated: { var result = CalcLogic.clearAll() displayText = result.display expressionText = result.expression } } Shortcut { sequence: "Backspace" onActivated: mainWindow.handleButtonClick("←") } Shortcut { sequences: ["Enter", "Return"] onActivated: mainWindow.handleButtonClick("=") } Shortcut { sequence: "Delete" onActivated: mainWindow.handleButtonClick("C") } } }