From f588976046c882a4ee4c1db03dd200530478a1fc Mon Sep 17 00:00:00 2001 From: Tim Angus Date: Thu, 19 Oct 2023 17:40:13 +0100 Subject: [PATCH] Add macOS specific Outline --- .../Shared/Controls/+macos/Outline.qml | 69 +++++++++++++++++++ source/shared/ui/shared.qrc | 1 + 2 files changed, 70 insertions(+) create mode 100644 source/shared/ui/qml/app/graphia/Shared/Controls/+macos/Outline.qml diff --git a/source/shared/ui/qml/app/graphia/Shared/Controls/+macos/Outline.qml b/source/shared/ui/qml/app/graphia/Shared/Controls/+macos/Outline.qml new file mode 100644 index 000000000..33bf582c6 --- /dev/null +++ b/source/shared/ui/qml/app/graphia/Shared/Controls/+macos/Outline.qml @@ -0,0 +1,69 @@ +/* Copyright © 2013-2023 Graphia Technologies Ltd. + * + * This file is part of Graphia. + * + * Graphia 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. + * + * Graphia 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 Graphia. If not, see . + */ + +import QtQuick + +import app.graphia +import app.graphia.Shared.Controls + +// The Rectangle based implementation of Outline can't render half pixel widths +// that you see on Retina displays, so on macOS we do it manually using a Canvas + +Canvas +{ + id: root + + property bool outlineVisible: true + readonly property real outlineWidth: outlineVisible ? 1 : 0 + property color color: ControlColors.outline + + clip: outlineVisible + + onPaint: function(rect) + { + let context = getContext("2d"); + context.clearRect(0, 0, width, height); + + if(!outlineVisible) + return; + + context.beginPath(); + + context.strokeStyle = root.color; + context.lineWidth = 1.0 / Screen.devicePixelRatio; + + context.moveTo(0, 0); + context.lineTo(width, 0); + context.lineTo(width, height); + context.lineTo(0, height); + context.lineTo(0, 0); + + context.closePath(); + + context.stroke(); + } + + onOutlineVisibleChanged: { requestPaint(); } + onColorChanged: { requestPaint(); } + PaletteChangeNotifier { onPaletteChanged: { parent.requestPaint(); } } + Connections + { + target: Screen + function onDevicePixelRatioChanged() { parent.requestPaint(); } + } +} diff --git a/source/shared/ui/shared.qrc b/source/shared/ui/shared.qrc index d1399dc67..9f5025a13 100644 --- a/source/shared/ui/shared.qrc +++ b/source/shared/ui/shared.qrc @@ -11,6 +11,7 @@ qml/app/graphia/Shared/Controls/ListTabView.qml qml/app/graphia/Shared/Controls/NodeAttributeTableView.qml qml/app/graphia/Shared/Controls/Outline.qml + qml/app/graphia/Shared/Controls/+macos/Outline.qml qml/app/graphia/Shared/Controls/PlatformMenuItem.qml qml/app/graphia/Shared/Controls/PlatformMenu.qml qml/app/graphia/Shared/Controls/PlatformMenuBar.qml