diff --git a/lib/appmenuapplet.cpp b/lib/appmenuapplet.cpp --- a/lib/appmenuapplet.cpp +++ b/lib/appmenuapplet.cpp @@ -233,9 +233,11 @@ QMenu *menu = nullptr; QAction *action = nullptr; - if (view() == CompactView) { + if (view() == CompactView || idx < -5) { + int i = 0; + if (idx < -5) i = -(idx + 10); // full representation but part of menu is hidden menu = new QMenu(); - for (int i=0; irowCount(); i++) { + for (; irowCount(); i++) { const QModelIndex index = m_model->index(i, 0); const QVariant data = m_model->data(index, AppMenuModel::ActionRole); action = (QAction *)data.value(); diff --git a/package/contents/ui/AppMenu.qml b/package/contents/ui/AppMenu.qml --- a/package/contents/ui/AppMenu.qml +++ b/package/contents/ui/AppMenu.qml @@ -13,7 +13,7 @@ property bool appmenuFontBold: plasmoid.configuration.appmenuFontBold property bool appmenuDoNotHide: plasmoid.configuration.appmenuDoNotHide property bool appmenuEnabledAndNonEmpty: appmenuEnabled && appMenuModel !== null && appMenuModel.menuAvailable - property bool appmenuOpened: appmenuEnabled && plasmoid.nativeInterface.currentIndex > -1 + property bool appmenuOpened: appmenuEnabled && (plasmoid.nativeInterface.currentIndex >= 0 || plasmoid.nativeInterface.currentIndex <= -10) property var appMenuModel: null property bool appmenuButtonsOffsetEnabled: !buttonsStandalone && appmenuNextToButtons && childrenRect.width > 0 @@ -22,13 +22,33 @@ : 0 property int alignLeft: plasmoid.configuration.appmenuAlignLeft - visible: appmenuEnabledAndNonEmpty && !noWindowActive && (appmenuDoNotHide || mouseHover || appmenuOpened) + property int effectiveWidth: appmenu.width - buttonGrid.anchors.leftMargin - controlButtonsArea.width + property int firstHidden: 0 + onEffectiveWidthChanged: Qt.callLater(fixOverflow) + + function fixOverflow() { + var show = true + for (var i = 0; i < buttonRepeater.count; i++) { + var item = buttonRepeater.itemAt(i) + var space_needed = item.width + (i == buttonRepeater.count - 1 ? + 0 : appmenuRestButton.width) + if (show && item.x + space_needed > effectiveWidth) { + firstHidden = i + show = false + } + + item.visible = show + } + appmenuRestButton.visible = !show + if (show) + firstHidden = buttonRepeater.count + } + GridLayout { id: buttonGrid - - Layout.minimumWidth: implicitWidth + Layout.minimumWidth: 0 Layout.minimumHeight: implicitHeight flow: GridLayout.LeftToRight @@ -54,9 +74,13 @@ Connections { target: plasmoid.nativeInterface onRequestActivateIndex: { - var idx = Math.max(0, Math.min(buttonRepeater.count - 1, index)) - var button = buttonRepeater.itemAt(index) - if (button) { + if (index < -5) { + index = index - appmenuRestButton.buttonIndex + appmenu.firstHidden + } + + var idx = Math.max(0, Math.min(appmenu.firstHidden, index)) + var button = idx === appmenu.firstHidden ? appmenuRestButton : buttonRepeater.itemAt(index) + if (button && button.visible) { button.clicked(null) } } @@ -106,6 +130,52 @@ onExited: { appmenuButtonBackground.border.color = 'transparent' } + + onXChanged: Qt.callLater(fixOverflow) + onWidthChanged: Qt.callLater(fixOverflow) + } + } + + MouseArea { + id: appmenuRestButton + + visible: false + hoverEnabled: true + + property int buttonIndex: -10 - appmenu.firstHidden + + property bool menuOpened: plasmoid.nativeInterface.currentIndex <= -10 + + width: appmenuRestButtonBackground.width + height: appmenuRestButtonBackground.height + + Rectangle { + id: appmenuRestButtonBackground + border.color: 'transparent' + width: appmenuRestButtonTitle.implicitWidth + units.smallSpacing * 3 + height: appmenuFillHeight ? appmenu.height : appmenuRestButtonTitle.implicitHeight + units.smallSpacing + color: appmenuRestButton.menuOpened ? theme.highlightColor : 'transparent' + radius: units.smallSpacing / 2 + } + + PlasmaComponents.Label { + id: appmenuRestButtonTitle + anchors.centerIn: appmenuRestButtonBackground + font.pixelSize: fontPixelSize * plasmoid.configuration.appmenuButtonTextSizeScale + text: 'ยป' + font.weight: appmenuFontBold ? Font.Bold : theme.defaultFont.weight + } + + onClicked: { + plasmoid.nativeInterface.trigger(this, buttonIndex) + } + + onEntered: { + appmenuRestButtonBackground.border.color = theme.highlightColor + } + + onExited: { + appmenuRestButtonBackground.border.color = 'transparent' } } }