Skip to content

Commit

Permalink
Add macOS specific Outline
Browse files Browse the repository at this point in the history
  • Loading branch information
timangus committed Oct 19, 2023
1 parent 25abc78 commit f588976
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

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(); }
}
}
1 change: 1 addition & 0 deletions source/shared/ui/shared.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<file>qml/app/graphia/Shared/Controls/ListTabView.qml</file>
<file>qml/app/graphia/Shared/Controls/NodeAttributeTableView.qml</file>
<file>qml/app/graphia/Shared/Controls/Outline.qml</file>
<file>qml/app/graphia/Shared/Controls/+macos/Outline.qml</file>
<file>qml/app/graphia/Shared/Controls/PlatformMenuItem.qml</file>
<file>qml/app/graphia/Shared/Controls/PlatformMenu.qml</file>
<file>qml/app/graphia/Shared/Controls/PlatformMenuBar.qml</file>
Expand Down

0 comments on commit f588976

Please sign in to comment.