Массовые исправления UX: вкладки (MouseArea не блокирует ×), контент редактора (onDocIndexChanged), авто-расширение .md, ошибка дубликата, ПКМ-создание внутри папок, точки в календаре, граф (зум колесом, клик по файлу, pan правой кнопкой), fileExists(), 16/16 тестов
This commit is contained in:
+50
-12
@@ -11,6 +11,9 @@ Canvas {
|
||||
|
||||
property var pos: ({}) // key -> {x,y}
|
||||
property string dragKey: ""
|
||||
property real zoom: 1.0
|
||||
property real panX: 0
|
||||
property real panY: 0
|
||||
|
||||
function nodeForKey(key) {
|
||||
for (let i = 0; i < nodes.length; ++i)
|
||||
@@ -21,13 +24,14 @@ Canvas {
|
||||
function relayout() {
|
||||
pos = {}
|
||||
const n = nodes.length
|
||||
if (n === 0) return
|
||||
if (n === 0) { requestPaint(); return }
|
||||
const cx = width / 2, cy = height / 2
|
||||
const rad = Math.min(width, height) / 2 - 30
|
||||
for (let i = 0; i < n; ++i) {
|
||||
const a = (i / n) * 2 * Math.PI - Math.PI / 2
|
||||
pos[nodes[i].key] = { x: cx + rad * Math.cos(a), y: cy + rad * Math.sin(a) }
|
||||
}
|
||||
zoom = 1.0; panX = 0; panY = 0
|
||||
requestPaint()
|
||||
}
|
||||
|
||||
@@ -35,13 +39,18 @@ Canvas {
|
||||
onWidthChanged: relayout()
|
||||
onHeightChanged: relayout()
|
||||
|
||||
onPaint: {
|
||||
function paintCanvas() {
|
||||
const ctx = getContext("2d")
|
||||
ctx.clearRect(0, 0, width, height)
|
||||
if (nodes.length === 0) return
|
||||
|
||||
ctx.save()
|
||||
ctx.translate(width / 2 + panX, height / 2 + panY)
|
||||
ctx.scale(zoom, zoom)
|
||||
ctx.translate(-width / 2, -height / 2)
|
||||
|
||||
// рёбра
|
||||
ctx.lineWidth = 1
|
||||
ctx.lineWidth = 1 / zoom
|
||||
ctx.strokeStyle = "#b9c6d6"
|
||||
for (let i = 0; i < edges.length; ++i) {
|
||||
const f = pos[edges[i].from]
|
||||
@@ -70,21 +79,34 @@ Canvas {
|
||||
ctx.lineWidth = 1
|
||||
ctx.stroke()
|
||||
ctx.fillStyle = "#5a6a7d"
|
||||
ctx.font = "9px sans-serif"
|
||||
const label = isFile ? nd.name : nd.name
|
||||
const txt = label.length > 14 ? label.substring(0, 13) + "…" : label
|
||||
ctx.fillText(txt, p.x, p.y + r + 10)
|
||||
ctx.font = (9 / zoom) + "px sans-serif"
|
||||
const txt = nd.name.length > 14 ? nd.name.substring(0, 13) + "…" : nd.name
|
||||
ctx.fillText(txt, p.x, p.y + r + 10 / zoom)
|
||||
}
|
||||
|
||||
ctx.restore()
|
||||
}
|
||||
|
||||
onPaint: paintCanvas()
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
||||
onWheel: (w) => {
|
||||
// Масштабирование колесом мыши
|
||||
const factor = w.angleDelta.y > 0 ? 1.15 : 0.87
|
||||
g.zoom = Math.max(0.2, Math.min(5.0, g.zoom * factor))
|
||||
g.requestPaint()
|
||||
}
|
||||
onPressed: (m) => {
|
||||
dragKey = ""
|
||||
// Переводим экранные координаты в координаты графа
|
||||
const gx = (m.x - width / 2 - panX) / zoom + width / 2
|
||||
const gy = (m.y - height / 2 - panY) / zoom + height / 2
|
||||
for (const key in g.pos) {
|
||||
const p = g.pos[key]
|
||||
const dx = m.x - p.x, dy = m.y - p.y
|
||||
if (dx * dx + dy * dy <= 144) { // радиус захвата 12px
|
||||
const dx = gx - p.x, dy = gy - p.y
|
||||
if (dx * dx + dy * dy <= 256) { // радиус захвата 16px
|
||||
dragKey = key
|
||||
break
|
||||
}
|
||||
@@ -92,16 +114,28 @@ Canvas {
|
||||
}
|
||||
onPositionChanged: (m) => {
|
||||
if (dragKey.length > 0 && g.pos[dragKey]) {
|
||||
g.pos[dragKey] = { x: m.x, y: m.y }
|
||||
const gx = (m.x - width / 2 - panX) / zoom + width / 2
|
||||
const gy = (m.y - height / 2 - panY) / zoom + height / 2
|
||||
g.pos[dragKey] = { x: gx, y: gy }
|
||||
g.requestPaint()
|
||||
} else if (m.buttons & Qt.RightButton) {
|
||||
// Перетаскивание фона (pan)
|
||||
panX += m.x - m.__lastX
|
||||
panY += m.y - m.__lastY
|
||||
g.requestPaint()
|
||||
}
|
||||
m.__lastX = m.x
|
||||
m.__lastY = m.y
|
||||
}
|
||||
onReleased: (m) => {
|
||||
if (dragKey.length === 0) {
|
||||
// Клик по узлу (открыть файл)
|
||||
const gx = (m.x - width / 2 - panX) / zoom + width / 2
|
||||
const gy = (m.y - height / 2 - panY) / zoom + height / 2
|
||||
for (const key in g.pos) {
|
||||
const p = g.pos[key]
|
||||
const dx = m.x - p.x, dy = m.y - p.y
|
||||
if (dx * dx + dy * dy <= 100) {
|
||||
const dx = gx - p.x, dy = gy - p.y
|
||||
if (dx * dx + dy * dy <= 144) {
|
||||
const nd = g.nodeForKey(key)
|
||||
if (nd && nd.type === "file")
|
||||
g.fileClicked(nd.key)
|
||||
@@ -111,5 +145,9 @@ Canvas {
|
||||
}
|
||||
dragKey = ""
|
||||
}
|
||||
onDoubleClicked: (m) => {
|
||||
// Двойной клик — сброс позиции/масштаба
|
||||
g.zoom = 1.0; g.panX = 0; g.panY = 0; g.relayout()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user