Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/VLC/modules/gui/qt/widgets/qml/   (VLC Media Plyer ©)  Datei vom 23.9.2026 mit Größe 5 kB image not shown  

Quelle  NavigableCol.qml  Sprache: unbekannt

 
Spracherkennung für: .qml vermutete Sprache: Delphi {Delphi[56] SPS[48] Masm[45]} [Methode: maximale Elemente, drei Dimensionen]

/*****************************************************************************
 * Copyright (C) 2019 VLC authors and VideoLAN
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * ( at your option ) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

import QtQuick
import QtQuick.Templates as T

import VLC.MainInterface
import VLC.Util

T.Container {
    id: root

    // Properties

    property int indexFocus: -1

    property int _countEnabled: 0


    implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
                            implicitContentWidth + leftPadding + rightPadding)

    implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
                             implicitContentHeight + topPadding + bottomPadding)


    // Settings

    Navigation.navigable: (_countEnabled > 0)

    // Events

    onIndexFocusChanged: if (_hasFocus()) _applyFocus()

    onActiveFocusChanged: {
        // NOTE: We try to restore the preferred focused item.
        if (!activeFocus || _applyFocus())
            return;

        // Next item
        if (focusReason === Qt.TabFocusReason) {
            for (let i = 0; i < repeater.count; i++) {
                const item = repeater.itemAt(i);

                if (root._isNavigable(item)) {
                    Helpers.transferFocus(item, Qt.TabFocusReason);

                    return;
                }
            }
        }
        // Previous item
        else if (focusReason === Qt.BacktabFocusReason) {
            for (let i = repeater.count - 1; i >= 0; i--) {
                const item = repeater.itemAt(i);

                if (root._isNavigable(item)) {
                    Helpers.transferFocus(item, Qt.BacktabFocusReason);

                    return;
                }
            }
        }
        // NOTE: We make sure that one item has the focus.
        else {
            let itemFocus = undefined;

            for (let i = 0 ; i < repeater.count; i++) {
                const item = repeater.itemAt(i);

                if (root._isNavigable(item)) {
                    // NOTE: We already have a focused item, so we keep it this way.
                    if (item.activeFocus)
                        return;

                    if (itemFocus == undefined)
                        itemFocus = item;
                }
            }

            if (itemFocus)
                Helpers.transferFocus(itemFocus, focusReason);
        }
    }

    // Keys

    Keys.priority: Keys.AfterItem

    Keys.onPressed: (event) => root.Navigation.defaultKeyAction(event)

    // Functions

    function _isNavigable(item) {
        return item.visible && item.enabled && item.Navigation.navigable
    }

    function _applyFocus() {
        if (indexFocus < 0 || indexFocus >= count) return false;

        const item = repeater.itemAt(indexFocus);

        if (root._isNavigable(item)) {
            Helpers.transferFocus(item, focusReason);

            return true;
        }

        return false;
    }

    function _hasFocus() {
        for (let i = 0 ; i < count; i++) {
            if (repeater.itemAt(i).activeFocus)
                return true;
        }

        return false;
    }

    // Childs

    contentItem: Column {
        spacing: root.spacing

        Repeater{
            id: repeater

            model: root.contentModel

            onItemAdded: (index, item) => {
                if (item.enabled) root._countEnabled += 1;

                item.onEnabledChanged.connect(() => {
                    if (root && item)
                        root._countEnabled += (item.enabled ? 1 : -1);
                });

                item.Navigation.upAction = function() {
                    let i = index;

                    do {
                        i--;
                    } while (i >= 0
                             &&
                             !root._isNavigable(repeater.itemAt(i)));

                    if (i == -1)
                        root.Navigation.defaultNavigationUp();
                    else
                        Helpers.transferFocus(repeater.itemAt(i), Qt.BacktabFocusReason);
                }

                item.Navigation.downAction = function() {
                    let i = index;

                    do {
                        i++;
                    } while (i < repeater.count
                             &&
                             !root._isNavigable(repeater.itemAt(i)));

                    if (i == repeater.count)
                        root.Navigation.defaultNavigationDown();
                    else
                        Helpers.transferFocus(repeater.itemAt(i), Qt.TabFocusReason);
                }
            }

            onItemRemoved: (index, item) => {
                if (item.enabled) root._countEnabled -= 1
            }
        }
    }
}

[Dauer der Verarbeitung: 0.2 Sekunden, vorverarbeitet 2026-10-24]