diff --git a/src/controls/ApplicationWindow.qml b/src/controls/ApplicationWindow.qml index 0f767cf..845798c 100644 --- a/src/controls/ApplicationWindow.qml +++ b/src/controls/ApplicationWindow.qml @@ -1,572 +1,572 @@ /* * Copyright 2018 Camilo Higuita * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, 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 Library 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.9 import QtQuick.Controls 2.2 import QtQuick.Layouts 1.3 import QtGraphicalEffects 1.0 import QtQuick.Window 2.3 import org.kde.kirigami 2.7 as Kirigami import org.kde.mauikit 1.0 as Maui import QtQuick.Controls.Material 2.1 import "private" Kirigami.AbstractApplicationWindow { id: root visible: true width: Screen.width * (Kirigami.Settings.isMobile ? 1 : 0.4) height: Screen.height * (Kirigami.Settings.isMobile ? 1 : 0.4) contentItem.anchors.leftMargin: root.sideBar && !root.globalDrawer ? ((root.sideBar.collapsible && root.sideBar.collapsed) ? root.sideBar.collapsedSize : (root.sideBar.modal ? 0 : root.sideBar.width * root.sideBar.position)) : (!root.sideBar && root.globalDrawer && (root.globalDrawer.modal === false) ? root.globalDrawer.width * root.globalDrawer.position : 0) property Maui.AbstractSideBar sideBar /***************************************************/ /******************** ALIASES *********************/ /*************************************************/ property alias headBar : _headBar property alias footBar: _footBar property alias dialog: dialogLoader.item property alias leftIcon : menuBtn property alias menuButton : menuBtn property alias mainMenu : mainMenu.contentData property alias about : aboutDialog property alias accounts: _accountsDialogLoader.item property var currentAccount: Maui.App.accounts.currentAccount property alias notifyDialog: _notify wideScreen: isWide /***************************************************/ /*********************** UI ***********************/ /*************************************************/ property bool isWide : root.width >= Kirigami.Units.gridUnit * 30 property Flickable flickable : null property int footerPositioning : Kirigami.Settings.isMobile && flickable ? ListView.PullBackHeader : ListView.InlineFooter property int headerPositioning : Kirigami.Settings.isMobile && flickable ? ListView.PullBackHeader : ListView.InlineHeader /***************************************************/ /********************* COLORS *********************/ /*************************************************/ property color headBarBGColor: Kirigami.Theme.backgroundColor property color headBarFGColor: Kirigami.Theme.textColor /***************************************************/ /**************** READONLY PROPS ******************/ /*************************************************/ readonly property bool isMobile : Kirigami.Settings.isMobile readonly property bool isAndroid: Maui.Handy.isAndroid readonly property bool isTouch: Maui.Handy.isTouch readonly property real screenWidth : Screen.width readonly property real screenHeight : Screen.height /***************************************************/ /******************** SIGNALS *********************/ /*************************************************/ signal menuButtonClicked(); onClosing: { if(!Kirigami.Settings.isMobile) { const height = root.height const width = root.width const x = root.x const y = root.y Maui.FM.saveSettings("GEOMETRY", Qt.rect(x, y, width, height), "WINDOW") } } property bool isPortrait: Screen.primaryOrientation === Qt.PortraitOrientation || Screen.primaryOrientation === Qt.InvertedPortraitOrientation onIsPortraitChanged: { if(isPortrait) { console.log("PORTARIT MODE CHANGED") width: Screen.width height: Screen.height } } // onHeadBarBGColorChanged: // { // if(!isMobile && colorSchemeName.length > 0) // Maui.KDE.setColorScheme(colorSchemeName, headBarBGColor, headBarFGColor) // else if(isAndroid && headBar.position === ToolBar.Header) // Maui.Android.statusbarColor(headBarBGColor, false) // else if(isAndroid && headBar.position === ToolBar.Footer) // Maui.Android.statusbarColor(Kirigami.Theme.viewBackgroundColor, true) // // } // // onHeadBarFGColorChanged: // { // if(!isAndroid && !isMobile && colorSchemeName.length > 0 && headBar.position === ToolBar.Header) // Maui.KDE.setColorScheme(colorSchemeName, headBarBGColor, headBarFGColor) // else if(isAndroid && headBar.position === ToolBar.Header) // Maui.Android.statusbarColor(headBarBGColor, false) // else if(isAndroid && headBar.position === ToolBar.Footer) // Maui.Android.statusbarColor(Kirigami.Theme.viewBackgroundColor, true) // } /* * background: Rectangle * { * color: bgColor } */ Component { id: _accountsComponent ColumnLayout { visible: Maui.App.handleAccounts spacing: Maui.Style.space.medium Kirigami.Icon { visible: Maui.App.accounts.currentAccountIndex >= 0 source: "user-identity" Layout.preferredHeight: Maui.Style.iconSizes.large Layout.preferredWidth: Maui.Style.iconSizes.large Layout.alignment: Qt.AlignCenter Layout.margins: Maui.Style.space.medium } Label { visible: Maui.App.accounts.currentAccountIndex >= 0 text: currentAccount.user Layout.fillWidth: true horizontalAlignment: Qt.AlignHCenter elide: Text.ElideMiddle wrapMode: Text.NoWrap font.bold: true font.weight: Font.Bold } Kirigami.Separator { visible: _accountsListing.count > 0 Layout.fillWidth: true } ListBrowser { id: _accountsListing visible: _accountsListing.count > 0 Layout.fillWidth: true Layout.preferredHeight: Math.min(listView.contentHeight, 300) listView.spacing: Maui.Style.space.medium Kirigami.Theme.backgroundColor: "transparent" currentIndex: Maui.App.accounts.currentAccountIndex model: Maui.BaseModel { list: Maui.App.accounts } delegate: Maui.ListBrowserDelegate { iconSource: "amarok_artist" iconSizeHint: Maui.Style.iconSizes.medium label1.text: model.user label2.text: model.server width: _accountsListing.width height: Maui.Style.rowHeight * 1.2 leftPadding: Maui.Style.space.tiny rightPadding: Maui.Style.space.tiny onClicked: Maui.App.accounts.currentAccountIndex = index } Component.onCompleted: { if(_accountsListing.count > 0) Maui.App.accounts.currentAccountIndex = 0 } } Kirigami.Separator { visible: _accountsListing.count > 0 Layout.fillWidth: true } Button { Layout.margins: Maui.Style.space.small Layout.preferredHeight: implicitHeight Layout.alignment: Qt.AlignCenter text: qsTr("Manage accounts") icon.name: "list-add-user" onClicked: { if(root.accounts) accounts.open() mainMenu.close() } Kirigami.Theme.backgroundColor: Qt.rgba(Kirigami.Theme.backgroundColor.r, Kirigami.Theme.backgroundColor.g, Kirigami.Theme.backgroundColor.b, 0.1) Kirigami.Theme.textColor: Kirigami.Theme.textColor } Kirigami.Separator { Layout.fillWidth: true } } } Connections { target: root.flickable ? root.flickable : null enabled: root.flickable && (root.header || root.footer) property int oldContentY property bool updatingContentY: false onContentYChanged: { if(root.flickable.atYBeginning && !root.flickable.dragging) { if(root.header) root.header.height = root.header.implicitHeight if(root.footer) root.footer.height = root.footer.implicitHeight oldContentY = 0 updatingContentY = false return; } if (updatingContentY || !root.flickable) { oldContentY = root.flickable.contentY; return; //TODO: merge //if moves but not dragging, just update oldContentY } else if (!root.flickable.dragging) { oldContentY = root.flickable.contentY; return; } var oldFHeight var oldHHeight - if(root.footer && root.footer.visible) + if(root.footer) { if (root.footerPositioning === ListView.InlineFooter) { root.footer.height = root.footer.implicitHeight } else if (root.footerPositioning === ListView.PullBackFooter) { oldFHeight = root.footer.height; root.footer.height = Math.max(0, Math.min(root.footer.implicitHeight, root.footer.height + oldContentY - root.flickable.contentY)); } } - if(root.header && root.header.visible) + if(root.header) { if (root.headerPositioning === ListView.InlineHeader ) { root.header.height = root.header.implicitHeight } else if (root.headerPositioning === ListView.PullBackHeader) { oldHHeight = root.header.height; root.header.height = Math.max(0, Math.min(root.header.implicitHeight, root.header.height + oldContentY - root.flickable.contentY)); } } //if the implicitHeight is changed, use that to simulate scroll if ((root.footer && oldFHeight !== root.footer.height)|| ( root.header && oldHHeight !== root.header.height)) { updatingContentY = true; if(oldHHeight !== root.header.height) root.flickable.contentY -= (oldHHeight - root.header.height) updatingContentY = false; } else { oldContentY = root.flickable.contentY; } } onMovementEnded: { - if (root.headerPositioning === ListView.PullBackHeader) + if (root.headerPositioning === ListView.PullBackHeader && root.header) { if (root.header.height > (root.header.implicitHeight/2) ) { root.header.height = root.header.implicitHeight } else { root.header.height = 0 } } - if (root.footerPositioning === ListView.PullBackFooter) + if (root.footerPositioning === ListView.PullBackFooter && root.footer) { if (root.footer.height > (root.footer.implicitHeight/2) ) { root.footer.height = root.footer.implicitHeight } else { root.footer.height = 0 } } } } property Maui.ToolBar mheadBar : Maui.ToolBar { id: _headBar visible: count > 1 position: ToolBar.Header width: root.width height: implicitHeight - onImplicitHeightChanged: height = implicitHeight // Kirigami.Theme.backgroundColor: headBarBGColor // Kirigami.Theme.textColor: headBarFGColor // Kirigami.Theme.inherit: true leftContent: [ ToolButton { id: menuBtn icon.name: "application-menu" icon.color: headBarFGColor icon.width: Maui.Style.iconSizes.medium icon.height: Maui.Style.iconSizes.medium checked: mainMenu.visible onClicked: { menuButtonClicked() mainMenu.visible ? mainMenu.close() : mainMenu.popup(parent, parent.x , parent.height+ Maui.Style.space.medium) } Menu { id: mainMenu modal: true z: 999 width: Maui.Style.unit * 250 Loader { id: _accountsMenuLoader width: parent.width * 0.9 anchors.horizontalCenter: parent.horizontalCenter active: Maui.App.handleAccounts sourceComponent: Maui.App.handleAccounts ? _accountsComponent : null } MenuItem { text: qsTr("About") icon.name: "documentinfo" onTriggered: aboutDialog.open() } } } ] } property Maui.ToolBar mfootBar : Maui.ToolBar { id: _footBar visible: count position: ToolBar.Footer width: root.width height: implicitHeight - onImplicitHeightChanged: height = implicitHeight } header: headBar.count && headBar.position === ToolBar.Header ? headBar : null footer: Column { id: _footer visible : children + onImplicitHeightChanged: height = implicitHeight + children: { if(headBar.position === ToolBar.Footer && headBar.count && footBar.count) return [footBar , headBar] else if(headBar.position === ToolBar.Footer && headBar.count) return [headBar] else if(footBar.count) return [footBar] else return null } } Maui.AboutDialog { id: aboutDialog } Loader { id: _accountsDialogLoader source: Maui.App.handleAccounts ? "private/AccountsHelper.qml" : "" } Maui.Dialog { id: _notify property var cb : ({}) property alias iconName : _notifyTemplate.iconSource property alias title : _notifyTemplate.label1 property alias body: _notifyTemplate.label2 verticalAlignment: Qt.AlignTop defaultButtons: _notify.cb !== null rejectButton.visible: false onAccepted: { if(_notify.cb) { _notify.cb() _notify.close() } } page.padding: Maui.Style.space.medium footBar.background: null maxHeight: Math.max(Maui.Style.iconSizes.large + Maui.Style.space.huge, (_notifyTemplate.implicitHeight)) + Maui.Style.space.big + footBar.height maxWidth: Kirigami.Settings.isMobile ? parent.width * 0.9 : Maui.Style.unit * 500 widthHint: 0.8 Timer { id: _notifyTimer onTriggered: { if(_mouseArea.containsPress || _mouseArea.containsMouse) return; _notify.close() } } onClosed: _notifyTimer.stop() Maui.ListItemTemplate { id: _notifyTemplate anchors.fill: parent iconSizeHint: Maui.Style.iconSizes.huge label1.font.bold: true label1.font.weight: Font.Bold label1.font.pointSize: Maui.Style.fontSizes.big iconSource: "dialog-warning" } MouseArea { id: _mouseArea height: parent.height width: parent.width anchors.centerIn: parent hoverEnabled: true } function show(callback) { _notify.cb = callback || null _notifyTimer.start() _notify.open() } } Loader { id: dialogLoader } Component.onCompleted: { if(isAndroid) { if(headBar.position === ToolBar.Footer) Maui.Android.statusbarColor(Kirigami.Theme.backgroundColor, true) else Maui.Android.statusbarColor(headBar.Kirigami.Theme.backgroundColor, true) } if(!Kirigami.Settings.isMobile) { const rect = Maui.FM.loadSettings("GEOMETRY", "WINDOW", Qt.rect(root.x, root.y, root.width, root.height)) root.x = rect.x root.y = rect.y root.width = rect.width root.height = rect.height } } Connections { target: Maui.App onSendNotification: notify(icon, title, body, callback, timeout, buttonText) } function notify(icon, title, body, callback, timeout, buttonText) { _notify.iconName = icon || "emblem-warning" _notify.title.text = title _notify.body.text = body _notifyTimer.interval = timeout ? timeout : 2500 _notify.acceptButton.text = buttonText || qsTr ("Accept") _notify.show(callback) } } diff --git a/src/controls/GridBrowserDelegate.qml b/src/controls/GridBrowserDelegate.qml index 7df62ec..2502750 100644 --- a/src/controls/GridBrowserDelegate.qml +++ b/src/controls/GridBrowserDelegate.qml @@ -1,226 +1,225 @@ /* * Copyright 2018 Camilo Higuita * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, 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 Library 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.0 import QtQuick.Controls 2.2 import QtQuick.Layouts 1.3 import org.kde.kirigami 2.7 as Kirigami import org.kde.mauikit 1.0 as Maui import QtGraphicalEffects 1.0 import "private" Maui.ItemDelegate { id: control property int folderSize : Maui.Style.iconSizes.big property int emblemSize: Maui.Style.iconSizes.medium property bool showLabel : true property bool showEmblem : false property bool showTooltip : false property bool showThumbnails : false property bool isSelected : false property bool keepEmblemOverlay : false property string rightEmblem property string leftEmblem - property alias dropArea : _dropArea - + property alias dropArea : _dropArea isCurrentItem : GridView.isCurrentItem || isSelected signal emblemClicked(int index) signal rightEmblemClicked(int index) signal leftEmblemClicked(int index) signal contentDropped(var drop) ToolTip.delay: 1000 ToolTip.timeout: 5000 ToolTip.visible: control.hovered && control.showTooltip ToolTip.text: model.tooltip ? model.tooltip : model.path - background: null + background: Item {} DropArea { id: _dropArea anchors.fill: parent enabled: control.draggable Rectangle { anchors.fill: parent radius: Maui.Style.radiusV color: control.Kirigami.Theme.highlightColor visible: parent.containsDrag } onDropped: { control.contentDropped(drop) } } Drag.active: mouseArea.drag.active && control.draggable Drag.dragType: Drag.Automatic Drag.supportedActions: Qt.CopyAction Drag.mimeData: { "text/uri-list": model.path } Maui.Badge { id: _leftEmblemIcon iconName: control.leftEmblem visible: (control.hovered || control.keepEmblemOverlay || control.isSelected) && control.showEmblem && control.leftEmblem z: mouseArea.z + 1 anchors.top: parent.top anchors.left: parent.left onClicked: leftEmblemClicked(index) size: Maui.Style.iconSizes.small } Maui.Badge { id: _rightEmblemIcon iconName: rightEmblem visible: (control.hovered || control.keepEmblemOverlay) && control.showEmblem && control.rightEmblem z: 999 size: Maui.Style.iconSizes.medium anchors.top: parent.top anchors.right: parent.right onClicked: rightEmblemClicked(index) } Component { id: _imgComponent Image { id: img anchors.centerIn: parent source: model.thumbnail && model.thumbnail.length ? model.thumbnail : "" height: Math.min (parent.height, img.implicitHeight) width: Math.min(parent.width, img.implicitWidth) sourceSize.width: width sourceSize.height: height horizontalAlignment: Qt.AlignHCenter verticalAlignment: Qt.AlignVCenter fillMode: Image.PreserveAspectCrop cache: true asynchronous: true smooth: !Kirigami.Settings.isMobile layer.enabled: true layer.effect: OpacityMask { maskSource: Item { width: img.width height: img.height Rectangle { anchors.centerIn: parent width: img.width height: img.height radius: Maui.Style.radiusV } } } } } Component { id: _iconComponent Item { anchors.fill: parent Kirigami.Icon { anchors.centerIn: parent source: model.icon fallback: "qrc:/assets/application-x-zerosize.svg" height: Math.min(control.folderSize, parent.width) width: height } } } ColumnLayout { id: _layout anchors.fill: parent spacing: Maui.Style.space.tiny opacity: (model.hidden == true || model.hidden == "true" )? 0.5 : 1 Loader { id: _loader sourceComponent: model.mime ? (Maui.FM.checkFileType(Maui.FMList.IMAGE, model.mime) && control.showThumbnails && model.thumbnail && model.thumbnail.length? _imgComponent : _iconComponent) : _iconComponent Layout.preferredHeight: Math.min(control.folderSize, width) Layout.fillWidth: true Layout.alignment: Qt.AlignCenter Layout.margins: Maui.Style.unit } Item { Layout.margins: Maui.Style.space.tiny Layout.fillHeight: true Layout.fillWidth: true Label { id: label text: model.label width: parent.width anchors.centerIn: parent height: Math.min(implicitHeight + Maui.Style.space.medium, _layout.height - _loader.height) horizontalAlignment: Qt.AlignHCenter verticalAlignment: Qt.AlignVCenter elide: Qt.ElideRight wrapMode: Text.Wrap color: control.Kirigami.Theme.textColor Rectangle { anchors.fill: parent Behavior on color { ColorAnimation { duration: Kirigami.Units.longDuration } } color: control.isCurrentItem || control.hovered ? Qt.rgba(control.Kirigami.Theme.highlightColor.r, control.Kirigami.Theme.highlightColor.g, control.Kirigami.Theme.highlightColor.b, 0.2) : control.Kirigami.Theme.backgroundColor radius: control.radius border.color: control.isCurrentItem ? control.Kirigami.Theme.highlightColor : "transparent" } } } } } diff --git a/src/controls/ItemDelegate.qml b/src/controls/ItemDelegate.qml index fc42640..3cd68a3 100644 --- a/src/controls/ItemDelegate.qml +++ b/src/controls/ItemDelegate.qml @@ -1,154 +1,178 @@ /* * Copyright 2018 Camilo Higuita * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, 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 Library 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.12 import QtQuick.Controls 2.2 import QtQuick.Layouts 1.3 import org.kde.kirigami 2.7 as Kirigami import org.kde.mauikit 1.0 as Maui import QtGraphicalEffects 1.0 import "private" -ItemDelegate +Kirigami.DelegateRecycler { + id: control - - default property alias content : _content.data - - property alias mouseArea : _mouseArea -// property alias tapArea : _tapArea - property bool draggable: false - property bool isCurrentItem : false - - property int radius: Maui.Style.radiusV - highlighted: isCurrentItem - //override the itemdelegate default signals to allow dragging content - signal pressed(var mouse) - signal pressAndHold(var mouse) - signal clicked(var mouse) - signal rightClicked(var mouse) - signal doubleClicked(var mouse) - + Kirigami.Theme.inherit: false Kirigami.Theme.backgroundColor: "transparent" - - hoverEnabled: !Kirigami.Settings.isMobile - - padding: 0 - bottomPadding: padding - rightPadding: padding - leftPadding: padding - topPadding: padding - MouseArea - { - id: _mouseArea -// enabled: !Kirigami.Settings.isMobile - anchors.fill: parent - acceptedButtons: Qt.RightButton | Qt.LeftButton - property int startX - property int startY - - onClicked: - { - if(!Kirigami.Settings.isMobile && mouse.button === Qt.RightButton) - control.rightClicked(mouse) - else - control.clicked(mouse) - } - - onDoubleClicked: control.doubleClicked(mouse) - - onPressed: + default property alias content : _content.data + + property alias mouseArea : _mouseArea + // property alias tapArea : _tapArea + property bool draggable: false + property bool isCurrentItem : false + + property int radius: Maui.Style.radiusV + + property alias padding: _delegate.padding + property alias leftPadding: _delegate.leftPadding + property alias rightPadding: _delegate.rightPadding + property alias topPadding: _delegate.topPadding + property alias bottomPadding: _delegate.bottomPadding + + property alias hovered: _delegate.hovered + property alias hoverEnabled: _delegate.hoverEnabled + property alias highlighted: _delegate.highlighted + + signal pressed(var mouse) + signal pressAndHold(var mouse) + signal clicked(var mouse) + signal rightClicked(var mouse) + signal doubleClicked(var mouse) + + property alias background : _delegate.background + + ItemDelegate { - if(control.draggable && mouse.source !== Qt.MouseEventSynthesizedByQt) + id: _delegate + anchors.fill: parent + + highlighted: control.isCurrentItem + //override the itemdelegate default signals to allow dragging content + + hoverEnabled: !Kirigami.Settings.isMobile + + padding: 0 + bottomPadding: padding + rightPadding: padding + leftPadding: padding + topPadding: padding + + MouseArea { - drag.target = control - control.grabToImage(function(result) + id: _mouseArea + // enabled: !Kirigami.Settings.isMobile + anchors.fill: parent + acceptedButtons: Qt.RightButton | Qt.LeftButton + property int startX + property int startY + + onClicked: { - parent.Drag.imageSource = result.url - }) - }else drag.target = null - - - startX = control.x - startY = control.y - control.pressed(mouse) - } - - onReleased : - { - control.x = startX - control.y = startY - } - - onPressAndHold : control.pressAndHold(mouse) - } - -// TapHandler -// { -// id: _tapArea -// enabled: Kirigami.Settings.isMobile -// acceptedButtons: Qt.RightButton -// onSingleTapped: control.clicked(eventPoint) -// onDoubleTapped: control.doubleClicked(eventPoint) -// onLongPressed: control.pressAndHold(eventPoint) -// } - - contentItem: Item{} - - Item - { - id: _content - anchors - { - fill: parent - topMargin: control.topPadding - bottomMargin: control.bottomPadding - leftMargin: control.leftPadding - rightMargin: control.rightPadding - margins: control.padding - } - } - - background: Rectangle - { - anchors - { - fill: parent - topMargin: control.topPadding - bottomMargin: control.bottomPadding - leftMargin: control.leftPadding - rightMargin: control.rightPadding - margins: control.padding - } - - Behavior on color - { - ColorAnimation + if(!Kirigami.Settings.isMobile && mouse.button === Qt.RightButton) + control.rightClicked(mouse) + else + control.clicked(mouse) + } + + onDoubleClicked: control.doubleClicked(mouse) + + onPressed: + { + if(control.draggable && mouse.source !== Qt.MouseEventSynthesizedByQt) + { + drag.target = _delegate + _delegate.grabToImage(function(result) + { + console.log(result.url) + parent.Drag.imageSource = result.url + }) + }else drag.target = null + + startX = control.x + startY = control.y + control.pressed(mouse) + } + + onReleased : + { + control.x = startX + control.y = startY + } + + onPressAndHold : control.pressAndHold(mouse) + } + + // TapHandler + // { + // id: _tapArea + // enabled: Kirigami.Settings.isMobile + // acceptedButtons: Qt.RightButton + // onSingleTapped: control.clicked(eventPoint) + // onDoubleTapped: control.doubleClicked(eventPoint) + // onLongPressed: control.pressAndHold(eventPoint) + // } + + contentItem: Item{} + + Item + { + id: _content + anchors + { + fill: parent + topMargin: _delegate.topPadding + bottomMargin: _delegate.bottomPadding + leftMargin: _delegate.leftPadding + rightMargin: _delegate.rightPadding + margins: _delegate.padding + } + } + + background: Rectangle { - duration: Kirigami.Units.shortDuration + anchors + { + fill: parent + topMargin: _delegate.topPadding + bottomMargin: _delegate.bottomPadding + leftMargin: _delegate.leftPadding + rightMargin: _delegate.rightPadding + margins: _delegate.padding + } + + Behavior on color + { + ColorAnimation + { + duration: Kirigami.Units.shortDuration + } + } + color: control.isCurrentItem || control.hovered ? Qt.rgba(control.Kirigami.Theme.highlightColor.r, control.Kirigami.Theme.highlightColor.g, control.Kirigami.Theme.highlightColor.b, 0.2) : control.Kirigami.Theme.backgroundColor + + radius: control.radius + border.color: control.isCurrentItem ? control.Kirigami.Theme.highlightColor : "transparent" } + } - color: control.isCurrentItem || control.hovered ? Qt.rgba(control.Kirigami.Theme.highlightColor.r, control.Kirigami.Theme.highlightColor.g, control.Kirigami.Theme.highlightColor.b, 0.2) : control.Kirigami.Theme.backgroundColor - - radius: control.radius - border.color: control.isCurrentItem ? control.Kirigami.Theme.highlightColor : "transparent" - } + } + diff --git a/src/controls/Page.qml b/src/controls/Page.qml index b3e21c1..975cbab 100644 --- a/src/controls/Page.qml +++ b/src/controls/Page.qml @@ -1,250 +1,245 @@ /* * Copyright 2018 Camilo Higuita * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, 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 Library 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.10 import QtQuick.Controls 2.10 import QtQuick.Layouts 1.3 import org.kde.mauikit 1.0 as Maui import org.kde.kirigami 2.7 as Kirigami import QtQuick.Layouts 1.3 Page { id: control focus: true leftPadding: control.padding rightPadding: control.padding topPadding: control.padding bottomPadding: control.padding Kirigami.Theme.colorSet: Kirigami.Theme.View property bool showTitle : true property Flickable flickable : null property int footerPositioning : Kirigami.Settings.isMobile && flickable ? ListView.PullBackHeader : ListView.InlineFooter property int headerPositioning : Kirigami.Settings.isMobile && flickable ? ListView.PullBackHeader : ListView.InlineHeader signal goBackTriggered() signal goForwardTriggered() background: Rectangle { color: Kirigami.Theme.backgroundColor } Connections { target: control.flickable ? control.flickable : null enabled: control.flickable && (control.header || control.footer) property int oldContentY property bool updatingContentY: false onContentYChanged: { if(control.flickable.atYBeginning && !control.flickable.dragging) { if(control.header) control.header.y = 0 if(control.footer) control.footer.height = control.footer.implicitHeight oldContentY = 0 updatingContentY = false return; } if (updatingContentY || !control.flickable) { oldContentY = control.flickable.contentY; return; //TODO: merge //if moves but not dragging, just update oldContentY } else if (!control.flickable.dragging) { oldContentY = control.flickable.contentY; return; } var oldFHeight var oldHY if(control.footer) { if (control.footerPositioning === ListView.InlineFooter ) { control.footer.height = control.footer.implicitHeight } else if (control.footerPositioning === ListView.PullBackFooter) { oldFHeight = control.footer.height; control.footer.height = Math.max(0, Math.min(control.footer.implicitHeight, control.footer.height + oldContentY - control.flickable.contentY)); } } if(control.header) { if (control.headerPositioning === ListView.InlineHeader) { control.header.y = 0; } else if (control.headerPositioning === ListView.PullBackHeader) { oldHY = control.header.y control.header.y = Math.max(-(control.header.implicitHeight), Math.min(0, control.header.y + oldContentY - control.flickable.contentY)) } } //if the implicitHeight is changed, use that to simulate scroll if ((control.footer && oldFHeight !== control.footer.height) || (control.header && oldHY !== control.header.y)) { updatingContentY = true; if(control.header && oldHY !== control.header.y) control.flickable.contentY -= (oldHY - control.header.y) updatingContentY = false; } else { oldContentY = control.flickable.contentY; } } onMovementEnded: { if (control.headerPositioning === ListView.PullBackHeader && control.header) { if (control.header.y > -(control.header.implicitHeight/2) ) { control.header.y = 0; } else { control.header.y = -(control.header.implicitHeight) } } if (control.footerPositioning === ListView.PullBackFooter && control.footer) { if (control.footer.height > (control.footer.implicitHeight/2) ) { control.footer.height = control.footer.implicitHeight } else { control.footer.height = 0 } } } } property alias headBar : _headBar property alias footBar: _footBar property Maui.ToolBar mheadBar : Maui.ToolBar { id: _headBar visible: count > 1 width: control.width height: implicitHeight - position: ToolBar.Header - - onImplicitHeightChanged: height = implicitHeight - - readonly property int preferredHeight: Maui.Style.toolBarHeight + position: ToolBar.Header Component { id: _titleComponent Label { text: control.title elide : Text.ElideRight font.bold : false font.weight: Font.Bold color : Kirigami.Theme.textColor font.pointSize: Maui.Style.fontSizes.big horizontalAlignment : Text.AlignHCenter verticalAlignment : Text.AlignVCenter } } middleContent: Loader { Layout.fillWidth: sourceComponent === _titleComponent Layout.fillHeight: sourceComponent === _titleComponent sourceComponent: control.title && control.showTitle ? _titleComponent : undefined } } property Maui.ToolBar mfootBar : Maui.ToolBar { id: _footBar visible: count position: ToolBar.Footer width: control.width height: implicitHeight - onImplicitHeightChanged: height = implicitHeight - } header: headBar.count && headBar.position === ToolBar.Header ? headBar : null footer: Column { id: _footer visible : children + onImplicitHeightChanged: height = implicitHeight children: { if(headBar.position === ToolBar.Footer && headBar.count && footBar.count) return [footBar , headBar] else if(headBar.position === ToolBar.Footer && headBar.count) return [headBar] else if(footBar.count) return [footBar] else return [] } } Keys.onBackPressed: { control.goBackTriggered(); event.accepted = true } Shortcut { sequence: "Forward" onActivated: control.goForwardTriggered(); } Shortcut { sequence: StandardKey.Forward onActivated: control.goForwardTriggered(); } Shortcut { sequence: StandardKey.Back onActivated: control.goBackTriggered(); } }