Warning, /maui/mauikit/src/controls.5/TabBar.qml is written in an unsupported language. File is not indexed.

0001 import QtQuick 2.15
0002 import QtQuick.Controls 2.15 as QQC
0003 import QtQuick.Layouts 1.3
0004 import QtQuick.Window 2.15
0005 
0006 import org.mauikit.controls 1.3 as Maui
0007 
0008 import "private" as Private
0009 
0010 /**
0011  * TabBar
0012  * A global sidebar for the application window that can be collapsed.
0013  *
0014  *
0015  *
0016  *
0017  *
0018  *
0019  */
0020 QQC.TabBar
0021 {
0022     id: control
0023 
0024     implicitHeight: _layout.implicitHeight + topPadding +bottomPadding
0025 
0026     property alias content : _rightLayout.content
0027     property alias leftContent: _leftLayout.content
0028     property alias rightContent: _rightLayout.content
0029 
0030     property alias interactive: _content.interactive
0031     /**
0032      * showNewTabButton : bool
0033      */
0034     property bool showNewTabButton : true
0035     property bool showTabs : true
0036 
0037     /**
0038      * newTabClicked :
0039      */
0040     signal newTabClicked()
0041     signal newTabFocused(int index)
0042 
0043     background: Rectangle
0044     {
0045         color: Maui.Theme.backgroundColor
0046 
0047         Behavior on color
0048         {
0049             Maui.ColorTransition{}
0050         }
0051 
0052         Loader
0053         {
0054             z: 999
0055 
0056             asynchronous: true
0057             width: Maui.Style.iconSizes.medium
0058             height: parent.height
0059             active: !_content.atXEnd && !parent.fits
0060             visible: active
0061 
0062             anchors
0063             {
0064                 right: parent.right
0065                 top: parent.top
0066                 bottom: parent.bottom
0067             }
0068 
0069             sourceComponent: Maui.EdgeShadow
0070             {
0071                 edge: Qt.RightEdge
0072             }
0073         }
0074 
0075         Loader
0076         {
0077             z: 999
0078 
0079             asynchronous: true
0080             width: Maui.Style.iconSizes.medium
0081             height: parent.height
0082             active: !_content.atXBeginning && !parent.fits
0083             visible: active
0084             anchors
0085             {
0086                 left: parent.left
0087                 top: parent.top
0088                 bottom: parent.bottom
0089             }
0090 
0091             sourceComponent: Maui.EdgeShadow
0092             {
0093                 edge: Qt.LeftEdge
0094             }
0095         }
0096     }
0097 
0098     contentItem: Item
0099     {
0100         implicitHeight: _layout.implicitHeight
0101         readonly property bool fits : _content.contentWidth <= width
0102 
0103         Item
0104         {
0105             id: _dragHandler
0106             anchors.fill: parent
0107             DragHandler
0108             {
0109                 // enabled: !control.interactive
0110                 acceptedDevices: PointerDevice.GenericPointer
0111 
0112                 grabPermissions:  PointerHandler.CanTakeOverFromItems | PointerHandler.CanTakeOverFromHandlersOfDifferentType | PointerHandler.ApprovesTakeOverByAnything
0113                 onActiveChanged: if (active) { control.Window.window.startSystemMove(); }
0114             }
0115         }
0116 
0117         RowLayout
0118         {
0119             id: _layout
0120 
0121             anchors.fill: parent
0122             spacing: control.spacing
0123 
0124             Private.ToolBarSection
0125             {
0126                 id: _leftLayout
0127                 Layout.fillHeight: true
0128                 Layout.maximumWidth: implicitWidth
0129                 Layout.minimumWidth: implicitWidth
0130 
0131                 spacing: control.spacing
0132             }
0133 
0134             QQC.ScrollView
0135             {
0136                 Layout.fillWidth: true
0137 
0138                 orientation : Qt.Horizontal
0139 
0140                 QQC.ScrollBar.horizontal.policy: QQC.ScrollBar.AlwaysOff
0141                 QQC.ScrollBar.vertical.policy: QQC.ScrollBar.AlwaysOff
0142 
0143                 contentHeight: availableHeight
0144                 implicitHeight: _content.currentItem ? _content.currentItem.height : 0
0145 
0146                 ListView
0147                 {
0148                     id: _content
0149                     opacity: control.showTabs ? 1 : 0
0150                     visible: opacity > 0
0151 
0152                     clip: true
0153 
0154                     orientation: ListView.Horizontal
0155 
0156                     spacing: control.spacing
0157 
0158                     model: control.contentModel
0159                     currentIndex: control.currentIndex
0160 
0161                     interactive: Maui.Handy.isMobile
0162                     snapMode: ListView.SnapOneItem
0163 
0164                     highlightFollowsCurrentItem: true
0165                     highlightMoveDuration: 0
0166                     highlightResizeDuration : 0
0167 
0168                     boundsBehavior: Flickable.StopAtBounds
0169                     boundsMovement: Flickable.StopAtBounds
0170 
0171                     keyNavigationEnabled : true
0172                     keyNavigationWraps : true
0173 
0174                     onMovementEnded:
0175                     {
0176                         const newIndex = indexAt(contentX, contentY)
0177                         control.newTabFocused(newIndex)
0178                     }
0179 
0180                     Behavior on opacity
0181                     {
0182                         NumberAnimation
0183                         {
0184                             duration: Maui.Style.units.shortDuration
0185                             easing.type: Easing.InOutQuad
0186                         }
0187                     }
0188                 }
0189             }
0190 
0191             Private.ToolBarSection
0192             {
0193                 id: _rightLayout
0194                 Layout.fillHeight: true
0195                 Layout.maximumWidth: implicitWidth
0196                 Layout.minimumWidth: implicitWidth
0197 
0198                 spacing: control.spacing
0199             }
0200 
0201             Loader
0202             {
0203                 active: control.showNewTabButton
0204                 visible: active
0205                 asynchronous: true
0206 
0207                 sourceComponent: QQC.ToolButton
0208                 {
0209                     icon.name: "list-add"
0210                     onClicked: control.newTabClicked()
0211                     flat: true
0212                 }
0213             }
0214         }
0215     }
0216 
0217     function positionViewAtIndex(index : int)
0218     {
0219         _content.positionViewAtIndex(index, ListView.SnapPosition)
0220     }
0221 }