From ab00504a93b1400c26267cdb9bddaf4a3ec3a7e5 Mon Sep 17 00:00:00 2001 From: reionwong Date: Fri, 27 Aug 2021 19:11:18 +0800 Subject: [PATCH] Add tools bar --- images/cancel.svg | 22 ++++++++++++++ images/ok.svg | 18 +++++++++++ images/save.svg | 18 +++++++++++ qml.qrc | 4 +++ qml/ImageButton.qml | 69 ++++++++++++++++++++++++++++++++++++++++++ qml/main.qml | 55 +++++++++++++++++++++++++++++++++ src/screenshotview.cpp | 24 +++++++++++++++ src/screenshotview.h | 3 +- 8 files changed, 212 insertions(+), 1 deletion(-) create mode 100644 images/cancel.svg create mode 100644 images/ok.svg create mode 100644 images/save.svg create mode 100644 qml/ImageButton.qml diff --git a/images/cancel.svg b/images/cancel.svg new file mode 100644 index 0000000..b06c75e --- /dev/null +++ b/images/cancel.svg @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/images/ok.svg b/images/ok.svg new file mode 100644 index 0000000..1386827 --- /dev/null +++ b/images/ok.svg @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/images/save.svg b/images/save.svg new file mode 100644 index 0000000..68c6d93 --- /dev/null +++ b/images/save.svg @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/qml.qrc b/qml.qrc index 69145a8..09087fe 100644 --- a/qml.qrc +++ b/qml.qrc @@ -1,5 +1,9 @@ qml/main.qml + images/cancel.svg + qml/ImageButton.qml + images/ok.svg + images/save.svg diff --git a/qml/ImageButton.qml b/qml/ImageButton.qml new file mode 100644 index 0000000..7398379 --- /dev/null +++ b/qml/ImageButton.qml @@ -0,0 +1,69 @@ +/* + * 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 color hoveredColor: FishUI.Theme.darkMode ? Qt.lighter(FishUI.Theme.backgroundColor, 2) + : Qt.darker(FishUI.Theme.backgroundColor, 1.2) + property color pressedColor: FishUI.Theme.darkMode ? Qt.lighter(FishUI.Theme.backgroundColor, 1.5) + : Qt.darker(FishUI.Theme.backgroundColor, 1.3) + 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 + color: mouseArea.pressed ? pressedColor : mouseArea.containsMouse ? control.hoveredColor : "transparent" + } + + 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 + smooth: false + antialiasing: true + asynchronous: false + } +} diff --git a/qml/main.qml b/qml/main.qml index 9a011de..5b15501 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -20,6 +20,7 @@ import QtQuick 2.12 import QtQuick.Window 2.12 import QtQuick.Controls 2.12 +import QtQuick.Layouts 1.12 import QtGraphicalEffects 1.0 import FishUI 1.0 as FishUI @@ -116,6 +117,60 @@ Item { } } + Rectangle { + id: tools + + width: toolsLayout.implicitWidth + FishUI.Units.largeSpacing + height: 36 + FishUI.Units.smallSpacing + + visible: sizeToolTip.visible + + z: 999 + x: selectLayer.x + y: selectLayer.y + selectLayer.height + FishUI.Units.smallSpacing + + radius: FishUI.Theme.smallRadius + + color: FishUI.Theme.backgroundColor + + MouseArea { + anchors.fill: parent + } + + RowLayout { + id: toolsLayout + anchors.fill: parent + + anchors.leftMargin: FishUI.Units.smallSpacing + anchors.rightMargin: FishUI.Units.smallSpacing + anchors.topMargin: FishUI.Units.smallSpacing / 2 + anchors.bottomMargin: FishUI.Units.smallSpacing / 2 + + ImageButton { + iconMargins: FishUI.Units.largeSpacing + size: 36 + source: "qrc:/images/save.svg" + onClicked: view.saveFile(Qt.rect(selectLayer.x, + selectLayer.y, + selectLayer.width, + selectLayer.height)) + } + + ImageButton { + iconMargins: FishUI.Units.largeSpacing + size: 36 + source: "qrc:/images/cancel.svg" + onClicked: view.quit() + } + + ImageButton { + iconMargins: FishUI.Units.largeSpacing + size: 36 + source: "qrc:/images/ok.svg" + } + } + } + // Global MouseArea { id: mouseArea diff --git a/src/screenshotview.cpp b/src/screenshotview.cpp index b955bdc..ced82db 100644 --- a/src/screenshotview.cpp +++ b/src/screenshotview.cpp @@ -19,8 +19,11 @@ #include "screenshotview.h" #include +#include #include #include +#include +#include ScreenshotView::ScreenshotView(QQuickView *parent) : QQuickView(parent) @@ -29,7 +32,28 @@ ScreenshotView::ScreenshotView(QQuickView *parent) QPixmap p = qGuiApp->primaryScreen()->grabWindow(0); p.save("/tmp/cutefish-screenshot.png"); + rootContext()->setContextProperty("view", this); + setResizeMode(QQuickView::SizeRootObjectToView); setSource(QUrl("qrc:/qml/main.qml")); showFullScreen(); } + +void ScreenshotView::quit() +{ + qGuiApp->quit(); +} + +void ScreenshotView::saveFile(QRect rect) +{ + QString desktopPath = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); + QString fileName = QString("%1/Screenshot_%2.png") + .arg(desktopPath) + .arg(QDateTime::currentDateTime().toString("yyyyMMdd_hhmmss")); + + QImage image("/tmp/cutefish-screenshot.png"); + QImage cropped = image.copy(rect); + cropped.save(fileName); + + this->quit(); +} diff --git a/src/screenshotview.h b/src/screenshotview.h index ada85d2..32e57e1 100644 --- a/src/screenshotview.h +++ b/src/screenshotview.h @@ -29,7 +29,8 @@ class ScreenshotView : public QQuickView public: explicit ScreenshotView(QQuickView *parent = nullptr); -signals: + Q_INVOKABLE void quit(); + Q_INVOKABLE void saveFile(QRect rect); };