Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GUI: focus and tabbing #1971

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 39 additions & 44 deletions data/gui/normalStyle.css
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ QLineEdit {
font-size: 100%;
}

QTextEdit:focus,
QPlainTextEdit:focus,
QListWidget:focus,
QLineEdit:focus {
border: 2px solid rgb(161, 161, 161);
}

QTextEdit:disabled,
QListWidget:disabled,
QLineEdit:disabled {
Expand All @@ -75,7 +82,7 @@ QTextBrowser {
border: 0 solid rgb(0, 0, 0);
background: rgb(90, 90, 90);
color: rgb(3, 3, 3);
font-size: 100%;
font-size: 100%;
}

QGroupBox {
Expand Down Expand Up @@ -324,6 +331,12 @@ 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));
}
/*
* Only the space-pressable pushbutton should show a focus highlight!
*/
SpacePushButton:focus {
border: 2px solid rgb(161, 161, 161);
}

QPushButton:disabled {
color: rgb(61, 61, 61);
Expand Down Expand Up @@ -357,6 +370,12 @@ QCheckBox {
color: rgb(3, 3, 3);
background: none;
}
/*
* Only the space checkbox should show a focus highlight!
*/
SpaceCheckBox:focus {
border: 2px solid rgb(161, 161, 161);
}

QCheckBox:disabled {
color: rgb(50, 50, 50);
Expand Down Expand Up @@ -478,11 +497,7 @@ QRadioButton::indicator:unchecked:disabled {
* Spinners
*/

QSpinBox,
QTimeEdit,
QDoubleSpinBox,
AngleSpinBox,
QDateTimeEdit,
QAbstractSpinBox, /* QSpinBox, QDoubleSpinBox, AngleSpinBox, QDateTimeEdit, QDateEdit, QTimeEdit */
QComboBox {
padding-right: 0;
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 rgb(180, 180, 183), stop: 1 rgb(93, 95, 98));
Expand All @@ -491,11 +506,13 @@ QComboBox {
min-height: 22px;
}

QSpinBox::up-button,
QTimeEdit::up-button,
QDoubleSpinBox::up-button,
AngleSpinBox::up-button,
QDateTimeEdit::up-button {
QAbstractSpinBox:focus, /* QSpinBox, QDoubleSpinBox, AngleSpinBox, QDateTimeEdit, QDateEdit, QTimeEdit */
QComboBox:focus {
border: 2px solid rgb(100, 100, 100);
}

QAbstractSpinBox::up-button
{
subcontrol-origin: border;
subcontrol-position: top right;
width: 20px;
Expand All @@ -506,11 +523,7 @@ QDateTimeEdit::up-button {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 rgb(97, 97, 97), stop: 1 rgb(70, 70, 70));
}

QSpinBox::down-button,
QTimeEdit::down-button,
QDoubleSpinBox::down-button,
AngleSpinBox::down-button,
QDateTimeEdit::down-button {
QAbstractSpinBox::down-button {
subcontrol-origin: border;
subcontrol-position: bottom right;
width: 20px;
Expand All @@ -521,11 +534,7 @@ QDateTimeEdit::down-button {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 rgb(70, 70, 70), stop: 1 rgb(40, 40, 40));
}

QSpinBox::up-button:hover,
QTimeEdit::up-button:hover,
QDoubleSpinBox::up-button:hover,
AngleSpinBox::up-button:hover,
QDateTimeEdit::up-button:hover {
QAbstractSpinBox::up-button:hover {
subcontrol-origin: border;
subcontrol-position: top right;
width: 20px;
Expand All @@ -536,11 +545,7 @@ QDateTimeEdit::up-button:hover {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 rgb(87, 87, 77), stop: 1 rgb(70, 70, 70));
}

QSpinBox::down-button:hover,
QTimeEdit::down-button:hover,
QDoubleSpinBox::down-button:hover,
AngleSpinBox::down-button:hover,
QDateTimeEdit::down-button:hover {
QAbstractSpinBox::down-button:hover {
subcontrol-origin: border;
subcontrol-position: bottom right;
width: 20px;
Expand Down Expand Up @@ -607,38 +612,28 @@ QComboBox {
*/

QComboBox:disabled,
QSpinBox:disabled,
QDoubleSpinBox:disabled,
AngleSpinBox:disabled,
QDateTimeEdit:disabled {
QAbstractSpinBox:disabled
{
border: 1px solid rgb(31, 31, 31);
color: rgb(61, 61, 61);
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 rgba(150, 150, 153, 100%), stop: 1 rgba(120, 120, 120, 100%));
}

QComboBox:focus, QComboBox:hover,
QSpinBox:focus, QSpinBox:hover,
QDoubleSpinBox:focus, QDoubleSpinBox:hover,
AngleSpinBox:focus, AngleSpinBox:hover,
QDateTimeEdit:focus, QDateTimeEdit:hover {
QAbstractSpinBox:focus, QAbstractSpinBox:hover
{
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 rgb(180, 180, 163), stop: 1 rgb(93, 95, 78));
}

QSpinBox::up-button:disabled,
TimeEdit::up-button:disabled,
QDoubleSpinBox::up-button:disabled,
AngleSpinBox::up-button:disabled,
QDateTimeEdit::up-button:disabled {
QAbstractSpinBox::up-button:disabled
{
background: rgb(75, 75, 75);
border-top: 1px solid rgb(31, 31, 31);
border-right: 1px solid rgb(31, 31, 31);
}

QSpinBox::down-button:disabled,
QTimeEdit::down-button:disabled,
QDoubleSpinBox::down-button:disabled,
AngleSpinBox::down-button:disabled,
QDateTimeEdit::down-button:disabled {
QAbstractSpinBox::down-button:disabled
{
background: rgb(70, 70, 70);
border-bottom: 1px solid rgb(31, 31, 31);
border-right: 1px solid rgb(31, 31, 31);
Expand Down
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,10 @@ IF(STELLARIUM_GUI_MODE STREQUAL "Standard")
gui/ObsListDialog.cpp
gui/ObsListCreateEditDialog.hpp
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
Expand Down
37 changes: 37 additions & 0 deletions src/gui/SpaceCheckBox.cpp
Original file line number Diff line number Diff line change
@@ -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 "SpaceCheckBox.hpp"
#include <QKeyEvent>

SpaceCheckBox::SpaceCheckBox(QWidget* parent)
: QCheckBox(parent)
{
}

void SpaceCheckBox::keyReleaseEvent(QKeyEvent *e)
{
switch (e->key()) {
case Qt::Key_Space:
toggle();
break;
default:
QCheckBox::keyReleaseEvent(e);
}
}
42 changes: 42 additions & 0 deletions src/gui/SpaceCheckBox.hpp
Original file line number Diff line number Diff line change
@@ -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 SPACECHECKBOX_HPP
#define SPACECHECKBOX_HPP

#include <QCheckBox>

//! @class SpaceCheckBox
//! A QCheckBox which can be toggled by pressing (actually releasing) Space when it has focus.
//! To use this class in the QtCreator UI designer, add a regular QCheckBox to the UI,
//! then right-click on it and change its type to SpaceCheckBox.
//! Then it makes sense to put this checkbox into a useful GUI tab order.
class SpaceCheckBox : public QCheckBox
{
Q_OBJECT
public:
SpaceCheckBox(QWidget* parent=Q_NULLPTR);
~SpaceCheckBox() Q_DECL_OVERRIDE {}

protected:
//! This toggles the checkbox on releasing the Space bar.
virtual void keyReleaseEvent(QKeyEvent *e) Q_DECL_OVERRIDE;
};

#endif // SPACECHECKBOX_HPP
37 changes: 37 additions & 0 deletions src/gui/SpacePushButton.cpp
Original file line number Diff line number Diff line change
@@ -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 <QKeyEvent>

SpacePushButton::SpacePushButton(QWidget* parent)
: QPushButton(parent)
{
}

void SpacePushButton::keyReleaseEvent(QKeyEvent *e)
{
switch (e->key()) {
case Qt::Key_Space:
click();
break;
default:
QPushButton::keyReleaseEvent(e);
}
}
42 changes: 42 additions & 0 deletions src/gui/SpacePushButton.hpp
Original file line number Diff line number Diff line change
@@ -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 <QPushButton>

//! @class SpacePushButton
//! A QPushButton which can be triggered by pressing (actually: releasing) 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 keyReleaseEvent(QKeyEvent *e) Q_DECL_OVERRIDE;
};

#endif // SPACEPUSHBUTTON_HPP
7 changes: 6 additions & 1 deletion src/gui/helpDialogGui.ui
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@
</widget>
</item>
<item>
<widget class="QPushButton" name="editShortcutsButton">
<widget class="SpacePushButton" name="editShortcutsButton">
<property name="text">
<string extracomment="Same text as in the Configuration window!">Edit keyboard shortcuts...</string>
</property>
Expand Down Expand Up @@ -454,6 +454,11 @@
<extends>QPushButton</extends>
<header>gui/StelCloseButton.hpp</header>
</customwidget>
<customwidget>
<class>SpacePushButton</class>
<extends>QPushButton</extends>
<header>SpacePushButton.hpp</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
Expand Down
Loading