You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

139 lines
3.4 KiB
QML

5 years ago
import QtQuick 2.15
import QtQuick.Window 2.15
5 years ago
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
5 years ago
import FishUI 1.0 as FishUI
import Cutefish.TextEditor 1.0
5 years ago
FishUI.Window {
id: root
5 years ago
width: 640
height: 480
5 years ago
minimumWidth: 300
minimumHeight: 300
5 years ago
visible: true
5 years ago
title: qsTr("Text Editor")
5 years ago
FileHelper {
id: fileHelper
onNewPath: {
_tabView.addTab(textEditorCompeont, { fileUrl: path })
}
}
5 years ago
headerItem: Item {
Rectangle {
anchors.fill: parent
color: FishUI.Theme.backgroundColor
}
FishUI.TabBar {
id: _tabbar
5 years ago
anchors.fill: parent
5 years ago
anchors.margins: FishUI.Units.smallSpacing / 2
anchors.rightMargin: FishUI.Units.largeSpacing * 4
5 years ago
model: _tabView.count
5 years ago
currentIndex : _tabView.currentIndex
5 years ago
5 years ago
onNewTabClicked: {
addTab()
}
delegate: FishUI.TabButton {
id: _tabBtn
text: _tabView.contentModel.get(index).tabName
implicitHeight: _tabbar.height
implicitWidth: Math.min(_tabbar.width / _tabbar.count,
_tabBtn.contentWidth)
5 years ago
ToolTip.delay: 1000
ToolTip.timeout: 5000
5 years ago
checked: _tabView.currentIndex === index
5 years ago
ToolTip.visible: hovered
ToolTip.text: _tabView.contentModel.get(index).fileUrl
5 years ago
onClicked: {
_tabView.currentIndex = index
_tabView.currentItem.forceActiveFocus()
}
5 years ago
onCloseClicked: {
_tabView.closeTab(index)
5 years ago
}
}
}
}
DropArea {
id: _dropArea
anchors.fill: parent
onDropped: {
if (drop.hasUrls) {
for (var i = 0; i < drop.urls.length; ++i) {
fileHelper.addPath(drop.urls[i])
}
}
}
}
5 years ago
ColumnLayout {
5 years ago
anchors.fill: parent
5 years ago
spacing: 0
FishUI.TabView {
5 years ago
id: _tabView
5 years ago
Layout.fillWidth: true
Layout.fillHeight: true
}
Item {
5 years ago
id: _bottomItem
z: 999
5 years ago
Layout.fillWidth: true
5 years ago
Layout.preferredHeight: 20 + FishUI.Units.smallSpacing
Rectangle {
anchors.fill: parent
color: FishUI.Theme.backgroundColor
}
5 years ago
ColumnLayout {
anchors.fill: parent
5 years ago
anchors.leftMargin: FishUI.Units.smallSpacing
anchors.rightMargin: FishUI.Units.smallSpacing
anchors.bottomMargin: FishUI.Units.smallSpacing
Label {
text: _tabView.currentItem ? qsTr("Characters %1").arg(_tabView.currentItem.characterCount)
: ""
5 years ago
}
5 years ago
}
}
}
function addPath(path) {
_tabView.addTab(textEditorCompeont, { fileUrl: path })
}
5 years ago
function addTab() {
5 years ago
_tabView.addTab(textEditorCompeont, {})
5 years ago
}
Component {
id: textEditorCompeont
TextEditor {
fileUrl: "file:///home/cutefish/桌面/winepath"
5 years ago
}
}
Component.onCompleted: {
// addTab()
5 years ago
}
}