diff --git a/qgroundcontrol.pro b/qgroundcontrol.pro index 25bbe4ff2202fad9f5bbbbe711a6d3bc29b337c9..aae4cfebfc33734c015521edd9ccba2db5bfe315 100644 --- a/qgroundcontrol.pro +++ b/qgroundcontrol.pro @@ -270,7 +270,8 @@ INCLUDEPATH += \ src/ui/main \ src/ui/toolbar \ src/VehicleSetup \ - src/AutoPilotPlugins + src/AutoPilotPlugins \ + src/QmlControls FORMS += \ src/ui/MainWindow.ui \ @@ -495,7 +496,8 @@ HEADERS += \ src/ui/QGCCommConfiguration.h \ src/ui/QGCUDPLinkConfiguration.h \ src/uas/UASMessageHandler.h \ - src/ui/toolbar/MainToolBar.h + src/ui/toolbar/MainToolBar.h \ + src/QmlControls/MousePosition.h SOURCES += \ src/main.cc \ @@ -636,7 +638,8 @@ SOURCES += \ src/ui/QGCCommConfiguration.cc \ src/ui/QGCUDPLinkConfiguration.cc \ src/uas/UASMessageHandler.cc \ - src/ui/toolbar/MainToolBar.cc + src/ui/toolbar/MainToolBar.cc \ + src/QmlControls/MousePosition.cc # # Unit Test specific configuration goes here diff --git a/src/QGCApplication.cc b/src/QGCApplication.cc index 56276c75340386a618332656a115dd1756becff7..631649ba496558b333130b48a36b258fc83bff74 100644 --- a/src/QGCApplication.cc +++ b/src/QGCApplication.cc @@ -59,6 +59,7 @@ #include "QGCTemporaryFile.h" #include "QGCFileDialog.h" #include "QGCPalette.h" +#include "MousePosition.h" #ifdef QGC_RTLAB_ENABLED #include "OpalLink.h" @@ -249,8 +250,9 @@ void QGCApplication::_initCommon(void) // "Warning: Do not use this function in conjunction with Qt Style Sheets." // setFont(fontDatabase.font(fontFamilyName, "Roman", 12)); - // Register our Qml palette before anyone tries to use it + // Register our Qml objects qmlRegisterType("QGroundControl.Palette", 1, 0, "QGCPalette"); + qmlRegisterType("QGroundControl.MousePosition", 1, 0, "MousePosition"); } bool QGCApplication::_initForNormalAppBoot(void) diff --git a/src/QmlControls/MousePosition.cc b/src/QmlControls/MousePosition.cc new file mode 100644 index 0000000000000000000000000000000000000000..594f313e1068a0c7d01655728154c044906664f8 --- /dev/null +++ b/src/QmlControls/MousePosition.cc @@ -0,0 +1,32 @@ +/*===================================================================== + + QGroundControl Open Source Ground Control Station + + (c) 2009, 2015 QGROUNDCONTROL PROJECT + + This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL 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 3 of the License, or + (at your option) any later version. + + QGROUNDCONTROL 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 QGROUNDCONTROL. If not, see . + + ======================================================================*/ + +/// @file +/// @author Don Gagne + +#include "MousePosition.h" + +MousePosition::MousePosition(void) +{ + +} diff --git a/src/QmlControls/MousePosition.h b/src/QmlControls/MousePosition.h new file mode 100644 index 0000000000000000000000000000000000000000..64c7a3a4f5e72dee6a22b6d17f7349bddc278e50 --- /dev/null +++ b/src/QmlControls/MousePosition.h @@ -0,0 +1,50 @@ +/*===================================================================== + + QGroundControl Open Source Ground Control Station + + (c) 2009, 2015 QGROUNDCONTROL PROJECT + + This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL 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 3 of the License, or + (at your option) any later version. + + QGROUNDCONTROL 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 QGROUNDCONTROL. If not, see . + + ======================================================================*/ + +/// @file +/// @author Don Gagne + +#ifndef MOUSEPOSITION_H +#define MOUSEPOSITION_H + +#include +#include + +/// This Qml control is used to return global mouse positions. It is needed to fix +/// a problem with hover state of buttons not being updated correctly if the mouse +/// moves out of a QQuickWidget control. +class MousePosition : public QObject +{ + Q_OBJECT + +public: + MousePosition(void); + + Q_PROPERTY(int mouseX READ mouseX) + Q_PROPERTY(int mouseY READ mouseY) + + int mouseX(void) { return QCursor::pos().x(); } + int mouseY(void) { return QCursor::pos().y(); } +}; + +#endif diff --git a/src/QmlControls/QGCButton.qml b/src/QmlControls/QGCButton.qml index fddf540b3b48fa4623a19d181736cdd8453e9217..e48c93dbbde746f46ddb3a2e43809d0020622d3a 100644 --- a/src/QmlControls/QGCButton.qml +++ b/src/QmlControls/QGCButton.qml @@ -4,6 +4,7 @@ import QtQuick.Controls.Styles 1.2 import QtQuick.Controls.Private 1.0 import QGroundControl.Palette 1.0 +import QGroundControl.MousePosition 1.0 Button { // primary: true - this is the primary button for this group of buttons @@ -11,32 +12,50 @@ Button { property var __qgcPal: QGCPalette { colorGroupEnabled: enabled } - property bool __showHighlight: pressed | hovered | checked + property bool __showHighlight: (pressed | hovered | checked) && !__forceHoverOff - style: ButtonStyle { -/* - background: Rectangle { - implicitWidth: 100 - implicitHeight: 25 - color: __showHighlight ? - control.__qgcPal.buttonHighlight : - (primary ? control.__qgcPal.primaryButton : control.__qgcPal.button) - } + // This fixes the issue with button hover where if a Button is near the edge oa QQuickWidget you can + // move the mouse fast enough such that the MouseArea does not trigger an onExited. This is turn + // cause the hover property to not be cleared correctly. - label: Text { - width: parent.width - height: parent.height + property bool __forceHoverOff: false - verticalAlignment: TextEdit.AlignVCenter - horizontalAlignment: TextEdit.AlignHCenter + property int __lastMouseX: __behavior.mouseX + property int __lastMouseY: __behavior.mouseY + property int __lastCursorX: 0 + property int __lastCursorY: 0 - text: control.text - color: __showHighlight ? - control.__qgcPal.buttonHighlightText : - (primary ? control.__qgcPal.primaryButtonText : control.__qgcPal.buttonText) + property MousePosition __mousePosition: MousePosition { } + + Connections { + target: __behavior + onMouseXChanged: { + __lastCursorX = __mousePosition.mouseX + __lastCursorY = __mousePosition.mouseY + } + onMouseYChanged: { + __lastCursorX = __mousePosition.mouseX + __lastCursorY = __mousePosition.mouseY + } + onEntered: { __forceHoverOff; false; hoverTimer.start() } + onExited: { __forceHoverOff; false; hoverTimer.stop() } + } + + Timer { + id: hoverTimer + interval: 250 + repeat: true + + onTriggered: { + if (__lastCursorX != __mousePosition.mouseX || __lastCursorY != __mousePosition.mouseY) { + __forceHoverOff = true + } else { + __forceHoverOff = false } -*/ + } + } + style: ButtonStyle { /*! The padding between the background and the label components. */ padding { top: 4