mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-01-24 23:28:09 +00:00
feat(ui/modules/Linphone/Timeline/Timeline): handle correctly inserted entries
This commit is contained in:
parent
102bbb4cac
commit
02fdc59eca
3 changed files with 62 additions and 45 deletions
|
|
@ -327,6 +327,7 @@
|
|||
<file>ui/modules/Linphone/Styles/Timeline/TimelineStyle.qml</file>
|
||||
<file>ui/modules/Linphone/TelKeypad/TelKeypadButton.qml</file>
|
||||
<file>ui/modules/Linphone/TelKeypad/TelKeypad.qml</file>
|
||||
<file>ui/modules/Linphone/Timeline/Timeline.js</file>
|
||||
<file>ui/modules/Linphone/Timeline/Timeline.qml</file>
|
||||
<file>ui/scripts/LinphoneUtils/linphone-utils.js</file>
|
||||
<file>ui/scripts/LinphoneUtils/qmldir</file>
|
||||
|
|
|
|||
51
linphone-desktop/ui/modules/Linphone/Timeline/Timeline.js
Normal file
51
linphone-desktop/ui/modules/Linphone/Timeline/Timeline.js
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
// =============================================================================
|
||||
// `Timeline.qml` Logic.
|
||||
// =============================================================================
|
||||
|
||||
function setSelectedEntry (sipAddress) {
|
||||
var model = timeline.model
|
||||
var n = view.count
|
||||
|
||||
timeline._selectedSipAddress = sipAddress
|
||||
|
||||
for (var i = 0; i < n; i++) {
|
||||
if (sipAddress === model.data(model.index(i, 0)).sipAddress) {
|
||||
view.currentIndex = i
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function resetSelectedEntry () {
|
||||
view.currentIndex = -1
|
||||
timeline._selectedSipAddress = ''
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
function handleDataChanged (topLeft, bottomRight, roles) {
|
||||
var index = view.currentIndex
|
||||
var model = timeline.model
|
||||
var sipAddress = timeline._selectedSipAddress
|
||||
|
||||
if (
|
||||
index !== -1 &&
|
||||
sipAddress !== model.data(model.index(index, 0)).sipAddress
|
||||
) {
|
||||
setSelectedEntry(sipAddress)
|
||||
}
|
||||
}
|
||||
|
||||
function handleRowsAboutToBeRemoved (parent, first, last) {
|
||||
var index = view.currentIndex
|
||||
if (index >= first && index <= last) {
|
||||
view.currentIndex = -1
|
||||
}
|
||||
}
|
||||
|
||||
function handleCountChanged () {
|
||||
var sipAddress = timeline._selectedSipAddress
|
||||
if (sipAddress.length > 0) {
|
||||
setSelectedEntry(sipAddress)
|
||||
}
|
||||
}
|
||||
|
|
@ -4,7 +4,8 @@ import QtQuick.Layouts 1.3
|
|||
import Common 1.0
|
||||
import Linphone 1.0
|
||||
import Linphone.Styles 1.0
|
||||
import Utils 1.0
|
||||
|
||||
import 'Timeline.js' as Logic
|
||||
|
||||
// =============================================================================
|
||||
|
||||
|
|
@ -14,9 +15,10 @@ ColumnLayout {
|
|||
// ---------------------------------------------------------------------------
|
||||
|
||||
property alias model: view.model
|
||||
|
||||
property string _selectedSipAddress
|
||||
|
||||
property var _newInsertedItem
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
signal entrySelected (var entry)
|
||||
|
|
@ -24,21 +26,11 @@ ColumnLayout {
|
|||
// ---------------------------------------------------------------------------
|
||||
|
||||
function setSelectedEntry (sipAddress) {
|
||||
var n = model.rowCount()
|
||||
|
||||
for (var i = 0; i < n; i++) {
|
||||
_selectedSipAddress = sipAddress
|
||||
|
||||
if (sipAddress === model.data(model.index(i, 0)).sipAddress) {
|
||||
view.currentIndex = i
|
||||
return
|
||||
}
|
||||
}
|
||||
Logic.setSelectedEntry(sipAddress)
|
||||
}
|
||||
|
||||
function resetSelectedEntry () {
|
||||
view.currentIndex = -1
|
||||
_selectedSipAddress = ''
|
||||
Logic.resetSelectedEntry()
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
|
@ -50,37 +42,8 @@ ColumnLayout {
|
|||
Connections {
|
||||
target: model
|
||||
|
||||
// Handle if current entry was moved in timeline.
|
||||
onDataChanged: {
|
||||
var index = view.currentIndex
|
||||
if (
|
||||
index !== -1 &&
|
||||
_selectedSipAddress !== model.data(model.index(index, 0)).sipAddress
|
||||
) {
|
||||
setSelectedEntry(_selectedSipAddress)
|
||||
}
|
||||
}
|
||||
|
||||
// A timeline entry is removed from timeline if there is no history entry.
|
||||
onRowsAboutToBeRemoved: {
|
||||
var index = view.currentIndex
|
||||
if (index >= first && index <= last) {
|
||||
view.currentIndex = -1
|
||||
}
|
||||
}
|
||||
|
||||
// A entry is added when history is created.
|
||||
onRowsInserted: {
|
||||
if (_selectedSipAddress.length === 0) {
|
||||
return
|
||||
}
|
||||
|
||||
for (var i = first; i <= last; i++) {
|
||||
if (_selectedSipAddress === model.data(model.index(i, 0)).sipAddress) {
|
||||
view.currentIndex = i
|
||||
}
|
||||
}
|
||||
}
|
||||
onDataChanged: Logic.handleDataChanged(topLeft, bottomRight, roles)
|
||||
onRowsAboutToBeRemoved: Logic.handleRowsAboutToBeRemoved (parent, first, last)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
|
@ -175,5 +138,7 @@ ColumnLayout {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
onCountChanged: Logic.handleCountChanged()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue