/**************************************************************************** Copyright (C) 2013-2014 by Eike Hein <hein@kde.org> ** ** 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 2 of the License, or ** (at your option) 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, write to the ** Free Software Foundation, Inc., ** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . ****************************************************************************/import QtQuick 2.0import QtQuick.Layouts 1.1import org.kde.plasma.core 2.0 as PlasmaCoreItem {id: rootproperty bool vertical: (plasmoid.formFactor == PlasmaCore.Types.Vertical)property QtObject dashWindow: nullPlasmaCore.IconItem {id: buttonIconanchors.fill: parentvisible: !(plasmoid.configuration.useCustomButtonImage && plasmoid.configuration.customButtonImage)source: plasmoid.configuration.iconactive: mouseArea.containsMouseonWidthChanged: {if (vertical && visible) {root.Layout.minimumWidth = units.iconSizes.small;root.Layout.minimumHeight = parent.width;}}onHeightChanged: {if (!vertical && visible) {root.Layout.minimumWidth = parent.height;root.Layout.minimumHeight = units.iconSizes.small;}}onVisibleChanged: {if (visible) {if (vertical) {root.Layout.minimumWidth = units.iconSizes.small;root.Layout.minimumHeight = units.iconSizes.small;} else {root.Layout.minimumWidth = parent.height;root.Layout.minimumHeight = units.iconSizes.small;}}}}Image {id: buttonImagewidth: vertical ? parent.width : undefinedheight: vertical ? undefined : parent.heightonPaintedWidthChanged: {if (!vertical && visible) {root.Layout.minimumWidth = paintedWidth;root.Layout.minimumHeight = units.iconSizes.small;}}onPaintedHeightChanged: {if (vertical && visible) {root.Layout.minimumWidth = units.iconSizes.small;root.Layout.minimumHeight = paintedHeight;}}onVisibleChanged: {if (visible) {if (vertical) {root.Layout.minimumWidth = units.iconSizes.small;root.Layout.minimumHeight = paintedHeight;} else {root.Layout.minimumWidth = paintedWidth;root.Layout.minimumHeight = units.iconSizes.small;}}}visible: plasmoid.configuration.useCustomButtonImage && plasmoid.configuration.customButtonImagesource: plasmoid.configuration.customButtonImagefillMode: Image.PreserveAspectFitsmooth: true}MouseArea{id: mouseAreaproperty bool wasExpanded: false;anchors.fill: parenthoverEnabled: trueonPressed: {if (!isDash) {wasExpanded = plasmoid.expanded}}onClicked: {if (isDash) {dashWindow.toggle();buttonIcon.active = false;justOpenedTimer.start();} else {plasmoid.expanded = !wasExpanded;}}}Component.onCompleted: {if (isDash) {dashWindow = Qt.createQmlObject("DashboardRepresentation {}", root);plasmoid.activated.connect(function() {dashWindow.toggle()justOpenedTimer.start()})}}}