File indexing completed on 2024-06-23 05:13:36

0001 /*
0002     accessibility/accessiblevaluelabel.cpp
0003 
0004     This file is part of Kleopatra, the KDE keymanager
0005     SPDX-FileCopyrightText: 2022 g10 Code GmbH
0006     SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de>
0007 
0008     SPDX-License-Identifier: GPL-2.0-or-later
0009 */
0010 
0011 #include <config-kleopatra.h>
0012 
0013 #include "accessiblevaluelabel_p.h"
0014 
0015 #include "utils/accessibility.h"
0016 
0017 #include <QLabel>
0018 
0019 using namespace Kleo;
0020 
0021 static constexpr QAccessible::Role ValueRole = static_cast<QAccessible::Role>(QAccessible::UserRole);
0022 
0023 AccessibleValueLabel::AccessibleValueLabel(QWidget *w)
0024     : QAccessibleWidget{w, ValueRole}
0025 {
0026     Q_ASSERT(qobject_cast<QLabel *>(w));
0027 }
0028 
0029 QAccessible::State AccessibleValueLabel::state() const
0030 {
0031     auto state = QAccessibleWidget::state();
0032     state.readOnly = true;
0033     return state;
0034 }
0035 
0036 QString AccessibleValueLabel::text(QAccessible::Text t) const
0037 {
0038     QString str;
0039     switch (t) {
0040     case QAccessible::Value: {
0041         str = Kleo::getAccessibleValue(widget());
0042         if (str.isEmpty()) {
0043             str = label()->text();
0044         }
0045         break;
0046     }
0047     default:
0048         break;
0049     }
0050     if (str.isEmpty()) {
0051         str = QAccessibleWidget::text(t);
0052     }
0053     return str;
0054 }
0055 
0056 QLabel *AccessibleValueLabel::label() const
0057 {
0058     return qobject_cast<QLabel *>(object());
0059 }