diff --git a/src/controls/ApplicationWindow.qml b/src/controls/ApplicationWindow.qml index 56f50e9..9756ac9 100644 --- a/src/controls/ApplicationWindow.qml +++ b/src/controls/ApplicationWindow.qml @@ -1,578 +1,584 @@ /* * 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 onFlickableChanged: returnToBounds() 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.flickable != null && (root.header || root.footer) + enabled: root.flickable && (root.header || root.footer) property int oldContentY property bool updatingContentY: false - + property int oldContentHeight : root.flickable.height + onContentYChanged: - { - - if((root.flickable.atYBeginning && !root.flickable.dragging) || (root.flickable.contentHeight < root.flickable.height*1.5 )) + { + if(!root.flickable.dragging) + return; + + if((root.flickable.atYBeginning) || (root.flickable.contentHeight < oldContentHeight*1.5 )) { - returnToBounds() - + oldContentHeight = root.flickable.height + returnToBounds() return; } if (updatingContentY || !root.flickable) { oldContentY = root.flickable.contentY; + oldContentHeight = root.flickable.height + 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) { 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, + root.footer.height = Math.max(root.footer.hasOwnProperty("minimumHeight") ? root.footer.minimumHeight : 0, Math.min(root.footer.implicitHeight, root.footer.height + oldContentY - root.flickable.contentY)); } } 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, + root.header.height = Math.max(root.header.hasOwnProperty("minimumHeight") ? root.header.minimumHeight : 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) + if(root.header && oldHHeight !== root.header.height) root.flickable.contentY -= (oldHHeight - root.header.height) updatingContentY = false; } else { - oldContentY = root.flickable.contentY; + oldContentY = root.flickable.contentY + oldContentHeight = root.flickable.height + } } onMovementEnded: { + + if(!root.flickable.dragging) + return; + 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 + root.header.height = root.header.hasOwnProperty("minimumHeight") ? root.header.minimumHeight : 0 } } 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 + root.footer.height = root.footer.hasOwnProperty("minimumHeight") ? root.footer.minimumHeight : 0 } - } - + } } } property Maui.ToolBar mheadBar : Maui.ToolBar { id: _headBar visible: count > 1 position: ToolBar.Header width: root.width 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 } 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) } function returnToBounds() { if(root.header) root.header.height = root.header.implicitHeight if(root.footer) root.footer.height = root.footer.implicitHeight } } diff --git a/src/controls/ListBrowser.qml b/src/controls/ListBrowser.qml index 02c55de..6c25e72 100644 --- a/src/controls/ListBrowser.qml +++ b/src/controls/ListBrowser.qml @@ -1,177 +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.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 Kirigami.ScrollablePage { id: control property int itemSize : Maui.Style.iconSizes.big property bool showEmblem : true property bool keepEmblemOverlay : false property string rightEmblem property string leftEmblem property bool showDetailsInfo : false property bool showPreviewThumbnails: true property alias model : _listView.model property alias delegate : _listView.delegate property alias section : _listView.section property alias contentY: _listView.contentY property alias currentIndex : _listView.currentIndex property alias currentItem : _listView.currentItem property alias count : _listView.count property alias cacheBuffer : _listView.cacheBuffer property alias topMargin: _listView.topMargin property alias bottomMargin: _listView.bottomMargin property alias rightMargin: _listView.rightMargin property alias leftMarging: _listView.leftMargin property alias listView: _listView property alias holder : _holder signal itemClicked(int index) signal itemDoubleClicked(int index) signal itemRightClicked(int index) signal rightEmblemClicked(int index) signal leftEmblemClicked(int index) signal areaClicked(var mouse) signal areaRightClicked() signal keyPress(var event) spacing: 0 focus: true padding: 0 leftPadding: padding rightPadding: padding topPadding: padding bottomPadding: padding Keys.enabled: false Kirigami.Theme.colorSet: Kirigami.Theme.View + supportsRefreshing: false ListView { id: _listView focus: true clip: true spacing: Maui.Style.space.tiny snapMode: ListView.NoSnap boundsBehavior: !Kirigami.Settings.isMobile? Flickable.StopAtBounds : Flickable.OvershootBounds interactive: Maui.Handy.isTouch highlightFollowsCurrentItem: true highlightMoveDuration: 0 highlightResizeDuration : 0 keyNavigationEnabled : bool keyNavigationWraps : bool Keys.onPressed: control.keyPress(event) // ScrollBar.vertical: ScrollBar { } Maui.Holder { id: _holder anchors.fill : parent } delegate: Maui.ListBrowserDelegate { id: delegate width: parent.width height: itemSize + Maui.Style.space.big leftPadding: Maui.Style.space.small rightPadding: Maui.Style.space.small padding: 0 showDetailsInfo: control.showDetailsInfo folderSize : itemSize showTooltip: true showEmblem: control.showEmblem keepEmblemOverlay : control.keepEmblemOverlay showThumbnails: showPreviewThumbnails rightEmblem: control.rightEmblem leftEmblem: control.leftEmblem Connections { target: delegate onClicked: { control.currentIndex = index control.itemClicked(index) } onDoubleClicked: { control.currentIndex = index control.itemDoubleClicked(index) } onPressAndHold: { control.currentIndex = index control.itemRightClicked(index) } onRightClicked: { control.currentIndex = index control.itemRightClicked(index) } onRightEmblemClicked: { control.currentIndex = index control.rightEmblemClicked(index) } onLeftEmblemClicked: { control.currentIndex = index control.leftEmblemClicked(index) } } } MouseArea { anchors.fill: parent z: -1 acceptedButtons: Qt.RightButton | Qt.LeftButton onClicked: { control.forceActiveFocus() control.areaClicked(mouse) } onPressAndHold: control.areaRightClicked() } } } diff --git a/src/controls/Page.qml b/src/controls/Page.qml index b0ba62a..be4fea5 100644 --- a/src/controls/Page.qml +++ b/src/controls/Page.qml @@ -1,254 +1,260 @@ /* * 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 } onFlickableChanged: returnToBounds() Connections { - target: control.flickable ? control.flickable : null + target: control.flickable ? control.flickable : null enabled: control.flickable && (control.header || control.footer) property int oldContentY - property int oldContentHeight : control.flickable.height property bool updatingContentY: false - + property int oldContentHeight : control.flickable.height + onContentYChanged: { - if((control.flickable.atYBeginning && !control.flickable.dragging) || (control.flickable.contentHeight < oldContentHeight*1.5 )) + if(!control.flickable.dragging) + return; + + if((control.flickable.atYBeginning) || (control.flickable.contentHeight < oldContentHeight*1.5 )) { - returnToBounds() + oldContentHeight = control.flickable.height + returnToBounds() return; } if (updatingContentY || !control.flickable) { oldContentY = control.flickable.contentY; oldContentHeight = control.flickable.height + return; //TODO: merge //if moves but not dragging, just update oldContentY - } else if (!control.flickable.dragging) - { - oldContentY = control.flickable.contentY; - oldContentHeight = control.flickable.height - return; - } + } var oldFHeight - var oldHY + var oldHHeight if(control.footer) { - if (control.footerPositioning === ListView.InlineFooter ) + 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)); + control.footer.height = Math.max(control.footer.minimumHeight, + 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) + + if(control.header) { - oldHY = control.header.y - - control.header.y = Math.max(-(control.header.implicitHeight), - Math.min(0, control.header.y + oldContentY - control.flickable.contentY)) + if (control.headerPositioning === ListView.InlineHeader ) + { + control.header.height = control.header.implicitHeight + + } else if (control.headerPositioning === ListView.PullBackHeader) + { + oldHHeight = control.header.height; + control.header.height = Math.max(control.header.minimumHeight, + Math.min(control.header.implicitHeight, + control.header.height + 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)) { + if ((control.footer && oldFHeight !== control.footer.height) || ( control.header && oldHHeight !== control.header.height)) + { updatingContentY = true; - if(control.header && oldHY !== control.header.y) - control.flickable.contentY -= (oldHY - control.header.y) + if(control.header && oldHHeight !== control.header.height) + control.flickable.contentY -= (oldHHeight - control.header.height) updatingContentY = false; } else { - oldContentY = control.flickable.contentY; + oldContentY = control.flickable.contentY oldContentHeight = control.flickable.height } } onMovementEnded: { - if (control.headerPositioning === ListView.PullBackHeader && control.header) + if(!control.flickable.dragging) + return; + + if (control.headerPositioning === ListView.PullBackHeader && control.header) { - if (control.header.y >= -(control.header.implicitHeight/2) ) + if (control.header.height >= (control.header.implicitHeight/2) ) { - control.header.y = 0; + control.header.height = control.header.implicitHeight + } else { - control.header.y = -(control.header.implicitHeight) + control.header.height = control.header.minimumHeight } } - if (control.footerPositioning === ListView.PullBackFooter && control.footer) + 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 + control.footer.height = control.header.minimumHeight } - } + } + } } 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 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 } 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(); } function returnToBounds() { if(control.header) - control.header.y = 0 - - if(control.footer) + control.header.height = control.header.implicitHeight + + if(control.footer) control.footer.height = control.footer.implicitHeight } } diff --git a/src/controls/ToolBar.qml b/src/controls/ToolBar.qml index 935730d..05cc54b 100644 --- a/src/controls/ToolBar.qml +++ b/src/controls/ToolBar.qml @@ -1,301 +1,305 @@ /* * 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.6 import QtQuick.Controls 2.2 import org.kde.kirigami 2.7 as Kirigami import org.kde.mauikit 1.0 as Maui import QtQuick.Layouts 1.3 import QtGraphicalEffects 1.0 import "private" ToolBar { - id: control + id: control - implicitHeight: visible ? Maui.Style.toolBarHeight : 0 - implicitWidth: mainFlickable.contentWidth + property int minimumHeight: 1 + property int preferredHeight: Maui.Style.toolBarHeight + property int maximumHeight: Kirigami.Units.gridUnit * 3 + + implicitHeight: preferredHeight + spacing: Maui.Style.space.small padding: 0 property alias stickyRightContent : rightRowContent.sticky property alias stickyLeftContent : leftRowContent.sticky property alias stickyMiddleContent : middleRowContent.sticky property alias leftContent : leftRowContent.data property alias middleContent : middleRowContent.data property alias rightContent : rightRowContent.data property alias middleLayout : middleRowContent property alias leftLayout : leftRowContent property alias rightLayout : rightRowContent property alias layout : layout readonly property alias fits : mainFlickable.fits property int margins: Maui.Style.space.medium property int count : leftContent.length + middleContent.length + rightContent.length property bool flickable: true property bool strech : true property bool leftSretch: strech property bool rightSretch: strech property bool middleStrech: strech // leftPadding: Kirigami.Units.smallSpacing*2 // rightPadding: Kirigami.Units.smallSpacing*2 // background: Rectangle // { // id: headBarBG // color: colorScheme.backgroundColor // implicitHeight: Maui.Style.toolBarHeightAlt // radius: floating ? Maui.Style.radiusV : 0 // border.color: floating ? colorScheme.borderColor : "transparent" // // SequentialAnimation on radius // { // ColorAnimation { to: colorScheme.backgroundColor ; duration: 1000 } // } // // Kirigami.Separator // { // visible: drawBorder // color: colorScheme.borderColor // height: Maui.Style.unit // anchors // { // left: parent.left // right: parent.right // bottom: control.position == ToolBar.Footer ? undefined : parent.bottom // top: control.position == ToolBar.Footer ? parent.top : undefined // } // } // // layer.enabled: dropShadow // layer.effect: DropShadow // { // anchors.fill: headBarBG // horizontalOffset: 0 // verticalOffset: Maui.Style.unit * (altToolBars ? -1 : 1) // radius: 8 // samples: 25 // color: Qt.darker(colorScheme.backgroundColor, 1.4) // source: headBarBG // } // } MouseArea { id: _rightFlickRec width: Maui.Style.iconSizes.medium height: parent.height visible: !mainFlickable.atXEnd && !mainFlickable.fits && control.flickable hoverEnabled: true anchors { top: parent.top bottom: parent.bottom right: parent.right } z: 999 EdgeShadow { visible: true parent: parent edge: Qt.RightEdge anchors { right: parent.right top: parent.top bottom: parent.bottom } opacity: 1 Behavior on opacity { NumberAnimation { duration: Kirigami.Units.longDuration easing.type: Easing.InOutQuad } } } Kirigami.Icon { visible: !Kirigami.Settings.isMobile anchors.centerIn: parent source: "qrc:/assets/arrow-right.svg" isMask: true width: Maui.Style.iconSizes.small height: Maui.Style.iconSizes.small color: _rightFlickRec.hovered ? Kirigami.Theme.highlightColor : Kirigami.Theme.textColor } enabled: !mainFlickable.atXEnd opacity: enabled ? 1 : 0.4 onClicked: { if(!mainFlickable.atXEnd) mainFlickable.contentX += control.height if(mainFlickable.atXEnd) mainFlickable.returnToBounds() } } MouseArea { id: _leftFlickRec width: Maui.Style.iconSizes.medium height: parent.height visible: !mainFlickable.atXBeginning && !mainFlickable.fits && control.flickable hoverEnabled: true anchors { top: parent.top bottom: parent.bottom left: parent.left } z: 999 EdgeShadow { visible: true parent: parent edge: Qt.LeftEdge anchors { left: parent.left top: parent.top bottom: parent.bottom } opacity: 1 Behavior on opacity { NumberAnimation { duration: Kirigami.Units.longDuration easing.type: Easing.InOutQuad } } } Kirigami.Icon { anchors.centerIn: parent visible: !Kirigami.Settings.isMobile source: "qrc:/assets/arrow-left.svg" isMask: true width: Maui.Style.iconSizes.small height: Maui.Style.iconSizes.small color: _leftFlickRec.hovered ? Kirigami.Theme.highlightColor : Kirigami.Theme.textColor } enabled: !mainFlickable.atXBeginning opacity: enabled ? 1 : 0.4 onClicked: { if(!mainFlickable.atXBeginning) mainFlickable.contentX -= control.height if(mainFlickable.atXBeginning) mainFlickable.returnToBounds() } } Flickable { id: mainFlickable property bool fits : contentWidth < control.width onFitsChanged: returnToBounds() anchors.fill: parent anchors.leftMargin: !fits && _leftFlickRec.visible && control.flickable && !Kirigami.Settings.isMobile ? _leftFlickRec.width : margins anchors.rightMargin: !fits && _rightFlickRec.visible && control.flickable && !Kirigami.Settings.isMobile ? _rightFlickRec.width : margins flickableDirection: Flickable.HorizontalFlick interactive: !fits && Maui.Handy.isTouch contentWidth: ((control.margins) + Maui.Style.space.medium) + (control.stickyLeftContent ? leftRowContent.implicitWidth : leftRowContent.width) + (control.stickyMiddleContent ? middleRowContent.implicitWidth : middleRowContent.width) + (control.stickyRightContent ? rightRowContent.implicitWidth : rightRowContent.width) boundsBehavior: Kirigami.Settings.isMobile ? Flickable.DragOverBounds : Flickable.StopAtBounds clip: true RowLayout { id: layout width: control.width - control.margins - Maui.Style.space.medium height: control.height RowLayout { id: leftRowContent // visible: control.leftSretch && implicitWidth property bool sticky : false Layout.leftMargin: rightRowContent.implicitWidth && implicitWidth === 0 && middleRowContent.implicitWidth && control.leftSretch ? rightRowContent.implicitWidth : undefined Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft spacing: leftContent.length > 0 ? control.spacing : 0 Layout.minimumWidth: !sticky ? undefined : implicitWidth Layout.fillWidth: control.leftSretch && implicitWidth Layout.fillHeight: true } RowLayout { id: middleRowContent property bool sticky : false // visible: control.middleStrech && implicitWidth Layout.alignment: Qt.AlignCenter spacing: middleContent.length === 1 ? 0 : control.spacing Layout.minimumWidth: !sticky ? undefined : implicitWidth // Layout.maximumWidth: control.width - leftRowContent.implicitWidth - rightRowContent.implicitWidth Layout.fillWidth: control.middleStrech Layout.fillHeight: true } RowLayout { id: rightRowContent // visible: control.rightSretch && implicitWidth property bool sticky : false Layout.rightMargin: leftRowContent.implicitWidth && implicitWidth === 0 && middleRowContent.implicitWidth && control.rightSretch ? leftRowContent.implicitWidth : undefined Layout.alignment: Qt.AlignVCenter | Qt.AlignRight spacing: rightContent.length > 0 ? control.spacing : 0 Layout.minimumWidth: !sticky ? undefined : implicitWidth // Layout.maximumWidth: !sticky ? rightRowContent.width : implicitWidth Layout.fillWidth: control.rightSretch && implicitWidth Layout.fillHeight: true } } // ScrollBar.horizontal: ScrollBar { visible: false} } } diff --git a/src/utils/handy.cpp b/src/utils/handy.cpp index 0337c7d..a321f1c 100644 --- a/src/utils/handy.cpp +++ b/src/utils/handy.cpp @@ -1,221 +1,223 @@ /* * 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. */ #include "handy.h" #include "utils.h" #include #include #include #include #include #include #include #include "fmh.h" #if defined Q_OS_LINUX && !defined Q_OS_ANDROID #include #include #endif static const QUrl CONF_FILE = FMH::ConfigPath + "/kdeglobals"; + +#ifdef KSHAREDCONFIG_H static const auto confCheck = [](QString key, QVariant defaultValue) -> QVariant { - auto kconf = KSharedConfig::openConfig("kdeglobals"); - const auto group = kconf->group("KDE"); - if( group.hasKey(key)) - return group.readEntry(key, defaultValue); - - return defaultValue; -}; + auto kconf = KSharedConfig::openConfig("kdeglobals"); + const auto group = kconf->group("KDE"); + if( group.hasKey(key)) + return group.readEntry(key, defaultValue); + return defaultValue; +}; +#endif Handy::Handy(QObject *parent) : QObject(parent), m_isTouch(Handy::isTouch()) { #if defined Q_OS_LINUX && !defined Q_OS_ANDROID auto configWatcher = new QFileSystemWatcher({CONF_FILE.toLocalFile()}, this); m_singleClick = confCheck("SingleClick", m_singleClick).toBool(); emit singleClickChanged(); connect(configWatcher, &QFileSystemWatcher::fileChanged, [&](QString) { m_singleClick = confCheck("SingleClick", m_singleClick).toBool(); emit singleClickChanged(); }); #endif } #ifdef Q_OS_ANDROID static inline struct { QList urls; QString text; bool hasUrls(){ return !urls.isEmpty(); } bool hasText(){ return !text.isEmpty(); } } _clipboard; #endif QVariantMap Handy::appInfo() { auto res = QVariantMap({{FMH::MODEL_NAME[FMH::MODEL_KEY::NAME], qApp->applicationName()}, {FMH::MODEL_NAME[FMH::MODEL_KEY::VERSION], qApp->applicationVersion()}, {FMH::MODEL_NAME[FMH::MODEL_KEY::ORG], qApp->organizationName()}, {FMH::MODEL_NAME[FMH::MODEL_KEY::DOMAIN_M], qApp->organizationDomain()}, {"mauikit_version", MAUIKIT_VERSION_STR}, {"qt_version", QT_VERSION_STR} }); #ifdef Q_OS_ANDROID res.insert(FMH::MODEL_NAME[FMH::MODEL_KEY::ICON], QGuiApplication::windowIcon().name()); #else res.insert(FMH::MODEL_NAME[FMH::MODEL_KEY::ICON], QApplication::windowIcon().name()); #endif return res; } QVariantMap Handy::userInfo() { QString name = qgetenv("USER"); if (name.isEmpty()) name = qgetenv("USERNAME"); return QVariantMap({{FMH::MODEL_NAME[FMH::MODEL_KEY::NAME], name}}); } QString Handy::getClipboardText() { #ifdef Q_OS_ANDROID auto clipbopard = QGuiApplication::clipboard(); #else auto clipbopard = QApplication::clipboard(); #endif auto mime = clipbopard->mimeData(); if(mime->hasText()) return clipbopard->text(); return QString(); } QVariantMap Handy::getClipboard() { QVariantMap res; #ifdef Q_OS_ANDROID if(_clipboard.hasUrls()) res.insert("urls", QUrl::toStringList(_clipboard.urls)); if(_clipboard.hasText()) res.insert("text", _clipboard.text); #else auto clipboard = QApplication::clipboard(); auto mime = clipboard->mimeData(); if(mime->hasUrls()) res.insert("urls", QUrl::toStringList(mime->urls())); if(mime->hasText()) res.insert("text", mime->text()); #endif return res; } bool Handy::copyToClipboard(const QVariantMap &value) { #ifdef Q_OS_ANDROID if(value.contains("urls")) _clipboard.urls = QUrl::fromStringList(value["urls"].toStringList()); if(value.contains("text")) _clipboard.text = value["text"].toString(); return true; #else auto clipboard = QApplication::clipboard(); QMimeData* mimeData = new QMimeData(); if(value.contains("urls")) mimeData->setUrls(QUrl::fromStringList(value["urls"].toStringList())); if(value.contains("text")) mimeData->setText(value["text"].toString()); clipboard->setMimeData(mimeData); return true; #endif return false; } bool Handy::copyTextToClipboard(const QString &text) { #ifdef Q_OS_ANDROID Handy::copyToClipboard({{"text", text}}); #else QApplication::clipboard()->setText(text); #endif return true; } int Handy::version() { return QOperatingSystemVersion::current().majorVersion(); } bool Handy::isAndroid() { return FMH::isAndroid(); } bool Handy::isLinux() { return FMH::isLinux(); } bool Handy::isTouch() { qDebug()<< "CHECKIGN IS IT IS TROYCH"; for(const auto &device : QTouchDevice::devices()) { if(device->type() == QTouchDevice::TouchScreen) return true; qDebug()<< "DEVICE CAPABILITIES" << device->capabilities() << device->name(); } return false; } bool Handy::isWindows() { return FMH::isWindows(); } bool Handy::isMac() { return FMH::isMac(); }