Desktop client for Nextcloud to edit your notes.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
NNotes/main.qml

256 lines
4.4 KiB

import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.12
ApplicationWindow {
width: 1024
height: 720
visible: true
title: qsTr("NNotes 0.1")
DirectoryDialog {
id: dirDialog
onAccepted: {
noteHandler.setDirPath(dirPath)
treeView.model = noteHandler ? noteHandler.entryList() : null
}
}
// Shortcuts
// Save current document
Shortcut {
id: sc_save
sequence: "Ctrl+S"
}
// Exit application
Shortcut {
id: sc_quit
sequence: "Ctrl+Shift+Q"
}
menuBar: MenuBar {
Menu {
title: qsTr("File")
Action {
text: qsTr("Save")
onTriggered: {
// first, make sure to set the new file name if needed
noteName.save()
// then, set the file contents
noteEdit.save()
}
shortcut: sc_save.sequence
}
Action {
text: qsTr("&Change Nextcloud folder...")
onTriggered: dirDialog.open()
}
MenuSeparator {}
Action {
text: qsTr("&Close")
shortcut: sc_quit.sequence
onTriggered: Qt.callLater(Qt.quit)
}
}
}
Grid {
width: parent.width
height: parent.height
columns: 2
spacing: 0
NoteTreeView {
id: treeView
width: parent.width * .25
height: parent.height
model: noteHandler ? noteHandler.entryList() : null
onCurrentIndexChanged: {
noteEdit.text = noteHandler ? noteHandler.fileContents(currentIndex) : null
noteName.text = noteHandler ? noteHandler.filename(currentIndex) : null
}
}
Grid {
width: parent.width * .75
height: parent.height
rows: 2
spacing: 0
TextField {
id: noteName
width: parent.width
height: 35
text: noteHandler ? noteHandler.filename(treeView.currentIndex) : null
font.capitalization: Font.SmallCaps
font.bold: true
font.pointSize: 14
background: Rectangle {
id: bgrect
color: "white"
SequentialAnimation {
id: bgrAnimSaved
PropertyAnimation {
target: bgrect
property: "color"
to: "darkseagreen"
duration: 100
}
PropertyAnimation {
target: bgrect
property: "color"
to: "white"
duration: 1400
easing.type: Easing.OutCirc
}
}
SequentialAnimation {
id: bgrAnimError
PropertyAnimation {
target: bgrect
property: "color"
to: "darkred"
duration: 100
}
PropertyAnimation {
target: bgrect
property: "color"
to: "white"
duration: 1400
easing.type: Easing.OutCirc
}
}
}
function save() {
if (noteHandler) {
if (noteHandler.setFilename(treeView.currentIndex, text)) {
// reload the entry list
treeView.model = noteHandler.entryList();
// fancy animation!
bgrAnimSaved.start();
}
else {
bgrAnimError.start();
}
}
}
Keys.onReturnPressed: {
save();
}
Keys.onEnterPressed: {
save();
}
}
TextEdit {
id: noteEdit
width: parent.width
height: parent.height
padding: 5
Rectangle {
id: noteEditBgRect
width: parent.width
height: parent.height
z: -1
SequentialAnimation {
id: nebgrAnimSaved
PropertyAnimation {
target: noteEditBgRect
property: "color"
to: "darkseagreen"
duration: 100
}
PropertyAnimation {
target: noteEditBgRect
property: "color"
to: "white"
duration: 1400
easing.type: Easing.OutCirc
}
}
SequentialAnimation {
id: nebgrAnimError
PropertyAnimation {
target: noteEditBgRect
property: "color"
to: "darkred"
duration: 100
}
PropertyAnimation {
target: noteEditBgRect
property: "color"
to: "white"
duration: 1400
easing.type: Easing.OutCirc
}
}
Text {
id: savedText
anchors.centerIn: parent
font.family: getHandwritingFont()
font.pointSize: 36
color: "white"
function getHandwritingFont() {
if(Qt.platform.os == "windows") {
return "Segoe Script"
}
else {
return "Karumbi"
}
}
}
}
function save() {
if (noteHandler) {
if (noteHandler.saveContent(treeView.currentIndex, text)) {
// fancy animation!
savedText.text = qsTr("Saved.")
nebgrAnimSaved.start();
}
else {
savedText.text = qsTr("Failed.")
nebgrAnimError.start()
}
}
}
}
}
}
}