Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature for window handling in freamless mode #376

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
1 change: 1 addition & 0 deletions demo/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ ApplicationWindow {
id: demo

title: "Material for QtQuick Demo"
clientSideDecorations : true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think this should be the default behavior and the indentation is wrong use 4 spaces instead of tabs


// Necessary when loading the window from C++
visible: true
Expand Down
38 changes: 38 additions & 0 deletions modules/Material/ActionBar.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -203,6 +204,43 @@ Item {
overflowMenu.close();
}

/*!
\internal

put mousearea under everything blow
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typos

*/
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me this makes the window bounce a lot when dragging in X11

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a race condition, works fine on windows for some reason. It can be fixed by exposing QCursor::pos() from c++ to get the screen position of the mouse.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On X11 moving the window should be done using the _NET_WM_MOVERESIZE message of the EWMH (i.e. it should be done by the window manager and not by the app itself). In GDK there is the function gdk_window_begin_move_drag() which does exactly this but so far I haven't found any equivalent on Qt.
The same goes for wayland where wl_shell_surface_move() or xdg_surface_move() should be used. I am doubtful your approach would even work on wayland as wayland AFAIK does not allow you to access or set global window coordinates.

}
}
}

QtObject {
id: __internal

Expand Down
6 changes: 6 additions & 0 deletions modules/Material/ApplicationWindow.qml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ Controls.ApplicationWindow {
id: overlayLayer
}

Resizer{
id: __resizer
}

width: Units.dp(800)
height: Units.dp(600)

Expand Down Expand Up @@ -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;
Expand Down
89 changes: 89 additions & 0 deletions modules/Material/Resizer.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* QML Material - An application framework implementing Material Design.
* Copyright (C) 2016 hunt978([email protected])
*
* 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 <http://www.gnu.org/licenses/>.
*/

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read comment in Storage.qml first. But here you can create a property named target and set it in application window.

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
}
}
40 changes: 40 additions & 0 deletions modules/Material/Storage.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There has to be another way to do this without adding a new component, even if you need to create new properties in the existing components, creating global variables is not the solution.

* QML Material - An application framework implementing Material Design.
* Copyright (C) 2016 hunt978([email protected])
*
* 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 <http://www.gnu.org/licenses/>.
*/

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
}
2 changes: 2 additions & 0 deletions modules/Material/qmldir
Original file line number Diff line number Diff line change
Expand Up @@ -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