<commit_before>/*
    Copyright 2012 <NAME> <<EMAIL>>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) version 3, or any
    later version accepted by the membership of KDE e.V. (or its
    successor approved by the membership of KDE e.V.), which shall
    act as a proxy defined in Section 6 of version 3 of the license.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "mainwindow.h"

#include <qitemselectionmodel.h>
#include <qplaintextedit.h>
#include <qstring.h>
#include <qtreeview.h>

#include "kdeaccessibilityclient/registry.h"
#include "kdeaccessibilityclient/accessibleobject.h"

#include "accessibletree.h"

#include "tests_auto_modeltest_modeltest.h"

using namespace KAccessibleClient;

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent), m_model(0)
{
    ui.setupUi(this);

    m_registry = new KAccessibleClient::Registry(this);
    connect(m_registry, SIGNAL(focusChanged(KAccessibleClient::AccessibleObject)), this, SLOT(focusChanged(KAccessibleClient::AccessibleObject)));
    m_registry->subscribeEventListeners(KAccessibleClient::Registry::Focus);

    m_model = new AccessibleTree(this);
    ui.treeView->setModel(m_model);
    ui.treeView->setContextMenuPolicy(Qt::CustomContextMenu);
    connect(ui.treeView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(treeCustomContextMenuRequested(QPoint)));
    m_model->setRegistry(m_registry);

    // The ultimate model verificaton helper :p
    new ModelTest(m_model, this);

    connect(ui.treeView->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(selectionChanged(QModelIndex,QModelIndex)));
    connect(ui.action_Reset_tree, SIGNAL(triggered()), m_model, SLOT(resetModel()));
    ui.action_Reset_tree->setShortcut(QKeySequence(QKeySequence::Refresh));
}

void MainWindow::focusChanged(const KAccessibleClient::AccessibleObject &object)
{
    ui.label->setText(tr("Focus changed to: %1 - %2 (%3)").arg(object.name()).arg(object.roleName()).arg(object.role()));

    if (ui.action_Follow_Focus->isChecked()) {
        QModelIndex index = m_model->indexForAccessible(object);
        if (index.isValid()) {
            ui.treeView->scrollTo(index);
            ui.treeView->selectionModel()->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect);
        }
    }
}

void MainWindow::selectionChanged(const QModelIndex& current, const QModelIndex&)
{
    QString text;

    if (current.isValid() && current.internalPointer()) {
        KAccessibleClient::AccessibleObject acc = static_cast<AccessibleWrapper*>(current.internalPointer())->acc;
        text += acc.name() + " (" + acc.description() + ")\n";
        text += "role: " + acc.roleName() + "\n";
        text += "checked: " + (acc.isChecked() ? QLatin1String("yes") : QLatin1String("no")) + '\n';

        text += "\nchildCount: " + QString::number(acc.childCount()) + "\n";
        foreach (const KAccessibleClient::AccessibleObject &child, acc.children()) {
            text += "child: " + child.name() + " (" + child.roleName() + ")\n";
        }

        Q_FOREACH(QAction *a, acc.actions()) {
            ui.treeView->insertAction(0, a);
        }

        QRect rect = acc.boundingRect();
        text += "\nCurrent Focus Coords: ( " + QString::number(rect.x()+rect.width()/2);
        text += " , " + QString::number(rect.y()+rect.height()/2) + " )\n";

        rect = acc.characterRect();
        text += "\nCurrent Text Focus: ( " + QString::number(rect.x()+rect.width()/2);
        text += " , " + QString::number(rect.y()+rect.height()/2) + " )\n";

        QStringList interfaces = acc.supportedInterfaces();
        text += "\nImplements Component Interface: ";
        text += QString(interfaces.contains("org.a11y.atspi.Component") ? "True" : "False") + "\n";
        text += "\nImplements Text Interface: ";
        text += QString(interfaces.contains("org.a11y.atspi.Text") ? "True" : "False") + "\n";
        text += "\nImplements Action Interface: ";
        text += QString(interfaces.contains("org.a11y.atspi.Action") ? "True" : "False") + "\n";

        text += "\nList of Interfaces:-";
        for (int i=0 ; i<interfaces.size() ; ++i)
            text += "\n\t" + interfaces.at(i);
    }
<commit_msg>Not needed any longer<commit_after>/*
    Copyright 2012 <NAME> <<EMAIL>>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) version 3, or any
    later version accepted by the membership of KDE e.V. (or its
    successor approved by the membership of KDE e.V.), which shall
    act as a proxy defined in Section 6 of version 3 of the license.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "mainwindow.h"

#include <qitemselectionmodel.h>
#include <qplaintextedit.h>
#include <qstring.h>
#include <qtreeview.h>

#include "kdeaccessibilityclient/registry.h"
#include "kdeaccessibilityclient/accessibleobject.h"

#include "accessibletree.h"

#include "tests_auto_modeltest_modeltest.h"

using namespace KAccessibleClient;

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent), m_model(0)
{
    ui.setupUi(this);

    m_registry = new KAccessibleClient::Registry(this);
    connect(m_registry, SIGNAL(focusChanged(KAccessibleClient::AccessibleObject)), this, SLOT(focusChanged(KAccessibleClient::AccessibleObject)));
    m_registry->subscribeEventListeners(KAccessibleClient::Registry::Focus);

    m_model = new AccessibleTree(this);
    ui.treeView->setModel(m_model);
    ui.treeView->setContextMenuPolicy(Qt::CustomContextMenu);
    connect(ui.treeView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(treeCustomContextMenuRequested(QPoint)));
    m_model->setRegistry(m_registry);

    // The ultimate model verificaton helper :p
    new ModelTest(m_model, this);

    connect(ui.treeView->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(selectionChanged(QModelIndex,QModelIndex)));
    connect(ui.action_Reset_tree, SIGNAL(triggered()), m_model, SLOT(resetModel()));
    ui.action_Reset_tree->setShortcut(QKeySequence(QKeySequence::Refresh));
}

void MainWindow::focusChanged(const KAccessibleClient::AccessibleObject &object)
{
    ui.label->setText(tr("Focus changed to: %1 - %2 (%3)").arg(object.name()).arg(object.roleName()).arg(object.role()));

    if (ui.action_Follow_Focus->isChecked()) {
        QModelIndex index = m_model->indexForAccessible(object);
        if (index.isValid()) {
            ui.treeView->scrollTo(index);
            ui.treeView->selectionModel()->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect);
        }
    }
}

void MainWindow::selectionChanged(const QModelIndex& current, const QModelIndex&)
{
    QString text;

    if (current.isValid() && current.internalPointer()) {
        KAccessibleClient::AccessibleObject acc = static_cast<AccessibleWrapper*>(current.internalPointer())->acc;
        text += acc.name() + " (" + acc.description() + ")\n";
        text += "role: " + acc.roleName() + "\n";
        text += "checked: " + (acc.isChecked() ? QLatin1String("yes") : QLatin1String("no")) + '\n';

        text += "\nchildCount: " + QString::number(acc.childCount()) + "\n";
        foreach (const KAccessibleClient::AccessibleObject &child, acc.children()) {
            text += "child: " + child.name() + " (" + child.roleName() + ")\n";
        }

        QRect rect = acc.boundingRect();
        text += "\nCurrent Focus Coords: ( " + QString::number(rect.x()+rect.width()/2);
        text += " , " + QString::number(rect.y()+rect.height()/2) + " )\n";

        rect = acc.characterRect();
        text += "\nCurrent Text Focus: ( " + QString::number(rect.x()+rect.width()/2);
        text += " , " + QString::number(rect.y()+rect.height()/2) + " )\n";

        QStringList interfaces = acc.supportedInterfaces();
        text += "\nImplements Component Interface: ";
        text += QString(interfaces.contains("org.a11y.atspi.Component") ? "True" : "False") + "\n";
        text += "\nImplements Text Interface: ";
        text += QString(interfaces.contains("org.a11y.atspi.Text") ? "True" : "False") + "\n";
        text += "\nImplements Action Interface: ";
        text += QString(interfaces.contains("org.a11y.atspi.Action") ? "True" : "False") + "\n";

        text += "\nList of Interfaces:-";
        for (int i=0 ; i<interfaces.size() ; ++i)
            text += "\n\t" + interfaces.at(i);
    }

{'fraction_non_alphanumeric': 0.14567718779689645, 'fraction_numerical': 0.005594848516837327, 'mean_word_length': 3.8018246325392804, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 48, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1852171', 'n_tokens_mistral': 2893, 'n_tokens_neox': 2819, 'n_words': 668}