Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PIM
Kleopatra
Commits
f3c14393
Commit
f3c14393
authored
Jul 14, 2022
by
Ingo Klöcker
Browse files
Make focus helpers available for other dialogs
GnuPG-bug-id: 6080
parent
e53eedf0
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/newcertificatewizard/advancedsettingsdialog.cpp
View file @
f3c14393
...
...
@@ -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
...
...
src/utils/gui-helper.cpp
View file @
f3c14393
...
...
@@ -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
();
});
}
src/utils/gui-helper.h
View file @
f3c14393
...
...
@@ -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
);
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment