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

Add workaround for broken tab order of dialog buttons

At least with the KdeLayout the Close button is excluded from the
forward tab order (but not from the backward tab order), so that the
Close button cannot be selected by pressing Tab repeatedly.

The buttons are displayed in the order "Copy to Clipboard", "Save to
Disk...", "Close", but nextInFocusChain() of the Save button returns the
AuditLogViewer instead of the Close button. The complete picture is
as follows:
- focusProxy() of the button box is the Copy button (okay)
- nextInFocusChain() of the Copy button is the Save button (okay)
- nextInFocusChain() of the Save button is the AuditLogViewer (not okay)
- nextInFocusChain() of the Close button is the Copy button (not okay)
Seems to be a bug in Qt.

Creating the Close button after the custom buttons works around the
problem and fixes the tab order (at least for KdeLayout).

GnuPG-bug-id: 5535
parent d31ade75
/*
SPDX-FileCopyrightText: 2015-2021 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
SPDX-FileCopyrightText: 2015-2021 Laurent Montel <montel@kde.org>
SPDX-FileCopyrightText: 2021 g10 Code GmbH
SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "auditlogviewer.h"
#ifdef HAVE_PIMTEXTEDIT
......@@ -22,6 +24,9 @@
#include <QPushButton>
#include <QVBoxLayout>
#include <QStyle>
#include <QDebug>
using namespace Kleo::Private;
AuditLogViewer::AuditLogViewer(const QString &log, QWidget *parent)
......@@ -34,20 +39,25 @@ AuditLogViewer::AuditLogViewer(const QString &log, QWidget *parent)
#endif
{
setWindowTitle(i18nc("@title:window", "View GnuPG Audit Log"));
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Close);
QDialogButtonBox *buttonBox = new QDialogButtonBox{};
auto copyClipBtn = new QPushButton;
copyClipBtn->setText(i18n("&Copy to Clipboard"));
copyClipBtn->setObjectName(QStringLiteral("copyClipBtn"));
copyClipBtn->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
buttonBox->addButton(copyClipBtn, QDialogButtonBox::ActionRole);
connect(copyClipBtn, &QPushButton::clicked, this, &AuditLogViewer::slotCopyClip);
auto saveAsBtn = new QPushButton;
saveAsBtn->setText(i18n("&Save to Disk..."));
saveAsBtn->setObjectName(QStringLiteral("saveAsBtn"));
saveAsBtn->setIcon(QIcon::fromTheme(QStringLiteral("document-save-as")));
buttonBox->addButton(saveAsBtn, QDialogButtonBox::ActionRole);
connect(saveAsBtn, &QPushButton::clicked, this, &AuditLogViewer::slotSaveAs);
buttonBox->setStandardButtons(QDialogButtonBox::Close);
buttonBox->button(QDialogButtonBox::Close)->setObjectName(QStringLiteral("Close"));
m_textEdit->setObjectName(QStringLiteral("m_textEdit"));
m_textEdit->setReadOnly(true);
......@@ -55,6 +65,12 @@ AuditLogViewer::AuditLogViewer(const QString &log, QWidget *parent)
mainLayout->addWidget(m_textEdit);
mainLayout->addWidget(buttonBox);
// qDebug() << "buttonBox->style()->styleHint(QStyle::SH_DialogButtonLayout, ...):" << buttonBox->style()->styleHint(QStyle::SH_DialogButtonLayout, nullptr, buttonBox);
// qDebug() << __func__ << "buttonBox->focusProxy():" << buttonBox->focusProxy();
// qDebug() << __func__ << "copyClipBtn->nextInFocusChain():" << copyClipBtn->nextInFocusChain();
// qDebug() << __func__ << "saveAsBtn->nextInFocusChain():" << saveAsBtn->nextInFocusChain();
// qDebug() << __func__ << "closeBtn->nextInFocusChain():" << buttonBox->button(QDialogButtonBox::Close)->nextInFocusChain();
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
setAuditLog(log);
......
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