Commit b08682a3 authored by Ronan Abhamon's avatar Ronan Abhamon

feat(ui/modules/Linphone): supports scrollbar

parent a9d43492
......@@ -32,6 +32,11 @@ ChatProxyModel::ChatProxyModel (QObject *parent) : QSortFilterProxyModel(parent)
}
void ChatProxyModel::loadMoreEntries () {
// Do not increase `m_n_max_displayed_entries` if it's not necessary...
// Limit qml calls.
if (m_chat_model_filter.rowCount() <= m_n_max_displayed_entries)
return;
int count = rowCount();
m_n_max_displayed_entries += ENTRIES_CHUNK_SIZE;
......@@ -41,6 +46,13 @@ void ChatProxyModel::loadMoreEntries () {
emit moreEntriesLoaded();
}
void ChatProxyModel::setEntryTypeFilter (ChatModel::EntryType type) {
if (m_chat_model_filter.m_entry_type_filter != type) {
m_chat_model_filter.setEntryTypeFilter(type);
emit entryTypeFilterChanged(type);
}
}
void ChatProxyModel::removeEntry (int id) {
QModelIndex source_index = mapToSource(index(id, 0));
static_cast<ChatModel *>(m_chat_model_filter.sourceModel())->removeEntry(
......
......@@ -43,6 +43,7 @@ class ChatProxyModel : public QSortFilterProxyModel {
signals:
void sipAddressChanged (const QString &sipAddress);
void moreEntriesLoaded ();
void entryTypeFilterChanged (ChatModel::EntryType type);
public:
ChatProxyModel (QObject *parent = Q_NULLPTR);
......@@ -50,9 +51,7 @@ public:
public slots:
void loadMoreEntries ();
void setEntryTypeFilter (ChatModel::EntryType type) {
m_chat_model_filter.setEntryTypeFilter(type);
}
void setEntryTypeFilter (ChatModel::EntryType type);
void removeEntry (int id);
......
......@@ -5,6 +5,7 @@ import QtQuick.Layouts 1.3
import Common 1.0
import Linphone 1.0
import Linphone.Styles 1.0
import Utils 1.0
// ===================================================================
......@@ -16,7 +17,7 @@ ColumnLayout {
// Set the offset position to load more entries.
// Not a style property.
property int _loadMoreEntriesAtPosition: 1
property int _loadMoreEntriesAtPosition: 25
// -----------------------------------------------------------------
......@@ -27,11 +28,11 @@ ColumnLayout {
property bool _tryToLoadMoreEntries: true
function _loadMoreEntries () {
if (
function _loadMoreEntries (force) {
if ((
chat.visibleArea.yPosition * chat.height <= _loadMoreEntriesAtPosition &&
!_tryToLoadMoreEntries
) {
) || force) {
_tryToLoadMoreEntries = true
proxyModel.loadMoreEntries()
}
......@@ -181,16 +182,35 @@ ColumnLayout {
}
}
onContentYChanged: _loadMoreEntries()
Component.onCompleted: {
var initView = function () {
positionViewAtEnd()
_tryToLoadMoreEntries = false
}
// Received only if more entries was loaded.
proxyModel.moreEntriesLoaded.connect(function () {
if (ScrollBar.vertical.pressed && atYBeginning) {
// Use a timeout to not increase call stack.
Utils.setTimeout(chat, 0, function () {
_loadMoreEntries(true)
positionViewAtIndex(1, ListView.Beginning)
})
} else {
_tryToLoadMoreEntries = false
}
})
// When the view is changed (for example `Calls` -> `Messages`),
// the position is set at end and it can be possible to load
// more entries.
proxyModel.entryTypeFilterChanged.connect(initView)
// First render.
initView()
}
onContentYChanged: _loadMoreEntries()
}
// -----------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment