/
aserger
/
cutcalcut
Обзор
Документация
Войти
/
aserger
/
cutcalcut
Код
Запросы
2
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
develop
Calcul/ThemeManager.qml
177 строк
6 KB
SergeyParkhachevIP-415
Merge remote changes from origin/develop and resolve conflicts in ThemeManager.qml
15 дек 2025, 17:18
15 дек 2025, 17:18
b6dbad6
Код
Авторство
О чём код?
// ThemeManager.qml import QtQuick import Qt.labs.settings Item { visible: false id: themeManager signal themeChanged() readonly property var themes: [ { id: "default", name: "По умолчанию", // Цвета кнопок digit: "#ffffff", operation: "#999696", function: "#999696", clear: "#dc3545", // Кнопка C delete: "#dc3545", // Кнопка ← // Цвета интерфейса background: "#f8f9fa", menuBar: "#ffffff", display: "#ffffff", // Цвета текста text: "#212529", textSecondary: "#dc3545" }, { id: "dark", name: "Темная", digit: "#191919", operation: "#323232", function: "#323232", clear: "#dc3545", delete: "#dc3545", background: "#262626", menuBar: "#383838", display: "#383838", text: "#ffffff", textSecondary: "#ffffff" }, { id: "green", name: "Зеленая", digit: "#084F00", operation: "#197624", function: "#197624", clear: "#FF1515", delete: "#FF1515", background: "#002104", menuBar: "#002104", display: "#002104", text: "#ffffff", textSecondary: "#ffffff" }, { id: "purple", name: "Фиолетовая", digit: "#9c36b5", operation: "#FFC4FF", function: "#FFC4FF", clear: "#FF0000", delete: "#FF0000", background: "#320053", menuBar: "#320053", display: "#320053", text: "#ffffff", textSecondary: "#ffffff" } ] property var currentTheme: themes[0] property string currentThemeId: "default" Component.onCompleted: { setTheme(themeSettings.themeId) console.log("LOAD THEME:", themeSettings.themeId) } function setTheme(themeId) { console.log("SAVE THEME:", themeId) for (var i = 0; i < themes.length; i++) { if (themes[i].id === themeId) { currentTheme = themes[i] currentThemeId = themeId themeSettings.themeId = themeId themeChanged() return true } } return false } // Получить цвет по типу кнопки function getButtonColor(buttonType) { switch(buttonType) { case "operation": return currentTheme.operation; case "function": return currentTheme.function; case "clear": return currentTheme.clear; case "delete": return currentTheme.delete; default: return currentTheme.digit; } } // Получить цвет текста кнопки function getButtonTextColor(buttonType) { // Определяем цвет текста в зависимости от типа кнопки switch(buttonType) { case "clear": return "white"; // На красной всегда белый case "delete": return "white"; // На оранжевой всегда белый case "digit": { // Для цифр: проверяем светлый ли цвет var color = currentTheme.digit; var r = parseInt(color.substr(1, 2), 16); var g = parseInt(color.substr(3, 2), 16); var b = parseInt(color.substr(5, 2), 16); // Если цвет светлый - черный текст, иначе белый var brightness = (r * 299 + g * 587 + b * 114) / 1000; return brightness > 128 ? "black" : "white"; } case "operation": { // Для операций: проверяем светлый ли цвет var color = currentTheme.operation; var r = parseInt(color.substr(1, 2), 16); var g = parseInt(color.substr(3, 2), 16); var b = parseInt(color.substr(5, 2), 16); var brightness = (r * 299 + g * 587 + b * 114) / 1000; return brightness > 128 ? "black" : "white"; } case "function": { // Для функций: проверяем светлый ли цвет var color = currentTheme.function; var r = parseInt(color.substr(1, 2), 16); var g = parseInt(color.substr(3, 2), 16); var b = parseInt(color.substr(5, 2), 16); var brightness = (r * 299 + g * 587 + b * 114) / 1000; return brightness > 128 ? "black" : "white"; } default: return "white"; } } Settings { id: themeSettings category: "Calculator" property string themeId: "default" } // Загрузка темы из настроек function loadTheme() { try { var savedTheme = "default"; if (typeof localStorage !== 'undefined') { savedTheme = localStorage.getItem("calculator_theme") || "default"; } setTheme(savedTheme); } catch (e) { console.log("Не удалось загрузить тему:", e); setTheme("default"); } } }