Organize project files
Put QML components into folders, remove unused ones, split __init__.py with engine.py.
This commit is contained in:
12
harmonyqml/components/chat/Daybreak.qml
Normal file
12
harmonyqml/components/chat/Daybreak.qml
Normal file
@@ -0,0 +1,12 @@
|
||||
import QtQuick 2.7
|
||||
import "../base" as Base
|
||||
|
||||
Base.HLabel {
|
||||
text: date_time.toLocaleDateString()
|
||||
width: rootCol.width
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
topPadding: rootCol.isFirstMessage ? 0 : rootCol.verticalPadding * 4
|
||||
bottomPadding: rootCol.verticalPadding * 2
|
||||
font.pixelSize: normalSize * 1.1
|
||||
color: "darkolivegreen"
|
||||
}
|
107
harmonyqml/components/chat/MessageDelegate.qml
Normal file
107
harmonyqml/components/chat/MessageDelegate.qml
Normal file
@@ -0,0 +1,107 @@
|
||||
import QtQuick 2.7
|
||||
import QtQuick.Controls 2.0
|
||||
import QtQuick.Layouts 1.4
|
||||
import "../base" as Base
|
||||
|
||||
Column {
|
||||
id: rootCol
|
||||
|
||||
function mins_between(date1, date2) {
|
||||
return Math.round((((date2 - date1) % 86400000) % 3600000) / 60000)
|
||||
}
|
||||
|
||||
readonly property string displayName:
|
||||
Backend.getUser(sender_id).display_name
|
||||
|
||||
readonly property bool isOwn:
|
||||
chatPage.user.user_id === sender_id
|
||||
|
||||
readonly property var previousData:
|
||||
index > 0 ? messageListView.model.get(index - 1) : null
|
||||
|
||||
readonly property bool isFirstMessage: ! previousData
|
||||
|
||||
readonly property bool combine:
|
||||
! isFirstMessage &&
|
||||
previousData.sender_id == sender_id &&
|
||||
mins_between(previousData.date_time, date_time) <= 5
|
||||
|
||||
readonly property bool dayBreak:
|
||||
isFirstMessage ||
|
||||
previousData.date_time.getDay() != date_time.getDay()
|
||||
|
||||
readonly property bool talkBreak:
|
||||
! isFirstMessage &&
|
||||
! dayBreak &&
|
||||
mins_between(previousData.date_time, date_time) >= 20
|
||||
|
||||
|
||||
property int standardSpacing: 8
|
||||
property int horizontalPadding: 7
|
||||
property int verticalPadding: 5
|
||||
|
||||
width: parent.width
|
||||
topPadding:
|
||||
previousData === null ? 0 :
|
||||
talkBreak ? standardSpacing * 6 :
|
||||
combine ? standardSpacing / 2 :
|
||||
standardSpacing * 1.2
|
||||
|
||||
Daybreak { visible: dayBreak }
|
||||
|
||||
|
||||
Row {
|
||||
id: row
|
||||
spacing: standardSpacing
|
||||
layoutDirection: isOwn ? Qt.RightToLeft : Qt.LeftToRight
|
||||
anchors.right: isOwn ? parent.right : undefined
|
||||
|
||||
Base.Avatar { id: avatar; invisible: combine; username: displayName }
|
||||
|
||||
ColumnLayout {
|
||||
spacing: 0
|
||||
|
||||
Base.HLabel {
|
||||
visible: ! combine
|
||||
id: nameLabel
|
||||
text: displayName
|
||||
background: Rectangle {color: "#DDD"}
|
||||
color: isOwn ? "teal" : "purple"
|
||||
elide: Text.ElideRight
|
||||
maximumLineCount: 1
|
||||
Layout.preferredWidth: contentLabel.width
|
||||
horizontalAlignment: isOwn ? Text.AlignRight : Text.AlignLeft
|
||||
|
||||
leftPadding: horizontalPadding
|
||||
rightPadding: horizontalPadding
|
||||
topPadding: verticalPadding
|
||||
}
|
||||
|
||||
Base.HLabel {
|
||||
id: contentLabel
|
||||
//text: (isOwn ? "" : content + " ") +
|
||||
//"<font size=" + smallSize + "px color=gray>" +
|
||||
//Qt.formatDateTime(date_time, "hh:mm:ss") +
|
||||
//"</font>" +
|
||||
// (isOwn ? " " + content : "")
|
||||
|
||||
text: content +
|
||||
" <font size=" + smallSize + "px color=gray>" +
|
||||
Qt.formatDateTime(date_time, "hh:mm:ss") +
|
||||
"</font>"
|
||||
textFormat: Text.RichText
|
||||
background: Rectangle {color: "#DDD"}
|
||||
wrapMode: Text.Wrap
|
||||
|
||||
leftPadding: horizontalPadding
|
||||
rightPadding: horizontalPadding
|
||||
bottomPadding: verticalPadding
|
||||
|
||||
Layout.minimumWidth: nameLabel.implicitWidth
|
||||
Layout.maximumWidth: Math.min(
|
||||
600, messageListView.width - avatar.width - row.spacing
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
24
harmonyqml/components/chat/MessageList.qml
Normal file
24
harmonyqml/components/chat/MessageList.qml
Normal file
@@ -0,0 +1,24 @@
|
||||
import QtQuick 2.7
|
||||
import QtQuick.Controls 2.2
|
||||
import QtQuick.Layouts 1.4
|
||||
|
||||
Rectangle {
|
||||
property int space: 8
|
||||
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
Layout.leftMargin: space
|
||||
Layout.rightMargin: space
|
||||
|
||||
ListView {
|
||||
id: messageListView
|
||||
anchors.fill: parent
|
||||
model: Backend.messagesModel[chatPage.room.room_id]
|
||||
delegate: MessageDelegate {}
|
||||
//highlight: Rectangle {color: "lightsteelblue"; radius: 5}
|
||||
|
||||
clip: true
|
||||
topMargin: space
|
||||
bottomMargin: space
|
||||
}
|
||||
}
|
49
harmonyqml/components/chat/RoomHeader.qml
Normal file
49
harmonyqml/components/chat/RoomHeader.qml
Normal file
@@ -0,0 +1,49 @@
|
||||
import QtQuick 2.7
|
||||
import QtQuick.Controls 2.2
|
||||
import QtQuick.Layouts 1.4
|
||||
import "../base" as Base
|
||||
|
||||
Rectangle {
|
||||
id: root
|
||||
Layout.fillWidth: true
|
||||
Layout.minimumHeight: 36
|
||||
Layout.maximumHeight: Layout.minimumHeight
|
||||
color: "#BBB"
|
||||
|
||||
RowLayout {
|
||||
id: "row"
|
||||
spacing: 12
|
||||
anchors.fill: parent
|
||||
|
||||
Base.Avatar {
|
||||
id: "avatar"
|
||||
Layout.alignment: Qt.AlignTop
|
||||
dimmension: root.Layout.minimumHeight
|
||||
username: chatPage.room.display_name
|
||||
}
|
||||
|
||||
Base.HLabel {
|
||||
id: "roomName"
|
||||
text: chatPage.room.display_name
|
||||
font.pixelSize: bigSize
|
||||
elide: Text.ElideRight
|
||||
maximumLineCount: 1
|
||||
Layout.maximumWidth: row.width - row.spacing * (row.children.length - 1) - avatar.width
|
||||
}
|
||||
|
||||
Base.HLabel {
|
||||
id: "roomSubtitle"
|
||||
text: chatPage.room.subtitle
|
||||
font.pixelSize: smallSize
|
||||
elide: Text.ElideRight
|
||||
maximumLineCount: 1
|
||||
Layout.maximumWidth:
|
||||
row.width -
|
||||
row.spacing * (row.children.length - 1) -
|
||||
avatar.width -
|
||||
roomName.width
|
||||
}
|
||||
|
||||
Item { Layout.fillWidth: true }
|
||||
}
|
||||
}
|
16
harmonyqml/components/chat/Root.qml
Normal file
16
harmonyqml/components/chat/Root.qml
Normal file
@@ -0,0 +1,16 @@
|
||||
import QtQuick 2.7
|
||||
import QtQuick.Controls 2.2
|
||||
import QtQuick.Layouts 1.4
|
||||
|
||||
ColumnLayout {
|
||||
property var user: null
|
||||
property var room: null
|
||||
|
||||
id: chatPage
|
||||
spacing: 0
|
||||
onFocusChanged: sendBox.setFocus()
|
||||
|
||||
RoomHeader {}
|
||||
MessageList {}
|
||||
SendBox { id: sendBox }
|
||||
}
|
63
harmonyqml/components/chat/SendBox.qml
Normal file
63
harmonyqml/components/chat/SendBox.qml
Normal file
@@ -0,0 +1,63 @@
|
||||
import QtQuick 2.7
|
||||
import QtQuick.Controls 2.2
|
||||
import QtQuick.Layouts 1.4
|
||||
import "../base" as Base
|
||||
|
||||
Rectangle {
|
||||
function setFocus() { textArea.forceActiveFocus() }
|
||||
|
||||
id: "root"
|
||||
Layout.fillWidth: true
|
||||
Layout.minimumHeight: 32
|
||||
Layout.preferredHeight: textArea.implicitHeight
|
||||
// parent.height / 2 causes binding loop?
|
||||
Layout.maximumHeight: pageStack.height / 2
|
||||
color: "#BBB"
|
||||
|
||||
RowLayout {
|
||||
anchors.fill: parent
|
||||
spacing: 0
|
||||
|
||||
Base.Avatar {
|
||||
id: "avatar"
|
||||
username: chatPage.user.display_name
|
||||
dimmension: root.Layout.minimumHeight
|
||||
//visible: textArea.text === ""
|
||||
visible: textArea.height <= root.Layout.minimumHeight
|
||||
}
|
||||
|
||||
ScrollView {
|
||||
Layout.fillHeight: true
|
||||
Layout.fillWidth: true
|
||||
id: sendBoxScrollView
|
||||
clip: true
|
||||
|
||||
TextArea {
|
||||
id: textArea
|
||||
placeholderText: qsTr("Type a message...")
|
||||
wrapMode: TextEdit.Wrap
|
||||
selectByMouse: true
|
||||
font.family: "Roboto"
|
||||
font.pixelSize: 16
|
||||
focus: true
|
||||
|
||||
Keys.onReturnPressed: {
|
||||
event.accepted = true
|
||||
|
||||
if (event.modifiers & Qt.ShiftModifier ||
|
||||
event.modifiers & Qt.ControlModifier ||
|
||||
event.modifiers & Qt.AltModifier) {
|
||||
textArea.insert(textArea.cursorPosition, "\n")
|
||||
return
|
||||
}
|
||||
|
||||
Backend.sendMessage(chatPage.user.user_id,
|
||||
chatPage.room.room_id,
|
||||
textArea.text)
|
||||
textArea.clear()
|
||||
}
|
||||
Keys.onEnterPressed: Keys.onReturnPressed(event) // numpad enter
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user