diff --git a/CMakeLists.txt b/CMakeLists.txt
index 39f0e05..386859e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -17,6 +17,7 @@ find_package(KF5SyntaxHighlighting)
set(PROJECT_SOURCES
src/main.cpp
src/documenthandler.cpp
+ src/highlightmodel.cpp
qml.qrc
)
diff --git a/qml.qrc b/qml.qrc
index a79fe14..6e940fd 100644
--- a/qml.qrc
+++ b/qml.qrc
@@ -9,5 +9,6 @@
images/dark/close.svg
images/light/add.svg
images/light/close.svg
+ qml/TabCloseButton.qml
diff --git a/qml/CTabBar.qml b/qml/CTabBar.qml
index b122ed3..52a4924 100644
--- a/qml/CTabBar.qml
+++ b/qml/CTabBar.qml
@@ -8,8 +8,6 @@ import FishUI 1.0 as FishUI
TabBar {
id: control
- // property var model
-
implicitWidth: _content.width
default property alias content : _content.data
@@ -28,6 +26,7 @@ TabBar {
ScrollView {
id: _scrollView
+
Layout.fillWidth: true
Layout.fillHeight: true
@@ -45,13 +44,13 @@ TabBar {
height: _scrollView.height
}
}
-
}
Loader {
active: control.newTabVisibile
visible: active
asynchronous: true
+
Layout.fillHeight: true
Layout.preferredWidth: visible ? height : 0
diff --git a/qml/CTabButton.qml b/qml/CTabButton.qml
index a43b068..a970c3b 100644
--- a/qml/CTabButton.qml
+++ b/qml/CTabButton.qml
@@ -28,8 +28,8 @@ Item {
anchors.leftMargin: FishUI.Units.smallSpacing / 2
anchors.rightMargin: FishUI.Units.smallSpacing / 2
anchors.topMargin: FishUI.Units.smallSpacing / 2
- color: _mouseArea.containsMouse ? FishUI.Theme.textColor : "transparent"
- opacity: _mouseArea.pressed ? 0.1 : 0.05
+ color: _mouseArea.containsMouse ? FishUI.Theme.textColor : FishUI.Theme.secondBackgroundColor
+ opacity: _mouseArea.containsMouse ? _mouseArea.pressed ? 0.1 : 0.05 : 1
border.width: 0
radius: FishUI.Theme.smallRadius
}
@@ -56,6 +56,7 @@ Item {
Label {
text: control.text
+ leftPadding: FishUI.Units.smallSpacing / 2
Layout.fillWidth: true
Layout.fillHeight: true
horizontalAlignment: Qt.AlignHCenter
@@ -66,12 +67,12 @@ Item {
wrapMode: Text.NoWrap
}
- FishUI.RoundImageButton {
- visible: control.checked
+ TabCloseButton {
+ enabled: control.checked
Layout.preferredHeight: 24
Layout.preferredWidth: 24
size: 24
- source: "qrc:/images/" + (FishUI.Theme.darkMode || control.checked ? "dark/" : "light/") + "close.svg"
+ source: !enabled ? "" : "qrc:/images/" + (FishUI.Theme.darkMode || control.checked ? "dark/" : "light/") + "close.svg"
onClicked: control.closeClicked()
}
}
diff --git a/qml/TabCloseButton.qml b/qml/TabCloseButton.qml
new file mode 100644
index 0000000..fa1674a
--- /dev/null
+++ b/qml/TabCloseButton.qml
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2021 CutefishOS Team.
+ *
+ * Author: Reion Wong
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+import QtQuick 2.12
+import QtQuick.Window 2.3
+import QtQuick.Controls 2.4
+import FishUI 1.0 as FishUI
+
+Item {
+ id: control
+
+ property var size: 32
+ property var iconMargins: 0
+ height: size
+ width: size
+
+ property alias background: _background
+ property color backgroundColor: "transparent"
+ property color hoveredColor: "#FF5C6D"
+ property color pressedColor: "#CC4A57"
+ property alias source: _image.source
+ property alias image: _image
+ signal clicked()
+
+ Rectangle {
+ id: _background
+ anchors.fill: parent
+ anchors.margins: size * 0.1
+ radius: control.height / 2
+ opacity: 0.9
+ color: mouseArea.pressed ? pressedColor : mouseArea.containsMouse ? control.hoveredColor : control.backgroundColor
+ }
+
+ MouseArea {
+ id: mouseArea
+ anchors.fill: parent
+ hoverEnabled: true
+
+ onClicked: control.clicked()
+ }
+
+ Image {
+ id: _image
+ objectName: "image"
+ anchors.fill: parent
+ anchors.margins: control.iconMargins
+ fillMode: Image.PreserveAspectFit
+ sourceSize: Qt.size(width, height)
+ cache: true
+ asynchronous: false
+ }
+}
diff --git a/qml/TextEditor.qml b/qml/TextEditor.qml
index 6c1537f..a1e0335 100644
--- a/qml/TextEditor.qml
+++ b/qml/TextEditor.qml
@@ -30,6 +30,9 @@ Item {
body.select(start, end)
}
+ onFileSaved: {
+ root.showPassiveNotification(qsTr("Saved successfully"), 3000)
+ }
}
ScrollView {
@@ -73,6 +76,14 @@ Item {
color: FishUI.Theme.backgroundColor
}
+ Keys.enabled: true
+ Keys.onPressed: {
+ if ((event.modifiers & Qt.ControlModifier) && (event.key === Qt.Key_S)) {
+ control.save()
+ event.accepted = true
+ }
+ }
+
Loader {
id: _linesCounter
active: control.showLineNumbers && !document.isRich
@@ -96,8 +107,6 @@ Item {
ListView {
id: _linesCounterList
-// anchors.fill: parent
-// anchors.topMargin: body.topPadding + body.textMargin
model: document.lineCount
clip: true
@@ -188,4 +197,8 @@ Item {
body.forceActiveFocus()
}
}
+
+ function save() {
+ document.saveAs(document.fileUrl)
+ }
}
diff --git a/qml/main.qml b/qml/main.qml
index ee53482..ee0b0b1 100644
--- a/qml/main.qml
+++ b/qml/main.qml
@@ -5,6 +5,7 @@ import QtQuick.Layouts 1.15
import FishUI 1.0 as FishUI
FishUI.Window {
+ id: root
width: 640
height: 480
minimumWidth: 300
@@ -13,7 +14,13 @@ FishUI.Window {
title: qsTr("Text Editor")
headerItem: Item {
+ Rectangle {
+ anchors.fill: parent
+ color: FishUI.Theme.backgroundColor
+ }
+
CTabBar {
+ id: _tabbar
anchors.fill: parent
anchors.margins: FishUI.Units.smallSpacing / 2
anchors.rightMargin: FishUI.Units.largeSpacing * 2
@@ -31,7 +38,8 @@ FishUI.Window {
CTabButton {
text: _tabView.contentModel.get(index).fileName
implicitHeight: parent.height
- implicitWidth: parent.width / _repeater.count
+ implicitWidth: _repeater.count === 1 ? 150
+ : parent.width / _repeater.count
ToolTip.delay: 1000
ToolTip.timeout: 5000
@@ -96,13 +104,11 @@ FishUI.Window {
id: textEditorCompeont
TextEditor {
- fileUrl: "file:///home/reion/Cutefish/core/notificationd/view.cpp"
+ fileUrl: ""
}
}
Component.onCompleted: {
addTab()
- addTab()
- addTab()
}
}
diff --git a/src/highlightmodel.cpp b/src/highlightmodel.cpp
new file mode 100644
index 0000000..615ab0e
--- /dev/null
+++ b/src/highlightmodel.cpp
@@ -0,0 +1,13 @@
+#include "highlightmodel.h"
+#include
+
+HighlightModel::HighlightModel(QObject *parent)
+ : QObject(parent)
+{
+ for (KSyntaxHighlighting::Definition def : m_repository.definitions()) {
+ if (def.isHidden())
+ continue;
+
+ qDebug() << def.translatedName();
+ }
+}
diff --git a/src/highlightmodel.h b/src/highlightmodel.h
new file mode 100644
index 0000000..65c6e4b
--- /dev/null
+++ b/src/highlightmodel.h
@@ -0,0 +1,20 @@
+#ifndef HIGHLIGHTMODEL_H
+#define HIGHLIGHTMODEL_H
+
+#include
+
+#include
+#include
+
+class HighlightModel : public QObject
+{
+ Q_OBJECT
+
+public:
+ explicit HighlightModel(QObject *parent = nullptr);
+
+private:
+ KSyntaxHighlighting::Repository m_repository;
+};
+
+#endif // HIGHLIGHTMODEL_H
diff --git a/src/main.cpp b/src/main.cpp
index 5abb5ec..5990811 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,6 +1,7 @@
#include
#include
#include "documenthandler.h"
+#include "highlightmodel.h"
int main(int argc, char *argv[])
{
@@ -12,6 +13,8 @@ int main(int argc, char *argv[])
qmlRegisterType("Cutefish.TextEditor", 1, 0, "DocumentHandler");
+ HighlightModel m;
+
QQmlApplicationEngine engine;
const QUrl url(QStringLiteral("qrc:/qml/main.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,