From a31cf8b0036baad4f3eb1a151107a83d00b29452 Mon Sep 17 00:00:00 2001 From: Matti Viljanen Date: Sun, 28 Aug 2022 00:52:34 +0300 Subject: [PATCH] Add ImageButton --- application/qml/components/ImageButton.qml | 47 ++++++++++++++++++++++ application/qml/pages/AboutPage.qml | 16 +------- harbour-batterybuddy.pro | 3 +- 3 files changed, 51 insertions(+), 15 deletions(-) create mode 100644 application/qml/components/ImageButton.qml diff --git a/application/qml/components/ImageButton.qml b/application/qml/components/ImageButton.qml new file mode 100644 index 0000000..6807f24 --- /dev/null +++ b/application/qml/components/ImageButton.qml @@ -0,0 +1,47 @@ +/** + * Battery Buddy, a Sailfish application to prolong battery lifetime + * + * Copyright (C) 2019-2020 Matti Viljanen + * + * Battery Buddy 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 (at your option) any later version. + * + * Battery Buddy 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 Battery Buddy. If not, see . + * + * Author: Matti Viljanen + */ + +import QtQuick 2.0 +import Sailfish.Silica 1.0 + +BackgroundItem { + id: root + property string source + + anchors.horizontalCenter: parent.horizontalCenter + width: Theme.iconSizeExtraLarge + height: Theme.iconSizeExtraLarge * (image.baseHeight / image.baseWidth) + contentItem.radius: Theme.paddingMedium + + Rectangle { + anchors.fill: parent + radius: Theme.paddingMedium + color: Theme.rgba(Theme.highlightBackgroundColor, Theme.highlightBackgroundOpacity) + Image { + id: image + anchors.centerIn: parent + source: Qt.resolvedUrl(root.source) + property real baseWidth: root.width * 0.85 * (sourceSize.width > sourceSize.height ? 1.0 : (sourceSize.width / sourceSize.height)) + property real baseHeight: root.width * 0.85 * (sourceSize.height > sourceSize.width ? 1.0 : (sourceSize.height / sourceSize.width)) + width: baseWidth * (root.down ? 0.95 : 1.0) + height: baseHeight * (root.down ? 0.95 : 1.0) + smooth: true + asynchronous: true + } + } +} diff --git a/application/qml/pages/AboutPage.qml b/application/qml/pages/AboutPage.qml index 2b60a89..eefb437 100644 --- a/application/qml/pages/AboutPage.qml +++ b/application/qml/pages/AboutPage.qml @@ -93,21 +93,9 @@ Page { text: "Copyright 2021 Peter Gantner (nephros)" } - BackgroundItem { - anchors.horizontalCenter: parent.horizontalCenter - width: Theme.iconSizeExtraLarge * 1.2 - height: Theme.iconSizeExtraLarge * 1.2 + ImageButton { + source: Qt.resolvedUrl("/usr/share/harbour-batterybuddy/images/ko-fi.png") onClicked: Qt.openUrlExternally("https://ko-fi.com/direc85") - contentItem.radius: Theme.paddingSmall - - Image { - anchors.centerIn: parent - source: Qt.resolvedUrl("/usr/share/harbour-batterybuddy/images/ko-fi.png") - width: Theme.iconSizeExtraLarge - height: Theme.iconSizeExtraLarge - smooth: true - asynchronous: true - } } AboutLabel { diff --git a/harbour-batterybuddy.pro b/harbour-batterybuddy.pro index 4343a74..bff2efb 100644 --- a/harbour-batterybuddy.pro +++ b/harbour-batterybuddy.pro @@ -3,4 +3,5 @@ CONFIG += ordered SUBDIRS = application service DISTFILES += \ - application/qml/components/CoverLabel.qml + application/qml/components/CoverLabel.qml \ + application/qml/components/ImageButton.qml