[42529] | 1 | /* $Id: UITextTable.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
[77432] | 3 | * VBox Qt GUI - UITextTable class implementation.
|
---|
[42529] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[98103] | 7 | * Copyright (C) 2012-2023 Oracle and/or its affiliates.
|
---|
[42529] | 8 | *
|
---|
[96407] | 9 | * This file is part of VirtualBox base platform packages, as
|
---|
| 10 | * available from https://www.virtualbox.org.
|
---|
| 11 | *
|
---|
| 12 | * This program is free software; you can redistribute it and/or
|
---|
| 13 | * modify it under the terms of the GNU General Public License
|
---|
| 14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
| 15 | * License.
|
---|
| 16 | *
|
---|
| 17 | * This program is distributed in the hope that it will be useful, but
|
---|
| 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 20 | * General Public License for more details.
|
---|
| 21 | *
|
---|
| 22 | * You should have received a copy of the GNU General Public License
|
---|
| 23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 24 | *
|
---|
| 25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
[42529] | 26 | */
|
---|
| 27 |
|
---|
[95608] | 28 | /* Qt includes: */
|
---|
| 29 | #include <QAccessibleObject>
|
---|
| 30 | #include <QRegularExpression>
|
---|
| 31 |
|
---|
[42529] | 32 | /* GUI includes: */
|
---|
[77432] | 33 | #include "UITextTable.h"
|
---|
[42529] | 34 |
|
---|
[95608] | 35 | /* Other VBox includes: */
|
---|
| 36 | #include "iprt/assert.h"
|
---|
[77435] | 37 |
|
---|
[95608] | 38 |
|
---|
| 39 | /** QAccessibleObject extension used as an accessibility interface for UITextTableLine. */
|
---|
| 40 | class UIAccessibilityInterfaceForUITextTableLine : public QAccessibleObject
|
---|
| 41 | {
|
---|
| 42 | public:
|
---|
| 43 |
|
---|
| 44 | /** Returns an accessibility interface for passed @a strClassname and @a pObject. */
|
---|
| 45 | static QAccessibleInterface *pFactory(const QString &strClassname, QObject *pObject)
|
---|
| 46 | {
|
---|
| 47 | /* Creating UITextTableLine accessibility interface: */
|
---|
| 48 | if (pObject && strClassname == QLatin1String("UITextTableLine"))
|
---|
| 49 | return new UIAccessibilityInterfaceForUITextTableLine(pObject);
|
---|
| 50 |
|
---|
| 51 | /* Null by default: */
|
---|
| 52 | return 0;
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | /** Constructs an accessibility interface passing @a pObject to the base-class. */
|
---|
| 56 | UIAccessibilityInterfaceForUITextTableLine(QObject *pObject)
|
---|
| 57 | : QAccessibleObject(pObject)
|
---|
| 58 | {}
|
---|
| 59 |
|
---|
| 60 | /** Returns the parent. */
|
---|
| 61 | virtual QAccessibleInterface *parent() const RT_OVERRIDE
|
---|
| 62 | {
|
---|
| 63 | /* Make sure item still alive: */
|
---|
| 64 | AssertPtrReturn(line(), 0);
|
---|
| 65 |
|
---|
| 66 | /* Always return parent object: */
|
---|
| 67 | return QAccessible::queryAccessibleInterface(line()->parent());
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | /** Returns the number of children. */
|
---|
| 71 | virtual int childCount() const RT_OVERRIDE { return 0; }
|
---|
| 72 | /** Returns the child with the passed @a iIndex. */
|
---|
| 73 | virtual QAccessibleInterface *child(int iIndex) const RT_OVERRIDE { Q_UNUSED(iIndex); return 0; }
|
---|
| 74 | /** Returns the index of the passed @a pChild. */
|
---|
| 75 | virtual int indexOfChild(const QAccessibleInterface *pChild) const RT_OVERRIDE { Q_UNUSED(pChild); return -1; }
|
---|
| 76 |
|
---|
| 77 | /** Returns a text for the passed @a enmTextRole. */
|
---|
| 78 | virtual QString text(QAccessible::Text enmTextRole) const RT_OVERRIDE
|
---|
| 79 | {
|
---|
| 80 | /* Make sure line still alive: */
|
---|
| 81 | AssertPtrReturn(line(), QString());
|
---|
| 82 |
|
---|
| 83 | /* Return the description: */
|
---|
| 84 | if (enmTextRole == QAccessible::Description)
|
---|
| 85 | {
|
---|
| 86 | const QString str1 = line()->string1();
|
---|
| 87 | QString str2 = line()->string2();
|
---|
| 88 | if (!str2.isEmpty())
|
---|
| 89 | str2.remove(QRegularExpression("<a[^>]*>|</a>"));
|
---|
| 90 | return str2.isEmpty() ? str1 : QString("%1: %2").arg(str1, str2);
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | /* Null-string by default: */
|
---|
| 94 | return QString();
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | /** Returns the role. */
|
---|
| 98 | virtual QAccessible::Role role() const RT_OVERRIDE
|
---|
| 99 | {
|
---|
| 100 | /* Return the role: */
|
---|
| 101 | return QAccessible::ListItem;
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | /** Returns the state. */
|
---|
| 105 | virtual QAccessible::State state() const RT_OVERRIDE
|
---|
| 106 | {
|
---|
| 107 | /* Return the state: */
|
---|
| 108 | return QAccessible::State();
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | private:
|
---|
| 112 |
|
---|
| 113 | /** Returns corresponding UITextTableLine. */
|
---|
| 114 | UITextTableLine *line() const { return qobject_cast<UITextTableLine*>(object()); }
|
---|
| 115 | };
|
---|
| 116 |
|
---|
| 117 |
|
---|
| 118 | /*********************************************************************************************************************************
|
---|
| 119 | * Class UITextTableLine implementation. *
|
---|
| 120 | *********************************************************************************************************************************/
|
---|
| 121 |
|
---|
[77435] | 122 | UITextTableLine::UITextTableLine(const QString &str1, const QString &str2, QObject *pParent /* = 0 */)
|
---|
| 123 | : QObject(pParent)
|
---|
| 124 | , m_str1(str1)
|
---|
| 125 | , m_str2(str2)
|
---|
[95608] | 126 | {
|
---|
| 127 | /* Install UITextTableLine accessibility interface factory: */
|
---|
| 128 | QAccessible::installFactory(UIAccessibilityInterfaceForUITextTableLine::pFactory);
|
---|
| 129 | }
|
---|
[77435] | 130 |
|
---|
| 131 | UITextTableLine::UITextTableLine(const UITextTableLine &other)
|
---|
| 132 | : QObject(other.parent())
|
---|
| 133 | , m_str1(other.string1())
|
---|
| 134 | , m_str2(other.string2())
|
---|
[95608] | 135 | {
|
---|
| 136 | /* Install UITextTableLine accessibility interface factory: */
|
---|
| 137 | QAccessible::installFactory(UIAccessibilityInterfaceForUITextTableLine::pFactory);
|
---|
| 138 | }
|
---|
[77435] | 139 |
|
---|
| 140 | UITextTableLine &UITextTableLine::operator=(const UITextTableLine &other)
|
---|
| 141 | {
|
---|
| 142 | setParent(other.parent());
|
---|
| 143 | set1(other.string1());
|
---|
| 144 | set2(other.string2());
|
---|
| 145 | return *this;
|
---|
| 146 | }
|
---|
| 147 |
|
---|
| 148 | bool UITextTableLine::operator==(const UITextTableLine &other) const
|
---|
| 149 | {
|
---|
| 150 | return string1() == other.string1()
|
---|
| 151 | && string2() == other.string2();
|
---|
| 152 | }
|
---|