/** * is called after a reparent has taken place to fix up the focus chain(s) */ void QGraphicsWidgetPrivate::fixFocusChainBeforeReparenting(QGraphicsWidget *newParent, QGraphicsScene *oldScene, QGraphicsScene *newScene) { Q_Q(QGraphicsWidget); Q_ASSERT(focusNext && focusPrev); QGraphicsWidget *n = q; //last one in 'new' list QGraphicsWidget *o = 0; //last one in 'old' list QGraphicsWidget *w = focusNext; QGraphicsWidget *firstOld = 0; bool wasPreviousNew = true; while (w != q) { bool isCurrentNew = q->isAncestorOf(w); if (isCurrentNew) { if (!wasPreviousNew) { n->d_func()->focusNext = w; w->d_func()->focusPrev = n; } n = w; } else /*if (!isCurrentNew)*/ { if (wasPreviousNew) { if (o) { o->d_func()->focusNext = w; w->d_func()->focusPrev = o; } else { firstOld = w; } } o = w; } w = w->d_func()->focusNext; wasPreviousNew = isCurrentNew; } // repair the 'old' chain if (firstOld) { o->d_func()->focusNext = firstOld; firstOld->d_func()->focusPrev = o; } // update tabFocusFirst for oldScene if the item is going to be removed from oldScene if (newParent) newScene = newParent->scene(); if (oldScene && newScene != oldScene) oldScene->d_func()->tabFocusFirst = (firstOld && firstOld->scene() == oldScene) ? firstOld : 0; QGraphicsItem *topLevelItem = newParent ? newParent->topLevelItem() : 0; QGraphicsWidget *topLevel = 0; if (topLevelItem && topLevelItem->isWidget()) topLevel = static_cast<QGraphicsWidget *>(topLevelItem); if (topLevel && newParent) { QGraphicsWidget *last = topLevel->d_func()->focusPrev; // link last with new chain last->d_func()->focusNext = q; focusPrev = last; // link last in chain with topLevel->d_func()->focusPrev = n; n->d_func()->focusNext = topLevel; } else { // q is the start of the focus chain n->d_func()->focusNext = q; focusPrev = n; } }
/* short show (); */ NS_IMETHODIMP nsFilePicker::Show(PRInt16* aReturn) { nsCAutoString directory; if (mDisplayDirectory) { mDisplayDirectory->GetNativePath(directory); } QStringList filters; PRUint32 count = mFilters.Length(); for (PRUint32 i = 0; i < count; ++i) { filters.append(mFilters[i].get()); } QGraphicsWidget* parentWidget = 0; if (mParent) { parentWidget = static_cast<QGraphicsWidget*> (mParent->GetNativeData(NS_NATIVE_WIDGET)); } QWidget* parentQWidget = 0; if (parentWidget && parentWidget->scene()) { if (parentWidget->scene()->views().size()>0) { parentQWidget = parentWidget->scene()->views()[0]; } } QStringList files; QString selected; switch (mMode) { case nsIFilePicker::modeOpen: selected = MozFileDialog::getOpenFileName(parentQWidget, mCaption, directory.get(), filters.join(";")); if (selected.isNull()) { *aReturn = nsIFilePicker::returnCancel; return NS_OK; } break; case nsIFilePicker::modeOpenMultiple: files = MozFileDialog::getOpenFileNames(parentQWidget, mCaption, directory.get(), filters.join(";")); if (files.empty()) { *aReturn = nsIFilePicker::returnCancel; return NS_OK; } selected = files[0]; break; case nsIFilePicker::modeSave: { nsCOMPtr<nsIFile> targetFile; NS_GetSpecialDirectory(NS_UNIX_XDG_DOCUMENTS_DIR, getter_AddRefs(targetFile)); if (!targetFile) { // failed to get the XDG directory, using $HOME for now NS_GetSpecialDirectory(NS_UNIX_HOME_DIR, getter_AddRefs(targetFile)); } if (targetFile) { targetFile->Append(mDefault); nsString targetPath; targetFile->GetPath(targetPath); bool exists = false; targetFile->Exists(&exists); if (exists) { // file exists already create temporary filename QTemporaryFile temp(QString::fromUtf16(targetPath.get())); temp.open(); selected = temp.fileName(); temp.close(); } else { selected = QString::fromUtf16(targetPath.get()); } } } break; case nsIFilePicker::modeGetFolder: selected = MozFileDialog::getExistingDirectory(parentQWidget, mCaption, directory.get()); if (selected.isNull()) { *aReturn = nsIFilePicker::returnCancel; return NS_OK; } break; default: break; } if (!selected.isEmpty()) { QString path = QFile::encodeName(selected); mFile.Assign(path.toUtf8().data()); } *aReturn = nsIFilePicker::returnOK; if (mMode == modeSave) { nsCOMPtr<nsIFile> file; GetFile(getter_AddRefs(file)); if (file) { bool exists = false; file->Exists(&exists); if (exists) { *aReturn = nsIFilePicker::returnReplace; } } } return NS_OK; }