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) ...@@ -32,6 +32,11 @@ ChatProxyModel::ChatProxyModel (QObject *parent) : QSortFilterProxyModel(parent)
} }
void ChatProxyModel::loadMoreEntries () { 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(); int count = rowCount();
m_n_max_displayed_entries += ENTRIES_CHUNK_SIZE; m_n_max_displayed_entries += ENTRIES_CHUNK_SIZE;
...@@ -41,6 +46,13 @@ void ChatProxyModel::loadMoreEntries () { ...@@ -41,6 +46,13 @@ void ChatProxyModel::loadMoreEntries () {
emit moreEntriesLoaded(); 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) { void ChatProxyModel::removeEntry (int id) {
QModelIndex source_index = mapToSource(index(id, 0)); QModelIndex source_index = mapToSource(index(id, 0));
static_cast<ChatModel *>(m_chat_model_filter.sourceModel())->removeEntry( static_cast<ChatModel *>(m_chat_model_filter.sourceModel())->removeEntry(
......
...@@ -43,6 +43,7 @@ class ChatProxyModel : public QSortFilterProxyModel { ...@@ -43,6 +43,7 @@ class ChatProxyModel : public QSortFilterProxyModel {
signals: signals:
void sipAddressChanged (const QString &sipAddress); void sipAddressChanged (const QString &sipAddress);
void moreEntriesLoaded (); void moreEntriesLoaded ();
void entryTypeFilterChanged (ChatModel::EntryType type);
public: public:
ChatProxyModel (QObject *parent = Q_NULLPTR); ChatProxyModel (QObject *parent = Q_NULLPTR);
...@@ -50,9 +51,7 @@ public: ...@@ -50,9 +51,7 @@ public:
public slots: public slots:
void loadMoreEntries (); void loadMoreEntries ();
void setEntryTypeFilter (ChatModel::EntryType type) { void setEntryTypeFilter (ChatModel::EntryType type);
m_chat_model_filter.setEntryTypeFilter(type);
}
void removeEntry (int id); void removeEntry (int id);
......
...@@ -5,6 +5,7 @@ import QtQuick.Layouts 1.3 ...@@ -5,6 +5,7 @@ import QtQuick.Layouts 1.3
import Common 1.0 import Common 1.0
import Linphone 1.0 import Linphone 1.0
import Linphone.Styles 1.0 import Linphone.Styles 1.0
import Utils 1.0
// =================================================================== // ===================================================================
...@@ -16,7 +17,7 @@ ColumnLayout { ...@@ -16,7 +17,7 @@ ColumnLayout {
// Set the offset position to load more entries. // Set the offset position to load more entries.
// Not a style property. // Not a style property.
property int _loadMoreEntriesAtPosition: 1 property int _loadMoreEntriesAtPosition: 25
// ----------------------------------------------------------------- // -----------------------------------------------------------------
...@@ -27,11 +28,11 @@ ColumnLayout { ...@@ -27,11 +28,11 @@ ColumnLayout {
property bool _tryToLoadMoreEntries: true property bool _tryToLoadMoreEntries: true
function _loadMoreEntries () { function _loadMoreEntries (force) {
if ( if ((
chat.visibleArea.yPosition * chat.height <= _loadMoreEntriesAtPosition && chat.visibleArea.yPosition * chat.height <= _loadMoreEntriesAtPosition &&
!_tryToLoadMoreEntries !_tryToLoadMoreEntries
) { ) || force) {
_tryToLoadMoreEntries = true _tryToLoadMoreEntries = true
proxyModel.loadMoreEntries() proxyModel.loadMoreEntries()
} }
...@@ -181,16 +182,35 @@ ColumnLayout { ...@@ -181,16 +182,35 @@ ColumnLayout {
} }
} }
onContentYChanged: _loadMoreEntries()
Component.onCompleted: { Component.onCompleted: {
positionViewAtEnd() var initView = function () {
_tryToLoadMoreEntries = false positionViewAtEnd()
_tryToLoadMoreEntries = false
}
// Received only if more entries was loaded.
proxyModel.moreEntriesLoaded.connect(function () { proxyModel.moreEntriesLoaded.connect(function () {
_tryToLoadMoreEntries = false 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