Warning, /network/neochat/src/qml/QuickFormatBar.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2022 James Graham <james.h.graham@protonmail.com>
0002 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0003 
0004 import QtQuick
0005 import QtQuick.Controls as QQC2
0006 import QtQuick.Layouts
0007 
0008 import org.kde.kirigami as Kirigami
0009 
0010 QQC2.Popup {
0011     id: root
0012 
0013     property var selectionStart
0014     property var selectionEnd
0015 
0016     signal formattingSelected(var format, int selectionStart, int selectionEnd)
0017 
0018     padding: 1
0019 
0020     contentItem: Flow {
0021         QQC2.ToolButton {
0022             icon.name: "format-text-bold"
0023             text: i18n("Bold")
0024             display: QQC2.AbstractButton.IconOnly
0025 
0026             onClicked: {
0027                 const format = {
0028                     start: "**",
0029                     end: "**",
0030                     extra: ""
0031                 };
0032                 formattingSelected(format, selectionStart, selectionEnd);
0033                 root.close();
0034             }
0035 
0036             QQC2.ToolTip.text: text
0037             QQC2.ToolTip.visible: hovered
0038             QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
0039         }
0040         QQC2.ToolButton {
0041             icon.name: "format-text-italic"
0042             text: i18n("Italic")
0043             display: QQC2.AbstractButton.IconOnly
0044 
0045             onClicked: {
0046                 const format = {
0047                     start: "*",
0048                     end: "*",
0049                     extra: ""
0050                 };
0051                 formattingSelected(format, selectionStart, selectionEnd);
0052                 root.close();
0053             }
0054 
0055             QQC2.ToolTip.text: text
0056             QQC2.ToolTip.visible: hovered
0057             QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
0058         }
0059         QQC2.ToolButton {
0060             icon.name: "format-text-strikethrough"
0061             text: i18n("Strikethrough")
0062             display: QQC2.AbstractButton.IconOnly
0063 
0064             onClicked: {
0065                 const format = {
0066                     start: "<del>",
0067                     end: "</del>",
0068                     extra: ""
0069                 };
0070                 formattingSelected(format, selectionStart, selectionEnd);
0071                 root.close();
0072             }
0073 
0074             QQC2.ToolTip.text: text
0075             QQC2.ToolTip.visible: hovered
0076             QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
0077         }
0078         QQC2.ToolButton {
0079             icon.name: "format-text-code"
0080             text: i18n("Code block")
0081             display: QQC2.AbstractButton.IconOnly
0082 
0083             onClicked: {
0084                 const format = {
0085                     start: "`",
0086                     end: "`",
0087                     extra: ""
0088                 };
0089                 formattingSelected(format, selectionStart, selectionEnd);
0090                 root.close();
0091             }
0092 
0093             QQC2.ToolTip.text: text
0094             QQC2.ToolTip.visible: hovered
0095             QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
0096         }
0097         QQC2.ToolButton {
0098             icon.name: "format-text-blockquote"
0099             text: i18n("Quote")
0100             display: QQC2.AbstractButton.IconOnly
0101 
0102             onClicked: {
0103                 const format = {
0104                     start: selectionStart == 0 ? ">" : "\n>",
0105                     end: "\n\n",
0106                     extra: ""
0107                 };
0108                 formattingSelected(format, selectionStart, selectionEnd);
0109                 root.close();
0110             }
0111 
0112             QQC2.ToolTip.text: text
0113             QQC2.ToolTip.visible: hovered
0114             QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
0115         }
0116         QQC2.ToolButton {
0117             icon.name: "link"
0118             text: i18n("Insert link")
0119             display: QQC2.AbstractButton.IconOnly
0120 
0121             onClicked: {
0122                 const format = {
0123                     start: "[",
0124                     end: "](",
0125                     extra: ")"
0126                 };
0127                 formattingSelected(format, selectionStart, selectionEnd);
0128                 root.close();
0129             }
0130 
0131             QQC2.ToolTip.text: text
0132             QQC2.ToolTip.visible: hovered
0133             QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
0134         }
0135     }
0136 }