Commit f3c14393 authored by Ingo Klöcker's avatar Ingo Klöcker
Browse files

Make focus helpers available for other dialogs

GnuPG-bug-id: 6080
parent e53eedf0
......@@ -17,6 +17,7 @@
#include "keyalgo_p.h"
#include "listwidget.h"
#include "utils/gui-helper.h"
#include "utils/scrollarea.h"
#include <settings.h>
......@@ -1063,33 +1064,6 @@ void AdvancedSettingsDialog::updateWidgetVisibility()
slotKeyMaterialSelectionChanged();
}
template<typename UnaryPredicate>
bool focusFirstButtonIf(const std::vector<QAbstractButton *> &buttons, UnaryPredicate p)
{
auto it = std::find_if(std::begin(buttons), std::end(buttons), p);
if (it != std::end(buttons)) {
(*it)->setFocus();
return true;
}
return false;
}
static bool focusFirstCheckedButton(const std::vector<QAbstractButton *> &buttons)
{
return focusFirstButtonIf(buttons,
[](auto btn) {
return btn && btn->isEnabled() && btn->isChecked();
});
}
static bool focusFirstEnabledButton(const std::vector<QAbstractButton *> &buttons)
{
return focusFirstButtonIf(buttons,
[](auto btn) {
return btn && btn->isEnabled();
});
}
void AdvancedSettingsDialog::setInitialFocus()
{
// first try the key type radio buttons
......
......@@ -105,3 +105,30 @@ void Kleo::forceSetTabOrder(QWidget *first, QWidget *second)
second->setFocusPolicy(secondFocusPolicy);
}
}
template<typename UnaryPredicate>
bool focusFirstButtonIf(const std::vector<QAbstractButton *> &buttons, UnaryPredicate p)
{
auto it = std::find_if(std::begin(buttons), std::end(buttons), p);
if (it != std::end(buttons)) {
(*it)->setFocus();
return true;
}
return false;
}
bool Kleo::focusFirstCheckedButton(const std::vector<QAbstractButton *> &buttons)
{
return focusFirstButtonIf(buttons,
[](auto btn) {
return btn && btn->isEnabled() && btn->isChecked();
});
}
bool Kleo::focusFirstEnabledButton(const std::vector<QAbstractButton *> &buttons)
{
return focusFirstButtonIf(buttons,
[](auto btn) {
return btn && btn->isEnabled();
});
}
......@@ -48,4 +48,22 @@ void aggressive_raise(QWidget *w, bool stayOnTop);
*/
void forceSetTabOrder(QWidget *first, QWidget *second);
/**
* Gives the keyboard input focus to the first of the \p buttons, that is
* enabled and checked.
*
* Returns true, if a button was given focus. Returns false, if no button was
* found that is enabled and checked.
*/
bool focusFirstCheckedButton(const std::vector<QAbstractButton *> &buttons);
/**
* Gives the keyboard input focus to the first of the \p buttons, that is
* enabled.
*
* Returns true, if a button was given focus. Returns false, if no button was
* found that is enabled.
*/
bool focusFirstEnabledButton(const std::vector<QAbstractButton *> &buttons);
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment