Skip to content

Commit

Permalink
Merge pull request #5920 from opengisch/borderless
Browse files Browse the repository at this point in the history
Keyboard shortcut for all + borderless window mode for QField on windows/linux/macos
  • Loading branch information
nirvn authored Jan 2, 2025
2 parents e138987 + e896797 commit 4be990c
Show file tree
Hide file tree
Showing 9 changed files with 153 additions and 49 deletions.
8 changes: 8 additions & 0 deletions src/core/focusstack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,11 @@ void FocusStack::setUnfocused( QQuickItem *item )
}
}
}

void FocusStack::forceActiveFocusOnLastTaker() const
{
if ( mStackList.isEmpty() )
return;

mStackList.last()->forceActiveFocus();
}
1 change: 1 addition & 0 deletions src/core/focusstack.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class FocusStack : public QObject

public:
Q_INVOKABLE void addFocusTaker( QQuickItem *item );
Q_INVOKABLE void forceActiveFocusOnLastTaker() const;

private slots:
void itemFocusChanged( bool itemActiveFocus );
Expand Down
17 changes: 1 addition & 16 deletions src/qml/DashBoard.qml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ Drawer {
}
}

onOpened: {
contentItem.forceActiveFocus();
}

width: Math.min(300, mainWindow.width)
height: parent.height
edge: Qt.LeftEdge
Expand Down Expand Up @@ -234,18 +230,7 @@ Drawer {
}
}

onPositionChanged: {
if (checked) {
changeMode("digitize");
} else {
if (digitizingToolbar.rubberbandModel && digitizingToolbar.rubberbandModel.vertexCount > 1) {
displayToast(qsTr("Finish or dimiss the digitizing feature before toggling to browse mode"));
checked = !checked;
} else {
changeMode("browse");
}
}
}
onPositionChanged: mainWindow.toggleDigitizeMode()
}
}

Expand Down
7 changes: 2 additions & 5 deletions src/qml/WelcomeScreen.qml
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ Page {

QfToolButton {
id: currentProjectButton
visible: false
visible: qgisProject && !!qgisProject.fileName
anchors {
top: parent.top
left: parent.left
Expand All @@ -799,7 +799,7 @@ Page {

QfToolButton {
id: exitButton
visible: false
visible: qgisProject && !!qgisProject.fileName && (Qt.platform.os === "ios" || Qt.platform.os === "android" || mainWindow.sceneBorderless)
anchors {
top: parent.top
right: parent.right
Expand Down Expand Up @@ -918,9 +918,6 @@ Page {

function adjustWelcomeScreen() {
if (visible) {
const currentProjectButtonVisible = !!qgisProject.fileName;
currentProjectButton.visible = currentProjectButtonVisible;
exitButton.visible = currentProjectButtonVisible && (Qt.platform.os === "ios" || Qt.platform.os === "android");
if (firstShown) {
welcomeText.text = " ";
} else {
Expand Down
1 change: 1 addition & 0 deletions src/qml/imports/Theme/QfButton.qml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Button {
bottomInset: 2
leftInset: 4
rightInset: 4
focusPolicy: Qt.NoFocus

icon.color: button.color
font: Theme.defaultFont
Expand Down
4 changes: 4 additions & 0 deletions src/qml/imports/Theme/QfDialog.qml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ Dialog {

x: (mainWindow.width - width) / 2
y: (mainWindow.height - height) / 2

onClosed: {
focusstack.forceActiveFocusOnLastTaker();
}
}
1 change: 1 addition & 0 deletions src/qml/imports/Theme/QfToolButton.qml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ RoundButton {
height: 48
implicitWidth: width
implicitHeight: height
focusPolicy: Qt.NoFocus

topInset: 0
bottomInset: 0
Expand Down
1 change: 1 addition & 0 deletions src/qml/imports/Theme/QfToolButtonDrawer.qml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Container {
}
spacing: 4
clip: true
focusPolicy: Qt.NoFocus

Behavior on width {
enabled: true
Expand Down
162 changes: 134 additions & 28 deletions src/qml/qgismobileapp.qml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ ApplicationWindow {
id: mainWindow
objectName: 'mainWindow'
visible: true
flags: Qt.Window | Qt.WindowTitleHint | Qt.WindowSystemMenuHint | (Qt.platform.os === "ios" ? Qt.MaximizeUsingFullscreenGeometryHint : 0) | (Qt.platform.os !== "ios" && Qt.platform.os !== "android" ? Qt.WindowMinMaxButtonsHint | Qt.WindowCloseButtonHint : 0)
flags: Qt.Window | Qt.WindowTitleHint | Qt.WindowSystemMenuHint | (sceneBorderless ? Qt.FramelessWindowHint : 0) | (Qt.platform.os === "ios" ? Qt.MaximizeUsingFullscreenGeometryHint : 0) | (Qt.platform.os !== "ios" && Qt.platform.os !== "android" ? Qt.WindowMinMaxButtonsHint | Qt.WindowCloseButtonHint : 0)

Material.theme: Theme.darkTheme ? "Dark" : "Light"
Material.accent: Theme.mainColor

property bool sceneBorderless: false
property double sceneTopMargin: platformUtilities.sceneMargins(mainWindow)["top"]
property double sceneBottomMargin: platformUtilities.sceneMargins(mainWindow)["bottom"]

Expand Down Expand Up @@ -111,43 +112,100 @@ ApplicationWindow {
visible: true
focus: true

property int previousVisibilityState: Window.Windowed

Keys.onReleased: event => {
if (event.key === Qt.Key_Back || event.key === Qt.Key_Escape) {
if (featureForm.visible) {
featureForm.hide();
} else if (stateMachine.state === 'measure') {
mainWindow.closeMeasureTool();
} else {
mainWindow.close();
}
event.accepted = true;
} else if (event.key === Qt.Key_F11) {
if (Qt.platform.os !== "android" && Qt.platform.os !== "ios") {
if (mainWindow.visibility !== Window.FullScreen) {
previousVisibilityState = mainWindow.visibility;
mainWindow.visibility = Window.FullScreen;
if (event.modifiers === Qt.NoModifier) {
if (event.key === Qt.Key_Back || event.key === Qt.Key_Escape) {
if (featureForm.visible) {
featureForm.hide();
} else if (stateMachine.state === 'measure') {
mainWindow.closeMeasureTool();
} else {
mainWindow.visibility = Window.Windowed;
if (previousVisibilityState === Window.Maximized) {
mainWindow.showMaximized();
}
mainWindow.close();
}
event.accepted = true;
}
}
}

Component.onCompleted: focusstack.addFocusTaker(this)
}

Shortcut {
property int previousVisibilityState: Window.Windowed
enabled: Qt.platform.os !== "android" && Qt.platform.os !== "ios"
sequence: "F11"
onActivated: {
if (mainWindow.visibility !== Window.FullScreen) {
previousVisibilityState = mainWindow.visibility;
mainWindow.visibility = Window.FullScreen;
} else {
mainWindow.visibility = Window.Windowed;
if (previousVisibilityState === Window.Maximized) {
mainWindow.showMaximized();
}
}
}
}

Shortcut {
enabled: Qt.platform.os !== "android" && Qt.platform.os !== "ios"
sequence: "F12"
onActivated: {
mainWindow.sceneBorderless = !mainWindow.sceneBorderless;
if (mainWindow.sceneBorderless) {
displayToast(qsTr("Borderless mode activated, use the top left and botom right corner to move and resize the window"));
}
}
}

Shortcut {
enabled: keyHandler.focus
sequence: "Ctrl+K"
onActivated: {
locatorItem.state = "on";
}
}

Shortcut {
enabled: true
sequence: "Ctrl+M"
onActivated: {
activateMeasurementMode();
}
}

Shortcut {
enabled: keyHandler.focus || welcomeScreen.focus
sequence: "Ctrl+O"
onActivated: {
welcomeScreen.openLocalDataPicker();
}
}

Shortcut {
enabled: projectInfo.insertRights
sequence: "Ctrl++"
onActivated: {
mainWindow.toggleDigitizeMode();
}
}

Shortcut {
enabled: keyHandler.focus && stateMachine.state === "digitize"
sequence: "Ctrl+Space"
onActivated: {
digitizingToolbar.triggerAddVertex();
}
}

//currentRubberband provides the rubberband depending on the current state (digitize or measure)
property Rubberband currentRubberband
property LayerObserver layerObserverAlias: layerObserver
property QgsGpkgFlusher gpkgFlusherAlias: gpkgFlusher

signal closeMeasureTool
signal changeMode(string mode)
signal toggleDigitizeMode

Item {
id: stateMachine
Expand Down Expand Up @@ -192,6 +250,18 @@ ApplicationWindow {
state: "browse"
}

onToggleDigitizeMode: {
if (stateMachine.state === "digitize") {
if (digitizingToolbar.rubberbandModel && digitizingToolbar.rubberbandModel.vertexCount > 1) {
displayToast(qsTr("Finish or dimiss the digitizing feature before toggling to browse mode"));
} else {
changeMode("browse");
}
} else {
changeMode("digitize");
}
}

onChangeMode: mode => {
if (stateMachine.state === mode)
return;
Expand Down Expand Up @@ -2248,12 +2318,12 @@ ApplicationWindow {
mapSettings: mapCanvas.mapSettings
interactive: !welcomeScreen.visible && !qfieldSettings.visible && !qfieldCloudScreen.visible && !qfieldLocalDataPickerScreen.visible && !codeReader.visible && !screenLocker.enabled

onOpenedChanged: {
if (!opened) {
if (featureForm.visible) {
featureForm.focus = true;
}
}
onAboutToShow: {
dashBoard.contentItem.forceActiveFocus();
}

onClosed: {
focusstack.forceActiveFocusOnLastTaker();
}

function ensureEditableLayerSelected() {
Expand Down Expand Up @@ -4213,7 +4283,7 @@ ApplicationWindow {
standardButtons: Dialog.Ok | Dialog.Cancel
onAccepted: {
featureForm.state = "Hidden";
activateMeasurementMode();
mentMode();
}
onDiscarded: {
cancelAlgorithmDialog.visible = false;
Expand Down Expand Up @@ -4269,4 +4339,40 @@ ApplicationWindow {
settings.setValue("/QField/showMapCanvasGuide", false);
}
}

Rectangle {
anchors.top: parent.top
anchors.left: parent.left

width: 14
height: 14
color: "transparent"

MouseArea {
enabled: mainWindow.sceneBorderless
anchors.fill: parent
cursorShape: enabled ? Qt.DragMoveCursor : Qt.ArrowCursor
onPressed: mouse => {
mainWindow.startSystemMove();
}
}
}

Rectangle {
anchors.bottom: parent.bottom
anchors.right: parent.right

width: 14
height: 14
color: "transparent"

MouseArea {
enabled: mainWindow.sceneBorderless
anchors.fill: parent
cursorShape: enabled ? Qt.SizeFDiagCursor : Qt.ArrowCursor
onPressed: mouse => {
mainWindow.startSystemResize(Qt.RightEdge | Qt.BottomEdge);
}
}
}
}

1 comment on commit 4be990c

@qfield-fairy
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.