From 4edfaf18f20d60f27c0f1d72d0ebdb217f3b352e Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Thu, 11 Aug 2011 23:31:20 +0200 Subject: [PATCH] Add ChatLine item --- src/qmlui/qml/ChatLine.qml | 11 +++++++++++ src/qmlui/qml/ChatView.qml | 33 +++++++++------------------------ src/qmlui/qml/qml.qrc | 1 + src/qmlui/qmlmessagemodel.h | 2 +- 4 files changed, 22 insertions(+), 25 deletions(-) create mode 100644 src/qmlui/qml/ChatLine.qml diff --git a/src/qmlui/qml/ChatLine.qml b/src/qmlui/qml/ChatLine.qml new file mode 100644 index 00000000..1cf3ae8f --- /dev/null +++ b/src/qmlui/qml/ChatLine.qml @@ -0,0 +1,11 @@ +import QtQuick 1.1 + +Item { + Row { + id: chatLine + Text { text: timestamp; wrapMode: Text.NoWrap; width: 100 } + Text { text: sender; wrapMode: Text.NoWrap; width: 100 } + Text { text: contents; wrapMode: Text.Wrap; width: chatView.width-200} + } + height: chatLine.height +} diff --git a/src/qmlui/qml/ChatView.qml b/src/qmlui/qml/ChatView.qml index 69968732..5781fc78 100644 --- a/src/qmlui/qml/ChatView.qml +++ b/src/qmlui/qml/ChatView.qml @@ -4,41 +4,26 @@ import QtQuick 1.0 Rectangle { id: container - Component { - id: msgDelegate - Item { - id: msgDelegateItem - Row { - id: chatline - Text { text: timestamp; wrapMode: Text.NoWrap; width: 100 } - Text { text: sender; wrapMode: Text.NoWrap; width: 100 } - Text { text: contents; wrapMode: Text.Wrap; width: flickable.width-200} - } - height: chatline.height - } - } - ListView { - id: flickable + id: chatView anchors.fill: parent - - model: msgModel - - delegate: msgDelegate + delegate: Component { + ChatLine { } + } Connections { target: msgModel - onRowsInserted: flickable.positionViewAtEnd(); + onRowsInserted: chatView.positionViewAtEnd(); } Rectangle { id: scrollbar - anchors.right: flickable.right - y: flickable.visibleArea.yPosition * flickable.height + anchors.right: chatView.right + y: chatView.visibleArea.yPosition * chatView.height width: 10 - height: flickable.visibleArea.heightRatio * flickable.height - color: "black" + height: chatView.visibleArea.heightRatio * chatView.height + color: "grey" } } } diff --git a/src/qmlui/qml/qml.qrc b/src/qmlui/qml/qml.qrc index d58f0f6c..9da24580 100644 --- a/src/qmlui/qml/qml.qrc +++ b/src/qmlui/qml/qml.qrc @@ -1,6 +1,7 @@ + ChatLine.qml ChatView.qml diff --git a/src/qmlui/qmlmessagemodel.h b/src/qmlui/qmlmessagemodel.h index c5af0107..052db04a 100644 --- a/src/qmlui/qmlmessagemodel.h +++ b/src/qmlui/qmlmessagemodel.h @@ -37,7 +37,7 @@ public: UserRole }; - QmlMessageModel(QObject *parent); + QmlMessageModel(QObject *parent = 0); virtual QVariant data(const QModelIndex &index, int role) const; virtual inline const MessageModelItem *messageItemAt(int i) const { return &_messageList[i]; } -- 2.20.1