/* * 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.Controls 2.12 import QtQuick.Layouts 1.12 import QtGraphicalEffects 1.0 import FishUI 1.0 as FishUI import Cutefish.StatusBar 1.0 Item { id: control property string popupText: "" property bool checked: false signal clicked signal rightClicked MouseArea { id: _mouseArea anchors.fill: parent acceptedButtons: Qt.LeftButton | Qt.RightButton hoverEnabled: true onClicked: { if (mouse.button == Qt.LeftButton) control.clicked() else if (mouse.button == Qt.RightButton) control.rightClicked() } onPressed: { popupTips.hide() } onContainsMouseChanged: { if (containsMouse && control.popupText !== "") { popupTips.popupText = control.popupText popupTips.position = Qt.point(control.mapToGlobal(0, 0).x + (control.width / 2 - popupTips.width / 2), control.height + FishUI.Units.smallSpacing) popupTips.show() } else { popupTips.hide() } } } Rectangle { anchors.fill: parent anchors.topMargin: 1 anchors.bottomMargin: 1 radius: FishUI.Theme.smallRadius color: { if (control.checked) { return (FishUI.Theme.darkMode) ? Qt.rgba(255, 255, 255, 0.2) : Qt.rgba(0, 0, 0, 0.1) } if (_mouseArea.containsMouse) { if (_mouseArea.containsPress) return (FishUI.Theme.darkMode) ? Qt.rgba(255, 255, 255, 0.3) : Qt.rgba(0, 0, 0, 0.2) else return (FishUI.Theme.darkMode) ? Qt.rgba(255, 255, 255, 0.2) : Qt.rgba(0, 0, 0, 0.1) } return "transparent" } } }