Commit 5f43557e authored by camilo neon's avatar camilo neon
Browse files

fix editor context menu on long press

parent efdabffc
import QtQuick 2.10
import QtQuick.Controls 2.10
import QtQuick.Layouts 1.3
import org.kde.mauikit 1.0 as Maui
import org.kde.kirigami 2.7 as Kirigami
import "private"
/**
* Editor
* A text area for editing text with convinient functions.
* The Editor is controlled by the DocumentHandler which controls the files I/O,
* the syntax highlighting styles, and many more text editing properties.
*
*
*
*
*
*/
Maui.Page
{
id: control
Kirigami.Theme.inherit: false
Kirigami.Theme.colorSet: Kirigami.Theme.View
import QtQuick 2.10
import QtQuick.Controls 2.10
import QtQuick.Layouts 1.3
import org.kde.mauikit 1.0 as Maui
import org.kde.kirigami 2.7 as Kirigami
import "private"
/**
* showLineCount : bool
* If a small text tooltip should be visible at the editor right bottom area, displaying the
* number of count of lines and words.
*/
property bool showLineCount : true
/**
* showSyntaxHighlightingLanguages : bool
*/
property bool showSyntaxHighlightingLanguages: false
/**
* body : TextArea
* Access to the editor text area.
*/
property alias body : body
/**
* document : DocumentHandler
* The DocumentHandler
*/
property alias document : document
/**
* scrollView : ScrollablePage
*/
property alias scrollView: _scrollView
/**
* text : string
*/
property alias text: body.text
/**
* uppercase : bool
*/
property alias uppercase: document.uppercase
/**
* underline : bool
*/
property alias underline: document.underline
/**
* italic : bool
*/
property alias italic: document.italic
/**
* bold : bool
*/
property alias bold: document.bold
/**
* canRedo : bool
*/
property alias canRedo: body.canRedo
/**
* fileUrl : url
* If a file url is provided the DocumentHandler will try to open its contents and display it.
*/
property alias fileUrl : document.fileUrl
/**
* showLineNumbers : bool
* If a sidebar listing each line number should be visible.
*/
property bool showLineNumbers : false
focus: true
title: document.fileName
showTitle: false
flickable: _scrollView.flickable
Maui.DocumentHandler
{
id: document
document: body.textDocument
cursorPosition: body.cursorPosition
selectionStart: body.selectionStart
selectionEnd: body.selectionEnd
backgroundColor: control.Kirigami.Theme.backgroundColor
enableSyntaxHighlighting: false
}
Row
* Editor
* A text area for editing text with convinient functions.
* The Editor is controlled by the DocumentHandler which controls the files I/O,
* the syntax highlighting styles, and many more text editing properties.
*
*
*
*
*
*/
Maui.Page
{
z: _scrollView.z +1
visible: showLineCount
anchors
id: control
Kirigami.Theme.inherit: false
Kirigami.Theme.colorSet: Kirigami.Theme.View
/**
* showLineCount : bool
* If a small text tooltip should be visible at the editor right bottom area, displaying the
* number of count of lines and words.
*/
property bool showLineCount : true
/**
* showSyntaxHighlightingLanguages : bool
*/
property bool showSyntaxHighlightingLanguages: false
/**
* body : TextArea
* Access to the editor text area.
*/
property alias body : body
/**
* document : DocumentHandler
* The DocumentHandler
*/
property alias document : document
/**
* scrollView : ScrollablePage
*/
property alias scrollView: _scrollView
/**
* text : string
*/
property alias text: body.text
/**
* uppercase : bool
*/
property alias uppercase: document.uppercase
/**
* underline : bool
*/
property alias underline: document.underline
/**
* italic : bool
*/
property alias italic: document.italic
/**
* bold : bool
*/
property alias bold: document.bold
/**
* canRedo : bool
*/
property alias canRedo: body.canRedo
/**
* fileUrl : url
* If a file url is provided the DocumentHandler will try to open its contents and display it.
*/
property alias fileUrl : document.fileUrl
/**
* showLineNumbers : bool
* If a sidebar listing each line number should be visible.
*/
property bool showLineNumbers : false
focus: true
title: document.fileName
showTitle: false
flickable: _scrollView.flickable
Maui.DocumentHandler
{
right: parent.right
bottom: parent.bottom
margins: Maui.Style.space.big
id: document
document: body.textDocument
cursorPosition: body.cursorPosition
selectionStart: body.selectionStart
selectionEnd: body.selectionEnd
backgroundColor: control.Kirigami.Theme.backgroundColor
enableSyntaxHighlighting: false
}
width: implicitWidth
height: implicitHeight
Label
Row
{
text: body.length + " / " + body.lineCount
color: control.Kirigami.Theme.textColor
opacity: 0.5
}
}
Menu
{
id: documentMenu
z: 999
MenuItem
{
text: i18n("Copy")
onTriggered: body.copy()
enabled: body.selectedText.length
}
MenuItem
{
text: i18n("Cut")
onTriggered: body.cut()
enabled: !body.readOnly && body.selectedText.length
}
MenuItem
{
text: i18n("Paste")
onTriggered: body.paste()
enabled: !body.readOnly
}
MenuItem
{
text: i18n("Select All")
onTriggered: body.selectAll()
}
MenuItem
{
text: i18n("Search Selected Text on Google...")
onTriggered: Qt.openUrlExternally("https://www.google.com/search?q="+body.selectedText)
enabled: body.selectedText.length
}
}
headBar.visible: !body.readOnly
headBar.leftContent: [
Maui.ToolActions
{
expanded: true
autoExclusive: false
checkable: false
Action
{
icon.name: "edit-undo"
enabled: body.canUndo
onTriggered: body.undo()
}
Action
{
icon.name: "edit-redo"
enabled: body.canRedo
onTriggered: body.redo()
z: _scrollView.z +1
visible: showLineCount
anchors
{
right: parent.right
bottom: parent.bottom
margins: Maui.Style.space.big
}
width: implicitWidth
height: implicitHeight
Label
{
text: body.length + " / " + body.lineCount
color: control.Kirigami.Theme.textColor
opacity: 0.5
}
}
},
Maui.ToolActions
{
visible: (document.isRich || body.textFormat === Text.RichText) && !body.readOnly
expanded: true
autoExclusive: false
checkable: false
Action
Menu
{
icon.name: "format-text-bold"
checked: document.bold
onTriggered: document.bold = !document.bold
id: documentMenu
z: 999
MenuItem
{
text: i18n("Copy")
onTriggered: body.copy()
enabled: body.selectedText.length
}
MenuItem
{
text: i18n("Cut")
onTriggered: body.cut()
enabled: !body.readOnly && body.selectedText.length
}
MenuItem
{
text: i18n("Paste")
onTriggered: body.paste()
enabled: !body.readOnly
}
MenuItem
{
text: i18n("Select All")
onTriggered: body.selectAll()
}
MenuItem
{
text: i18n("Search Selected Text on Google...")
onTriggered: Qt.openUrlExternally("https://www.google.com/search?q="+body.selectedText)
enabled: body.selectedText.length
}
}
Action
headBar.visible: !body.readOnly
headBar.leftContent: [
Maui.ToolActions
{
icon.name: "format-text-italic"
checked: document.italic
onTriggered: document.italic = !document.italic
}
Action
expanded: true
autoExclusive: false
checkable: false
Action
{
icon.name: "edit-undo"
enabled: body.canUndo
onTriggered: body.undo()
}
Action
{
icon.name: "edit-redo"
enabled: body.canRedo
onTriggered: body.redo()
}
},
Maui.ToolActions
{
icon.name: "format-text-underline"
checked: document.underline
onTriggered: document.underline = !document.underline
visible: (document.isRich || body.textFormat === Text.RichText) && !body.readOnly
expanded: true
autoExclusive: false
checkable: false
Action
{
icon.name: "format-text-bold"
checked: document.bold
onTriggered: document.bold = !document.bold
}
Action
{
icon.name: "format-text-italic"
checked: document.italic
onTriggered: document.italic = !document.italic
}
Action
{
icon.name: "format-text-underline"
checked: document.underline
onTriggered: document.underline = !document.underline
}
Action
{
icon.name: "format-text-uppercase"
checked: document.uppercase
onTriggered: document.uppercase = !document.uppercase
}
}
Action
]
footBar.rightContent: ComboBox
{
icon.name: "format-text-uppercase"
checked: document.uppercase
onTriggered: document.uppercase = !document.uppercase
visible: control.showSyntaxHighlightingLanguages
model: document.getLanguageNameList()
currentIndex: -1
onCurrentIndexChanged: document.formatName = model[currentIndex]
}
}
]
footBar.rightContent: ComboBox
{
visible: control.showSyntaxHighlightingLanguages
model: document.getLanguageNameList()
currentIndex: -1
onCurrentIndexChanged: document.formatName = model[currentIndex]
}
ColumnLayout
{
anchors.fill: parent
spacing: 0
Repeater
ColumnLayout
{
model: document.alerts
Maui.ToolBar
anchors.fill: parent
spacing: 0
Repeater
{
id: _alertBar
property var alert : model.alert
readonly property int index_ : index
Layout.fillWidth: true
Kirigami.Theme.backgroundColor:
model: document.alerts
Maui.ToolBar
{
switch(alert.level)
id: _alertBar
property var alert : model.alert
readonly property int index_ : index
Layout.fillWidth: true
Kirigami.Theme.backgroundColor:
{
case 0: return Kirigami.Theme.positiveTextColor
case 1: return Kirigami.Theme.neutralTextColor
case 2: return Kirigami.Theme.negativeTextColor
switch(alert.level)
{
case 0: return Kirigami.Theme.positiveTextColor
case 1: return Kirigami.Theme.neutralTextColor
case 2: return Kirigami.Theme.negativeTextColor
}
}
}
leftContent: Maui.ListItemTemplate
{
Layout.fillWidth: true
Layout.fillHeight: true
label1.text: alert.title
label2.text: alert.body
}
rightContent: Repeater
{
model: alert.actionLabels()
Button
leftContent: Maui.ListItemTemplate
{
id: _alertAction
property int index_ : index
text: modelData
onClicked: alert.triggerAction(_alertAction.index_, _alertBar.index_)
Kirigami.Theme.backgroundColor: Qt.rgba(Kirigami.Theme.backgroundColor.r, Kirigami.Theme.backgroundColor.g, Kirigami.Theme.backgroundColor.b, 0.2)
Kirigami.Theme.textColor: Kirigami.Theme.textColor
Layout.fillWidth: true
Layout.fillHeight: true
label1.text: alert.title
label2.text: alert.body
}
rightContent: Repeater
{
model: alert.actionLabels()
Button
{
id: _alertAction
property int index_ : index
text: modelData
onClicked: alert.triggerAction(_alertAction.index_, _alertBar.index_)
Kirigami.Theme.backgroundColor: Qt.rgba(Kirigami.Theme.backgroundColor.r, Kirigami.Theme.backgroundColor.g, Kirigami.Theme.backgroundColor.b, 0.2)
Kirigami.Theme.textColor: Kirigami.Theme.textColor
}
}
}
}
}
PinchArea
{
id: pinchArea
Layout.fillWidth: true
Layout.fillHeight: true
property real minScale: 1.0
property real maxScale: 3.0
pinch.minimumScale: minScale
pinch.maximumScale: maxScale
pinch.dragAxis: Pinch.XandYAxis
onPinchFinished:
{
console.log("pinch.scale", pinch.scale)
if(pinch.scale > 1.5)
control.zoomIn()
else control.zoomOut()
}
MouseArea
{
anchors.fill: parent
onPressed:
{
console.log("Editor")
body.forceActiveFocus()
}
}
Kirigami.ScrollablePage
PinchArea
{
id: _scrollView
focus: true
anchors.fill: parent
contentWidth: control.width
contentHeight: body.contentHeight
leftPadding: 0
rightPadding: 0
topPadding: 0
bottomPadding: 0
background: Rectangle
id: pinchArea
Layout.fillWidth: true
Layout.fillHeight: true
property real minScale: 1.0
property real maxScale: 3.0
pinch.minimumScale: minScale
pinch.maximumScale: maxScale
pinch.dragAxis: Pinch.XandYAxis
onPinchFinished:
{