From d289e54f2d2aa066cb383d8c8249bd7594bdf7b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Arve=20S=C3=A6ther?= Date: Wed, 6 Apr 2011 10:47:28 +0200 Subject: Make accessibility work on Windows with alien This means that there will be no implicit conversion to windows handles anymore! Enabler for making QML accessible on windows. (cherry picked from commit a3ac7deb5dfe48c5fdd0e170c20b6852c3bb41de) Reviewed-by: Frederik Gladhorn --- src/gui/accessible/qaccessible_win.cpp | 126 +++++++++++++++++++++++++++++---- 1 file changed, 113 insertions(+), 13 deletions(-) diff --git a/src/gui/accessible/qaccessible_win.cpp b/src/gui/accessible/qaccessible_win.cpp index caa2104..0e69a5e 100644 --- a/src/gui/accessible/qaccessible_win.cpp +++ b/src/gui/accessible/qaccessible_win.cpp @@ -47,6 +47,8 @@ #include "qt_windows.h" #include "qwidget.h" #include "qsettings.h" +#include +#include #include #if !defined(WINABLEAPI) @@ -159,6 +161,12 @@ void showDebug(const char* funcName, const QAccessibleInterface *iface) # define showDebug(f, iface) #endif +// This stuff is used for widgets/items with no window handle: +typedef QMap > NotifyMap; +Q_GLOBAL_STATIC(NotifyMap, qAccessibleRecentSentEvents) +static int eventNum = 0; + + void QAccessible::initialize() { @@ -251,17 +259,15 @@ void QAccessible::updateAccessibility(QObject *o, int who, Event reason) // An event has to be associated with a window, // so find the first parent that is a widget. QWidget *w = 0; - if (o->isWidgetType()) { - w = (QWidget*)o; - } else { - QObject *p = o; - while ((p = p->parent()) != 0) { - if (p->isWidgetType()) { - w = (QWidget*)p; + QObject *p = o; + do { + if (p->isWidgetType()) { + w = static_cast(p); + if (w->internalWinId()) break; - } } - } + p = p->parent(); + } while (p); if (!w) { if (reason != QAccessible::ContextHelpStart && @@ -282,12 +288,81 @@ void QAccessible::updateAccessibility(QObject *o, int who, Event reason) } } + WId wid = w->internalWinId(); if (reason != MenuCommand) { // MenuCommand is faked - ptrNotifyWinEvent(reason, w->winId(), OBJID_CLIENT, who); + if (w != o) { + // See comment "SENDING EVENTS TO OBJECTS WITH NO WINDOW HANDLE" + eventNum %= 50; //[0..49] + int eventId = - eventNum - 1; + + qAccessibleRecentSentEvents()->insert(eventId, qMakePair(o,who)); + ptrNotifyWinEvent(reason, wid, OBJID_CLIENT, eventId ); + + ++eventNum; + } else { + ptrNotifyWinEvent(reason, wid, OBJID_CLIENT, who); + } } #endif // Q_WS_WINCE } +/* == SENDING EVENTS TO OBJECTS WITH NO WINDOW HANDLE == + + If the user requested to send the event to a widget with no window, + we need to send an event to an object with no hwnd. + The way we do that is to send it to the *first* ancestor widget + with a window. + Then we'll need a way of identifying the child: + We'll just keep a list of the most recent events that we have sent, + where each entry in the list is identified by a negative value + between [-50,-1]. This negative value we will pass on to + NotifyWinEvent() as the child id. When the negative value have + reached -50, it will wrap around to -1. This seems to be enough + + Now, when the client receives that event, he will first call + AccessibleObjectFromEvent() where dwChildID is the special + negative value. AccessibleObjectFromEvent does two steps: + 1. It will first sent a WM_GETOBJECT to the server, asking + for the IAccessible interface for the HWND. + 2. With the IAccessible interface it got hold of it will call + acc_getChild where the child id argument is the special + negative identifier. In our reimplementation of get_accChild + we check for this if the child id is negative. If it is, then + we'll look up in our table for the entry that is associated + with that value. + The entry will then contain a pointer to the QObject /QWidget + that we can use to call queryAccessibleInterface() on. + + + The following figure shows how the interaction between server and + client is in the case when the server is sending an event. + +SERVER (Qt) | CLIENT | +--------------------------------------------+---------------------------------------+ + | +acc->updateAccessibility(obj, childIndex) | + | +recentEvents()->insert(- 1 - eventNum, | + qMakePair(obj, childIndex) | +NotifyWinEvent(hwnd, childId) => | + | AccessibleObjectFromEvent(event, hwnd, OBJID_CLIENT, childId ) + | will do: + <=== 1. send WM_GETOBJECT(hwnd, OBJID_CLIENT) +widget ~= hwnd +iface = queryAccessibleInteface(widget) +(create IAccessible interface wrapper for + iface) + return iface ===> IAccessible* iface; (for hwnd) + | + <=== call iface->get_accChild(childId) +get_accChild() { | + if (varChildID.lVal < 0) { + QPair ref = recentEvents().value(varChildID.lVal); + [...] + } +*/ + + void QAccessible::setRootObject(QObject *o) { if (rootObjectHandler) { @@ -418,15 +493,18 @@ public: delete accessible; } + /* IUnknown */ HRESULT STDMETHODCALLTYPE QueryInterface(REFIID, LPVOID *); ULONG STDMETHODCALLTYPE AddRef(); ULONG STDMETHODCALLTYPE Release(); + /* IDispatch */ HRESULT STDMETHODCALLTYPE GetTypeInfoCount(unsigned int *); HRESULT STDMETHODCALLTYPE GetTypeInfo(unsigned int, unsigned long, ITypeInfo **); HRESULT STDMETHODCALLTYPE GetIDsOfNames(const _GUID &, wchar_t **, unsigned int, unsigned long, long *); HRESULT STDMETHODCALLTYPE Invoke(long, const _GUID &, unsigned long, unsigned short, tagDISPPARAMS *, tagVARIANT *, tagEXCEPINFO *, unsigned int *); + /* IAccessible */ HRESULT STDMETHODCALLTYPE accHitTest(long xLeft, long yTop, VARIANT *pvarID); HRESULT STDMETHODCALLTYPE accLocation(long *pxLeft, long *pyTop, long *pcxWidth, long *pcyHeight, VARIANT varID); HRESULT STDMETHODCALLTYPE accNavigate(long navDir, VARIANT varStart, VARIANT *pvarEnd); @@ -451,6 +529,7 @@ public: HRESULT STDMETHODCALLTYPE get_accFocus(VARIANT *pvarID); HRESULT STDMETHODCALLTYPE get_accSelection(VARIANT *pvarChildren); + /* IOleWindow */ HRESULT STDMETHODCALLTYPE GetWindow(HWND *phwnd); HRESULT STDMETHODCALLTYPE ContextSensitiveHelp(BOOL fEnterMode); @@ -896,9 +975,30 @@ HRESULT STDMETHODCALLTYPE QWindowsAccessible::get_accChild(VARIANT varChildID, I if (varChildID.vt == VT_EMPTY) return E_INVALIDARG; + + int childIndex = varChildID.lVal; QAccessibleInterface *acc = 0; - RelationFlag rel = varChildID.lVal ? Child : Self; - accessible->navigate(rel, varChildID.lVal, &acc); + + if (childIndex < 0) { + const int entry = childIndex; + QPair ref = qAccessibleRecentSentEvents()->value(entry); + if (ref.first) { + acc = queryAccessibleInterface(ref.first); + if (acc && ref.second) { + if (ref.second) { + QAccessibleInterface *res; + int index = acc->navigate(Child, ref.second, &res); + delete acc; + if (index == -1) + return E_INVALIDARG; + acc = res; + } + } + } + } else { + RelationFlag rel = childIndex ? Child : Self; + accessible->navigate(rel, childIndex, &acc); + } if (acc) { QWindowsAccessible* wacc = new QWindowsAccessible(acc); @@ -1203,7 +1303,7 @@ HRESULT STDMETHODCALLTYPE QWindowsAccessible::GetWindow(HWND *phwnd) if (!o || !o->isWidgetType()) return E_FAIL; - *phwnd = static_cast(o)->winId(); + *phwnd = static_cast(o)->effectiveWinId(); return S_OK; } -- cgit v0.12 From 96406a7dd609e75340f7b4a05726c60c197786b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Arve=20S=C3=A6ther?= Date: Thu, 5 May 2011 16:19:16 +0200 Subject: Fix updateAccessibility for QGraphicsObjects If updateAccessibility is called on a QGraphicsObject, walk up and find the closest ancestor widget with a HWND. (cherry picked from commit d4291591dfb6a7b1f5c7d00879e8162e84d9ab1b) Reviewed-by: Frederik Gladhorn --- src/gui/accessible/qaccessible_win.cpp | 124 ++++++++++++++++++++++++++++++++- 1 file changed, 123 insertions(+), 1 deletion(-) diff --git a/src/gui/accessible/qaccessible_win.cpp b/src/gui/accessible/qaccessible_win.cpp index 0e69a5e..98db529 100644 --- a/src/gui/accessible/qaccessible_win.cpp +++ b/src/gui/accessible/qaccessible_win.cpp @@ -49,6 +49,9 @@ #include "qsettings.h" #include #include +#include +#include +#include #include #if !defined(WINABLEAPI) @@ -150,6 +153,106 @@ static const char *roleString(QAccessible::Role role) return roles[int(role)]; } +static const char *eventString(QAccessible::Event ev) +{ + static const char *events[] = { + "null", // 0 + "SoundPlayed" /*= 0x0001*/, + "Alert" /*= 0x0002*/, + "ForegroundChanged" /*= 0x0003*/, + "MenuStart" /*= 0x0004*/, + "MenuEnd" /*= 0x0005*/, + "PopupMenuStart" /*= 0x0006*/, + "PopupMenuEnd" /*= 0x0007*/, + "ContextHelpStart" /*= 0x000C*/, // 8 + "ContextHelpEnd" /*= 0x000D*/, + "DragDropStart" /*= 0x000E*/, + "DragDropEnd" /*= 0x000F*/, + "DialogStart" /*= 0x0010*/, + "DialogEnd" /*= 0x0011*/, + "ScrollingStart" /*= 0x0012*/, + "ScrollingEnd" /*= 0x0013*/, + "MenuCommand" /*= 0x0018*/, // 16 + + // Values from IAccessible2 + "ActionChanged" /*= 0x0101*/, // 17 + "ActiveDescendantChanged", + "AttributeChanged", + "DocumentContentChanged", + "DocumentLoadComplete", + "DocumentLoadStopped", + "DocumentReload", + "HyperlinkEndIndexChanged", + "HyperlinkNumberOfAnchorsChanged", + "HyperlinkSelectedLinkChanged", + "HypertextLinkActivated", + "HypertextLinkSelected", + "HyperlinkStartIndexChanged", + "HypertextChanged", + "HypertextNLinksChanged", + "ObjectAttributeChanged", + "PageChanged", + "SectionChanged", + "TableCaptionChanged", + "TableColumnDescriptionChanged", + "TableColumnHeaderChanged", + "TableModelChanged", + "TableRowDescriptionChanged", + "TableRowHeaderChanged", + "TableSummaryChanged", + "TextAttributeChanged", + "TextCaretMoved", + // TextChanged, deprecated, use TextUpdated + //TextColumnChanged = TextCaretMoved + 2, + "TextInserted", + "TextRemoved", + "TextUpdated", + "TextSelectionChanged", + "VisibleDataChanged", /*= 0x0101+32*/ + "ObjectCreated" /*= 0x8000*/, // 49 + "ObjectDestroyed" /*= 0x8001*/, + "ObjectShow" /*= 0x8002*/, + "ObjectHide" /*= 0x8003*/, + "ObjectReorder" /*= 0x8004*/, + "Focus" /*= 0x8005*/, + "Selection" /*= 0x8006*/, + "SelectionAdd" /*= 0x8007*/, + "SelectionRemove" /*= 0x8008*/, + "SelectionWithin" /*= 0x8009*/, + "StateChanged" /*= 0x800A*/, + "LocationChanged" /*= 0x800B*/, + "NameChanged" /*= 0x800C*/, + "DescriptionChanged" /*= 0x800D*/, + "ValueChanged" /*= 0x800E*/, + "ParentChanged" /*= 0x800F*/, + "HelpChanged" /*= 0x80A0*/, + "DefaultActionChanged" /*= 0x80B0*/, + "AcceleratorChanged" /*= 0x80C0*/ + }; + int e = int(ev); + if (e <= 0x80c0) { + const int last = sizeof(events)/sizeof(char*) - 1; + + if (e <= 0x07) + return events[e]; + else if (e <= 0x13) + return events[e - 0x0c + 8]; + else if (e == 0x18) + return events[16]; + else if (e <= 0x0101 + 32) + return events[e - 0x101 + 17]; + else if (e <= 0x800f) + return events[e - 0x8000 + 49]; + else if (e == 0x80a0) + return events[last - 2]; + else if (e == 0x80b0) + return events[last - 1]; + else if (e == 0x80c0) + return events[last]; + } + return "unknown"; +}; + void showDebug(const char* funcName, const QAccessibleInterface *iface) { qDebug() << "Role:" << roleString(iface->role(0)) @@ -266,9 +369,28 @@ void QAccessible::updateAccessibility(QObject *o, int who, Event reason) if (w->internalWinId()) break; } - p = p->parent(); + if (QGraphicsObject *gfxObj = qobject_cast(p)) { + QGraphicsItem *parentItem = gfxObj->parentItem(); + if (parentItem) { + p = parentItem->toGraphicsObject(); + } else { + QGraphicsView *view = 0; + if (QGraphicsScene *scene = gfxObj->scene()) { + QWidget *fw = QApplication::focusWidget(); + const QList views = scene->views(); + for (int i = 0 ; i < views.count() && view != fw; ++i) { + view = views.at(i); + } + } + p = view; + } + } else { + p = p->parent(); + } + } while (p); + //qDebug() << "updateAccessibility(), hwnd:" << w << ", object:" << o << "," << eventString(reason); if (!w) { if (reason != QAccessible::ContextHelpStart && reason != QAccessible::ContextHelpEnd) -- cgit v0.12 From 4687938fd03ed65306039af6b4e5e192ec8bf491 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Arve=20S=C3=A6ther?= Date: Thu, 5 May 2011 16:21:36 +0200 Subject: Call updateAccessibility on the QGraphicsObject in updateMicroFocus Since QGraphicsObjects now can be in the a11y hierarchy, we should treat them just like we treat widgets. (cherry picked from commit 860745a4713b29857d14571572504da71a2ca077) Reviewed-by: Frederik Gladhorn --- src/gui/graphicsview/qgraphicsitem.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index e67fe82..41ff317 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -7395,15 +7395,19 @@ void QGraphicsItem::updateMicroFocus() if (QWidget *fw = QApplication::focusWidget()) { if (scene()) { for (int i = 0 ; i < scene()->views().count() ; ++i) { - if (scene()->views().at(i) == fw) - if (QInputContext *inputContext = fw->inputContext()) + if (scene()->views().at(i) == fw) { + if (QInputContext *inputContext = fw->inputContext()) { inputContext->update(); - } - } #ifndef QT_NO_ACCESSIBILITY - // ##### is this correct - QAccessible::updateAccessibility(fw, 0, QAccessible::StateChanged); + // ##### is this correct + if (toGraphicsObject()) + QAccessible::updateAccessibility(toGraphicsObject(), 0, QAccessible::StateChanged); #endif + break; + } + } + } + } } #endif } -- cgit v0.12 From 9a02ad74693f1835745ec20798b353f7e62bcd5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Arve=20S=C3=A6ther?= Date: Thu, 5 May 2011 16:28:58 +0200 Subject: Notify a11y framework of FocusChanges for QGraphicsObject (cherry picked from commit 1b5cb7865eb8b48a2721f9b9c3ccd2fb25f8175d) Reviewed-by: Frederik Gladhorn --- src/gui/graphicsview/qgraphicsscene.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index 0713d09..ba4c914 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -245,6 +245,10 @@ #include #include #include +#ifndef QT_NO_ACCESSIBILITY +# include +#endif + #include #include #ifdef Q_WS_X11 @@ -837,6 +841,14 @@ void QGraphicsScenePrivate::setFocusItemHelper(QGraphicsItem *item, if (item) focusItem = item; updateInputMethodSensitivityInViews(); + +#ifndef QT_NO_ACCESSIBILITY + if (focusItem) { + if (QGraphicsObject *focusObj = focusItem->toGraphicsObject()) { + QAccessible::updateAccessibility(focusObj, 0, QAccessible::Focus); + } + } +#endif if (item) { QFocusEvent event(QEvent::FocusIn, focusReason); sendEvent(item, &event); -- cgit v0.12 From a825b3a9e6132842090e43fae85d2c6c61b2def6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Arve=20S=C3=A6ther?= Date: Thu, 5 May 2011 16:40:45 +0200 Subject: Avoided calling updateAccessibility() from updateMicroFocus if the item was hidden This had the following negative effect in qmlviewer: - Every time the qmlviewer logged something to its QPlainTextEdit (regardless of if it was visible or not) it would call updateMicroFocus (because appending to QPlainTextEdit would move the cursor). The result was that the AT client got overloaded with accessibility state changes, and response time got really bad. (cherry picked from commit ad50e45311cce712fbe35641cde973d616ff560d) Reviewed-by: Frederik Gladhorn --- src/gui/kernel/qwidget.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index ebc9dd5..434a788 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -11344,8 +11344,10 @@ void QWidget::updateMicroFocus() } #endif #ifndef QT_NO_ACCESSIBILITY - // ##### is this correct - QAccessible::updateAccessibility(this, 0, QAccessible::StateChanged); + if (isVisible()) { + // ##### is this correct + QAccessible::updateAccessibility(this, 0, QAccessible::StateChanged); + } #endif } -- cgit v0.12 From aad99f4fae89796f7013901344260eb50e4126bb Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Mon, 6 Jun 2011 13:16:22 +0200 Subject: Build fix for Mac OS 10.5 The build breaks because QString defines a template function that interferes with a system header. The easy fix is to just make sure we include the system headers before any Qt headers. This fix turned out to already be in for Qt5, but that change contained other stuff as well, and were not suited for cherry-picking. Rev-By: msorvig --- src/corelib/tools/qlocale.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp index 5c4085a..a72ad02 100644 --- a/src/corelib/tools/qlocale.cpp +++ b/src/corelib/tools/qlocale.cpp @@ -48,6 +48,11 @@ static QSystemLocale *QSystemLocale_globalSystemLocale(); QT_END_NAMESPACE #endif +#if !defined(QWS) && defined(Q_OS_MAC) +# include "private/qcore_mac_p.h" +# include +#endif + #include "qplatformdefs.h" #include "qdatastream.h" @@ -65,10 +70,6 @@ QT_END_NAMESPACE # include "qt_windows.h" # include #endif -#if !defined(QWS) && defined(Q_OS_MAC) -# include "private/qcore_mac_p.h" -# include -#endif #include "private/qnumeric_p.h" #include "private/qsystemlibrary_p.h" -- cgit v0.12 From 32079bb0b348ef5f7126e69be9bcfb249c1a6412 Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Sun, 5 Jun 2011 04:16:13 -0700 Subject: Avoid bogus accessibility focus events from menus. Do not send accessibility focus events when menus are involved. There are focus events to preserve the old focus when showing a new popup window. Reviewed-by: Jan-Arve --- src/gui/kernel/qwidget.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index 434a788..8ca9d8d 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -6427,6 +6427,10 @@ void QWidget::setFocus(Qt::FocusReason reason) if (!(testAttribute(Qt::WA_WState_Created) && window()->windowType() != Qt::Popup && internalWinId())) //setFocusWidget will already post a focus event for us (that the AT client receives) on Windows # endif +# ifdef Q_OS_UNIX + // menus update the focus manually and this would create bogus events + if (!(f->inherits("QMenuBar") || f->inherits("QMenu") || f->inherits("QMenuItem"))) +# endif QAccessible::updateAccessibility(f, 0, QAccessible::Focus); #endif #ifndef QT_NO_GRAPHICSVIEW -- cgit v0.12 From df6713b8f55fc007796f404a3615bf348d1d0782 Mon Sep 17 00:00:00 2001 From: Pierre Rossi Date: Fri, 20 May 2011 14:16:33 +0200 Subject: Add tilde (both ~ and ~) expansion to QFileDialog on UNIX. Task-number: QTBUG-3265 Reviewed-by: Thiago --- src/gui/dialogs/qfiledialog.cpp | 77 ++++++++++++++++++++++++++++-- tests/auto/qfiledialog/tst_qfiledialog.cpp | 38 +++++++++++++++ 2 files changed, 111 insertions(+), 4 deletions(-) diff --git a/src/gui/dialogs/qfiledialog.cpp b/src/gui/dialogs/qfiledialog.cpp index 897a916..8da60e6 100644 --- a/src/gui/dialogs/qfiledialog.cpp +++ b/src/gui/dialogs/qfiledialog.cpp @@ -66,6 +66,9 @@ #if defined(Q_OS_WINCE) extern bool qt_priv_ptr_valid; #endif +#if defined(Q_OS_UNIX) +#include +#endif #endif QT_BEGIN_NAMESPACE @@ -858,23 +861,78 @@ void QFileDialog::selectFile(const QString &filename) d->lineEdit()->setText(file); } +#ifdef Q_OS_UNIX +Q_AUTOTEST_EXPORT QString qt_tildeExpansion(const QString &path, bool *expanded = 0) +{ + if (expanded != 0) + *expanded = false; + if (!path.startsWith(QLatin1Char('~'))) + return path; + QString ret = path; + QStringList tokens = ret.split(QDir::separator()); + if (tokens.first() == QLatin1String("~")) { + ret.replace(0, 1, QDir::homeDirPath()); + } else { + QString userName = tokens.first(); + userName.remove(0, 1); +#if defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_OPENBSD) + passwd pw; + passwd *tmpPw; + char buf[200]; + const int bufSize = sizeof(buf); + int err = getpwnam_r(userName.toLocal8Bit().constData(), &pw, buf, bufSize, &tmpPw); + if (err || !tmpPw) + return ret; + const QString homePath = QString::fromLocal8Bit(pw.pw_dir); +#else + passwd *pw = getpwnam(userName.toLocal8Bit().constData()); + if (!pw) + return ret; + const QString homePath = QString::fromLocal8Bit(pw->pw_dir); +#endif + ret.replace(0, tokens.first().length(), homePath); + } + if (expanded != 0) + *expanded = true; + return ret; +} +#endif + /** Returns the text in the line edit which can be one or more file names */ QStringList QFileDialogPrivate::typedFiles() const { + Q_Q(const QFileDialog); QStringList files; QString editText = lineEdit()->text(); - if (!editText.contains(QLatin1Char('"'))) + if (!editText.contains(QLatin1Char('"'))) { +#ifdef Q_OS_UNIX + const QString prefix = q->directory().absolutePath() + QDir::separator(); + if (QFile::exists(prefix + editText)) + files << editText; + else + files << qt_tildeExpansion(editText); +#else files << editText; - else { +#endif + } else { // " is used to separate files like so: "file1" "file2" "file3" ... // ### need escape character for filenames with quotes (") QStringList tokens = editText.split(QLatin1Char('\"')); for (int i=0; idirectory().absolutePath() + QDir::separator(); + if (QFile::exists(prefix + token)) + files << token; + else + files << qt_tildeExpansion(token); +#else files << toInternal(tokens.at(i)); +#endif } } return addDefaultSuffixToFiles(files); @@ -3338,6 +3396,17 @@ QStringList QFSCompleter::splitPath(const QString &path) const pathCopy = pathCopy.mid(2); else doubleSlash.clear(); +#elif defined(Q_OS_UNIX) + bool expanded; + pathCopy = qt_tildeExpansion(pathCopy, &expanded); + if (expanded) { + QFileSystemModel *dirModel; + if (proxyModel) + dirModel = qobject_cast(proxyModel->sourceModel()); + else + dirModel = sourceModel; + dirModel->fetchMore(dirModel->index(pathCopy)); + } #endif QRegExp re(QLatin1Char('[') + QRegExp::escape(sep) + QLatin1Char(']')); @@ -3354,14 +3423,14 @@ QStringList QFSCompleter::splitPath(const QString &path) const parts.append(QString()); #else QStringList parts = pathCopy.split(re); - if (path[0] == sep[0]) // read the "/" at the beginning as the split removed it + if (pathCopy[0] == sep[0]) // read the "/" at the beginning as the split removed it parts[0] = sep[0]; #endif #if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN) bool startsFromRoot = !parts.isEmpty() && parts[0].endsWith(QLatin1Char(':')); #else - bool startsFromRoot = path[0] == sep[0]; + bool startsFromRoot = pathCopy[0] == sep[0]; #endif if (parts.count() == 1 || (parts.count() > 1 && !startsFromRoot)) { const QFileSystemModel *dirModel; diff --git a/tests/auto/qfiledialog/tst_qfiledialog.cpp b/tests/auto/qfiledialog/tst_qfiledialog.cpp index 42e82a9..24ac9f7 100644 --- a/tests/auto/qfiledialog/tst_qfiledialog.cpp +++ b/tests/auto/qfiledialog/tst_qfiledialog.cpp @@ -78,6 +78,10 @@ # define STRINGIFY(x) #x # define TOSTRING(x) STRINGIFY(x) # define SRCDIR "C:/Private/" TOSTRING(SYMBIAN_SRCDIR_UID) "/" +#elif defined(Q_OS_UNIX) +#ifdef QT_BUILD_INTERNAL +extern Q_GUI_EXPORT QString qt_tildeExpansion(const QString &path, bool *expanded = 0); +#endif #endif class QNonNativeFileDialog : public QFileDialog @@ -144,6 +148,10 @@ private slots: void clearLineEdit(); void enableChooseButton(); void hooks(); +#ifdef Q_OS_UNIX + void tildeExpansion_data(); + void tildeExpansion(); +#endif private: QByteArray userSettings; @@ -1323,5 +1331,35 @@ void tst_QFiledialog::hooks() QCOMPARE(QFileDialog::getSaveFileName(), QString("saveName")); } +#ifdef Q_OS_UNIX +void tst_QFiledialog::tildeExpansion_data() +{ + QTest::addColumn("tildePath"); + QTest::addColumn("expandedPath"); + + QTest::newRow("empty path") << QString() << QString(); + QTest::newRow("~") << QString::fromLatin1("~") << QDir::homePath(); + QTest::newRow("~/some/sub/dir/") << QString::fromLatin1("~/some/sub/dir") << QDir::homePath() + + QString::fromLatin1("/some/sub/dir"); + QString userHome = QString(qgetenv("USER")); + userHome.prepend('~'); + QTest::newRow("current user (~ syntax)") << userHome << QDir::homePath(); + QString invalid = QString::fromLatin1("~thisIsNotAValidUserName"); + QTest::newRow("invalid user name") << invalid << invalid; +} + + +void tst_QFiledialog::tildeExpansion() +{ +#ifndef QT_BUILD_INTERNAL + QSKIP("Test case relies on developer build (AUTOTEST_EXPORT)", SkipAll); +#endif + QFETCH(QString, tildePath); + QFETCH(QString, expandedPath); + + QCOMPARE(qt_tildeExpansion(tildePath), expandedPath); +} +#endif + QTEST_MAIN(tst_QFiledialog) #include "tst_qfiledialog.moc" -- cgit v0.12 From 13d438ef43a3cb2a90acfaa5304cba34b31fb627 Mon Sep 17 00:00:00 2001 From: Pierre Rossi Date: Thu, 9 Jun 2011 10:42:09 +0200 Subject: Fix some issues introduced in df6713b8f55fc007796f40. Remove homeDirPath(), which is part of Qt3Support. Add a #else to the #ifdef QT_BUILD_INTERNAL so that the autotest compiles also with non-developer builds. Reviewed-by: TrustMe --- src/gui/dialogs/qfiledialog.cpp | 2 +- tests/auto/qfiledialog/tst_qfiledialog.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/gui/dialogs/qfiledialog.cpp b/src/gui/dialogs/qfiledialog.cpp index 8da60e6..d7716f7 100644 --- a/src/gui/dialogs/qfiledialog.cpp +++ b/src/gui/dialogs/qfiledialog.cpp @@ -871,7 +871,7 @@ Q_AUTOTEST_EXPORT QString qt_tildeExpansion(const QString &path, bool *expanded QString ret = path; QStringList tokens = ret.split(QDir::separator()); if (tokens.first() == QLatin1String("~")) { - ret.replace(0, 1, QDir::homeDirPath()); + ret.replace(0, 1, QDir::homePath()); } else { QString userName = tokens.first(); userName.remove(0, 1); diff --git a/tests/auto/qfiledialog/tst_qfiledialog.cpp b/tests/auto/qfiledialog/tst_qfiledialog.cpp index 24ac9f7..955860d 100644 --- a/tests/auto/qfiledialog/tst_qfiledialog.cpp +++ b/tests/auto/qfiledialog/tst_qfiledialog.cpp @@ -1353,11 +1353,12 @@ void tst_QFiledialog::tildeExpansion() { #ifndef QT_BUILD_INTERNAL QSKIP("Test case relies on developer build (AUTOTEST_EXPORT)", SkipAll); -#endif +#else QFETCH(QString, tildePath); QFETCH(QString, expandedPath); QCOMPARE(qt_tildeExpansion(tildePath), expandedPath); +#endif } #endif -- cgit v0.12 From 731d843b52b0a0bc387c50c2af37a71f87804f4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Mill=C3=A1n=20Soto?= Date: Fri, 3 Jun 2011 20:44:37 +0200 Subject: Check validator when changing text using accessibility functions. Reviewed-by: Frederik Gladhorn --- src/plugins/accessible/widgets/simplewidgets.cpp | 9 ++++++++- tests/auto/qaccessibility/tst_qaccessibility.cpp | 6 ++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/plugins/accessible/widgets/simplewidgets.cpp b/src/plugins/accessible/widgets/simplewidgets.cpp index aa64630..ac40aef 100644 --- a/src/plugins/accessible/widgets/simplewidgets.cpp +++ b/src/plugins/accessible/widgets/simplewidgets.cpp @@ -703,7 +703,14 @@ void QAccessibleLineEdit::setText(Text t, int control, const QString &text) QAccessibleWidgetEx::setText(t, control, text); return; } - lineEdit()->setText(text); + + QString newText = text; + if (lineEdit()->validator()) { + int pos = 0; + if (lineEdit()->validator()->validate(newText, pos) != QValidator::Acceptable) + return; + } + lineEdit()->setText(newText); } /*! \reimp */ diff --git a/tests/auto/qaccessibility/tst_qaccessibility.cpp b/tests/auto/qaccessibility/tst_qaccessibility.cpp index 7ff1a08..235449b 100644 --- a/tests/auto/qaccessibility/tst_qaccessibility.cpp +++ b/tests/auto/qaccessibility/tst_qaccessibility.cpp @@ -3190,6 +3190,12 @@ void tst_QAccessibility::lineEditTest() QTestAccessibility::clearEvents(); le2->setFocus(Qt::TabFocusReason); QTRY_VERIFY(QTestAccessibility::events().contains(QTestAccessibilityEvent(le2, 0, QAccessible::Focus))); + + le->setText(QLatin1String("500")); + le->setValidator(new QIntValidator()); + iface->setText(QAccessible::Value, 0, QLatin1String("This text is not a number")); + QCOMPARE(le->text(), QLatin1String("500")); + delete iface; delete le; delete le2; -- cgit v0.12 From 636b7088eb3740800f54a7c1634d3e041e688270 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Mill=C3=A1n=20Soto?= Date: Sat, 4 Jun 2011 18:06:47 +0200 Subject: Do not expose text when echo mode is not Normal. Reviewed-by: Frederik Gladhorn --- src/plugins/accessible/widgets/simplewidgets.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/plugins/accessible/widgets/simplewidgets.cpp b/src/plugins/accessible/widgets/simplewidgets.cpp index ac40aef..3b9ccfa 100644 --- a/src/plugins/accessible/widgets/simplewidgets.cpp +++ b/src/plugins/accessible/widgets/simplewidgets.cpp @@ -808,6 +808,10 @@ QString QAccessibleLineEdit::text(int startOffset, int endOffset) { if (startOffset > endOffset) return QString(); + + if (lineEdit()->echoMode() != QLineEdit::Normal) + return QString(); + return lineEdit()->text().mid(startOffset, endOffset - startOffset); } -- cgit v0.12 From 683d391480cf81b4cd1db7d36fa366fc2c7db5e1 Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Thu, 5 May 2011 18:50:35 +0200 Subject: Remove stray semicolon. Reviewed-by: TrustMe --- src/plugins/accessible/widgets/simplewidgets.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/accessible/widgets/simplewidgets.cpp b/src/plugins/accessible/widgets/simplewidgets.cpp index 3b9ccfa..a544a31 100644 --- a/src/plugins/accessible/widgets/simplewidgets.cpp +++ b/src/plugins/accessible/widgets/simplewidgets.cpp @@ -176,7 +176,7 @@ QString QAccessibleButton::text(Text t, int child) const break; } if (str.isEmpty()) - str = QAccessibleWidgetEx::text(t, child);; + str = QAccessibleWidgetEx::text(t, child); return qt_accStripAmp(str); } -- cgit v0.12 From b99344a7ec3e863da2d84f2ca5fd7e478cb18066 Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Thu, 5 May 2011 18:51:59 +0200 Subject: QAccessibleToolButton::text should return accessibleName if set. This was most likely a copy and paste error. Reviewed-by: Denis Dzyubenko --- src/plugins/accessible/widgets/simplewidgets.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/accessible/widgets/simplewidgets.cpp b/src/plugins/accessible/widgets/simplewidgets.cpp index a544a31..554e7f3 100644 --- a/src/plugins/accessible/widgets/simplewidgets.cpp +++ b/src/plugins/accessible/widgets/simplewidgets.cpp @@ -396,7 +396,7 @@ QString QAccessibleToolButton::text(Text t, int child) const QString str; switch (t) { case Name: - str = toolButton()->text(); + str = toolButton()->accessibleName(); if (str.isEmpty()) str = toolButton()->text(); break; -- cgit v0.12 From b606ccbc19cac720bc50a44b2f1195d53f6691e2 Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Wed, 18 May 2011 21:46:26 +0200 Subject: Remove more inconsistencies with invisible. Visible status should not influence child count and other properties. Reviewed-by: Jan-Arve --- src/plugins/accessible/widgets/rangecontrols.cpp | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/src/plugins/accessible/widgets/rangecontrols.cpp b/src/plugins/accessible/widgets/rangecontrols.cpp index 1f5407a..736ed88 100644 --- a/src/plugins/accessible/widgets/rangecontrols.cpp +++ b/src/plugins/accessible/widgets/rangecontrols.cpp @@ -83,8 +83,6 @@ QAbstractSpinBox *QAccessibleAbstractSpinBox::abstractSpinBox() const /*! \reimp */ int QAccessibleAbstractSpinBox::childCount() const { - if (!abstractSpinBox()->isVisible()) - return 0; return ValueDown; } @@ -344,8 +342,6 @@ QDoubleSpinBox *QAccessibleDoubleSpinBox::doubleSpinBox() const /*! \reimp */ int QAccessibleDoubleSpinBox::childCount() const { - if (!doubleSpinBox()->isVisible()) - return 0; return ValueDown; } @@ -410,8 +406,6 @@ QVariant QAccessibleDoubleSpinBox::invokeMethodEx(QAccessible::Method, int, cons /*! \reimp */ QString QAccessibleDoubleSpinBox::text(Text textType, int child) const { - if (!doubleSpinBox()->isVisible()) - return QString(); switch (textType) { case Name: if (child == ValueUp) @@ -540,16 +534,12 @@ QRect QAccessibleScrollBar::rect(int child) const /*! \reimp */ int QAccessibleScrollBar::childCount() const { - if (!scrollBar()->isVisible()) - return 0; return LineDown; } /*! \reimp */ QString QAccessibleScrollBar::text(Text t, int child) const { - if (!scrollBar()->isVisible()) - return QString(); switch (t) { case Value: if (!child || child == Position) @@ -698,16 +688,12 @@ QRect QAccessibleSlider::rect(int child) const /*! \reimp */ int QAccessibleSlider::childCount() const { - if (!slider()->isVisible()) - return 0; return PageRight; } /*! \reimp */ QString QAccessibleSlider::text(Text t, int child) const { - if (!slider()->isVisible()) - return QString(); switch (t) { case Value: if (!child || child == 2) @@ -932,15 +918,11 @@ QRect QAccessibleDial::rect(int child) const int QAccessibleDial::childCount() const { - if (!dial()->isVisible()) - return 0; return SliderHandle; } QString QAccessibleDial::text(Text textType, int child) const { - if (!dial()->isVisible()) - return QString(); if (textType == Value && child >= Self && child <= SliderHandle) return QString::number(dial()->value()); if (textType == Name) { -- cgit v0.12 From da9b2156015a946122eacc64437d214d1e184f35 Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Wed, 18 May 2011 18:20:38 +0200 Subject: When asking for relations, don't crash on children that don't return an interface. Reviewed-by: Jan-Arve --- src/gui/accessible/qaccessiblewidget.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/gui/accessible/qaccessiblewidget.cpp b/src/gui/accessible/qaccessiblewidget.cpp index 2b2cec0..52aab32 100644 --- a/src/gui/accessible/qaccessiblewidget.cpp +++ b/src/gui/accessible/qaccessiblewidget.cpp @@ -704,13 +704,16 @@ int QAccessibleWidget::navigate(RelationFlag relation, int entry, int sibCount = pIface->childCount(); QAccessibleInterface *candidate = 0; for (int i = 0; i < sibCount && entry; ++i) { - pIface->navigate(Child, i+1, &candidate); - Q_ASSERT(candidate); - if (candidate->relationTo(0, this, 0) & Label) + const int childId = pIface->navigate(Child, i+1, &candidate); + Q_ASSERT(childId >= 0); + if (childId > 0) + candidate = pIface; + if (candidate->relationTo(childId, this, 0) & Label) --entry; if (!entry) break; - delete candidate; + if (candidate != pIface) + delete candidate; candidate = 0; } if (!candidate) { -- cgit v0.12 From 031958c130904c16a4bafa5617aaa197469efa9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Mill=C3=A1n=20Soto?= Date: Mon, 13 Jun 2011 00:31:38 +0200 Subject: Incorrect property name in QAccessibleAbstractSpinBox::setCurrentValue Merge-request: 1263 Reviewed-by: Frederik Gladhorn --- src/plugins/accessible/widgets/rangecontrols.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/accessible/widgets/rangecontrols.cpp b/src/plugins/accessible/widgets/rangecontrols.cpp index 8868d53..485983e 100644 --- a/src/plugins/accessible/widgets/rangecontrols.cpp +++ b/src/plugins/accessible/widgets/rangecontrols.cpp @@ -212,7 +212,7 @@ QVariant QAccessibleAbstractSpinBox::currentValue() void QAccessibleAbstractSpinBox::setCurrentValue(const QVariant &value) { - abstractSpinBox()->setProperty("setValue", value); + abstractSpinBox()->setProperty("value", value); } QVariant QAccessibleAbstractSpinBox::maximumValue() -- cgit v0.12