This repository has been archived on 2021-06-24. You can view files and clone it, but cannot push or open issues or pull requests.
ui/qml/main.qml

285 lines
7.7 KiB
QML
Raw Normal View History

2018-10-23 18:52:13 +00:00
import QtGraphicalEffects 1.0
import QtQuick 2.7
import QtQuick.Controls 2.4
import QtQuick.Controls.Material 2.0
import QtQuick.Layouts 1.3
2018-10-30 19:48:37 +00:00
import QtQuick.Window 2.11
2018-10-23 18:52:13 +00:00
2018-10-28 02:49:14 +00:00
import "fonts/Twemoji.js" as T
2019-01-26 22:54:08 +00:00
import "overlays"
2018-11-22 00:01:17 +00:00
import "panes"
2018-10-23 18:52:13 +00:00
import "widgets"
2019-01-30 19:46:22 +00:00
import "utils.js" as Utils
2018-10-23 18:52:13 +00:00
2019-02-13 00:06:52 +00:00
ApplicationWindow {
2018-10-29 18:00:21 +00:00
id: windowItem
2019-01-30 19:58:23 +00:00
width: 1200
height: 800
2019-02-13 00:06:52 +00:00
visible: true
title: "cwtch" + ""
2018-10-23 18:52:13 +00:00
2018-10-29 18:00:21 +00:00
readonly property real ratio: height / width
2018-10-23 18:52:13 +00:00
2019-02-03 00:04:41 +00:00
readonly property string cwtch_background_color: '#EEEEFF'
readonly property string cwtch_color: '#B09CBC'
readonly property string cwtch_dark_color: '#4B3557'
2018-10-29 18:00:21 +00:00
FontAwesome { // PRETTY BUTTON ICONS
2018-10-28 02:49:14 +00:00
id: awesome
resource: "qrc:/qml/fonts/fontawesome.ttf"
}
2018-10-29 18:00:21 +00:00
function parse(text, size) { // REPLACE EMOJI WITH <IMG> TAGS
2018-10-28 02:49:14 +00:00
T.twemoji.base = "qrc:/qml/fonts/twemoji/"
T.twemoji.ext = ".png"
T.twemoji.size = "72x72"
T.twemoji.className = "\" height=\""+size+"\" width=\""+size
var retText = T.twemoji.parse(Utils.htmlEscaped(text))
return retText.replace(/\n/g,"<br/>")
2018-10-28 02:49:14 +00:00
}
2018-10-29 18:00:21 +00:00
function restoreEmoji(text) { // REPLACE <IMG> TAGS WITH EMOJI
2018-10-28 02:49:14 +00:00
var re = /<img src="qrc:\/qml\/fonts\/twemoji\/72x72\/([^"]*?)\.png" width="10" height="10" \/>/g
var arr
var newtext = text
while (arr = re.exec(text)) {
var pieces = arr[1].split("-")
var replacement = ""
for (var i = 0; i < pieces.length; i++) {
replacement += T.twemoji.convert.fromCodePoint(pieces[i])
}
newtext = newtext.replace(arr[0], replacement)
}
return newtext
}
2019-04-16 19:40:19 +00:00
function ptToPx(pt) {
return Screen.pixelDensity * 25.4 * pt / 72
}
function pxToPt(px) {
return px * 72 / (Screen.pixelDensity * 25.4)
}
2018-10-30 19:48:37 +00:00
2018-10-28 02:49:14 +00:00
2018-10-29 18:00:21 +00:00
/* Rectangle { // THE TOOLBAR
id: toolbar
anchors.top: parent.top
anchors.left: parent.left
width: ratio >= 0.92 ? parent.width : 70
height: ratio >= 0.92 ? 70 : parent.height
color: "#4B3557"
GridLayout {
width: parent.width
height: parent.height
columns: ratio >= 0.92 ? children.length : 1
ContactPicture {
Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter
source: "qrc:/qml/images/profiles/001-centaur.png"
status: -2
}
ContactPicture {
Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter
source: "qrc:/qml/images/profiles/002-kraken.png"
status: -2
}
ContactPicture {
Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter
source: "qrc:/qml/images/profiles/003-dinosaur.png"
status: -2
}
ContactPicture {
Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter
source: "qrc:/qml/images/profiles/004-tree-1.png"
status: -2
}
ContactPicture {
Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter
source: "qrc:/qml/images/profiles/005-hand.png"
status: -2
}
}
}*/
StackLayout {
id: parentStack
anchors.fill: parent
2018-10-23 18:52:13 +00:00
currentIndex: 0
readonly property int splashPane: 0
readonly property int managementPane: 1
readonly property int profilePane: 2
property alias pane: parentStack.currentIndex
Rectangle { // Splash pane
color: "#FFFFFF"
//Layout.fillHeight: true
//Layout.minimumWidth: Layout.maximumWidth
//Layout.minimumHeight: parent.height
anchors.fill: parent
2018-10-23 18:52:13 +00:00
visible: true
2018-10-23 18:52:13 +00:00
SplashPane {
id: splashPane
anchors.fill: parent
running: true
}
}
Rectangle { // Profile login/management pane
anchors.fill: parent
visible: false
color: "#D2C0DD"
ProfileManagerPane {
id: profilesPane
anchors.fill: parent
}
}
RowLayout { // CONTAINS EVERYTHING EXCEPT THE TOOLBAR
/* anchors.left: ratio >= 0.92 ? parent.left : toolbar.right
anchors.top: ratio >= 0.92 ? toolbar.bottom : parent.top
anchors.right: parent.right
anchors.bottom: parent.bottom */
anchors.fill: parent
spacing: 0
2018-10-23 18:52:13 +00:00
2018-10-29 18:00:21 +00:00
Rectangle { // THE LEFT PANE WITH TOOLS AND CONTACTS
color: "#D2C0DD"
Layout.fillHeight: true
Layout.minimumWidth: Layout.maximumWidth
Layout.maximumWidth: theStack.pane == theStack.emptyPane ? parent.width : 450
2019-04-17 21:03:50 +00:00
visible: (ratio <= 1.08 && windowItem.width >= 700 && !Qt.inputMethod.visible) || theStack.pane == theStack.emptyPane
2018-10-29 18:00:21 +00:00
2019-02-02 00:12:44 +00:00
ContactList{
anchors.fill: parent
}
}
2018-10-29 18:00:21 +00:00
Rectangle { // THE RIGHT PANE WHERE THE MESSAGES AND STUFF GO
color: "#EEEEFF"
Layout.fillWidth: true
Layout.fillHeight: true
2018-10-29 18:00:21 +00:00
StackLayout {
id: theStack
anchors.fill: parent
currentIndex: 0
2018-10-29 18:00:21 +00:00
property alias pane: theStack.currentIndex
readonly property int emptyPane: 0
readonly property int messagePane: 1
readonly property int settingsPane: 2
readonly property int userProfilePane: 3
readonly property int groupProfilePane: 4
readonly property int addGroupPane: 5
2018-10-29 18:00:21 +00:00
property string title
2018-10-29 18:00:21 +00:00
Item { anchors.fill: parent } // empty
OverlayPane { // messagePane
title: theStack.title
anchors.fill: parent
}
SettingsPane{ anchors.fill: parent }
PeerSettingsPane { anchors.fill: parent }
GroupSettingsPane{ anchors.fill: parent }
AddGroupPane { anchors.fill: parent }
}
}
}
focus: true
Keys.onPressed: {
if (event.key == Qt.Key_Back) {
event.accepted = true
if (theStack.currentIndex == theStack.emptyPane) {
androidCwtchActivity.rootHomeButtonHandle()
} else if (theStack.currentIndex == theStack.userProfilePane || theStack.currentIndex == theStack.groupProfilePane) {
theStack.currentIndex = theStack.messagePane
} else {
theStack.currentIndex = theStack.emptyPane
}
}
}
2018-10-23 18:52:13 +00:00
}
PropertyAnimation { id: anmPopup; easing.type: Easing.InQuart; duration: 7000; target: popup; property: "opacity"; to: 0; }
2018-10-29 18:00:21 +00:00
Rectangle { // THE ERROR MESSAGE POPUP
2018-10-23 18:52:13 +00:00
id: popup
anchors.top: parent.top
anchors.horizontalCenter: parent.horizontalCenter
anchors.topMargin: 20
width: lblPopup.width + 30
2019-04-17 21:03:50 +00:00
height: lblPopup.height + 8 * gcd.themeScale
2018-10-23 18:52:13 +00:00
color: "#000000"
opacity: 0.5
radius: 15
visible: false
Label {
id: lblPopup
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
2019-04-17 21:03:50 +00:00
font.pixelSize: 18 * gcd.themeScale
2018-10-23 18:52:13 +00:00
color: "#FFFFFF"
}
}
2018-10-29 18:00:21 +00:00
Connections { // POPUPS ARE INVOKED BY GO FUNCS
2018-10-23 18:52:13 +00:00
target: gcd
onInvokePopup: function(str) {
lblPopup.text = str
popup.opacity = 0.5
popup.visible = true
anmPopup.restart()
}
2019-02-02 00:27:17 +00:00
onSetToolbarTitle: function(str) {
theStack.title = str
}
onLoaded: function() {
parentStack.pane = parentStack.managementPane
splashPane.running = false
}
2018-10-23 18:52:13 +00:00
}
Connections {
target: Qt.application
onStateChanged: function() {
// https://doc.qt.io/qt-5/qt.html#ApplicationState-enum
if (Qt.application.state == 4) {
// Active
gcd.onActivate()
}
}
}
}