From 3d08c783864faa35b953ba7343ecec6fb337961f Mon Sep 17 00:00:00 2001 From: hunt978 Date: Sun, 24 Jan 2016 23:58:29 +0800 Subject: [PATCH] feature for window handling in freamless mode add/update conponents: Storage.qml : storage global data cross over all app sessions Resizer.qml : right-bottom icon for resizing window size ActionBar.qml : add window draging(pos) double-click(normal/fullscreen) the feature is enabled when ApplicationWindows.clientSideDecorations set be true --- demo/main.qml | 1 + modules/Material/ActionBar.qml | 38 +++++++++++ modules/Material/ApplicationWindow.qml | 6 ++ modules/Material/Resizer.qml | 89 ++++++++++++++++++++++++++ modules/Material/Storage.qml | 40 ++++++++++++ modules/Material/qmldir | 2 + 6 files changed, 176 insertions(+) create mode 100644 modules/Material/Resizer.qml create mode 100644 modules/Material/Storage.qml diff --git a/demo/main.qml b/demo/main.qml index a4d1726d..ebc4da85 100644 --- a/demo/main.qml +++ b/demo/main.qml @@ -6,6 +6,7 @@ ApplicationWindow { id: demo title: "Material for QtQuick Demo" + clientSideDecorations : true // Necessary when loading the window from C++ visible: true diff --git a/modules/Material/ActionBar.qml b/modules/Material/ActionBar.qml index 21e87291..bbb1295e 100644 --- a/modules/Material/ActionBar.qml +++ b/modules/Material/ActionBar.qml @@ -18,6 +18,7 @@ */ import QtQuick 2.4 import QtQuick.Layouts 1.1 +import QtQuick.Window 2.2 import Material 0.2 import Material.Extras 0.1 import Material.ListItems 0.1 as ListItem @@ -203,6 +204,43 @@ Item { overflowMenu.close(); } + /*! + \internal + + put mousearea under everything blow + */ + MouseArea { + anchors.fill: parent + + property var previousPosition + property var enable : Storage.target.clientSideDecorations + + onPressed: { + previousPosition = Qt.point(mouseX, mouseY) + } + + onDoubleClicked: { + if( enable ){ + if( Storage.target.visibility != Window.FullScreen ){ + Storage.target.visibility = Window.FullScreen + }else{ + Storage.target.visibility = Window.Windowed + } + } + } + + onPositionChanged: { + if (pressedButtons == Qt.LeftButton + && Storage.target.visibility != Window.FullScreen + && enable ) { + var dx = mouseX - previousPosition.x + var dy = mouseY - previousPosition.y + Storage.target.x = Storage.target.x + dx + Storage.target.y = Storage.target.y + dy + } + } + } + QtObject { id: __internal diff --git a/modules/Material/ApplicationWindow.qml b/modules/Material/ApplicationWindow.qml index 3c6c1609..0b505dff 100644 --- a/modules/Material/ApplicationWindow.qml +++ b/modules/Material/ApplicationWindow.qml @@ -127,6 +127,10 @@ Controls.ApplicationWindow { id: overlayLayer } + Resizer{ + id: __resizer + } + width: Units.dp(800) height: Units.dp(600) @@ -176,6 +180,8 @@ Controls.ApplicationWindow { if (clientSideDecorations) flags |= Qt.FramelessWindowHint + Storage.target = platformExtensions.window; + function calculateDiagonal() { return Math.sqrt(Math.pow((Screen.width/Screen.pixelDensity), 2) + Math.pow((Screen.height/Screen.pixelDensity), 2)) * 0.039370; diff --git a/modules/Material/Resizer.qml b/modules/Material/Resizer.qml new file mode 100644 index 00000000..4f2a735a --- /dev/null +++ b/modules/Material/Resizer.qml @@ -0,0 +1,89 @@ +/* + * QML Material - An application framework implementing Material Design. + * Copyright (C) 2016 hunt978(bootsing.hoo@gmail.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +import Material 0.2 +import QtQuick 2.4 +import QtQuick.Window 2.2 + +/*! + \qmltype Reziser + \inqmlmodule Material + + \brief Reziser allow Material apps resize window size under frameless mode + the app will show a litter icon in right-bottom corner when the mouse hover + the area. then user can resize the window by draging the window. +*/ +Icon +{ + id : __resizer + + anchors.bottom: parent.bottom + anchors.right : parent.right + + colorize : true + color : Theme.primaryColor + opacity : (Storage.target.visibility != Window.FullScreen) ? __resizer.opacity : 0 + + name : "device/signal_cellular_0_bar" + + MouseArea { + anchors.fill: parent + hoverEnabled: true + + property var previousPosition + property var enable : (Storage.target.visibility != Window.FullScreen) + && Storage.target.clientSideDecorations + + onPressed: { + if( enable ){ + previousPosition = Qt.point(mouseX, mouseY) + } + } + + onPositionChanged: { + if (pressedButtons == Qt.LeftButton && enable) { + var width = (mouseX - previousPosition.x) + Storage.target.width + var height = (mouseY - previousPosition.y) + Storage.target.height + if( width > 0 ){ + Storage.target.width = width + } + if( height > 0 ){ + Storage.target.height = height + } + } + } + + onEntered : { + if( enable ){ + cursorShape = Qt.SizeFDiagCursor + __resizer.opacity = 1 + } + } + + onExited : { + if( enable ){ + cursorShape = Qt.ArrowCursor + __resizer.opacity = 0 + } + } + } + + Component.onCompleted: { + __resizer.opacity = 0 + } +} diff --git a/modules/Material/Storage.qml b/modules/Material/Storage.qml new file mode 100644 index 00000000..41cbafee --- /dev/null +++ b/modules/Material/Storage.qml @@ -0,0 +1,40 @@ +/* + * QML Material - An application framework implementing Material Design. + * Copyright (C) 2016 hunt978(bootsing.hoo@gmail.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +import QtQuick 2.4 + +pragma Singleton + +/*! + \qmltype Storage + \inqmlmodule Material + + \brief Storage allow Material apps share setting over all sessions +*/ +Object +{ + /*! + Top Window Object. + */ + property var target: null + + /*! + Custom data storage + */ + property var customData : null +} \ No newline at end of file diff --git a/modules/Material/qmldir b/modules/Material/qmldir index 399da227..bc4d5a39 100644 --- a/modules/Material/qmldir +++ b/modules/Material/qmldir @@ -51,8 +51,10 @@ Tooltip 0.1 Tooltip.qml View 0.1 View.qml Wave 0.1 Wave.qml Window 0.1 Window.qml +Resizer 0.1 Resizer.qml singleton Device 0.1 Device.qml singleton MaterialAnimation 0.1 MaterialAnimation.qml singleton Palette 0.1 Palette.qml singleton Theme 0.1 Theme.qml singleton Units 0.1 Units.qml +singleton Storage 0.1 Storage.qml