Skip to content

Commit cd4a0dc

Browse files
committed
Add a space pressable pushbutton with focus highlight indicator
1 parent 2a060db commit cd4a0dc

4 files changed

Lines changed: 85 additions & 2 deletions

File tree

data/gui/normalStyle.css

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,10 @@ QPushButton {
336336
font-size: 100%;
337337
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 rgb(183, 184, 185), stop: 1 rgb(111, 113, 114));
338338
}
339-
340-
QPushButton:focus {
339+
/*
340+
* Only the space-pressable pushbutton should show a focus highlight!
341+
*/
342+
SpacePushButton:focus {
341343
border: 2px solid rgb(161, 161, 161);
342344
}
343345

src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,8 @@ IF(STELLARIUM_GUI_MODE STREQUAL "Standard")
348348
gui/ObsListCreateEditDialog.cpp
349349
gui/SpaceCheckBox.hpp
350350
gui/SpaceCheckBox.cpp
351+
gui/SpacePushButton.hpp
352+
gui/SpacePushButton.cpp
351353
gui/StelDialog.hpp
352354
gui/StelDialog_p.hpp
353355
gui/StelDialog.cpp

src/gui/SpacePushButton.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/***************************************************************************
2+
* Copyright (C) 2021 Georg Zotti *
3+
* *
4+
* This program is free software; you can redistribute it and/or modify *
5+
* it under the terms of the GNU General Public License as published by *
6+
* the Free Software Foundation; either version 2 of the License, or *
7+
* (at your option) any later version. *
8+
* *
9+
* This program is distributed in the hope that it will be useful, *
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12+
* GNU General Public License for more details. *
13+
* *
14+
* You should have received a copy of the GNU General Public License *
15+
* along with this program; if not, write to the *
16+
* Free Software Foundation, Inc., *
17+
* 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. *
18+
***************************************************************************/
19+
20+
#include "SpacePushButton.hpp"
21+
#include <QKeyEvent>
22+
23+
SpacePushButton::SpacePushButton(QWidget* parent)
24+
: QPushButton(parent)
25+
{
26+
}
27+
28+
void SpacePushButton::keyPressEvent(QKeyEvent *e)
29+
{
30+
switch (e->key()) {
31+
case Qt::Key_Space:
32+
animateClick();
33+
break;
34+
default:
35+
QPushButton::keyPressEvent(e);
36+
}
37+
}

src/gui/SpacePushButton.hpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Stellarium
3+
* Copyright (C) 2021 Georg Zotti
4+
*
5+
* This program is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU General Public License
7+
* as published by the Free Software Foundation; either version 2
8+
* of the License, or (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program; if not, write to the Free Software
17+
* Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18+
*/
19+
20+
#ifndef SPACEPUSHBUTTON_HPP
21+
#define SPACEPUSHBUTTON_HPP
22+
23+
#include <QPushButton>
24+
25+
//! @class SpacePushButton
26+
//! A QPushButton which can be triggered by pressing Space when it has focus.
27+
//! To use this class in the QtCreator UI designer, add a regular QPushButton to the UI,
28+
//! then right-click on it and change its type to SpacePushButton.
29+
//! Then it makes sense to put this button into a useful GUI tab order.
30+
class SpacePushButton : public QPushButton
31+
{
32+
Q_OBJECT
33+
public:
34+
SpacePushButton(QWidget* parent=Q_NULLPTR);
35+
~SpacePushButton() Q_DECL_OVERRIDE {}
36+
37+
protected:
38+
//! This triggers the button on pressing the Space bar.
39+
virtual void keyPressEvent(QKeyEvent *e) Q_DECL_OVERRIDE;
40+
};
41+
42+
#endif // SPACEPUSHBUTTON_HPP

0 commit comments

Comments
 (0)