ukui-menu/qml/AppUI/PluginSelectMenu.qml

151 lines
4.9 KiB
QML
Raw Normal View History

2023-03-22 16:42:06 +08:00
/*
* Copyright (C) 2023, KylinSoft Co., Ltd.
*
* 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 3 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, see <https://www.gnu.org/licenses/>.
*
*/
import QtQuick 2.12
import QtQuick.Layouts 1.12
import QtQuick.Controls 2.12
import AppControls2 1.0 as AppControls2
import org.ukui.menu.core 1.0
import org.ukui.menu.utils 1.0
RowLayout {
id: pluginSelectMenuRoot
property var model: appPageHeaderUtils.model(PluginGroup.SortMenuItem)
spacing: 2
function resetFocus() {
if(!mainWindow.isFullScreen) {
normalUI.focusToFalse();
}
}
2023-03-22 16:42:06 +08:00
AppControls2.RoundButton {
id: pluginSelectButton
Layout.fillHeight: true
Layout.fillWidth: true
Layout.maximumWidth: height
activeFocusOnTab: true
ToolTip.delay: 500
2023-06-02 15:44:16 +08:00
ToolTip.text: qsTr("Switch Sort Type")
ToolTip.visible: containsMouse
2023-03-22 16:42:06 +08:00
highlight: mainWindow.isFullScreen
autoHighLight: !mainWindow.isFullScreen
buttonIcon: "image://appicon/ukui-selected"
onClicked: {
resetFocus();
pluginSelectMenuRoot.model.autoSwitchProvider();
}
Keys.onPressed: {
if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return) {
pluginSelectMenuRoot.model.autoSwitchProvider();
}
}
}
MouseArea {
id: sortMenuMouseArea
Layout.alignment: Qt.AlignVCenter
Layout.fillWidth: true
Layout.fillHeight: true
Layout.maximumWidth: 16
Layout.maximumHeight: 16
ToolTip.delay: 500
2023-06-02 15:44:16 +08:00
ToolTip.text: qsTr("Sort Type Options")
ToolTip.visible: containsMouse
hoverEnabled: true
activeFocusOnTab: true
Keys.onPressed: {
if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return) {
sortMenuClicked();
}
}
onClicked: {
resetFocus();
sortMenuClicked();
}
function sortMenuClicked() {
2023-03-22 16:42:06 +08:00
if(sortMenuSelector.state === "sortMenuClose") {
2023-04-11 15:17:37 +08:00
sortMenuSelector.state = "sortMenuOpen";
2023-03-22 16:42:06 +08:00
}
var pressY = sortMenuMouseArea.mapToGlobal(0, 0).y;
var pressX = sortMenuMouseArea.mapToGlobal(0, 0).x;
pluginSelectMenuRoot.model.openMenu(pluginSelectButton.height - y - mouseY + 8, pressX, pressY);
}
AppControls2.StyleBackground {
anchors.fill: parent
useStyleTransparent: false
paletteRole: Palette.Highlight
alpha: 0
borderColor: Palette.Highlight
border.width: sortMenuMouseArea.activeFocus ? 2 : 0
}
2023-03-22 16:42:06 +08:00
ThemeIcon {
id: sortMenuSelector
anchors.fill: parent
2023-03-22 16:42:06 +08:00
source: "image://appicon/ukui-up-symbolic"
opacity: 0.5
highLight: mainWindow.isFullScreen
state: "sortMenuClose"
states: [
State {
name: "sortMenuOpen"
PropertyChanges { target: sortMenuSelector; rotation: 0 }
},
State {
name: "sortMenuClose"
PropertyChanges { target: sortMenuSelector; rotation: 180 }
}
]
transitions: [
Transition {
to: "sortMenuOpen"
2023-04-11 15:17:37 +08:00
RotationAnimation { duration: 100; direction: RotationAnimation.Counterclockwise}
2023-03-22 16:42:06 +08:00
},
Transition {
to: "sortMenuClose"
2023-04-11 15:17:37 +08:00
RotationAnimation { duration: 100; direction: RotationAnimation.Clockwise }
2023-03-22 16:42:06 +08:00
}
]
Component.onCompleted: {
updateProviderIcon();
pluginSelectMenuRoot.model.currentIndexChanged.connect(updateProviderIcon);
2023-04-11 15:17:37 +08:00
pluginSelectMenuRoot.model.menuClosed.connect(changeMenuStatus);
}
Component.onDestruction: {
pluginSelectMenuRoot.model.currentIndexChanged.disconnect(updateProviderIcon);
2023-04-11 15:17:37 +08:00
pluginSelectMenuRoot.model.menuClosed.disconnect(changeMenuStatus);
}
function updateProviderIcon() {
pluginSelectButton.buttonIcon = pluginSelectMenuRoot.model.currentProviderIcon();
}
2023-04-11 15:17:37 +08:00
function changeMenuStatus() {
sortMenuSelector.state = "sortMenuClose";
}
}
}
}