|
| 1 | +/* |
| 2 | + Copyright (c) 2008-2022, Benoit AUTHEMAN All rights reserved. |
| 3 | +
|
| 4 | + Redistribution and use in source and binary forms, with or without |
| 5 | + modification, are permitted provided that the following conditions are met: |
| 6 | + * Redistributions of source code must retain the above copyright |
| 7 | + notice, this list of conditions and the following disclaimer. |
| 8 | + * Redistributions in binary form must reproduce the above copyright |
| 9 | + notice, this list of conditions and the following disclaimer in the |
| 10 | + documentation and/or other materials provided with the distribution. |
| 11 | + * Neither the name of the author or Destrat.io nor the |
| 12 | + names of its contributors may be used to endorse or promote products |
| 13 | + derived from this software without specific prior written permission. |
| 14 | +
|
| 15 | + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 16 | + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 17 | + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 18 | + DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY |
| 19 | + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 20 | + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 21 | + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 22 | + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 | + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 24 | + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 | +*/ |
| 26 | + |
| 27 | +import QtQuick.Window 2.2 |
| 28 | +import QtQuick 2.13 |
| 29 | + |
| 30 | +import QtQuick.Controls 2.13 |
| 31 | + |
| 32 | +import QtQuick.Layouts 1.3 |
| 33 | +import QtQuick.Controls.Material 2.1 |
| 34 | +import QtQuick.Shapes 1.0 |
| 35 | + |
| 36 | +import QuickQanava 2.0 as Qan |
| 37 | +import "qrc:/QuickQanava" as Qan |
| 38 | + |
| 39 | +ApplicationWindow { |
| 40 | + id: window |
| 41 | + visible: true |
| 42 | + width: 1280 |
| 43 | + height: 720 // MPEG - 2 HD 720p - 1280 x 720 16:9 |
| 44 | + title: "Tools test" |
| 45 | + Pane { |
| 46 | + anchors.fill: parent |
| 47 | + padding: 0 |
| 48 | + } |
| 49 | + |
| 50 | + function centerItem(item) { |
| 51 | + if (!item || !window.contentItem) |
| 52 | + return |
| 53 | + var windowCenter = Qt.point( |
| 54 | + (window.contentItem.width - item.width) / 2., |
| 55 | + (window.contentItem.height - item.height) / 2.) |
| 56 | + var graphNodeCenter = window.contentItem.mapToItem( |
| 57 | + graphView.containerItem, windowCenter.x, windowCenter.y) |
| 58 | + item.x = graphNodeCenter.x |
| 59 | + item.y = graphNodeCenter.y |
| 60 | + } |
| 61 | + |
| 62 | + Qan.GraphView { |
| 63 | + id: graphView |
| 64 | + anchors.fill: parent |
| 65 | + graph: topology |
| 66 | + navigable: true |
| 67 | + resizeHandlerColor: Material.accent |
| 68 | + gridThickColor: Material.theme === Material.Dark ? "#4e4e4e" : "#c1c1c1" |
| 69 | + |
| 70 | + Qan.Graph { |
| 71 | + id: topology |
| 72 | + objectName: "graph" |
| 73 | + anchors.fill: parent |
| 74 | + clip: true |
| 75 | + connectorEnabled: true |
| 76 | + selectionColor: Material.accent |
| 77 | + connectorColor: Material.accent |
| 78 | + connectorEdgeColor: Material.accent |
| 79 | + onConnectorEdgeInserted: edge => { |
| 80 | + //if (edge) |
| 81 | + // edge.label = "My edge" |
| 82 | + } |
| 83 | + property Component faceNodeComponent: Qt.createComponent("qrc:/FaceNode.qml") |
| 84 | + |
| 85 | + Component.onCompleted: { |
| 86 | + var n1 = topology.insertNode() |
| 87 | + n1.label = "n1" |
| 88 | + |
| 89 | + var n2 = topology.insertNode() |
| 90 | + n2.label = "n2" |
| 91 | + n2.item.x = 150 |
| 92 | + n2.item.y = 55 |
| 93 | + |
| 94 | + graphView.centerOnPosition(Qt.point(0, 0)); |
| 95 | + } |
| 96 | + } // Qan.Graph: graph |
| 97 | + } |
| 98 | + |
| 99 | + Qan.GraphPreview { |
| 100 | + id: graphPreview |
| 101 | + source: graphView |
| 102 | + viewWindowColor: Material.accent |
| 103 | + anchors.right: graphView.right |
| 104 | + anchors.bottom: graphView.bottom |
| 105 | + anchors.rightMargin: 8 |
| 106 | + anchors.bottomMargin: 8 |
| 107 | + width: previewMenu.mediumPreview.width |
| 108 | + height: previewMenu.mediumPreview.height |
| 109 | + Menu { |
| 110 | + id: previewMenu |
| 111 | + readonly property size smallPreview: Qt.size(150, 85) |
| 112 | + readonly property size mediumPreview: Qt.size(250, 141) |
| 113 | + readonly property size largePreview: Qt.size(350, 198) |
| 114 | + MenuItem { |
| 115 | + text: "Hide preview" |
| 116 | + onTriggered: graphPreview.visible = false |
| 117 | + } |
| 118 | + MenuSeparator { } |
| 119 | + MenuItem { |
| 120 | + text: qsTr('Small') |
| 121 | + checkable: true |
| 122 | + checked: graphPreview.width === previewMenu.smallPreview.width && |
| 123 | + graphPreview.height === previewMenu.smallPreview.height |
| 124 | + onTriggered: { |
| 125 | + graphPreview.width = previewMenu.smallPreview.width |
| 126 | + graphPreview.height = previewMenu.smallPreview.height |
| 127 | + } |
| 128 | + } |
| 129 | + MenuItem { |
| 130 | + text: qsTr('Medium') |
| 131 | + checkable: true |
| 132 | + checked: graphPreview.width === previewMenu.mediumPreview.width && |
| 133 | + graphPreview.height === previewMenu.mediumPreview.height |
| 134 | + onTriggered: { |
| 135 | + graphPreview.width = previewMenu.mediumPreview.width |
| 136 | + graphPreview.height = previewMenu.mediumPreview.height |
| 137 | + } |
| 138 | + } |
| 139 | + MenuItem { |
| 140 | + text: qsTr('Large') |
| 141 | + checkable: true |
| 142 | + checked: graphPreview.width === previewMenu.largePreview.width && |
| 143 | + graphPreview.height === previewMenu.largePreview.height |
| 144 | + onTriggered: { |
| 145 | + graphPreview.width = previewMenu.largePreview.width |
| 146 | + graphPreview.height = previewMenu.largePreview.height |
| 147 | + } |
| 148 | + } |
| 149 | + } |
| 150 | + MouseArea { |
| 151 | + anchors.fill: parent |
| 152 | + acceptedButtons: Qt.RightButton |
| 153 | + onClicked: previewMenu.open(mouse.x, mouse.y) |
| 154 | + } |
| 155 | + } |
| 156 | + |
| 157 | + Qan.HeatMapPreview { |
| 158 | + id: heatMapPreview |
| 159 | + anchors.left: graphView.left |
| 160 | + anchors.bottom: graphView.bottom |
| 161 | + source: graphView |
| 162 | + viewWindowColor: Material.accent |
| 163 | + Menu { |
| 164 | + id: heatMapMenu |
| 165 | + MenuItem { |
| 166 | + text: qsTr("Clear heat map") |
| 167 | + onClicked: heatMapPreview.clearHeatMap() |
| 168 | + } |
| 169 | + MenuItem { |
| 170 | + text: qsTr("Increase preview size") |
| 171 | + onTriggered: { |
| 172 | + heatMapPreview.width *= 1.15 |
| 173 | + heatMapPreview.height *= 1.15 |
| 174 | + } |
| 175 | + } |
| 176 | + MenuItem { |
| 177 | + text: qsTr("Decrease preview size") |
| 178 | + onTriggered: { |
| 179 | + heatMapPreview.width *= Math.max(50, heatMapPreview.width * 0.85) |
| 180 | + heatMapPreview.height *= Math.max(50, heatMapPreview.height * 0.85) |
| 181 | + } |
| 182 | + } |
| 183 | + } |
| 184 | + MouseArea { |
| 185 | + anchors.fill: parent |
| 186 | + acceptedButtons: Qt.RightButton; preventStealing: true |
| 187 | + onClicked: { |
| 188 | + if (mouse.button === Qt.RightButton) { |
| 189 | + heatMapMenu.x = mouse.x |
| 190 | + heatMapMenu.y = mouse.y |
| 191 | + heatMapMenu.open() |
| 192 | + } |
| 193 | + } |
| 194 | + } |
| 195 | + } // Qan.HeatMapPreview |
| 196 | +} // ApplicationWindow |
0 commit comments