Commit 9f4b6e76 authored by Don Gagne's avatar Don Gagne

Fix hover state of Button

parent f743d7d6
......@@ -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
......
......@@ -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<QGCPalette>("QGroundControl.Palette", 1, 0, "QGCPalette");
qmlRegisterType<MousePosition>("QGroundControl.MousePosition", 1, 0, "MousePosition");
}
bool QGCApplication::_initForNormalAppBoot(void)
......
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009, 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
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 <http://www.gnu.org/licenses/>.
======================================================================*/
/// @file
/// @author Don Gagne <don@thegagnes.com>
#include "MousePosition.h"
MousePosition::MousePosition(void)
{
}
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009, 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
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 <http://www.gnu.org/licenses/>.
======================================================================*/
/// @file
/// @author Don Gagne <don@thegagnes.com>
#ifndef MOUSEPOSITION_H
#define MOUSEPOSITION_H
#include <QObject>
#include <QCursor>
/// 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
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment