Newer
Older
/***************************************************************************************************
*
* Patro - A Python library to make patterns for fashion design
* Copyright (C) 2017 Fabrice Salvaire
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*
***************************************************************************************************/
import QtQuick 2.11
import QtQuick.Controls 2.4
import Patro 1.0
ApplicationWindow {
id: application_window
title: 'Patro'
visible: true
Component.onCompleted: {
console.info('ApplicationWindow.onCompleted')
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
menuBar: MenuBar {
Menu {
title: qsTr('&File')
Action { text: qsTr('&Open') }
MenuSeparator { }
Action {
text: qsTr('&Quit')
onTriggered: application_window.close()
}
}
Menu {
title: qsTr('&Help')
Action { text: qsTr('&About') }
}
}
header: ToolBar {
RowLayout {
anchors.fill: parent
ToolButton {
icon.source: 'qrc:/icons/36x36/settings-overscan-black.png'
onClicked: scene_view.fit_scene()
}
ToolButton {
icon.source: 'qrc:/icons/36x36/zoom-in-black.png'
onClicked: {
var zoom_factor = 1 + application_window.zoom_step/100
scene_view.zoom_at_center(scene_view.zoom*zoom_factor)
}
}
ToolButton {
icon.source: 'qrc:/icons/36x36/zoom-out-black.png'
onClicked: {
var zoom_factor = 1 - application_window.zoom_step/100
scene_view.zoom_at_center(scene_view.zoom*zoom_factor)
}
}
Item {
Layout.fillWidth: true
}
}
}
footer: ToolBar {
RowLayout {
anchors.fill: parent
Text {
id: position_label
text: ''
}
}
}
PaintedSceneItem {
id: scene_view
anchors.fill: parent
scene: application.scene
property real pan_speed: 1.5 // scale to speedup the mouse paning
property int pan_step: 10 // px
Keys.onLeftPressed: scene_view.pan_x_y(-pan_step, 0)
Keys.onRightPressed: scene_view.pan_x_y(pan_step, 0)
Keys.onDownPressed: scene_view.pan_x_y(0, -pan_step)
Keys.onUpPressed: scene_view.pan_x_y(0, pan_step)
function pan_x_y(dx, dy) {
var dxy = Qt.point(dx, dy)
acceptedButtons: Qt.LeftButton | Qt.MiddleButton | Qt.RightButton
// var point ???
property var mouse_start
Component.onCompleted: {
mouse_start = null
}
// onClicked: {
// if (mouse.button == Qt.LeftButton) {
// console.info('Mouse left', mouse.x, mouse.y)
// }
// }
if (mouse.button == Qt.LeftButton) {
// console.info('Mouse left', mouse.x, mouse.y)
var position = Qt.point(mouse.x, mouse.y)
scene_view.item_at(position)
}
else if (mouse.button == Qt.MiddleButton) {
// console.info('Mouse left', mouse.x, mouse.y)
mouse_start = Qt.point(mouse.x, mouse.y)
}
}
onReleased: {
mouse_start = null
// console.info('onPositionChanged', mouse.button, mouse_start)
var dx = (mouse.x - mouse_start.x)
var dy = (mouse_start.y - mouse.y)
dx *= scene_view.pan_speed
dy *= scene_view.pan_speed
mouse_start = Qt.point(mouse.x, mouse.y)
} else {
position_label.text = scene_view.format_coordinate(Qt.point(mouse.x, mouse.y))
}
onWheel: {
var direction = wheel.angleDelta.y > 0
// console.info('Mouse wheel', wheel.x, wheel.y, direction)
var zoom = scene_view.zoom
if (direction)
zoom *= 2
else
zoom /= 2
scene_view.zoom_at(Qt.point(wheel.x, wheel.y), zoom)
}