C

Qt Quick Ultralite Automotive Cluster Demo

// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial

pragma Singleton
import QtQuick 2.15

QtObject {
    id: phonemodel

    property int contactTabIndex: 0
    readonly property int contactTabSwitchDuration: 350
    property int favContactsIndex: 0
    property int recentContactsIndex: 0
    property int allContactsIndex: 0
    property int currentContactIndex: 0
    property int contactScrollDuration: 250
    property bool inCall: false

    // FIXME: it's not possible for now to check size of model
    readonly property int phoneTabCount: 3
    readonly property int favContactsCount: 3
    readonly property int recentContactsCount: 2
    readonly property int allContactsCount: 5

    readonly property int maxCallDuration: 25 * 1000
    readonly property int minCallDuration: 15 * 1000

    onInCallChanged: {
        ConnectivityService.ongoingCall = inCall;
    }

    onContactTabIndexChanged: adjustCurrentContactIndex()

    function adjustCurrentContactIndex() {
        if (contactTabIndex == 0) {
            currentContactIndex = favContactsIndex
        }
        if (contactTabIndex == 1) {
            currentContactIndex = recentContactsIndex
        }
        else if (contactTabIndex == 2) {
            currentContactIndex = allContactsIndex
        }
    }

    function nextTab() {
        contactTabIndex = (contactTabIndex + 1) % phoneTabCount
    }

    function previousTab() {
        contactTabIndex = (contactTabIndex + phoneTabCount - 1) % phoneTabCount
    }

    function previousContact() {
        if (contactTabIndex == 0) {
            favContactsIndex = (favContactsIndex + favContactsCount - 1) % favContactsCount
        }
        if (contactTabIndex == 1) {
            recentContactsIndex = (recentContactsIndex + recentContactsCount - 1) % recentContactsCount
        }
        else if (contactTabIndex == 2) {
            allContactsIndex = (allContactsIndex + allContactsCount - 1) % allContactsCount
        }
        adjustCurrentContactIndex()
    }

    function nextContact() {
        if (contactTabIndex == 0) {
            favContactsIndex = (favContactsIndex + 1) % favContactsCount
        }
        if (contactTabIndex == 1) {
            recentContactsIndex = (recentContactsIndex + 1) % recentContactsCount
        }
        else if (contactTabIndex == 2) {
            allContactsIndex = (allContactsIndex + 1) % allContactsCount
        }
        adjustCurrentContactIndex()
    }
}