Index: sources/gui/qml/components/MainMenu.qml =================================================================== diff -u -r50e38888132835a21357dfadff7a9bb1ccfdd334 -r0808e668ca656c86185c3fa69e4a70dbdb4192c9 --- sources/gui/qml/components/MainMenu.qml (.../MainMenu.qml) (revision 50e38888132835a21357dfadff7a9bb1ccfdd334) +++ sources/gui/qml/components/MainMenu.qml (.../MainMenu.qml) (revision 0808e668ca656c86185c3fa69e4a70dbdb4192c9) @@ -24,162 +24,98 @@ * \brief The MainMenu Component * which contains three [Treatment, Manager, Settings] */ -Item { id: _root - enum Position { - Top, - Bottom - } +Rectangle { id: _root - property var titles : [] - property var visibleItems : [] + property alias index : _listView.currentIndex 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 property int titlePixelSize : 40 + property color backgroundColor : Colors.backgroundMainMenu + property int highlightHeight : 10 + property bool isMainMenu : false + property bool isMainTreatment : false - /*! - * \brief Emits when a menu item pressed - * \param vIndex is the index of the pressed item - */ - signal itemPressed(int vIndex) - onItemPressed: { - currentIndex = vIndex - let itemAt = _repeater.itemAt(vIndex) - if (itemAt) - _highlightRect.x = itemAt.x - else { - _highlightRect.x = _rightTouchRect.x - } - } + width : parent.width + height : Variables.mainMenuHeight + color : _root.backgroundColor + clip : true - function isItemVisible ( vIndex ) { - return visibleItems [ vIndex ] !== false // used "!== false" to cover undefined as true. + gradient: Gradient { + GradientStop { position: 0.2; color: Qt.lighter(Colors.backgroundMain, 1.2) } + GradientStop { position: 0.8; color: Qt.darker (Colors.backgroundMain, 1.2) } } - function emit_itemPressed ( vIndex ) { - if ( isItemVisible ( vIndex ) ) - itemPressed ( vIndex ) + signal itemPressed(int vIndex) + + ListModel { id: _mainTreatmentModel + ListElement { text: qsTr("Treatment") } + ListElement { text: qsTr("Trends") } + ListElement { text: qsTr("Heparin") } } - 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 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) + ListModel { id: _mainMenuModel + ListElement { text: qsTr("Treatment") } + ListElement { text: qsTr("Prescriptions") } + ListElement { text: qsTr("Settings") } } - /*! type:int - * this property holds the width of each partition - * regarding to the menuitem count and menu width - */ - property int partitionWidth : _private.partitionWidth - property alias spacing : _row.spacing - property alias leftPdding : _row.leftPadding - property alias rightPdding : _row.rightPadding + ListView { id: _listView + property alias index : _listView.currentIndex + anchors.fill : parent + anchors.leftMargin : 30 + anchors.rightMargin : anchors.leftMargin + model : isMainMenu ? _mainMenuModel : + isMainTreatment ? _mainTreatmentModel : + null + currentIndex : 0 + highlightFollowsCurrentItem : true + highlightMoveDuration : 500 + highlightMoveVelocity : -1 + orientation : ListView.Horizontal + interactive : false - clip: true - x: 0 - y: Variables.applicationHeight - Variables.mainMenuHeight - width: parent.width - height: Variables.mainMenuHeight + onCurrentIndexChanged: itemPressed(currentIndex) - Rectangle { id: _backgroundRect - anchors.fill: parent - color: Colors.backgroundMainMenu - gradient: Gradient { - GradientStop { position: 0.2; color: Qt.lighter(Colors.backgroundMain, 1.2) } - GradientStop { position: 0.8; color: Qt.darker (Colors.backgroundMain, 1.2) } + highlight: Rectangle { id: _highlightRectangle + objectName: "_highlightRectangle" + color: "transparent" + + Rectangle { + id: _highlightedItem + objectName: "highlightedItem" + anchors { + horizontalCenter: parent.horizontalCenter + bottom: parent.bottom + bottomMargin: (height / 2) * -1 + } + height: _root.highlightHeight + width: parent.width / 2 + radius: 10 + color: Colors.backgroundButtonSelect + } } - } - MouseArea { id: _clickPropagationDisabler - anchors.fill: parent - } + delegate: Item { id: _delegateControl + objectName : "delegateControl" + width : ListView.view.count ? ListView.view.width / ListView.view.count : 0 + height : ListView.view.height - ImageLogoDDarkTransparent { id: _image - visible: hasLogo - anchors.centerIn: parent - } - - // normal texts with highlighter bottom ribon. - Row { id: _row - anchors.fill: parent - spacing : partitionWidth - leftPadding : partitionWidth - rightPadding: partitionWidth - - Repeater { id: _repeater - model: _private.repeaterTitles TouchRect { id : _touchRect - objectName: "_touchRect" + index //SquishQt testability + objectName: "_touchRect" + index 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. + anchors.fill: parent + text.text : model.text border.width: 0 - pixelSize : titlePixelSize //// ----- @LEAHIZED + pixelSize : titlePixelSize + onPressed: { - emit_itemPressed(index) + if (_listView.currentIndex !== index) { + _listView.currentIndex = index + } } } } } - - // the right outer most text with vertical line as a separator - Line { - visible: hasRightText && isItemVisible(_rightTouchRect.index) - orientation: Line.Orientation.Vertical - length: parent.height - rightTextGaps - anchors.right: _rightTouchRect.left - anchors.verticalCenter: parent.verticalCenter - } - 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 - onPressed: { - emit_itemPressed(index) - } - anchors.right: parent.right - anchors.rightMargin: parent.rightPdding - anchors.verticalCenter: parent.verticalCenter - } - - // normal text bottom highlighter - Rectangle { id : _highlightRect - color: Colors.backgroundButtonSelect - width: partitionWidth - x : leftPdding - height: 10 - radius: 10 - anchors.bottom: parent.bottom - 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 = isHidden ? - Variables.mainMenuHeight : 0 - } else { - y = Variables.applicationHeight - (isHidden ? 0 : Variables.mainMenuHeight) - } - } + Behavior on anchors.bottomMargin { PropertyAnimation { } } }