New Setting/Account page.

This commit is contained in:
Black Hat 2018-09-10 11:56:32 +08:00
parent 0f3d7db0d1
commit 647a2cdbf2
5 changed files with 87 additions and 118 deletions

View File

@ -7,31 +7,84 @@ import Matrique.Settings 0.1
import "component" import "component"
import "form" import "form"
import "qrc:/js/util.js" as Util
Page { Page {
property alias listModel: accountSettingsListView.model property alias listModel: accountSettingsListView.model
Page { Page {
id: accountForm id: accountForm
parent: null parent: null
padding: 64 padding: 64
ListView { ColumnLayout {
anchors.fill: parent anchors.fill: parent
id: accountSettingsListView ListView {
Layout.fillWidth: true
Layout.fillHeight: true
spacing: 0 id: accountSettingsListView
delegate: RowLayout{ delegate: SwipeDelegate {
Label { width: accountSettingsListView.width
text: accountID height: 64
}
ItemDelegate { clip: true
text: "Logout"
onClicked: matriqueController.logout(connection); Row {
anchors.fill: parent
anchors.margins: 8
spacing: 8
ImageItem {
width: parent.height
height: parent.height
hint: name
defaultColor: Util.stringToColor(name)
image: avatar
}
ColumnLayout {
Label {
text: name
}
Label {
text: accountID
}
}
}
swipe.right: Rectangle {
width: parent.height
height: parent.height
anchors.right: parent.right
color: Material.accent
MaterialIcon {
anchors.fill: parent
icon: "\ue879"
color: "white"
}
SwipeDelegate.onClicked: matriqueController.logout(connection)
}
} }
} }
Button {
text: "Add Account"
flat: true
highlighted: true
onClicked: Util.pushToStack(stackView, loginPage)
}
} }
} }
@ -40,6 +93,8 @@ Page {
parent: null parent: null
padding: 64
Column { Column {
Switch { Switch {
text: "Lazy load at initial sync" text: "Lazy load at initial sync"
@ -69,6 +124,8 @@ Page {
parent: null parent: null
padding: 64
Column { Column {
Switch { Switch {
text: "Dark theme" text: "Dark theme"
@ -95,6 +152,7 @@ Page {
Page { Page {
id: aboutForm id: aboutForm
parent: null parent: null
padding: 64 padding: 64
@ -112,48 +170,52 @@ Page {
} }
} }
RowLayout { Rectangle {
ColumnLayout { width: 240
Layout.preferredWidth: 240 height: parent.height
Layout.fillHeight: true
spacing: 0 id: settingDrawer
color: MSettings.darkTheme ? "#323232" : "#f3f3f3"
Column {
anchors.fill: parent
ItemDelegate { ItemDelegate {
Layout.fillWidth: true width: parent.width
text: "Account" text: "Account"
onClicked: pushToStack(accountForm) onClicked: pushToStack(accountForm)
} }
ItemDelegate { ItemDelegate {
Layout.fillWidth: true width: parent.width
text: "General" text: "General"
onClicked: pushToStack(generalForm) onClicked: pushToStack(generalForm)
} }
ItemDelegate { ItemDelegate {
Layout.fillWidth: true width: parent.width
text: "Appearance" text: "Appearance"
onClicked: pushToStack(appearanceForm) onClicked: pushToStack(appearanceForm)
} }
ItemDelegate { ItemDelegate {
Layout.fillWidth: true width: parent.width
text: "About" text: "About"
onClicked: pushToStack(aboutForm) onClicked: pushToStack(aboutForm)
} }
} }
}
StackView { StackView {
Layout.fillWidth: true anchors.fill: parent
Layout.fillHeight: true anchors.leftMargin: settingDrawer.width
id: settingStackView id: settingStackView
}
} }
function pushToStack(item) { function pushToStack(item) {

View File

@ -1,79 +0,0 @@
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtGraphicalEffects 1.0
import QtQuick.Controls.Material 2.2
Item {
property bool round: true
property string source: ""
property string displayText: ""
readonly property bool showImage: source
readonly property bool showInitial: !showImage && displayText || avatar.status != Image.Ready
id: item
Image {
width: item.width
height: item.width
id: avatar
visible: showImage
source: item.source
mipmap: true
layer.enabled: true
fillMode: Image.PreserveAspectCrop
sourceSize.width: item.width
layer.effect: OpacityMask {
maskSource: Item {
width: avatar.width
height: avatar.width
Rectangle {
anchors.centerIn: parent
width: avatar.width
height: avatar.width
radius: round? avatar.width / 2 : 0
}
}
}
}
Label {
anchors.fill: parent
color: "white"
visible: showInitial
text: showInitial ? getInitials(displayText)[0] : ""
font.pixelSize: 22
font.bold: true
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
background: Rectangle {
anchors.fill: parent
radius: round? width / 2 : 0
color: showInitial ? stringToColor(displayText) : Material.accent
}
}
function getInitials(text) {
if (!text) return "N"
var initial = text.toUpperCase().replace(/[^a-zA-Z- ]/g, "").match(/\b\w/g);
if (!initial) return "N"
return initial
}
function stringToColor(str) {
var hash = 0;
for (var i = 0; i < str.length; i++) {
hash = str.charCodeAt(i) + ((hash << 5) - hash);
}
var colour = '#';
for (var j = 0; j < 3; j++) {
var value = (hash >> (j * 8)) & 0xFF;
colour += ('00' + value.toString(16)).substr(-2);
}
return colour;
}
}

View File

@ -242,19 +242,6 @@ ApplicationWindow {
} }
} }
SideNavButton {
Layout.fillWidth: true
Layout.preferredHeight: width
MaterialIcon {
anchors.fill: parent
icon: "\ue8b8"
color: "white"
}
page: loginPage
}
SideNavButton { SideNavButton {
Layout.fillWidth: true Layout.fillWidth: true
Layout.preferredHeight: width Layout.preferredHeight: width

View File

@ -6,7 +6,6 @@
<file>asset/font/material.ttf</file> <file>asset/font/material.ttf</file>
<file>qml/Login.qml</file> <file>qml/Login.qml</file>
<file>qml/main.qml</file> <file>qml/main.qml</file>
<file>qml/component/ImageStatus.qml</file>
<file>qml/form/RoomForm.qml</file> <file>qml/form/RoomForm.qml</file>
<file>qml/Room.qml</file> <file>qml/Room.qml</file>
<file>qml/component/SideNavButton.qml</file> <file>qml/component/SideNavButton.qml</file>

View File

@ -17,7 +17,7 @@ class MatriqueUser : public User {
QImage getAvatar() { return avatar(64); } QImage getAvatar() { return avatar(64); }
signals: signals:
void inheritedAvatarChanged(User* user, const Room* roomContext); void inheritedAvatarChanged(User* user, const Room* roomContext); // https://bugreports.qt.io/browse/QTBUG-7684
}; };
#endif // MATRIQUEUSER_H #endif // MATRIQUEUSER_H