Browse Source

Fix hover state of Button

QGC4.4
Don Gagne 10 years ago
parent
commit
9f4b6e76f5
  1. 9
      qgroundcontrol.pro
  2. 4
      src/QGCApplication.cc
  3. 32
      src/QmlControls/MousePosition.cc
  4. 50
      src/QmlControls/MousePosition.h
  5. 59
      src/QmlControls/QGCButton.qml

9
qgroundcontrol.pro

@ -270,7 +270,8 @@ INCLUDEPATH += \
src/ui/main \ src/ui/main \
src/ui/toolbar \ src/ui/toolbar \
src/VehicleSetup \ src/VehicleSetup \
src/AutoPilotPlugins src/AutoPilotPlugins \
src/QmlControls
FORMS += \ FORMS += \
src/ui/MainWindow.ui \ src/ui/MainWindow.ui \
@ -495,7 +496,8 @@ HEADERS += \
src/ui/QGCCommConfiguration.h \ src/ui/QGCCommConfiguration.h \
src/ui/QGCUDPLinkConfiguration.h \ src/ui/QGCUDPLinkConfiguration.h \
src/uas/UASMessageHandler.h \ src/uas/UASMessageHandler.h \
src/ui/toolbar/MainToolBar.h src/ui/toolbar/MainToolBar.h \
src/QmlControls/MousePosition.h
SOURCES += \ SOURCES += \
src/main.cc \ src/main.cc \
@ -636,7 +638,8 @@ SOURCES += \
src/ui/QGCCommConfiguration.cc \ src/ui/QGCCommConfiguration.cc \
src/ui/QGCUDPLinkConfiguration.cc \ src/ui/QGCUDPLinkConfiguration.cc \
src/uas/UASMessageHandler.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 # Unit Test specific configuration goes here

4
src/QGCApplication.cc

@ -59,6 +59,7 @@
#include "QGCTemporaryFile.h" #include "QGCTemporaryFile.h"
#include "QGCFileDialog.h" #include "QGCFileDialog.h"
#include "QGCPalette.h" #include "QGCPalette.h"
#include "MousePosition.h"
#ifdef QGC_RTLAB_ENABLED #ifdef QGC_RTLAB_ENABLED
#include "OpalLink.h" #include "OpalLink.h"
@ -249,8 +250,9 @@ void QGCApplication::_initCommon(void)
// "Warning: Do not use this function in conjunction with Qt Style Sheets." // "Warning: Do not use this function in conjunction with Qt Style Sheets."
// setFont(fontDatabase.font(fontFamilyName, "Roman", 12)); // 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<QGCPalette>("QGroundControl.Palette", 1, 0, "QGCPalette");
qmlRegisterType<MousePosition>("QGroundControl.MousePosition", 1, 0, "MousePosition");
} }
bool QGCApplication::_initForNormalAppBoot(void) bool QGCApplication::_initForNormalAppBoot(void)

32
src/QmlControls/MousePosition.cc

@ -0,0 +1,32 @@
/*=====================================================================
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)
{
}

50
src/QmlControls/MousePosition.h

@ -0,0 +1,50 @@
/*=====================================================================
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

59
src/QmlControls/QGCButton.qml

@ -4,6 +4,7 @@ import QtQuick.Controls.Styles 1.2
import QtQuick.Controls.Private 1.0 import QtQuick.Controls.Private 1.0
import QGroundControl.Palette 1.0 import QGroundControl.Palette 1.0
import QGroundControl.MousePosition 1.0
Button { Button {
// primary: true - this is the primary button for this group of buttons // primary: true - this is the primary button for this group of buttons
@ -11,32 +12,50 @@ Button {
property var __qgcPal: QGCPalette { colorGroupEnabled: enabled } property var __qgcPal: QGCPalette { colorGroupEnabled: enabled }
property bool __showHighlight: pressed | hovered | checked property bool __showHighlight: (pressed | hovered | checked) && !__forceHoverOff
style: ButtonStyle { // 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
background: Rectangle { // cause the hover property to not be cleared correctly.
implicitWidth: 100
implicitHeight: 25
color: __showHighlight ?
control.__qgcPal.buttonHighlight :
(primary ? control.__qgcPal.primaryButton : control.__qgcPal.button)
}
label: Text { property bool __forceHoverOff: false
width: parent.width
height: parent.height
verticalAlignment: TextEdit.AlignVCenter property int __lastMouseX: __behavior.mouseX
horizontalAlignment: TextEdit.AlignHCenter property int __lastMouseY: __behavior.mouseY
property int __lastCursorX: 0
property int __lastCursorY: 0
text: control.text property MousePosition __mousePosition: MousePosition { }
color: __showHighlight ?
control.__qgcPal.buttonHighlightText : Connections {
(primary ? control.__qgcPal.primaryButtonText : control.__qgcPal.buttonText) 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. */ /*! The padding between the background and the label components. */
padding { padding {
top: 4 top: 4

Loading…
Cancel
Save