From b26b74db8f7c132c0d585fdcc0ddb7d5b84a947b Mon Sep 17 00:00:00 2001 From: cutefishd Date: Sat, 27 Mar 2021 02:02:42 +0800 Subject: [PATCH] Adjust UI --- cutefish-calculator.desktop | 2 +- qml.qrc | 4 +- qml/ButtonsView.qml | 69 -------------------------------- qml/CTextField.qml | 58 --------------------------- qml/StandardButton.qml | 58 +++++++++++++++++++++++++++ qml/StandardPad.qml | 39 ++++++++++++++++++ qml/Zone.qml | 14 ++++++- qml/main.qml | 9 ++--- translations/cs_CZ.ts | 79 ------------------------------------- translations/de_DE.ts | 79 ------------------------------------- translations/en_US.ts | 71 +-------------------------------- translations/es_ES.ts | 79 ------------------------------------- translations/es_MX.ts | 79 ------------------------------------- translations/it_IT.ts | 79 ------------------------------------- translations/nb_NO.ts | 79 ------------------------------------- translations/pl_PL.ts | 79 ------------------------------------- translations/pt_BR.ts | 79 ------------------------------------- translations/ru_RU.ts | 79 ------------------------------------- translations/si_LK.ts | 79 ------------------------------------- translations/zh_CN.ts | 67 ------------------------------- translations/zh_HK.ts | 79 ------------------------------------- translations/zh_TW.ts | 79 ------------------------------------- 22 files changed, 117 insertions(+), 1222 deletions(-) delete mode 100644 qml/ButtonsView.qml delete mode 100644 qml/CTextField.qml create mode 100644 qml/StandardButton.qml create mode 100644 qml/StandardPad.qml delete mode 100644 translations/cs_CZ.ts delete mode 100644 translations/de_DE.ts delete mode 100644 translations/es_ES.ts delete mode 100644 translations/es_MX.ts delete mode 100644 translations/it_IT.ts delete mode 100644 translations/nb_NO.ts delete mode 100644 translations/pl_PL.ts delete mode 100644 translations/pt_BR.ts delete mode 100644 translations/ru_RU.ts delete mode 100644 translations/si_LK.ts delete mode 100644 translations/zh_HK.ts delete mode 100644 translations/zh_TW.ts diff --git a/cutefish-calculator.desktop b/cutefish-calculator.desktop index 8d9a0ca..367a0f3 100644 --- a/cutefish-calculator.desktop +++ b/cutefish-calculator.desktop @@ -2,7 +2,7 @@ Name=Calculator Name[zh_CN]=计算器 Exec=cutefish-calculator -Icon=calculator +Icon=cutefish-calculator Terminal=false Type=Application StartupNotify=true diff --git a/qml.qrc b/qml.qrc index b82fe0e..2eb68fa 100644 --- a/qml.qrc +++ b/qml.qrc @@ -1,8 +1,8 @@ qml/main.qml - qml/ButtonsView.qml qml/Zone.qml - qml/CTextField.qml + qml/StandardButton.qml + qml/StandardPad.qml diff --git a/qml/ButtonsView.qml b/qml/ButtonsView.qml deleted file mode 100644 index 66fd315..0000000 --- a/qml/ButtonsView.qml +++ /dev/null @@ -1,69 +0,0 @@ -import QtQuick 2.12 -import QtQuick.Layouts 1.3 -import QtQuick.Controls 2.5 -import MeuiKit 1.0 as Meui - -Item { - id: buttonsView - - property var labels - property var targets - property int rowsCount: 5 - - signal buttonClicked(string strToAppend) - signal buttonLongPressed(string strToAppend) - - Grid { - id: grid - anchors.centerIn: parent - anchors.margins: Meui.Units.smallSpacing - columns: getColumnsCount() - rows: buttonsView.rowsCount - - Repeater { - model: buttonsView.labels - - MouseArea { - id: buttonRect - width: buttonsView.width / grid.columns - Meui.Units.smallSpacing / 2 - height: buttonsView.height / grid.rows - Meui.Units.smallSpacing / 2 - onClicked: buttonsView.buttonClicked(targets[index]) - onPressAndHold: buttonsView.buttonLongPressed(targets[index]) - - Rectangle { - anchors.centerIn: parent - radius: Meui.Theme.smallRadius - width: parent.width - radius - height: parent.height - radius - color: buttonRect.pressed ? Meui.Theme.highlightColor : Qt.rgba(Meui.Theme.backgroundColor.r, - Meui.Theme.backgroundColor.g, - Meui.Theme.backgroundColor.b, 0.5) - - border.width: 1 - border.color: Meui.Theme.darkMode ? Qt.lighter(Meui.Theme.backgroundColor, 1.1) : Qt.darker(Meui.Theme.backgroundColor, 1.1) - - Behavior on color { - ColorAnimation { - duration: 50 - } - } - } - - Text { - anchors.fill: parent - text: modelData - horizontalAlignment: Qt.AlignHCenter - verticalAlignment: Qt.AlignVCenter - fontSizeMode: Text.Fit - minimumPointSize: Math.round(buttonRect.height / 5) - font.pointSize: Math.round(buttonRect.height / 5) - color: buttonRect.pressed ? Meui.Theme.highlightedTextColor : Meui.Theme.textColor - } - } - } - } - - function getColumnsCount() { - return Math.ceil(buttonsView.labels.length / buttonsView.rowsCount); - } -} diff --git a/qml/CTextField.qml b/qml/CTextField.qml deleted file mode 100644 index 5935eef..0000000 --- a/qml/CTextField.qml +++ /dev/null @@ -1,58 +0,0 @@ -import QtQuick 2.0 -import QtQuick.Controls 2.5 - -TextField { - id: textField - selectByMouse: true - horizontalAlignment: TextInput.AlignRight - focus: Qt.StrongFocus - font.pixelSize: 24 - - property int selectStart - property int selectEnd - property int curPos - - background: Rectangle { - border.width: 0 - color: "transparent" - } - - MouseArea { - anchors.fill: parent - cursorShape: Qt.IBeamCursor - acceptedButtons: Qt.RightButton - - onClicked: { - selectStart = textField.selectionStart; - selectEnd = textField.selectionEnd; - curPos = textField.cursorPosition; - contextMenu.x = mouse.x; - contextMenu.y = mouse.y; - contextMenu.open(); - textField.cursorPosition = curPos; - textField.select(selectStart, selectEnd); - } - } - - Menu { - id: contextMenu - MenuItem { - text: qsTr("Cut") - onTriggered: { - textField.cut() - } - } - MenuItem { - text: qsTr("Copy") - onTriggered: { - textField.copy() - } - } - MenuItem { - text: qsTr("Paste") - onTriggered: { - textField.paste() - } - } - } -} diff --git a/qml/StandardButton.qml b/qml/StandardButton.qml new file mode 100644 index 0000000..c383a5f --- /dev/null +++ b/qml/StandardButton.qml @@ -0,0 +1,58 @@ +import QtQuick 2.12 +import QtQuick.Controls 2.12 +import QtQuick.Layouts 1.12 +import MeuiKit 1.0 as Meui + +Item { + id: control + + signal clicked(string text) + + property string text + property alias textColor: _label.color + property bool flat: false + + Layout.fillWidth: true + Layout.fillHeight: true + + property color backgroundColor: Meui.Theme.secondBackgroundColor + property color hoveredColor: Meui.Theme.darkMode ? Qt.lighter(Meui.Theme.backgroundColor, 1.1) + : Qt.darker(Meui.Theme.backgroundColor, 1.1) + property color pressedColor: Meui.Theme.darkMode ? Qt.darker(Meui.Theme.backgroundColor, 1.05) + : Qt.darker(Meui.Theme.backgroundColor, 1.3) + + property color flatBg: Meui.Theme.highlightColor + property color flatHoveredBg: Meui.Theme.darkMode ? Qt.lighter(Meui.Theme.highlightColor, 1.1) + : Qt.darker(Meui.Theme.highlightColor, 1.1) + property color flatPressedBg: Meui.Theme.darkMode ? Qt.lighter(Meui.Theme.highlightColor, 1.05) + : Qt.darker(Meui.Theme.highlightColor, 1.3) + + Rectangle { + id: _background + anchors.fill: parent + color: !flat ? _mouseArea.pressed ? pressedColor : _mouseArea.containsMouse + ? hoveredColor : backgroundColor + : _mouseArea.pressed ? flatPressedBg : _mouseArea.containsMouse + ? flatHoveredBg : flatBg + opacity: !flat ? _mouseArea.pressed || _mouseArea.containsMouse ? 0.7 : 0.5 : 1.0 + } + + MouseArea { + id: _mouseArea + anchors.fill: parent + hoverEnabled: true + onClicked: control.clicked(control.text) + } + + Label { + id: _label + anchors.horizontalCenter: parent.horizontalCenter + anchors.verticalCenter: parent.verticalCenter + Layout.minimumWidth: parent.width + horizontalAlignment: Text.AlignHCenter + color: !flat ? Meui.Theme.textColor : Meui.Theme.highlightedTextColor + text: control.text + minimumPointSize: Math.round(control.height / 5) + font.pointSize: Math.round(control.height / 5) + } +} diff --git a/qml/StandardPad.qml b/qml/StandardPad.qml new file mode 100644 index 0000000..889300e --- /dev/null +++ b/qml/StandardPad.qml @@ -0,0 +1,39 @@ +import QtQuick 2.12 +import QtQuick.Controls 2.12 +import QtQuick.Layouts 1.12 +import MeuiKit 1.0 as Meui + +Item { + id: control + + signal pressed(string text) + + GridLayout { + id: _mainLayout + anchors.fill: parent + columnSpacing: 1 + rowSpacing: 1 + columns: 4 + + StandardButton { text: "C"; onClicked: control.pressed(text) } + StandardButton { text: "%"; onClicked: control.pressed(text) } + StandardButton { text: "←"; onClicked: control.pressed(text) } + StandardButton { text: "÷"; textColor: Meui.Theme.highlightColor; onClicked: control.pressed(text) } + StandardButton { text: "7"; onClicked: control.pressed(text) } + StandardButton { text: "8"; onClicked: control.pressed(text) } + StandardButton { text: "9"; onClicked: control.pressed(text) } + StandardButton { text: "×"; textColor: Meui.Theme.highlightColor; onClicked: control.pressed(text) } + StandardButton { text: "4"; onClicked: control.pressed(text) } + StandardButton { text: "5"; onClicked: control.pressed(text) } + StandardButton { text: "6"; onClicked: control.pressed(text) } + StandardButton { text: "-"; textColor: Meui.Theme.highlightColor; onClicked: control.pressed(text) } + StandardButton { text: "1"; onClicked: control.pressed(text) } + StandardButton { text: "2"; onClicked: control.pressed(text) } + StandardButton { text: "3"; onClicked: control.pressed(text) } + StandardButton { text: "+"; textColor: Meui.Theme.highlightColor; onClicked: control.pressed(text) } + StandardButton { text: "0"; onClicked: control.pressed(text) } + StandardButton { text: "."; onClicked: control.pressed(text) } + StandardButton { text: "()"; onClicked: control.pressed(text) } + StandardButton { text: "="; flat: true; onClicked: control.pressed(text) } + } +} diff --git a/qml/Zone.qml b/qml/Zone.qml index a34fdd6..f96ec38 100644 --- a/qml/Zone.qml +++ b/qml/Zone.qml @@ -51,13 +51,23 @@ Item { } } - CTextField { + TextField { id: textField height: 50 Layout.fillWidth: true Keys.onReturnPressed: appendToTextField('=') Keys.onEnterPressed: appendToTextField('=') + selectByMouse: true + horizontalAlignment: TextInput.AlignRight + focus: Qt.StrongFocus + font.pixelSize: 24 + + background: Rectangle { + border.width: 0 + color: "transparent" + } + leftPadding: Meui.Units.largeSpacing rightPadding: Meui.Units.largeSpacing } @@ -77,7 +87,7 @@ Item { historyModel.append({"text": expressionText}) } } - } else if (text === 'AC/C') { + } else if (text === 'C') { if (textField.text != "") textField.clear() else diff --git a/qml/main.qml b/qml/main.qml index fb06dfc..44c8b3d 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -33,7 +33,7 @@ Meui.Window { ColumnLayout { anchors.fill: parent - spacing: 0 + spacing: Meui.Units.smallSpacing Zone { id: zone @@ -41,13 +41,10 @@ Meui.Window { Layout.preferredHeight: parent.height * 0.35 } - ButtonsView { - id: buttons + StandardPad { Layout.fillWidth: true Layout.fillHeight: true - labels: ['AC/C', '%', '←', '÷', '7', '8', '9', '×', '4', '5', '6', '−', '1', '2', '3', '+', '0', '.', '()', '='] - targets: ['AC/C', '%', 'BACK', '/', '7', '8', '9', '*', '4', '5', '6', '-', '1', '2', '3', '+', '0', '.', '()', '='] - onButtonClicked: zone.appendToTextField(strToAppend) + onPressed: zone.appendToTextField(text) } } diff --git a/translations/cs_CZ.ts b/translations/cs_CZ.ts deleted file mode 100644 index 560c86e..0000000 --- a/translations/cs_CZ.ts +++ /dev/null @@ -1,79 +0,0 @@ - - - - - CTextField - - - Cut - Vyjmout - - - - Copy - Kopírovat - - - - Paste - Vložit - - - - QObject - - - Error: %1 - - - - - - - - - - - - - - - - Invalid expression. - - - - - - - Variable cannot be overwritten. - - - - - Identifier matches an existing function name. - - - - - - - Division by zero. - - - - - - Unknown function or variable. - - - - - main - - - Calculator - Kalkulačka - - - diff --git a/translations/de_DE.ts b/translations/de_DE.ts deleted file mode 100644 index c7d3081..0000000 --- a/translations/de_DE.ts +++ /dev/null @@ -1,79 +0,0 @@ - - - - - CTextField - - - Cut - Ausschneiden - - - - Copy - Kopie - - - - Paste - Einfügen - - - - QObject - - - Error: %1 - - - - - - - - - - - - - - - - Invalid expression. - - - - - - - Variable cannot be overwritten. - - - - - Identifier matches an existing function name. - - - - - - - Division by zero. - - - - - - Unknown function or variable. - - - - - main - - - Calculator - Rechner - - - diff --git a/translations/en_US.ts b/translations/en_US.ts index f560ca1..fa515d0 100644 --- a/translations/en_US.ts +++ b/translations/en_US.ts @@ -1,79 +1,12 @@ - - - CTextField - - - Cut - Cut - - - - Copy - Copy - - - - Paste - Paste - - - - QObject - - - Error: %1 - Error: %1 - - - - - - - - - - - - - - - Invalid expression. - Invalid expression. - - - - - - Variable cannot be overwritten. - Variable cannot be overwritten. - - - - Identifier matches an existing function name. - Identifier matches an existing function name. - - - - - - Division by zero. - Division by zero. - - - - - Unknown function or variable. - Unknown function or variable. - - + main Calculator - Calculator + diff --git a/translations/es_ES.ts b/translations/es_ES.ts deleted file mode 100644 index 91c7d13..0000000 --- a/translations/es_ES.ts +++ /dev/null @@ -1,79 +0,0 @@ - - - - - CTextField - - - Cut - Cortar - - - - Copy - Copiar - - - - Paste - Pegar - - - - QObject - - - Error: %1 - - - - - - - - - - - - - - - - Invalid expression. - - - - - - - Variable cannot be overwritten. - - - - - Identifier matches an existing function name. - - - - - - - Division by zero. - - - - - - Unknown function or variable. - - - - - main - - - Calculator - Calculadora - - - diff --git a/translations/es_MX.ts b/translations/es_MX.ts deleted file mode 100644 index bece95b..0000000 --- a/translations/es_MX.ts +++ /dev/null @@ -1,79 +0,0 @@ - - - - - CTextField - - - Cut - 剪低 - - - - Copy - 複製 - - - - Paste - 貼上 - - - - QObject - - - Error: %1 - - - - - - - - - - - - - - - - Invalid expression. - - - - - - - Variable cannot be overwritten. - - - - - Identifier matches an existing function name. - - - - - - - Division by zero. - - - - - - Unknown function or variable. - - - - - main - - - Calculator - - - - diff --git a/translations/it_IT.ts b/translations/it_IT.ts deleted file mode 100644 index 7a913e0..0000000 --- a/translations/it_IT.ts +++ /dev/null @@ -1,79 +0,0 @@ - - - - - CTextField - - - Cut - - - - - Copy - Copia - - - - Paste - - - - - QObject - - - Error: %1 - - - - - - - - - - - - - - - - Invalid expression. - - - - - - - Variable cannot be overwritten. - - - - - Identifier matches an existing function name. - - - - - - - Division by zero. - - - - - - Unknown function or variable. - - - - - main - - - Calculator - - - - diff --git a/translations/nb_NO.ts b/translations/nb_NO.ts deleted file mode 100644 index cb5f967..0000000 --- a/translations/nb_NO.ts +++ /dev/null @@ -1,79 +0,0 @@ - - - - - CTextField - - - Cut - Klipp ut - - - - Copy - Kopier - - - - Paste - Lim inn - - - - QObject - - - Error: %1 - - - - - - - - - - - - - - - - Invalid expression. - - - - - - - Variable cannot be overwritten. - - - - - Identifier matches an existing function name. - - - - - - - Division by zero. - - - - - - Unknown function or variable. - - - - - main - - - Calculator - Kalkulator - - - diff --git a/translations/pl_PL.ts b/translations/pl_PL.ts deleted file mode 100644 index 62473ad..0000000 --- a/translations/pl_PL.ts +++ /dev/null @@ -1,79 +0,0 @@ - - - - - CTextField - - - Cut - Wytnij - - - - Copy - Kopiuj - - - - Paste - Wklej - - - - QObject - - - Error: %1 - - - - - - - - - - - - - - - - Invalid expression. - - - - - - - Variable cannot be overwritten. - - - - - Identifier matches an existing function name. - - - - - - - Division by zero. - - - - - - Unknown function or variable. - - - - - main - - - Calculator - Kalkulator - - - diff --git a/translations/pt_BR.ts b/translations/pt_BR.ts deleted file mode 100644 index ac566bf..0000000 --- a/translations/pt_BR.ts +++ /dev/null @@ -1,79 +0,0 @@ - - - - - CTextField - - - Cut - Recortar - - - - Copy - Copiar - - - - Paste - Colar - - - - QObject - - - Error: %1 - - - - - - - - - - - - - - - - Invalid expression. - - - - - - - Variable cannot be overwritten. - - - - - Identifier matches an existing function name. - - - - - - - Division by zero. - - - - - - Unknown function or variable. - - - - - main - - - Calculator - Calculadora - - - diff --git a/translations/ru_RU.ts b/translations/ru_RU.ts deleted file mode 100644 index 9bf87de..0000000 --- a/translations/ru_RU.ts +++ /dev/null @@ -1,79 +0,0 @@ - - - - - CTextField - - - Cut - Вырезать - - - - Copy - Скопировать - - - - Paste - Вставить - - - - QObject - - - Error: %1 - - - - - - - - - - - - - - - - Invalid expression. - - - - - - - Variable cannot be overwritten. - - - - - Identifier matches an existing function name. - - - - - - - Division by zero. - - - - - - Unknown function or variable. - - - - - main - - - Calculator - Калькулятор - - - diff --git a/translations/si_LK.ts b/translations/si_LK.ts deleted file mode 100644 index 7b7e511..0000000 --- a/translations/si_LK.ts +++ /dev/null @@ -1,79 +0,0 @@ - - - - - CTextField - - - Cut - - - - - Copy - - - - - Paste - - - - - QObject - - - Error: %1 - - - - - - - - - - - - - - - - Invalid expression. - - - - - - - Variable cannot be overwritten. - - - - - Identifier matches an existing function name. - - - - - - - Division by zero. - - - - - - Unknown function or variable. - - - - - main - - - Calculator - - - - diff --git a/translations/zh_CN.ts b/translations/zh_CN.ts index 0f2bfe7..4215682 100644 --- a/translations/zh_CN.ts +++ b/translations/zh_CN.ts @@ -1,73 +1,6 @@ - - CTextField - - - Cut - 剪切 - - - - Copy - 复制 - - - - Paste - 粘贴 - - - - QObject - - - Error: %1 - - - - - - - - - - - - - - - - Invalid expression. - - - - - - - Variable cannot be overwritten. - - - - - Identifier matches an existing function name. - - - - - - - Division by zero. - - - - - - Unknown function or variable. - - - main diff --git a/translations/zh_HK.ts b/translations/zh_HK.ts deleted file mode 100644 index 5e26489..0000000 --- a/translations/zh_HK.ts +++ /dev/null @@ -1,79 +0,0 @@ - - - - - CTextField - - - Cut - 剪低 - - - - Copy - 複製 - - - - Paste - 貼上 - - - - QObject - - - Error: %1 - - - - - - - - - - - - - - - - Invalid expression. - - - - - - - Variable cannot be overwritten. - - - - - Identifier matches an existing function name. - - - - - - - Division by zero. - - - - - - Unknown function or variable. - - - - - main - - - Calculator - - - - diff --git a/translations/zh_TW.ts b/translations/zh_TW.ts deleted file mode 100644 index 7c9d0f2..0000000 --- a/translations/zh_TW.ts +++ /dev/null @@ -1,79 +0,0 @@ - - - - - CTextField - - - Cut - 剪下 - - - - Copy - 複製 - - - - Paste - 貼上 - - - - QObject - - - Error: %1 - - - - - - - - - - - - - - - - Invalid expression. - - - - - - - Variable cannot be overwritten. - - - - - Identifier matches an existing function name. - - - - - - - Division by zero. - - - - - - Unknown function or variable. - - - - - main - - - Calculator - - - -