Add TabCloseButton.qml

pull/4/head
reionwong 4 years ago
parent 9f05fb681a
commit 720c767d01

@ -17,6 +17,7 @@ find_package(KF5SyntaxHighlighting)
set(PROJECT_SOURCES
src/main.cpp
src/documenthandler.cpp
src/highlightmodel.cpp
qml.qrc
)

@ -9,5 +9,6 @@
<file>images/dark/close.svg</file>
<file>images/light/add.svg</file>
<file>images/light/close.svg</file>
<file>qml/TabCloseButton.qml</file>
</qresource>
</RCC>

@ -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

@ -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()
}
}

@ -0,0 +1,68 @@
/*
* Copyright (C) 2021 CutefishOS Team.
*
* Author: Reion Wong <reion@cutefishos.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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
}
}

@ -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)
}
}

@ -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()
}
}

@ -0,0 +1,13 @@
#include "highlightmodel.h"
#include <QDebug>
HighlightModel::HighlightModel(QObject *parent)
: QObject(parent)
{
for (KSyntaxHighlighting::Definition def : m_repository.definitions()) {
if (def.isHidden())
continue;
qDebug() << def.translatedName();
}
}

@ -0,0 +1,20 @@
#ifndef HIGHLIGHTMODEL_H
#define HIGHLIGHTMODEL_H
#include <QObject>
#include <KSyntaxHighlighting/Repository>
#include <KSyntaxHighlighting/Definition>
class HighlightModel : public QObject
{
Q_OBJECT
public:
explicit HighlightModel(QObject *parent = nullptr);
private:
KSyntaxHighlighting::Repository m_repository;
};
#endif // HIGHLIGHTMODEL_H

@ -1,6 +1,7 @@
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include "documenthandler.h"
#include "highlightmodel.h"
int main(int argc, char *argv[])
{
@ -12,6 +13,8 @@ int main(int argc, char *argv[])
qmlRegisterType<DocumentHandler>("Cutefish.TextEditor", 1, 0, "DocumentHandler");
HighlightModel m;
QQmlApplicationEngine engine;
const QUrl url(QStringLiteral("qrc:/qml/main.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,

Loading…
Cancel
Save