Keyboard integration for Streamlink quality confirmation (#3169)

Co-authored-by: zneix <zneix@zneix.eu>
This commit is contained in:
pajlada
2021-08-15 15:59:52 +02:00
committed by GitHub
parent b2d9b678a2
commit 1d664f88e5
5 changed files with 111 additions and 31 deletions
+64
View File
@@ -1,5 +1,7 @@
#include "widgets/BasePopup.hpp"
#include <QAbstractButton>
#include <QDialogButtonBox>
#include <QKeyEvent>
namespace chatterino {
@@ -20,4 +22,66 @@ void BasePopup::keyPressEvent(QKeyEvent *e)
BaseWindow::keyPressEvent(e);
}
bool BasePopup::handleEscape(QKeyEvent *e, QDialogButtonBox *buttonBox)
{
assert(buttonBox != nullptr);
if (e->key() == Qt::Key_Escape)
{
auto buttons = buttonBox->buttons();
for (auto *button : buttons)
{
if (auto role = buttonBox->buttonRole(button);
role == QDialogButtonBox::ButtonRole::RejectRole)
{
button->click();
return true;
}
}
}
return false;
}
bool BasePopup::handleEnter(QKeyEvent *e, QDialogButtonBox *buttonBox)
{
assert(buttonBox != nullptr);
if (!e->modifiers() ||
(e->modifiers() & Qt::KeypadModifier && e->key() == Qt::Key_Enter))
{
switch (e->key())
{
case Qt::Key_Enter:
case Qt::Key_Return: {
auto buttons = buttonBox->buttons();
QAbstractButton *acceptButton = nullptr;
for (auto *button : buttons)
{
if (button->hasFocus())
{
button->click();
return true;
}
if (auto role = buttonBox->buttonRole(button);
role == QDialogButtonBox::ButtonRole::AcceptRole)
{
acceptButton = button;
}
}
if (acceptButton != nullptr)
{
acceptButton->click();
return true;
}
}
break;
}
}
return false;
}
} // namespace chatterino