2016-07-06 11:04:07 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2021-09-23 15:45:44 +00:00
|
|
|
** Copyright (C) 2021 The Qt Company Ltd.
|
2017-02-22 12:59:07 +00:00
|
|
|
** Contact: https://www.qt.io/licensing/
|
2016-07-06 11:04:07 +00:00
|
|
|
**
|
|
|
|
** This file is part of the examples of the Qt Toolkit.
|
|
|
|
**
|
|
|
|
** $QT_BEGIN_LICENSE:BSD$
|
2017-02-22 12:59:07 +00:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
**
|
|
|
|
** BSD License Usage
|
|
|
|
** Alternatively, you may use this file under the terms of the BSD license
|
|
|
|
** as follows:
|
2016-07-06 11:04:07 +00:00
|
|
|
**
|
|
|
|
** "Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions are
|
|
|
|
** met:
|
|
|
|
** * Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** * Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in
|
|
|
|
** the documentation and/or other materials provided with the
|
|
|
|
** distribution.
|
|
|
|
** * Neither the name of The Qt Company Ltd nor the names of its
|
|
|
|
** contributors may be used to endorse or promote products derived
|
|
|
|
** from this software without specific prior written permission.
|
|
|
|
**
|
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-03-26 16:01:51 +00:00
|
|
|
import QtQuick
|
2021-09-23 15:45:44 +00:00
|
|
|
import QtCore
|
2020-03-26 16:01:51 +00:00
|
|
|
import QtQuick.Controls
|
|
|
|
import QtQuick.Window
|
2021-09-23 15:45:44 +00:00
|
|
|
import QtQuick.Dialogs
|
|
|
|
import Qt.labs.platform as Platform
|
2016-07-06 11:04:07 +00:00
|
|
|
|
2020-03-26 16:01:51 +00:00
|
|
|
import io.qt.examples.texteditor
|
2016-07-06 11:04:07 +00:00
|
|
|
|
2016-07-26 12:15:31 +00:00
|
|
|
// TODO:
|
|
|
|
// - make designer-friendly
|
|
|
|
|
2016-07-06 11:04:07 +00:00
|
|
|
ApplicationWindow {
|
|
|
|
id: window
|
|
|
|
width: 1024
|
|
|
|
height: 600
|
|
|
|
visible: true
|
2016-08-11 20:29:26 +00:00
|
|
|
title: document.fileName + " - Text Editor Example"
|
2016-07-06 11:04:07 +00:00
|
|
|
|
|
|
|
Component.onCompleted: {
|
|
|
|
x = Screen.width / 2 - width / 2
|
|
|
|
y = Screen.height / 2 - height / 2
|
|
|
|
}
|
|
|
|
|
2021-09-23 15:45:44 +00:00
|
|
|
Action {
|
|
|
|
id: openAction
|
|
|
|
shortcut: StandardKey.Open
|
|
|
|
onTriggered: openDialog.open()
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
2021-09-23 15:45:44 +00:00
|
|
|
|
|
|
|
Action {
|
|
|
|
id: saveAsAction
|
|
|
|
shortcut: StandardKey.SaveAs
|
|
|
|
onTriggered: saveDialog.open()
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
2021-09-23 15:45:44 +00:00
|
|
|
|
|
|
|
Action {
|
|
|
|
id: quitAction
|
|
|
|
shortcut: StandardKey.Quit
|
|
|
|
onTriggered: close()
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
2021-09-23 15:45:44 +00:00
|
|
|
|
|
|
|
Action {
|
|
|
|
id: copyAction
|
|
|
|
shortcut: StandardKey.Copy
|
|
|
|
onTriggered: textArea.copy()
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
2021-09-23 15:45:44 +00:00
|
|
|
|
|
|
|
Action {
|
|
|
|
id: cutAction
|
|
|
|
shortcut: StandardKey.Cut
|
|
|
|
onTriggered: textArea.cut()
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
2021-09-23 15:45:44 +00:00
|
|
|
|
|
|
|
Action {
|
|
|
|
id: pasteAction
|
|
|
|
shortcut: StandardKey.Paste
|
|
|
|
onTriggered: textArea.paste()
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
2021-09-23 15:45:44 +00:00
|
|
|
|
|
|
|
Action {
|
|
|
|
id: boldAction
|
|
|
|
shortcut: StandardKey.Bold
|
|
|
|
onTriggered: document.bold = !document.bold
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
2021-09-23 15:45:44 +00:00
|
|
|
|
|
|
|
Action {
|
|
|
|
id: italicAction
|
|
|
|
shortcut: StandardKey.Italic
|
|
|
|
onTriggered: document.italic = !document.italic
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
2021-09-23 15:45:44 +00:00
|
|
|
|
|
|
|
Action {
|
|
|
|
id: underlineAction
|
|
|
|
shortcut: StandardKey.Underline
|
|
|
|
onTriggered: document.underline = !document.underline
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
|
|
|
|
2021-09-23 15:45:44 +00:00
|
|
|
Platform.MenuBar {
|
|
|
|
Platform.Menu {
|
2016-09-07 15:19:43 +00:00
|
|
|
title: qsTr("&File")
|
2016-07-06 11:04:07 +00:00
|
|
|
|
2021-09-23 15:45:44 +00:00
|
|
|
Platform.MenuItem {
|
2016-09-07 15:19:43 +00:00
|
|
|
text: qsTr("&Open")
|
2016-07-06 11:04:07 +00:00
|
|
|
onTriggered: openDialog.open()
|
|
|
|
}
|
2021-09-23 15:45:44 +00:00
|
|
|
Platform.MenuItem {
|
2016-09-07 15:19:43 +00:00
|
|
|
text: qsTr("&Save As...")
|
2016-07-06 11:04:07 +00:00
|
|
|
onTriggered: saveDialog.open()
|
|
|
|
}
|
2021-09-23 15:45:44 +00:00
|
|
|
Platform.MenuItem {
|
2016-09-07 15:19:43 +00:00
|
|
|
text: qsTr("&Quit")
|
2019-08-19 14:01:05 +00:00
|
|
|
onTriggered: close()
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-23 15:45:44 +00:00
|
|
|
Platform.Menu {
|
2016-09-07 15:19:43 +00:00
|
|
|
title: qsTr("&Edit")
|
2016-07-06 11:04:07 +00:00
|
|
|
|
2021-09-23 15:45:44 +00:00
|
|
|
Platform.MenuItem {
|
2016-09-07 15:19:43 +00:00
|
|
|
text: qsTr("&Copy")
|
2016-07-06 11:04:07 +00:00
|
|
|
enabled: textArea.selectedText
|
|
|
|
onTriggered: textArea.copy()
|
|
|
|
}
|
2021-09-23 15:45:44 +00:00
|
|
|
Platform.MenuItem {
|
2016-09-07 15:19:43 +00:00
|
|
|
text: qsTr("Cu&t")
|
2016-07-06 11:04:07 +00:00
|
|
|
enabled: textArea.selectedText
|
|
|
|
onTriggered: textArea.cut()
|
|
|
|
}
|
2021-09-23 15:45:44 +00:00
|
|
|
Platform.MenuItem {
|
2016-09-07 15:19:43 +00:00
|
|
|
text: qsTr("&Paste")
|
2016-07-06 11:04:07 +00:00
|
|
|
enabled: textArea.canPaste
|
|
|
|
onTriggered: textArea.paste()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-23 15:45:44 +00:00
|
|
|
Platform.Menu {
|
2016-09-07 15:19:43 +00:00
|
|
|
title: qsTr("F&ormat")
|
2016-07-06 11:04:07 +00:00
|
|
|
|
2021-09-23 15:45:44 +00:00
|
|
|
Platform.MenuItem {
|
2016-09-07 15:19:43 +00:00
|
|
|
text: qsTr("&Bold")
|
2016-07-06 11:04:07 +00:00
|
|
|
checkable: true
|
|
|
|
checked: document.bold
|
|
|
|
onTriggered: document.bold = !document.bold
|
|
|
|
}
|
2021-09-23 15:45:44 +00:00
|
|
|
Platform.MenuItem {
|
2016-09-07 15:19:43 +00:00
|
|
|
text: qsTr("&Italic")
|
2016-07-06 11:04:07 +00:00
|
|
|
checkable: true
|
|
|
|
checked: document.italic
|
|
|
|
onTriggered: document.italic = !document.italic
|
|
|
|
}
|
2021-09-23 15:45:44 +00:00
|
|
|
Platform.MenuItem {
|
2016-09-07 15:19:43 +00:00
|
|
|
text: qsTr("&Underline")
|
2016-07-06 11:04:07 +00:00
|
|
|
checkable: true
|
|
|
|
checked: document.underline
|
|
|
|
onTriggered: document.underline = !document.underline
|
|
|
|
}
|
2021-09-23 15:45:44 +00:00
|
|
|
Platform.MenuItem {
|
|
|
|
text: qsTr("&Strikeout")
|
|
|
|
checkable: true
|
|
|
|
checked: document.strikeout
|
|
|
|
onTriggered: document.strikeout = !document.strikeout
|
|
|
|
}
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FileDialog {
|
|
|
|
id: openDialog
|
|
|
|
fileMode: FileDialog.OpenFile
|
2016-10-04 11:48:45 +00:00
|
|
|
selectedNameFilter.index: 1
|
2020-08-10 10:35:25 +00:00
|
|
|
nameFilters: ["Text files (*.txt)", "HTML files (*.html *.htm)", "Markdown files (*.md *.markdown)"]
|
2021-09-23 15:45:44 +00:00
|
|
|
currentFolder: StandardPaths.writableLocation(StandardPaths.DocumentsLocation)
|
2016-08-13 20:25:39 +00:00
|
|
|
onAccepted: document.load(file)
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FileDialog {
|
|
|
|
id: saveDialog
|
|
|
|
fileMode: FileDialog.SaveFile
|
2016-08-11 20:29:26 +00:00
|
|
|
defaultSuffix: document.fileType
|
2016-07-06 11:04:07 +00:00
|
|
|
nameFilters: openDialog.nameFilters
|
2016-10-04 11:48:45 +00:00
|
|
|
selectedNameFilter.index: document.fileType === "txt" ? 0 : 1
|
2021-09-23 15:45:44 +00:00
|
|
|
currentFolder: StandardPaths.writableLocation(StandardPaths.DocumentsLocation)
|
2016-08-13 20:25:39 +00:00
|
|
|
onAccepted: document.saveAs(file)
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FontDialog {
|
|
|
|
id: fontDialog
|
2021-09-23 15:45:44 +00:00
|
|
|
|
|
|
|
onAccepted: document.font = fontDialog.selectedFont
|
|
|
|
onVisibleChanged: if (visible) currentFont = document.font
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
|
|
|
|
2021-09-23 15:45:44 +00:00
|
|
|
Platform.ColorDialog {
|
2016-07-06 11:04:07 +00:00
|
|
|
id: colorDialog
|
|
|
|
currentColor: "black"
|
|
|
|
}
|
|
|
|
|
2021-09-23 15:45:44 +00:00
|
|
|
Platform.MessageDialog {
|
2016-07-06 11:04:07 +00:00
|
|
|
id: errorDialog
|
|
|
|
}
|
|
|
|
|
2021-09-23 15:45:44 +00:00
|
|
|
Platform.MessageDialog {
|
2019-08-19 14:01:05 +00:00
|
|
|
id : quitDialog
|
|
|
|
title: qsTr("Quit?")
|
|
|
|
text: qsTr("The file has been modified. Quit anyway?")
|
2021-09-23 15:45:44 +00:00
|
|
|
buttons: (Platform.MessageDialog.Yes | Platform.MessageDialog.No)
|
2019-08-19 14:01:05 +00:00
|
|
|
onYesClicked: Qt.quit()
|
|
|
|
}
|
|
|
|
|
2016-07-06 11:04:07 +00:00
|
|
|
header: ToolBar {
|
|
|
|
leftPadding: 8
|
|
|
|
|
2016-08-12 08:45:17 +00:00
|
|
|
Flow {
|
|
|
|
id: flow
|
|
|
|
width: parent.width
|
2016-07-06 11:04:07 +00:00
|
|
|
|
2016-08-12 08:45:17 +00:00
|
|
|
Row {
|
|
|
|
id: fileRow
|
|
|
|
ToolButton {
|
|
|
|
id: openButton
|
2016-07-26 12:15:31 +00:00
|
|
|
text: "\uF115" // icon-folder-open-empty
|
2016-08-12 08:45:17 +00:00
|
|
|
font.family: "fontello"
|
2021-09-23 15:45:44 +00:00
|
|
|
action: openAction
|
|
|
|
focusPolicy: Qt.TabFocus
|
2016-08-12 08:45:17 +00:00
|
|
|
}
|
|
|
|
ToolSeparator {
|
|
|
|
contentItem.visible: fileRow.y === editRow.y
|
|
|
|
}
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Row {
|
2016-08-12 08:45:17 +00:00
|
|
|
id: editRow
|
2016-07-06 11:04:07 +00:00
|
|
|
ToolButton {
|
|
|
|
id: copyButton
|
2016-07-26 12:15:31 +00:00
|
|
|
text: "\uF0C5" // icon-docs
|
2016-07-06 11:04:07 +00:00
|
|
|
font.family: "fontello"
|
|
|
|
focusPolicy: Qt.TabFocus
|
|
|
|
enabled: textArea.selectedText
|
2021-09-23 15:45:44 +00:00
|
|
|
action: copyAction
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
|
|
|
ToolButton {
|
|
|
|
id: cutButton
|
2016-07-26 12:15:31 +00:00
|
|
|
text: "\uE802" // icon-scissors
|
2016-07-06 11:04:07 +00:00
|
|
|
font.family: "fontello"
|
|
|
|
focusPolicy: Qt.TabFocus
|
|
|
|
enabled: textArea.selectedText
|
2021-09-23 15:45:44 +00:00
|
|
|
action: cutAction
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
|
|
|
ToolButton {
|
|
|
|
id: pasteButton
|
2016-07-26 12:15:31 +00:00
|
|
|
text: "\uF0EA" // icon-paste
|
2016-07-06 11:04:07 +00:00
|
|
|
font.family: "fontello"
|
|
|
|
focusPolicy: Qt.TabFocus
|
|
|
|
enabled: textArea.canPaste
|
2021-09-23 15:45:44 +00:00
|
|
|
action: pasteAction
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
2016-08-12 08:45:17 +00:00
|
|
|
ToolSeparator {
|
|
|
|
contentItem.visible: editRow.y === formatRow.y
|
|
|
|
}
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Row {
|
2016-08-12 08:45:17 +00:00
|
|
|
id: formatRow
|
2016-07-06 11:04:07 +00:00
|
|
|
ToolButton {
|
|
|
|
id: boldButton
|
2016-07-26 12:15:31 +00:00
|
|
|
text: "\uE800" // icon-bold
|
2016-07-06 11:04:07 +00:00
|
|
|
font.family: "fontello"
|
|
|
|
focusPolicy: Qt.TabFocus
|
|
|
|
checkable: true
|
|
|
|
checked: document.bold
|
2021-09-23 15:45:44 +00:00
|
|
|
action: boldAction
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
|
|
|
ToolButton {
|
|
|
|
id: italicButton
|
2016-07-26 12:15:31 +00:00
|
|
|
text: "\uE801" // icon-italic
|
2016-07-06 11:04:07 +00:00
|
|
|
font.family: "fontello"
|
|
|
|
focusPolicy: Qt.TabFocus
|
|
|
|
checkable: true
|
|
|
|
checked: document.italic
|
2021-09-23 15:45:44 +00:00
|
|
|
action: italicAction
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
|
|
|
ToolButton {
|
|
|
|
id: underlineButton
|
2016-07-26 12:15:31 +00:00
|
|
|
text: "\uF0CD" // icon-underline
|
2016-07-06 11:04:07 +00:00
|
|
|
font.family: "fontello"
|
|
|
|
focusPolicy: Qt.TabFocus
|
|
|
|
checkable: true
|
|
|
|
checked: document.underline
|
2021-09-23 15:45:44 +00:00
|
|
|
action: underlineAction
|
|
|
|
}
|
|
|
|
ToolButton {
|
|
|
|
id: strikeoutButton
|
|
|
|
text: "\uF0CC"
|
|
|
|
font.family: "fontello"
|
|
|
|
focusPolicy: Qt.TabFocus
|
|
|
|
checkable: true
|
|
|
|
checked: document.strikeout
|
|
|
|
onClicked: document.strikeout = !document.strikeout
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
2016-08-12 12:22:07 +00:00
|
|
|
ToolButton {
|
|
|
|
id: fontFamilyToolButton
|
2016-07-26 12:15:31 +00:00
|
|
|
text: qsTr("\uE808") // icon-font
|
2016-08-12 12:22:07 +00:00
|
|
|
font.family: "fontello"
|
|
|
|
font.bold: document.bold
|
|
|
|
font.italic: document.italic
|
|
|
|
font.underline: document.underline
|
2021-09-23 15:45:44 +00:00
|
|
|
font.strikeout: document.strikeout
|
|
|
|
focusPolicy: Qt.TabFocus
|
|
|
|
onClicked: fontDialog.open()
|
2016-08-12 12:22:07 +00:00
|
|
|
}
|
2016-07-06 11:04:07 +00:00
|
|
|
ToolButton {
|
|
|
|
id: textColorButton
|
2016-07-26 12:15:31 +00:00
|
|
|
text: "\uF1FC" // icon-brush
|
2016-07-06 11:04:07 +00:00
|
|
|
font.family: "fontello"
|
|
|
|
focusPolicy: Qt.TabFocus
|
|
|
|
onClicked: colorDialog.open()
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
width: aFontMetrics.width + 3
|
|
|
|
height: 2
|
|
|
|
color: document.textColor
|
|
|
|
parent: textColorButton.contentItem
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
anchors.baseline: parent.baseline
|
2016-08-12 12:22:07 +00:00
|
|
|
anchors.baselineOffset: 6
|
2016-07-06 11:04:07 +00:00
|
|
|
|
|
|
|
TextMetrics {
|
|
|
|
id: aFontMetrics
|
|
|
|
font: textColorButton.font
|
|
|
|
text: textColorButton.text
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-08-12 08:45:17 +00:00
|
|
|
ToolSeparator {
|
|
|
|
contentItem.visible: formatRow.y === alignRow.y
|
|
|
|
}
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Row {
|
2016-08-12 08:45:17 +00:00
|
|
|
id: alignRow
|
2016-07-06 11:04:07 +00:00
|
|
|
ToolButton {
|
|
|
|
id: alignLeftButton
|
2016-07-26 12:15:31 +00:00
|
|
|
text: "\uE803" // icon-align-left
|
2016-07-06 11:04:07 +00:00
|
|
|
font.family: "fontello"
|
|
|
|
focusPolicy: Qt.TabFocus
|
|
|
|
checkable: true
|
|
|
|
checked: document.alignment == Qt.AlignLeft
|
|
|
|
onClicked: document.alignment = Qt.AlignLeft
|
|
|
|
}
|
|
|
|
ToolButton {
|
|
|
|
id: alignCenterButton
|
2016-07-26 12:15:31 +00:00
|
|
|
text: "\uE804" // icon-align-center
|
2016-07-06 11:04:07 +00:00
|
|
|
font.family: "fontello"
|
|
|
|
focusPolicy: Qt.TabFocus
|
|
|
|
checkable: true
|
|
|
|
checked: document.alignment == Qt.AlignHCenter
|
|
|
|
onClicked: document.alignment = Qt.AlignHCenter
|
|
|
|
}
|
|
|
|
ToolButton {
|
|
|
|
id: alignRightButton
|
2016-07-26 12:15:31 +00:00
|
|
|
text: "\uE805" // icon-align-right
|
2016-07-06 11:04:07 +00:00
|
|
|
font.family: "fontello"
|
|
|
|
focusPolicy: Qt.TabFocus
|
|
|
|
checkable: true
|
|
|
|
checked: document.alignment == Qt.AlignRight
|
|
|
|
onClicked: document.alignment = Qt.AlignRight
|
|
|
|
}
|
|
|
|
ToolButton {
|
|
|
|
id: alignJustifyButton
|
2016-07-26 12:15:31 +00:00
|
|
|
text: "\uE806" // icon-align-justify
|
2016-07-06 11:04:07 +00:00
|
|
|
font.family: "fontello"
|
|
|
|
focusPolicy: Qt.TabFocus
|
|
|
|
checkable: true
|
|
|
|
checked: document.alignment == Qt.AlignJustify
|
|
|
|
onClicked: document.alignment = Qt.AlignJustify
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DocumentHandler {
|
|
|
|
id: document
|
|
|
|
document: textArea.textDocument
|
|
|
|
cursorPosition: textArea.cursorPosition
|
|
|
|
selectionStart: textArea.selectionStart
|
|
|
|
selectionEnd: textArea.selectionEnd
|
2016-08-13 11:40:36 +00:00
|
|
|
textColor: colorDialog.color
|
2021-09-23 15:45:44 +00:00
|
|
|
|
|
|
|
property alias family: document.font.family
|
|
|
|
property alias bold: document.font.bold
|
|
|
|
property alias italic: document.font.italic
|
|
|
|
property alias underline: document.font.underline
|
|
|
|
property alias strikeout: document.font.strikeout
|
|
|
|
property alias size: document.font.pointSize
|
|
|
|
|
2020-08-10 10:35:25 +00:00
|
|
|
Component.onCompleted: {
|
|
|
|
if (Qt.application.arguments.length === 2)
|
|
|
|
document.load("file:" + Qt.application.arguments[1]);
|
|
|
|
else
|
|
|
|
document.load("qrc:/texteditor.html")
|
|
|
|
}
|
2021-09-23 15:45:44 +00:00
|
|
|
onLoaded: function (text, format) {
|
2020-08-10 10:35:25 +00:00
|
|
|
textArea.textFormat = format
|
2016-08-11 20:41:11 +00:00
|
|
|
textArea.text = text
|
|
|
|
}
|
2021-09-23 15:45:44 +00:00
|
|
|
onError: function (message) {
|
2016-07-06 11:04:07 +00:00
|
|
|
errorDialog.text = message
|
|
|
|
errorDialog.visible = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Flickable {
|
|
|
|
id: flickable
|
|
|
|
flickableDirection: Flickable.VerticalFlick
|
|
|
|
anchors.fill: parent
|
|
|
|
|
|
|
|
TextArea.flickable: TextArea {
|
|
|
|
id: textArea
|
|
|
|
textFormat: Qt.RichText
|
|
|
|
wrapMode: TextArea.Wrap
|
|
|
|
focus: true
|
|
|
|
selectByMouse: true
|
2016-08-12 19:18:17 +00:00
|
|
|
persistentSelection: true
|
2016-07-06 11:04:07 +00:00
|
|
|
// Different styles have different padding and background
|
|
|
|
// decorations, but since this editor is almost taking up the
|
|
|
|
// entire window, we don't need them.
|
|
|
|
leftPadding: 6
|
|
|
|
rightPadding: 6
|
|
|
|
topPadding: 0
|
|
|
|
bottomPadding: 0
|
|
|
|
background: null
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
acceptedButtons: Qt.RightButton
|
|
|
|
anchors.fill: parent
|
|
|
|
onClicked: contextMenu.open()
|
|
|
|
}
|
|
|
|
|
2021-09-23 15:45:44 +00:00
|
|
|
onLinkActivated: function (link) {
|
|
|
|
Qt.openUrlExternally(link)
|
|
|
|
}
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ScrollBar.vertical: ScrollBar {}
|
|
|
|
}
|
|
|
|
|
2021-09-23 15:45:44 +00:00
|
|
|
Platform.Menu {
|
2016-07-06 11:04:07 +00:00
|
|
|
id: contextMenu
|
|
|
|
|
2021-09-23 15:45:44 +00:00
|
|
|
Platform.MenuItem {
|
2016-07-06 11:04:07 +00:00
|
|
|
text: qsTr("Copy")
|
|
|
|
enabled: textArea.selectedText
|
|
|
|
onTriggered: textArea.copy()
|
|
|
|
}
|
2021-09-23 15:45:44 +00:00
|
|
|
Platform.MenuItem {
|
2016-07-06 11:04:07 +00:00
|
|
|
text: qsTr("Cut")
|
|
|
|
enabled: textArea.selectedText
|
|
|
|
onTriggered: textArea.cut()
|
|
|
|
}
|
2021-09-23 15:45:44 +00:00
|
|
|
Platform.MenuItem {
|
2016-07-06 11:04:07 +00:00
|
|
|
text: qsTr("Paste")
|
|
|
|
enabled: textArea.canPaste
|
|
|
|
onTriggered: textArea.paste()
|
|
|
|
}
|
|
|
|
|
2021-09-23 15:45:44 +00:00
|
|
|
Platform.MenuSeparator {}
|
2016-07-06 11:04:07 +00:00
|
|
|
|
2021-09-23 15:45:44 +00:00
|
|
|
Platform.MenuItem {
|
2016-07-06 11:04:07 +00:00
|
|
|
text: qsTr("Font...")
|
|
|
|
onTriggered: fontDialog.open()
|
|
|
|
}
|
|
|
|
|
2021-09-23 15:45:44 +00:00
|
|
|
Platform.MenuItem {
|
2016-07-06 11:04:07 +00:00
|
|
|
text: qsTr("Color...")
|
|
|
|
onTriggered: colorDialog.open()
|
|
|
|
}
|
|
|
|
}
|
2019-08-19 14:01:05 +00:00
|
|
|
|
2021-09-23 15:45:44 +00:00
|
|
|
onClosing: function (close) {
|
2019-08-19 14:01:05 +00:00
|
|
|
if (document.modified) {
|
|
|
|
quitDialog.open()
|
|
|
|
close.accepted = false
|
|
|
|
}
|
|
|
|
}
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|