Index: sources/gui/qml/components/MainMenu.qml =================================================================== diff -u -refb033a62e24fe2d804221ea0cb496c5411fdb2b -r6c6f1f5d466badd9b4fd67be7c907234c342b2a2 --- sources/gui/qml/components/MainMenu.qml (.../MainMenu.qml) (revision efb033a62e24fe2d804221ea0cb496c5411fdb2b) +++ sources/gui/qml/components/MainMenu.qml (.../MainMenu.qml) (revision 6c6f1f5d466badd9b4fd67be7c907234c342b2a2) @@ -1,20 +1,20 @@ /*! * - * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. - * \copyright \n - * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, \n - * IN PART OR IN WHOLE, \n - * WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. \n + * Copyright (c) 2019-2023 Diality Inc. - All Rights Reserved. + * \copyright + * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN + * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * \file MainMenu.qml - * \date 2019/10/18 - * \author Behrouz NematiPour + * \author (last) Behrouz NematiPour + * \date (last) 27-Apr-2023 + * \author (original) Behrouz NematiPour + * \date (original) 17-Oct-2019 * */ // Qt import QtQuick 2.12 -import QtQuick.Controls 2.12 // Project // Qml imports @@ -30,14 +30,16 @@ Bottom } - property variant titles : [] - property bool hidden : false - property int position : MainMenu.Position.Bottom - property bool hasRightText : false - property int rightTextGaps : 20 - property bool hasLogo : false - property int currentIndex : 0 - property string currentTitle : titles[currentIndex] + property var titles : [] + property var visibleItems : [] + property bool hidden : false + property int position : MainMenu.Position.Bottom + property bool hasRightText : false + property int rightTextGaps : 20 + property bool hasLogo : false + property int currentIndex : 0 + property string currentTitle : titles[currentIndex] + property bool disable : false /*! * \brief Emits when a menu item pressed @@ -46,14 +48,31 @@ signal itemPressed(int vIndex) onItemPressed: { currentIndex = vIndex + let itemAt = _repeater.itemAt(vIndex) + if (itemAt) + _highlightRect.x = itemAt.x + else { + _highlightRect.x = _rightTouchRect.x + } } + function isItemVisible ( vIndex ) { + return visibleItems [ vIndex ] !== false // used "!== false" to cover undefined as true. + } + + function emit_itemPressed ( vIndex ) { + if ( isItemVisible ( vIndex ) ) + itemPressed ( vIndex ) + } + + onCurrentIndexChanged: emit_itemPressed(currentIndex) + /*! * this section olds somkind of the private sections of the object * this section is used as the calculation section whcih soppose not to be changed by user. */ QtObject { id: _private - readonly property variant repeaterTitles: hasRightText ? titles.slice(0,titles.length - 1) : titles + readonly property var repeaterTitles: hasRightText ? titles.slice(0,titles.length - 1) : titles readonly property string rightText : titles.length ? titles[titles.length - 1] : "" readonly property int partitionWidth: _row.width / ( _private.repeaterTitles.length * 2 + 1) } @@ -82,12 +101,9 @@ anchors.fill: parent } - Image { id: _image + ImageLogoDDT { id: _image visible: hasLogo anchors.centerIn: parent - width : Variables.logoWidth - height: Variables.logoHeight - source: "qrc:/images/iLogoDDT" } // normal texts with highlighter bottom ribon. @@ -101,37 +117,39 @@ model: _private.repeaterTitles TouchRect { id : _touchRect objectName: "_touchRect" + index //SquishQt testability - width: partitionWidth - height: parent.height - text.text: modelData + animated : false + width : partitionWidth + height : parent.height + text.text : isItemVisible(index) ? modelData : "" // didn't change the visibility to preserve the button location and just didn't display the title and highlihgt bar. border.width: 0 - button.onPressed: { - _highlightRect.x = _touchRect.x - itemPressed(index) + onPressed: { + emit_itemPressed(index) } } } } // the right outer most text with vertical line as a separator Line { - visible: hasRightText + visible: hasRightText && isItemVisible(_rightTouchRect.index) orientation: Line.Orientation.Vertical length: parent.height - rightTextGaps anchors.right: _rightTouchRect.left anchors.verticalCenter: parent.verticalCenter } - TouchRect { id : _rightTouchRect - visible: hasRightText - objectName: "_rightTouchRect" //SquishQt testability - width: partitionWidth + rightTextGaps - height: parent.height - text.text: _private.rightText + TouchRect { id : _rightTouchRect + property int index: titles.length ? titles.length - 1 : -1 + animated : false + visible : hasRightText + width : partitionWidth + rightTextGaps + height : parent.height + text.text : isItemVisible(index) ? _private.rightText : "" // didn't change the visibility to preserve the button location and just didn't display the title and highlihgt bar. border.width: 0 - button.onPressed: { - itemPressed( titles.length ? titles.length - 1 : -1 ) + onPressed: { + emit_itemPressed(index) } anchors.right: parent.right + anchors.rightMargin: parent.rightPdding anchors.verticalCenter: parent.verticalCenter } @@ -143,17 +161,18 @@ height: 10 radius: 10 anchors.bottom: parent.bottom - anchors.bottomMargin: -5 + anchors.bottomMargin: -(height / 2) Behavior on x { PropertyAnimation { /*duration: 500; easing.type: Easing.OutBounce*/ } } } // hidden animation to hide the menu nicely. Behavior on y { PropertyAnimation { /*duration: 500; easing.type: Easing.OutBounce*/ } } onHiddenChanged: { + let isHidden = hidden || disable if ( position === MainMenu.Position.Top ) { - y = hidden ? - Variables.mainMenuHeight : 0 + y = isHidden ? - Variables.mainMenuHeight : 0 } else { - y = Variables.applicationHeight - (hidden ? 0 : Variables.mainMenuHeight) + y = Variables.applicationHeight - (isHidden ? 0 : Variables.mainMenuHeight) } } }