From fe831e78653aa600ae1b0bd345156ba4cb28e96e Mon Sep 17 00:00:00 2001 From: miruka Date: Sun, 12 Jul 2020 16:14:24 -0400 Subject: [PATCH] Add power level display to member profile --- TODO.md | 3 +- src/gui/Base/PowerLevelControl.qml | 74 +++++++++++++++++++ .../RoomPane/MemberView/MemberProfile.qml | 57 ++++---------- src/icons/thin/user-power-default.svg | 3 + 4 files changed, 94 insertions(+), 43 deletions(-) create mode 100644 src/gui/Base/PowerLevelControl.qml create mode 100644 src/icons/thin/user-power-default.svg diff --git a/TODO.md b/TODO.md index dac504a6..0eb4f2e1 100644 --- a/TODO.md +++ b/TODO.md @@ -17,8 +17,7 @@ ## Refactoring - General change/upload avatar component for account and room settings -- Reorder QML object declarations, - conform to https://doc-snapshots.qt.io/qt5-dev/qml-codingconventions.html +- Refactor EventList.qml ## Issues diff --git a/src/gui/Base/PowerLevelControl.qml b/src/gui/Base/PowerLevelControl.qml new file mode 100644 index 00000000..74cd44b4 --- /dev/null +++ b/src/gui/Base/PowerLevelControl.qml @@ -0,0 +1,74 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later + +import QtQuick 2.12 +import QtQuick.Layouts 1.12 + +AutoDirectionLayout { + id: control + + property alias defaultLevel: field.defaultText + + readonly property int level: Math.min(100, parseInt(field.text || "0", 10)) + + function reset() { field.reset() } + + + rowSpacing: theme.spacing + + HSpacer {} + + HTextField { + id: field + + radius: 0 + horizontalAlignment: Qt.AlignHCenter + validator: IntValidator { top: 100 } + inputMethodHints: Qt.ImhFormattedNumbersOnly + maximumLength: control.level < 0 ? 16 : 3 + + onActiveFocusChanged: + if (! activeFocus && parseInt(text || "0", 10) > 100) + text = 100 + + Layout.minimumWidth: + mainUI.fontMetrics.boundingRect("-999").width + + leftPadding + + rightPadding + + Layout.alignment: Qt.AlignCenter + } + + Row { + Layout.preferredHeight: field.height + Layout.alignment: Qt.AlignCenter + + HButton { + height: parent.height + icon.name: "user-power-default" + toolTip.text: qsTr("Default") + checked: control.level >= 0 && control.level < 50 + uncheckable: false + onClicked: field.text = 0 + } + + HButton { + height: parent.height + icon.name: "user-power-50" + toolTip.text: qsTr("Moderator") + checked: control.level >= 50 && control.level < 100 + uncheckable: false + onClicked: field.text = 50 + } + + HButton { + height: parent.height + icon.name: "user-power-100" + toolTip.text: qsTr("Admin") + checked: control.level >= 100 + uncheckable: false + onClicked: field.text = 100 + } + } + + HSpacer {} +} diff --git a/src/gui/Pages/Chat/RoomPane/MemberView/MemberProfile.qml b/src/gui/Pages/Chat/RoomPane/MemberView/MemberProfile.qml index b4dbb2e3..b1f4e0fc 100644 --- a/src/gui/Pages/Chat/RoomPane/MemberView/MemberProfile.qml +++ b/src/gui/Pages/Chat/RoomPane/MemberView/MemberProfile.qml @@ -150,54 +150,29 @@ HListView { color: theme.colors.halfDimText Layout.fillWidth: true - Layout.bottomMargin: theme.spacing } - // TODO - // HColumnLayout { - // spacing: theme.spacing / 2 + HColumnLayout { + spacing: theme.spacing / 2 - // HLabel { - // text: qsTr("Power level:") - // wrapMode: HLabel.Wrap - // horizontalAlignment: Qt.AlignHCenter + Layout.preferredWidth: parent.width + Layout.bottomMargin: theme.spacing - // Layout.fillWidth: true - // } + HLabel { + text: qsTr("Power level:") + wrapMode: HLabel.Wrap + horizontalAlignment: Qt.AlignHCenter - // HRowLayout { - // spacing: theme.spacing + Layout.fillWidth: true + } - // HSpacer {} + PowerLevelControl { + defaultLevel: member.power_level + rowSpacing: parent.spacing - // Row { - // HButton { - // text: qsTr("Default") - // checked: levelBox.value >= 0 && levelBox.value < 50 - // onClicked: levelBox.value = 0 - // } - // HButton { - // text: qsTr("Moderator") - // checked: levelBox.value >= 50 && levelBox.value < 100 - // onClicked: levelBox.value = 50 - // } - // HButton { - // text: qsTr("Admin") - // checked: levelBox.value === 100 - // onClicked: levelBox.value = 100 - // } - // } - - // HSpinBox { - // id: levelBox - // from: -999 - // to: 100 - // defaultValue: member.power_level - // } - - // HSpacer {} - // } - // } + Layout.preferredWidth: parent.width + } + } } Component.onCompleted: loadDevices() diff --git a/src/icons/thin/user-power-default.svg b/src/icons/thin/user-power-default.svg new file mode 100644 index 00000000..405b2462 --- /dev/null +++ b/src/icons/thin/user-power-default.svg @@ -0,0 +1,3 @@ + + +