Files
Flora/qml/panels/FormatToolbar.qml
T

150 lines
5.4 KiB
QML
Raw Normal View History

import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
// Панель быстрого форматирования текста (видна в режиме редактирования).
// Работает с выделенным текстом в активной панели (targetPane).
Item {
id: toolbar
property var targetPane: null // EditorPane
readonly property bool usable: targetPane && targetPane.docIndex >= 0
signal tableRequested()
implicitHeight: 34
Rectangle {
anchors.fill: parent
color: "#f3f3f3"
border.color: "#ddd"
RowLayout {
anchors.fill: parent
anchors.leftMargin: 4
anchors.rightMargin: 4
spacing: 2
TbButton { text: "B"; tip: qsTr("Жирный"); onTapped: targetPane.applyInline("**", "**") }
TbButton { text: "I"; tip: qsTr("Курсив"); onTapped: targetPane.applyInline("*", "*") }
TbButton { text: "U"; tip: qsTr("Подчёркнутый"); onTapped: targetPane.applyInline("<u>", "</u>") }
TbButton { text: "S"; tip: qsTr("Зачёркнутый"); onTapped: targetPane.applyInline("~~", "~~") }
TbButton { text: "=="; tip: qsTr("Выделение текста"); onTapped: targetPane.applyInline("==", "==") }
TbButton {
text: "A"
tip: qsTr("Цвет текста")
bold: true
onTapped: { colorPopup.highlightMode = false; colorPopup.openAt(this) }
}
TbButton {
text: "A"
tip: qsTr("Цвет выделения")
accent: true
onTapped: { colorPopup.highlightMode = true; colorPopup.openAt(this) }
}
TbButton { text: "x²"; tip: qsTr("Верхний индекс"); onTapped: targetPane.applySubSup("sup") }
TbButton { text: "x₂"; tip: qsTr("Нижний индекс"); onTapped: targetPane.applySubSup("sub") }
Item { width: 6 }
Rectangle { width: 1; height: 20; color: "#ccc" }
Item { width: 6 }
TbButton { text: "H#"; tip: qsTr("Заголовок 1–6"); onTapped: headingMenu.popup() }
TbButton { text: "☰"; tip: qsTr("Списки"); onTapped: listMenu.popup() }
TbButton { text: "❝"; tip: qsTr("Цитата"); onTapped: targetPane.applyLinePrefix("> ") }
TbButton { text: "⚠"; tip: qsTr("Выноска"); onTapped: calloutMenu.popup() }
TbButton { text: "▦"; tip: qsTr("Таблица"); onTapped: toolbar.tableRequested() }
TbButton { text: "⊡"; tip: qsTr("Обтекание картинки/таблицы"); onTapped: targetPane.applyFloatWrap() }
Item { Layout.fillWidth: true }
}
}
// ---------- Меню: заголовки ----------
Menu {
id: headingMenu
title: qsTr("Заголовок")
Repeater {
model: [1, 2, 3, 4, 5, 6]
MenuItem {
text: "H" + modelData + " — " + "######".slice(0, modelData)
onClicked: targetPane.applyHeading(modelData)
}
}
}
// ---------- Меню: списки ----------
Menu {
id: listMenu
title: qsTr("Список")
MenuItem {
text: qsTr("Маркированный")
onClicked: targetPane.applyLinePrefix("- ")
}
MenuItem {
text: qsTr("Нумерованный")
onClicked: targetPane.applyLinePrefix("1. ")
}
MenuItem {
text: qsTr("Задачи (- [ ])")
onClicked: targetPane.applyTaskToggle()
}
}
// ---------- Меню: выноски ----------
Menu {
id: calloutMenu
title: qsTr("Выноска")
Repeater {
model: ["NOTE", "INFO", "WARN", "ERROR"]
MenuItem {
text: modelData
onClicked: targetPane.applyCallout(modelData)
}
}
}
// ---------- Палитра цветов ----------
property var colorList: [
"#000000", "#ffffff", "#9e9e9e", "#795548", "#607d8b",
"#f44336", "#ff9800", "#ffeb3b", "#4caf50", "#00bcd4",
"#2196f3", "#3f51b5", "#9c27b0", "#e91e63"
]
Popup {
id: colorPopup
property bool highlightMode: false
function openAt(btn) {
x = btn.mapToItem(toolbar, 0, 0).x
y = btn.mapToItem(toolbar, 0, 0).y + btn.height
open()
}
width: grid.width + 12
height: grid.height + 12
Grid {
id: grid
anchors.centerIn: parent
columns: 7
spacing: 3
Repeater {
model: toolbar.colorList
delegate: Rectangle {
width: 22
height: 22
radius: 3
color: modelData
border.color: modelData === "#ffffff" ? "#bbb" : "transparent"
MouseArea {
anchors.fill: parent
onClicked: {
toolbar.targetPane.applyColor(modelData, colorPopup.highlightMode)
colorPopup.close()
}
}
}
}
}
}
}