parent
6b10c2ef2d
commit
01196e8b50
|
@ -19,6 +19,23 @@ Item {
|
|||
MessageEventModel {
|
||||
id: messageEventModel
|
||||
room: currentRoom
|
||||
|
||||
onModelReset: {
|
||||
if (currentRoom)
|
||||
{
|
||||
var lastScrollPosition = currentRoom.savedTopVisibleIndex()
|
||||
if (lastScrollPosition === 0)
|
||||
messageListView.positionViewAtBeginning()
|
||||
else
|
||||
{
|
||||
console.log("Scrolling to position", lastScrollPosition)
|
||||
messageListView.positionViewAtIndex(lastScrollPosition, ListView.Contain)
|
||||
}
|
||||
if (messageListView.contentY < messageListView.originY + 10)
|
||||
currentRoom.getPreviousContent(100)
|
||||
}
|
||||
console.log("Model timeline reset")
|
||||
}
|
||||
}
|
||||
|
||||
RoomDrawer {
|
||||
|
@ -46,6 +63,8 @@ Item {
|
|||
Layout.fillWidth: true
|
||||
Layout.preferredHeight: 64
|
||||
|
||||
z: 10
|
||||
|
||||
color: Material.accent
|
||||
|
||||
ItemDelegate {
|
||||
|
@ -98,18 +117,10 @@ Item {
|
|||
}
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
Layout.leftMargin: 16
|
||||
|
||||
z: -10
|
||||
|
||||
spacing: 0
|
||||
|
||||
ListView {
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
Layout.margins: 16
|
||||
|
||||
id: messageListView
|
||||
|
||||
|
@ -118,10 +129,25 @@ Item {
|
|||
verticalLayoutDirection: ListView.BottomToTop
|
||||
spacing: 8
|
||||
|
||||
boundsBehavior: Flickable.DragOverBounds
|
||||
// flickDeceleration: 4096
|
||||
flickDeceleration: 4096
|
||||
|
||||
// cacheBuffer: 200
|
||||
boundsBehavior: Flickable.DragOverBounds
|
||||
|
||||
property int largestVisibleIndex: count > 0 ? indexAt(contentX, contentY + height - 1) : -1
|
||||
|
||||
onContentYChanged: {
|
||||
// Check whether we're about to bump into the ceiling in 2 seconds
|
||||
var curVelocity = verticalVelocity // Snapshot the current speed
|
||||
if( curVelocity < 0 && contentY + curVelocity*2 < originY)
|
||||
{
|
||||
// Request the amount of messages enough to scroll at this
|
||||
// rate for 3 more seconds
|
||||
var avgHeight = contentHeight / count
|
||||
currentRoom.getPreviousContent(-curVelocity*3 / avgHeight);
|
||||
}
|
||||
}
|
||||
|
||||
onMovementEnded: currentRoom.saveViewport(indexAt(contentX, contentY), largestVisibleIndex)
|
||||
|
||||
model: SortFilterProxyModel {
|
||||
id: sortedRoomListModel
|
||||
|
@ -195,11 +221,6 @@ Item {
|
|||
}
|
||||
}
|
||||
|
||||
ScrollBar.vertical: messageListViewScrollBar
|
||||
|
||||
onAtYBeginningChanged: atYBeginning && currentRoom ? currentRoom.getPreviousContent(20) : {}
|
||||
onAtYEndChanged: atYEnd && currentRoom ? currentRoom.markAllMessagesAsRead() : {}
|
||||
|
||||
RoundButton {
|
||||
width: 64
|
||||
height: 64
|
||||
|
@ -308,14 +329,6 @@ Item {
|
|||
}
|
||||
}
|
||||
|
||||
ScrollBar {
|
||||
Layout.preferredWidth: 16
|
||||
Layout.fillHeight: true
|
||||
|
||||
id: messageListViewScrollBar
|
||||
}
|
||||
}
|
||||
|
||||
Item {
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredHeight: 40
|
||||
|
|
|
@ -147,3 +147,31 @@ QDateTime SpectralRoom::lastActiveTime() {
|
|||
}
|
||||
|
||||
float SpectralRoom::orderForTag(QString name) { return tag(name).order; }
|
||||
|
||||
int SpectralRoom::savedTopVisibleIndex() const {
|
||||
return firstDisplayedMarker() == timelineEdge()
|
||||
? 0
|
||||
: firstDisplayedMarker() - messageEvents().rbegin();
|
||||
}
|
||||
|
||||
int SpectralRoom::savedBottomVisibleIndex() const {
|
||||
return lastDisplayedMarker() == timelineEdge()
|
||||
? 0
|
||||
: lastDisplayedMarker() - messageEvents().rbegin();
|
||||
}
|
||||
|
||||
void SpectralRoom::saveViewport(int topIndex, int bottomIndex) {
|
||||
if (topIndex == -1 || bottomIndex == -1 ||
|
||||
(bottomIndex == savedBottomVisibleIndex() &&
|
||||
(bottomIndex == 0 || topIndex == savedTopVisibleIndex())))
|
||||
return;
|
||||
if (bottomIndex == 0) {
|
||||
qDebug() << "Saving viewport as the latest available";
|
||||
setFirstDisplayedEventId({});
|
||||
setLastDisplayedEventId({});
|
||||
return;
|
||||
}
|
||||
qDebug() << "Saving viewport:" << topIndex << "thru" << bottomIndex;
|
||||
setFirstDisplayedEvent(maxTimelineIndex() - topIndex);
|
||||
setLastDisplayedEvent(maxTimelineIndex() - bottomIndex);
|
||||
}
|
||||
|
|
|
@ -38,6 +38,9 @@ class SpectralRoom : public Room {
|
|||
QDateTime lastActiveTime();
|
||||
|
||||
Q_INVOKABLE float orderForTag(QString name);
|
||||
Q_INVOKABLE int savedTopVisibleIndex() const;
|
||||
Q_INVOKABLE int savedBottomVisibleIndex() const;
|
||||
Q_INVOKABLE void saveViewport(int topIndex, int bottomIndex);
|
||||
|
||||
private:
|
||||
QString m_cachedInput;
|
||||
|
|
Loading…
Reference in New Issue