Fix: EditorPanel переписан на anchors (tabBar → formatToolbar → editorArea) вместо ColumnLayout — SplitView теперь корректно задаёт высоту; вкладки сверху, тулбар под ними, редактор заполняет остаток

This commit is contained in:
Flora (opencode)
2026-08-17 18:22:56 +03:00
parent 8048b2be2f
commit aa2e157f5f
+34 -75
View File
@@ -2,10 +2,9 @@ import QtQuick
import QtQuick.Controls import QtQuick.Controls
import QtQuick.Layouts import QtQuick.Layouts
// Центральная панель: панель вкладок + редактор. // Центральная панель: вкладки сверху, тулбар, редактор заполняет остаток.
// Корень — ColumnLayout (без обёртки Item), чтобы SplitView корректно // Используем anchors вместо ColumnLayout — SplitView корректно работает с anchors.
// задавал размеры и вкладки были сверху, а редактор снизу. Item {
ColumnLayout {
id: root id: root
function baseName(p) { function baseName(p) {
@@ -19,31 +18,13 @@ ColumnLayout {
return primaryPane return primaryPane
} }
function toolbarShouldShow() { // ---------- Вкладки (сверху) ----------
const p = primaryPane
const s = secondaryPane
return p.editMode
|| (s.visible && s.editMode)
}
Connections {
target: primaryPane
function onActiveFocusChanged() { formatToolbar.targetPane = root.activePane() }
}
Connections {
target: secondaryPane
function onActiveFocusChanged() { formatToolbar.targetPane = root.activePane() }
}
TableEditor {
id: tableEditor
onMarkdownReady: (md) => root.activePane().insertText(md)
}
// ---------- Панель вкладок ----------
Rectangle { Rectangle {
Layout.fillWidth: true id: tabBar
implicitHeight: 32 anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
height: 32
color: "#ececec" color: "#ececec"
RowLayout { RowLayout {
@@ -54,8 +35,7 @@ ColumnLayout {
Repeater { Repeater {
model: documentManager.openTabs model: documentManager.openTabs
delegate: Rectangle {
Rectangle {
id: tab id: tab
required property string modelData required property string modelData
required property int index required property int index
@@ -70,13 +50,11 @@ ColumnLayout {
anchors.leftMargin: 8 anchors.leftMargin: 8
anchors.rightMargin: 2 anchors.rightMargin: 2
spacing: 4 spacing: 4
MouseArea { MouseArea {
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: true Layout.fillHeight: true
onClicked: documentManager.setActiveIndex(index) onClicked: documentManager.setActiveIndex(index)
onDoubleClicked: documentManager.closeTab(index) onDoubleClicked: documentManager.closeTab(index)
Label { Label {
id: tabLabel id: tabLabel
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
@@ -86,7 +64,6 @@ ColumnLayout {
color: tab.active ? "#111" : "#555" color: tab.active ? "#111" : "#555"
} }
} }
ToolButton { ToolButton {
text: "\u2715" text: "\u2715"
implicitWidth: 20 implicitWidth: 20
@@ -109,14 +86,12 @@ ColumnLayout {
} }
ToolButton { ToolButton {
id: splitBtn
text: "\u25A1\u25A1" text: "\u25A1\u25A1"
checkable: true checkable: true
checked: documentManager.sideBySide checked: documentManager.sideBySide
enabled: documentManager.openTabs.length > 0 enabled: documentManager.openTabs.length > 0
ToolTip.visible: hovered ToolTip.text: qsTr("Открыть рядом")
ToolTip.text: qsTr("Открыть рядом (две панели)") onClicked: {
onToggled: {
if (checked) { if (checked) {
documentManager.setSecondaryIndex(documentManager.activeIndex) documentManager.setSecondaryIndex(documentManager.activeIndex)
documentManager.setSideBySide(true) documentManager.setSideBySide(true)
@@ -128,22 +103,25 @@ ColumnLayout {
} }
} }
// ---------- Панель форматирования ---------- // ---------- Формат-тулбар (под вкладками) ----------
FormatToolbar { FormatToolbar {
id: formatToolbar id: formatToolbar
Layout.fillWidth: true anchors.top: tabBar.bottom
visible: documentManager.activeIndex >= 0 && toolbarShouldShow() anchors.left: parent.left
anchors.right: parent.right
height: 34
visible: documentManager.activeIndex >= 0
targetPane: activePane() targetPane: activePane()
onTableRequested: { onTableRequested: { tableEditor.resetDialog(); tableEditor.open() }
tableEditor.resetDialog()
tableEditor.open()
}
} }
// ---------- Область редактора (одна или две панели) ---------- // ---------- Редактор (заполняет остаток) ----------
RowLayout { RowLayout {
Layout.fillWidth: true id: editorArea
Layout.fillHeight: true anchors.top: formatToolbar.bottom
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
spacing: 0 spacing: 0
EditorPane { EditorPane {
@@ -154,7 +132,6 @@ ColumnLayout {
onOpenBeside: { onOpenBeside: {
documentManager.setSecondaryIndex(documentManager.activeIndex) documentManager.setSecondaryIndex(documentManager.activeIndex)
documentManager.setSideBySide(true) documentManager.setSideBySide(true)
splitBtn.checked = true
} }
} }
@@ -172,36 +149,18 @@ ColumnLayout {
Layout.maximumWidth: 640 Layout.maximumWidth: 640
docIndex: documentManager.secondaryIndex docIndex: documentManager.secondaryIndex
closable: true closable: true
onClosePane: { onClosePane: documentManager.setSideBySide(false)
documentManager.setSideBySide(false)
splitBtn.checked = false
}
} }
} }
TableEditor { id: tableEditor; onMarkdownReady: (md) => activePane().insertText(md) }
// ---------- Горячие клавиши ---------- // ---------- Горячие клавиши ----------
Shortcut { Shortcut { sequence: "Ctrl+S"; onActivated: documentManager.saveAll() }
sequence: "Ctrl+S" Shortcut { sequence: "Ctrl+W"; onActivated: documentManager.closeTab(documentManager.activeIndex) }
context: Qt.WindowShortcut Shortcut { sequence: "Ctrl+E"; onActivated: primaryPane.editMode = !primaryPane.editMode }
onActivated: documentManager.saveAll() Shortcut { sequence: "Ctrl+Tab"; onActivated: {
}
Shortcut {
sequence: "Ctrl+W"
context: Qt.WindowShortcut
onActivated: documentManager.closeTab(documentManager.activeIndex)
}
Shortcut {
sequence: "Ctrl+E"
context: Qt.WindowShortcut
onActivated: primaryPane.editMode = !primaryPane.editMode
}
Shortcut {
sequence: "Ctrl+Tab"
context: Qt.WindowShortcut
onActivated: {
const n = documentManager.openTabs.length const n = documentManager.openTabs.length
if (n > 0) if (n > 0) documentManager.setActiveIndex((documentManager.activeIndex + 1) % n)
documentManager.setActiveIndex((documentManager.activeIndex + 1) % n) }}
}
}
} }