Skip to content

Commit

Permalink
Merge pull request #239 from cneben/f/#238-group-header-layout
Browse files Browse the repository at this point in the history
F/#238 group header layout
  • Loading branch information
cneben authored Aug 12, 2024
2 parents c0a19f2 + 1814e15 commit c7396e2
Show file tree
Hide file tree
Showing 28 changed files with 301 additions and 227 deletions.
18 changes: 9 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ add_subdirectory(src)

option(QUICK_QANAVA_BUILD_SAMPLES "Build QuickQanava samples" OFF)
if (${QUICK_QANAVA_BUILD_SAMPLES})
add_subdirectory(samples/advanced)
add_subdirectory(samples/connector)
add_subdirectory(samples/cpp)
add_subdirectory(samples/dataflow)
add_subdirectory(samples/edges)
#add_subdirectory(samples/advanced)
#add_subdirectory(samples/connector)
#add_subdirectory(samples/cpp)
#add_subdirectory(samples/dataflow)
#add_subdirectory(samples/edges)
add_subdirectory(samples/groups)
add_subdirectory(samples/navigable)
#add_subdirectory(samples/navigable)
add_subdirectory(samples/nodes)
add_subdirectory(samples/selection)
add_subdirectory(samples/style)
add_subdirectory(samples/topology)
#add_subdirectory(samples/selection)
#add_subdirectory(samples/style)
#add_subdirectory(samples/topology)
endif()
2 changes: 1 addition & 1 deletion src/Edge.qml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Qan.EdgeItem {
id: edgeItem

// Private hack for visual connector edge color dynamic modification
property color color: style ? style.lineColor : Qt.rgba(0.,0.,0.,1.)
property color color: style?.lineColor ?? Qt.rgba(0.,0.,0.,1.)
Qan.EdgeTemplate {
anchors.fill: parent
edgeItem: parent
Expand Down
8 changes: 2 additions & 6 deletions src/EdgeCurvedPath.qml
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,10 @@ ShapePath {
startX: edgeItem.p1.x
startY: edgeItem.p1.y
capStyle: ShapePath.FlatCap
strokeWidth: edgeItem &&
edgeItem.style ? edgeItem.style.lineWidth :
2
strokeWidth: edgeItem?.style?.lineWidth ?? 2
strokeColor: edgeTemplate.color
strokeStyle: edgeTemplate.dashed
dashPattern: edgeItem &&
edgeItem.style ? edgeItem.style.dashPattern :
[4, 2]
dashPattern: edgeItem?.style?.dashPattern ?? [4, 2]
fillColor: Qt.rgba(0,0,0,0)
PathCubic {
x: edgeItem.p2.x
Expand Down
3 changes: 1 addition & 2 deletions src/EdgeDstArrowPath.qml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ ShapePath {
strokeWidth: 2 // Fix to 2 to have "non sharp" edges
// Adding lineWidth / 2. to vertices A1 (base top) and A3 (base bottom) to take into
// account lineWidth in arrowLength
readonly property real lineWidth: edgeItem?.style ? edgeItem.style.lineWidth / 2. :
1
readonly property real lineWidth: edgeItem?.style?.lineWidth / 2. ?? 1
startX: edgeItem ? edgeItem.dstA1.x : 0
startY: edgeItem ? edgeItem.dstA1.y - lineWidth: 0
PathLine {
Expand Down
5 changes: 1 addition & 4 deletions src/EdgeDstCirclePath.qml
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ ShapePath {
return Qt.rgba(0.,0.,0.,0.);
return edgeTemplate ? edgeTemplate.color : Qt.rgba(0,0,0,1)
}
strokeWidth: edgeItem &&
edgeItem.style ? edgeItem.style.lineWidth :
2

strokeWidth: edgeItem?.style?.lineWidth ?? 2
startX: 0
startY: 0
PathArc {
Expand Down
3 changes: 1 addition & 2 deletions src/EdgeDstRectPath.qml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ ShapePath {
strokeColor: edgeTemplate.color
fillColor: edgeItem.dstShape === Qan.EdgeStyle.RectOpen ? Qt.rgba(0.,0.,0.,0.) :
edgeTemplate.color
strokeWidth: edgeItem.style ? edgeItem.style.lineWidth :
2
strokeWidth: edgeItem?.style?.lineWidth ?? 2

startX: edgeItem.dstA1.x
startY: edgeItem.dstA1.y
Expand Down
6 changes: 2 additions & 4 deletions src/EdgeOrthoPath.qml
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,10 @@ ShapePath {
startX: edgeItem.p1.x
startY: edgeItem.p1.y
capStyle: ShapePath.FlatCap
strokeWidth: edgeItem &&
edgeItem.style ? edgeItem.style.lineWidth :
2
strokeWidth: edgeItem?.style?.lineWidth ?? 2
strokeColor: edgeTemplate.color
strokeStyle: edgeTemplate.dashed
dashPattern: edgeItem.style ? edgeItem.style.dashPattern : [4, 2]
dashPattern: edgeItem?.style?.dashPattern ?? [4, 2]
fillColor: Qt.rgba(0,0,0,0)
PathLine {
x: edgeItem.c1.x
Expand Down
3 changes: 1 addition & 2 deletions src/EdgeSrcArrowPath.qml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ ShapePath {
fillColor: edgeItem &&
edgeItem.srcShape === Qan.EdgeStyle.ArrowOpen ? Qt.rgba(0.,0.,0.,0.) :
edgeTemplate.color
strokeWidth: edgeItem.style ? edgeItem.style.lineWidth :
2
strokeWidth: edgeItem?.style?.lineWidth ?? 2
startX: edgeItem.srcA1.x
startY: edgeItem.srcA1.y
PathLine { x: edgeItem.srcA3.x; y: edgeItem.srcA3.y }
Expand Down
3 changes: 1 addition & 2 deletions src/EdgeSrcCirclePath.qml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ ShapePath {
strokeColor: edgeTemplate.color
fillColor: edgeItem.srcShape === Qan.EdgeStyle.CircleOpen ? Qt.rgba(0.,0.,0.,0.) :
edgeTemplate.color
strokeWidth: edgeItem.style ? edgeItem.style.lineWidth :
2
strokeWidth: edgeItem?.style?.lineWidth ?? 2

startX: 0
startY: 0
Expand Down
4 changes: 1 addition & 3 deletions src/EdgeSrcRectPath.qml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ ShapePath {
fillColor: edgeItem &&
edgeItem.srcShape === Qan.EdgeStyle.RectOpen ? Qt.rgba(0.,0.,0.,0.) :
edgeTemplate.color
strokeWidth: edgeItem &&
edgeItem.style ? edgeItem.style.lineWidth :
2
strokeWidth: edgeItem?.style?.lineWidth ?? 2

startX: edgeItem.srcA1.x
startY: edgeItem.srcA1.y
Expand Down
8 changes: 2 additions & 6 deletions src/EdgeStraightPath.qml
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,10 @@ ShapePath {
startX: edgeItem.p1.x
startY: edgeItem.p1.y
capStyle: ShapePath.FlatCap
strokeWidth: edgeItem &&
edgeItem.style ? edgeItem.style.lineWidth :
2
strokeWidth: edgeItem?.style?.lineWidth ?? 2
strokeColor: edgeTemplate.color
strokeStyle: edgeTemplate.dashed
dashPattern: edgeItem &&
edgeItem.style ? edgeItem.style.dashPattern :
[2, 2]
dashPattern: edgeItem?.style?.dashPattern ?? [2, 2]
fillColor: Qt.rgba(0,0,0,0)
PathLine {
x: edgeItem.p2.x
Expand Down
9 changes: 4 additions & 5 deletions src/EdgeTemplate.qml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ Item {
id: edgeTemplate
property var edgeItem: undefined

property color color: edgeItem &&
edgeItem.style ? edgeItem.style.lineColor : Qt.rgba(0.,0.,0.,1.)
property color color: edgeItem?.style?.lineColor ?? Qt.rgba(0.,0.,0.,1.)
// Allow direct bypass of style
property var lineType: edgeItem.style ? edgeItem.style.lineType : Qan.EdgeStyle.Straight
property var dashed : edgeItem.style && style.dashed ? ShapePath.DashLine : ShapePath.SolidLine
property var lineType: edgeItem?.style?.lineType ?? Qan.EdgeStyle.Straight
property var dashed : edgeItem?.style?.dashed ? ShapePath.DashLine : ShapePath.SolidLine

visible: edgeItem.visible && !edgeItem.hidden

Expand Down Expand Up @@ -139,7 +138,7 @@ Item {
property var straightLine : undefined
property var orthoLine : undefined
property var lineType: edgeTemplate.lineType
property var lineWidth: edgeItem && edgeItem.style ? edgeItem.style.lineWidth + 2. : 4.
property var lineWidth: edgeItem?.style?.lineWidth + 2. ?? 4.
property var lineColor: edgeItem &&
edgeItem.graph ? edgeItem.graph.selectionColor :
Qt.rgba(0.1176, 0.5647, 1., 1.) // dodgerblue=rgb(30, 144, 255)
Expand Down
15 changes: 3 additions & 12 deletions src/Group.qml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import QtQuick.Layouts
import QuickQanava 2.0 as Qan
import "qrc:/QuickQanava" as Qan

//! \brief Default delegate for `qan::GroupItem`.
Qan.GroupItem {
id: groupItem

Expand All @@ -46,23 +47,13 @@ Qan.GroupItem {
height: 150

default property alias children : template
container: template.content // See qan::GroupItem::container property documentation

//! Show or hide group top left label editor (default to visible).
property alias labelEditorVisible : template.labelEditorVisible

//! Show or hide group top left expand button (default to visible).
property alias expandButtonVisible : template.expandButtonVisible
container: template.container // See qan::GroupItem::container property documentation
labelEditorVisible: template.labelEditorVisible

Qan.RectGroupTemplate {
id: template
anchors.fill: parent
groupItem: parent
z: 1
}

// Emitted by qan::GroupItem when node dragging start
onNodeDragEnter: { template.onNodeDragEnter() }
// Emitted by qan::GroupItem when node dragging ends
onNodeDragLeave: { template.onNodeDragLeave() }
}
10 changes: 6 additions & 4 deletions src/LabelEditor.qml
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ Loader {
//! Editor target node or group (or any Qan primitive with a \c label property).
property var target: undefined

property bool bold: false
property real pixelSize: 12
property real fontPixelSize: 11

onVisibleChanged: {
if (visible && !item)
Expand Down Expand Up @@ -101,8 +100,8 @@ Loader {
anchors.left: parent.left
anchors.right: parent.right
text: target ? target.label : ""
font.bold: labelEditorLoader.bold
font.pixelSize: labelEditorLoader.pixelSize
font.bold: false
font.pixelSize: 22
onAccepted: {
if (target &&
text.length !== 0)
Expand All @@ -115,6 +114,9 @@ Loader {
text !== target.label) // Ensure that last edition text is removed
text = target.label // for exemple if edition has been interrupted in a focus change
}
background: Rectangle {
color: Qt.rgba(0., 0., 0., 0.) // Disable editor background
}
Keys.onEscapePressed: {
// Cancel edition on escape
labelEditorLoader.visible = false;
Expand Down
10 changes: 3 additions & 7 deletions src/RectGlowEffect.qml
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,15 @@ Item {
property var style: undefined

// PRIVATE ////////////////////////////////////////////////////////////////
// Default settings for rect radius, shadow margin is the _maximum_ shadow radius (+vertical or horizontal offset).
readonly property real glowRadius: style ? style.effectRadius : 3.
readonly property color glowColor: style ? style.effectColor : Qt.rgba(0.7, 0.7, 0.7, 0.7)
readonly property real borderWidth: style ? style.borderWidth : 1.
readonly property real borderWidth2: borderWidth / 2.
readonly property real backRadius: style ? style.backRadius : 4.
readonly property real glowRadius: style?.effectRadius ?? 3.
readonly property real backRadius: style?.backRadius ?? 4.

Rectangle { // Hidden item used to generate shadow
id: border
anchors.fill: parent
anchors.margins: 1
radius: backRadius
color: glowColor
color: style?.effectColor ?? Qt.rgba(0.7, 0.7, 0.7, 0.7)
clip: true
visible: false
}
Expand Down
26 changes: 13 additions & 13 deletions src/RectGradientBackground.qml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

import QtQuick

import QuickQanava 2.0 as Qan
import QuickQanava 2.0 as Qan
import "qrc:/QuickQanava" as Qan

/*! \brief Node or group background component with gradient fill, no effect and backOpacity style support
Expand All @@ -43,13 +43,7 @@ import "qrc:/QuickQanava" as Qan
Item {
// PUBLIC /////////////////////////////////////////////////////////////////
property var style: undefined

property real backRadius: style ? style.backRadius : 4.
readonly property real backOpacity: style ? style.backOpacity : 0.8
readonly property color baseColor: style ? style.baseColor: Qt.rgba(0., 0., 0., 0.)
readonly property color backColor: style ? style.backColor : Qt.rgba(0., 0., 0., 0.)
readonly property real borderWidth: style ? style.borderWidth : 1.
readonly property color borderColor: style ? style.borderColor : Qt.rgba(1., 1., 1., 0.)
property real backRadius: style?.backRadius ?? 4.

// PRIVATE ////////////////////////////////////////////////////////////////
// Note: Top level item is used to isolate rendering of:
Expand All @@ -62,22 +56,28 @@ Item {
anchors.fill: parent
radius: backRadius
border.width: 0 // Do not draw border, just the background gradient (border is drawn in foreground)
opacity: backOpacity
opacity: style?.backOpacity ?? 0.8

// Note 20240105: Unfortunately we no longer have LinearGradient with Qt6, switching to a
// vertical gradient...
gradient: Gradient {
GradientStop { position: 0.0; color: baseColor }
GradientStop { position: 1.0; color: backColor }
GradientStop {
position: 0.0;
color: style?.baseColor ?? Qt.rgba(0., 0., 0., 0.)
}
GradientStop {
position: 1.0
color: style?.backColor ?? Qt.rgba(0., 0., 0., 0.)
}
}
}
Rectangle {
id: foreground
anchors.fill: parent // Background follow the content layout implicit size
radius: backRadius
color: Qt.rgba(0, 0, 0, 0) // Fully transparent
border.color: borderColor
border.width: borderWidth
border.color: style?.borderColor ?? Qt.rgba(1., 1., 1., 0.)
border.width: style?.borderWidth ?? 1.
antialiasing: true // Vertex antialiasing for borders
// Note: Do not enable layer to avoid aliasing at high scale
}
Expand Down
Loading

0 comments on commit c7396e2

Please sign in to comment.