⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qaccessiblewidgets.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/******************************************************************************** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.**** This file is part of the plugins of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file.  Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include "qaccessiblewidgets.h"#include "qabstracttextdocumentlayout.h"#include "qapplication.h"#include "qclipboard.h"#include "qtextedit.h"#include "private/qtextedit_p.h"#include "qtextdocument.h"#include "qtextobject.h"#include "qscrollbar.h"#include "qdebug.h"#include <QApplication>#include <QStackedWidget>#include <QToolBox>#include <QMdiArea>#include <QMdiSubWindow>#include <QWorkspace>#include <QDialogButtonBox>#include <limits.h>#include <QRubberBand>#include <QTextBrowser>#include <QCalendarWidget>#include <QAbstractItemView>#include <QDockWidget>#include <QMainWindow>#include <QAbstractButton>#include <private/qdockwidget_p.h>#include <QtGui/QFocusFrame>#ifndef QT_NO_ACCESSIBILITYusing namespace QAccessible2;QList<QWidget*> childWidgets(const QWidget *widget, bool includeTopLevel){    if (widget == 0)        return QList<QWidget*>();    QList<QObject*> list = widget->children();    QList<QWidget*> widgets;    for (int i = 0; i < list.size(); ++i) {        QWidget *w = qobject_cast<QWidget *>(list.at(i));        if (w && (includeTopLevel || !w->isWindow() ) && !qobject_cast<QFocusFrame*>(w))            widgets.append(w);    }    return widgets;}static inline int distance(QWidget *source, QWidget *target,                           QAccessible::RelationFlag relation){    if (!source || !target)        return -1;    int returnValue = -1;    switch (relation) {    case QAccessible::Up:        if (target->y() <= source->y())            returnValue = source->y() - target->y();        break;    case QAccessible::Down:        if (target->y() >= source->y() + source->height())            returnValue = target->y() - (source->y() + source->height());        break;    case QAccessible::Right:        if (target->x() >= source->x() + source->width())            returnValue = target->x() - (source->x() + source->width());        break;    case QAccessible::Left:        if (target->x() <= source->x())            returnValue = source->x() - target->x();        break;    default:        break;    }    return returnValue;}static inline QWidget *mdiAreaNavigate(QWidget *area,                                       QAccessible::RelationFlag relation, int entry){#if defined(QT_NO_MDIAREA) && defined(QT_NO_WORKSPACE)    Q_UNUSED(area);#endif#ifndef QT_NO_MDIAREA    const QMdiArea *mdiArea = qobject_cast<QMdiArea *>(area);#endif#ifndef QT_NO_WORKSPACE    const QWorkspace *workspace = qobject_cast<QWorkspace *>(area);#endif    if (true#ifndef QT_NO_MDIAREA        && !mdiArea#endif#ifndef QT_NO_WORKSPACE    && !workspace#endif    )        return 0;    QWidgetList windows;#ifndef QT_NO_MDIAREA    if (mdiArea) {        foreach (QMdiSubWindow *window, mdiArea->subWindowList())            windows.append(window);    } else#endif    {#ifndef QT_NO_WORKSPACE        foreach (QWidget *window, workspace->windowList())            windows.append(window->parentWidget());#endif    }    if (windows.isEmpty() || entry < 1 || entry > windows.count())        return 0;    QWidget *source = windows.at(entry - 1);    QMap<int, QWidget *> candidates;    foreach (QWidget *window, windows) {        if (source == window)            continue;        int candidateDistance = distance(source, window, relation);        if (candidateDistance >= 0)            candidates.insert(candidateDistance, window);    }    int minimumDistance = INT_MAX;    QWidget *target = 0;    foreach (QWidget *candidate, candidates.values()) {        switch (relation) {        case QAccessible::Up:        case QAccessible::Down:            if (qAbs(candidate->x() - source->x()) < minimumDistance) {                target = candidate;                minimumDistance = qAbs(candidate->x() - source->x());            }            break;        case QAccessible::Left:        case QAccessible::Right:            if (qAbs(candidate->y() - source->y()) < minimumDistance) {                target = candidate;                minimumDistance = qAbs(candidate->y() - source->y());            }            break;        default:            break;        }        if (minimumDistance == 0)            break;    }#ifndef QT_NO_WORKSPACE    if (workspace) {        foreach (QWidget *widget, workspace->windowList()) {            if (widget->parentWidget() == target)                target = widget;        }    }#endif    return target;}#ifndef QT_NO_TEXTEDIT/*!  \class QAccessibleTextEdit qaccessiblewidget.h  \brief The QAccessibleTextEdit class implements the QAccessibleInterface for richtext editors.  \internal*/static QTextBlock qTextBlockAt(const QTextDocument *doc, int pos){    Q_ASSERT(pos >= 0);    QTextBlock block = doc->begin();    int i = 0;    while (block.isValid() && i < pos) {        block = block.next();        ++i;    }    return block;}static int qTextBlockPosition(QTextBlock block){    int child = 0;    while (block.isValid()) {        block = block.previous();        ++child;    }    return child;}/*!  \fn QAccessibleTextEdit::QAccessibleTextEdit(QWidget* widget)  Constructs a QAccessibleTextEdit object for a \a widget.*/QAccessibleTextEdit::QAccessibleTextEdit(QWidget *o): QAccessibleWidgetEx(o, EditableText){    Q_ASSERT(widget()->inherits("QTextEdit"));    childOffset = QAccessibleWidgetEx::childCount();}/*! Returns the text edit. */QTextEdit *QAccessibleTextEdit::textEdit() const{    return static_cast<QTextEdit *>(widget());}QRect QAccessibleTextEdit::rect(int child) const{    if (child <= childOffset)        return QAccessibleWidgetEx::rect(child);     QTextEdit *edit = textEdit();     QTextBlock block = qTextBlockAt(edit->document(), child - childOffset - 1);     if (!block.isValid())         return QRect();     QRect rect = edit->document()->documentLayout()->blockBoundingRect(block).toRect();     rect.translate(-edit->horizontalScrollBar()->value(), -edit->verticalScrollBar()->value());     rect = edit->viewport()->rect().intersect(rect);     if (rect.isEmpty())         return QRect();     return rect.translated(edit->viewport()->mapToGlobal(QPoint(0, 0)));}int QAccessibleTextEdit::childAt(int x, int y) const{    QTextEdit *edit = textEdit();    if (!edit->isVisible())        return -1;    QPoint point = edit->viewport()->mapFromGlobal(QPoint(x, y));    QTextBlock block = edit->cursorForPosition(point).block();    if (block.isValid())        return qTextBlockPosition(block) + childOffset;    return QAccessibleWidgetEx::childAt(x, y);}/*! \reimp */QString QAccessibleTextEdit::text(Text t, int child) const{    if (t == Value) {        if (child > childOffset)            return qTextBlockAt(textEdit()->document(), child - childOffset - 1).text();        if (!child)            return textEdit()->toPlainText();    }    return QAccessibleWidgetEx::text(t, child);}/*! \reimp */void QAccessibleTextEdit::setText(Text t, int child, const QString &text){    if (t != Value || (child > 0 && child <= childOffset)) {        QAccessibleWidgetEx::setText(t, child, text);        return;    }    if (textEdit()->isReadOnly())        return;    if (!child) {        textEdit()->setText(text);        return;    }    QTextBlock block = qTextBlockAt(textEdit()->document(), child - childOffset - 1);    if (!block.isValid())        return;    QTextCursor cursor(block);    cursor.select(QTextCursor::BlockUnderCursor);    cursor.insertText(text);}/*! \reimp */QAccessible::Role QAccessibleTextEdit::role(int child) const{    if (child > childOffset)        return EditableText;    return QAccessibleWidgetEx::role(child);}QVariant QAccessibleTextEdit::invokeMethodEx(QAccessible::Method method, int child,                                                     const QVariantList &params){    if (child)        return QVariant();    switch (method) {    case ListSupportedMethods: {        QSet<QAccessible::Method> set;        set << ListSupportedMethods << SetCursorPosition << GetCursorPosition;        return qVariantFromValue(set | qvariant_cast<QSet<QAccessible::Method> >(                    QAccessibleWidgetEx::invokeMethodEx(method, child, params)));    }    case SetCursorPosition:        setCursorPosition(params.value(0).toInt());        return true;    case GetCursorPosition:        return textEdit()->textCursor().position();    default:        return QAccessibleWidgetEx::invokeMethodEx(method, child, params);    }}int QAccessibleTextEdit::childCount() const{    return childOffset + textEdit()->document()->blockCount();}#endif // QT_NO_TEXTEDIT#ifndef QT_NO_STACKEDWIDGET// ======================= QAccessibleStackedWidget ======================QAccessibleStackedWidget::QAccessibleStackedWidget(QWidget *widget)    : QAccessibleWidgetEx(widget, LayeredPane){    Q_ASSERT(qobject_cast<QStackedWidget *>(widget));}QVariant QAccessibleStackedWidget::invokeMethodEx(QAccessible::Method, int, const QVariantList &){    return QVariant();}int QAccessibleStackedWidget::childAt(int x, int y) const{    if (!stackedWidget()->isVisible())        return -1;    QWidget *currentWidget = stackedWidget()->currentWidget();    if (!currentWidget)        return -1;    QPoint position = currentWidget->mapFromGlobal(QPoint(x, y));    if (currentWidget->rect().contains(position))        return 1;    return -1;}int QAccessibleStackedWidget::childCount() const{    return stackedWidget()->count();}int QAccessibleStackedWidget::indexOfChild(const QAccessibleInterface *child) const{    if (!child || (stackedWidget()->currentWidget() != child->object()))        return -1;    return 1;}int QAccessibleStackedWidget::navigate(RelationFlag relation, int entry, QAccessibleInterface **target) const{    *target = 0;    QObject *targetObject = 0;    switch (relation) {    case Child:        if (entry != 1)            return -1;        targetObject = stackedWidget()->currentWidget();        break;    default:        return QAccessibleWidgetEx::navigate(relation, entry, target);    }    *target = QAccessible::queryAccessibleInterface(targetObject);    return *target ? 0 : -1;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -