summary refs log tree commit diff
path: root/resources/qml/components/PowerlevelIndicator.qml
diff options
context:
space:
mode:
Diffstat (limited to 'resources/qml/components/PowerlevelIndicator.qml')
-rw-r--r--resources/qml/components/PowerlevelIndicator.qml42
1 files changed, 42 insertions, 0 deletions
diff --git a/resources/qml/components/PowerlevelIndicator.qml b/resources/qml/components/PowerlevelIndicator.qml
new file mode 100644
index 00000000..4b826284
--- /dev/null
+++ b/resources/qml/components/PowerlevelIndicator.qml
@@ -0,0 +1,42 @@
+// SPDX-FileCopyrightText: Nheko Contributors
+//
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+import QtQuick
+import QtQuick.Controls
+import im.nheko
+
+Image {
+    required property int powerlevel
+    required property var permissions
+
+    readonly property bool isAdmin: permissions ? permissions.changeLevel(MtxEvent.PowerLevels) <= powerlevel : false
+    readonly property bool isModerator: permissions ? permissions.redactLevel() <= powerlevel : false
+    readonly property bool isDefault: permissions ? permissions.defaultLevel() <= powerlevel : false
+
+    readonly property string sourceUrl: {
+        if (isAdmin)
+             return "image://colorimage/:/icons/icons/ui/ribbon_star.svg?";
+        else if (isModerator)
+            return "image://colorimage/:/icons/icons/ui/ribbon.svg?";
+        else
+            return "image://colorimage/:/icons/icons/ui/person.svg?";
+    }
+
+    sourceSize.width: 16
+    sourceSize.height: 16
+    source: sourceUrl + (ma.hovered ? palette.highlight : palette.buttonText)
+    ToolTip.visible: ma.hovered
+    ToolTip.text: {
+        if (isAdmin)
+            return qsTr("Administrator: %1").arg(powerlevel);
+        else if (isModerator)
+            return qsTr("Moderator: %1").arg(powerlevel);
+        else
+            return qsTr("User: %1").arg(powerlevel);
+    }
+
+    HoverHandler {
+        id: ma
+    }
+}