From f0156a26c620a5a9abee164bacbde263dc41381a Mon Sep 17 00:00:00 2001 From: Georg Zotti Date: Mon, 18 Oct 2021 10:26:52 +0200 Subject: [PATCH] Add a space pressable pushbutton with focus highlight indicator --- data/gui/normalStyle.css | 6 ++++-- src/CMakeLists.txt | 2 ++ src/gui/SpacePushButton.cpp | 37 ++++++++++++++++++++++++++++++++ src/gui/SpacePushButton.hpp | 42 +++++++++++++++++++++++++++++++++++++ 4 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 src/gui/SpacePushButton.cpp create mode 100644 src/gui/SpacePushButton.hpp diff --git a/data/gui/normalStyle.css b/data/gui/normalStyle.css index 0dcd3a0fb4243..8476523ea96fc 100644 --- a/data/gui/normalStyle.css +++ b/data/gui/normalStyle.css @@ -336,8 +336,10 @@ QPushButton { font-size: 100%; background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 rgb(183, 184, 185), stop: 1 rgb(111, 113, 114)); } - -QPushButton:focus { +/* + * Only the space-pressable pushbutton should show a focus highlight! + */ +SpacePushButton:focus { border: 2px solid rgb(161, 161, 161); } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7bfda03c6b7cc..0795f4a172058 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -348,6 +348,8 @@ IF(STELLARIUM_GUI_MODE STREQUAL "Standard") gui/ObsListCreateEditDialog.cpp gui/SpaceCheckBox.hpp gui/SpaceCheckBox.cpp + gui/SpacePushButton.hpp + gui/SpacePushButton.cpp gui/StelDialog.hpp gui/StelDialog_p.hpp gui/StelDialog.cpp diff --git a/src/gui/SpacePushButton.cpp b/src/gui/SpacePushButton.cpp new file mode 100644 index 0000000000000..5c9d39e20615c --- /dev/null +++ b/src/gui/SpacePushButton.cpp @@ -0,0 +1,37 @@ +/*************************************************************************** + * Copyright (C) 2021 Georg Zotti * + * * + * This program 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 2 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. * + ***************************************************************************/ + +#include "SpacePushButton.hpp" +#include + +SpacePushButton::SpacePushButton(QWidget* parent) + : QPushButton(parent) +{ +} + +void SpacePushButton::keyPressEvent(QKeyEvent *e) +{ + switch (e->key()) { + case Qt::Key_Space: + animateClick(); + break; + default: + QPushButton::keyPressEvent(e); + } +} diff --git a/src/gui/SpacePushButton.hpp b/src/gui/SpacePushButton.hpp new file mode 100644 index 0000000000000..5a25b83c79c33 --- /dev/null +++ b/src/gui/SpacePushButton.hpp @@ -0,0 +1,42 @@ +/* + * Stellarium + * Copyright (C) 2021 Georg Zotti + * + * This program 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 2 + * 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. + */ + +#ifndef SPACEPUSHBUTTON_HPP +#define SPACEPUSHBUTTON_HPP + +#include + +//! @class SpacePushButton +//! A QPushButton which can be triggered by pressing Space when it has focus. +//! To use this class in the QtCreator UI designer, add a regular QPushButton to the UI, +//! then right-click on it and change its type to SpacePushButton. +//! Then it makes sense to put this button into a useful GUI tab order. +class SpacePushButton : public QPushButton +{ + Q_OBJECT +public: + SpacePushButton(QWidget* parent=Q_NULLPTR); + ~SpacePushButton() Q_DECL_OVERRIDE {} + +protected: + //! This triggers the button on pressing the Space bar. + virtual void keyPressEvent(QKeyEvent *e) Q_DECL_OVERRIDE; +}; + +#endif // SPACEPUSHBUTTON_HPP