QVariant QDeclarativeBasePositioner::itemChange(GraphicsItemChange change, const QVariant &value) { Q_D(QDeclarativeBasePositioner); if (change == ItemChildAddedChange){ QGraphicsItem* item = value.value<QGraphicsItem*>(); QDeclarativeItem* child = 0; if(item) child = qobject_cast<QDeclarativeItem*>(item->toGraphicsObject()); if (child) prePositioning(); } else if (change == ItemChildRemovedChange) { QGraphicsItem* item = value.value<QGraphicsItem*>(); QDeclarativeItem* child = 0; if(item) child = qobject_cast<QDeclarativeItem*>(item->toGraphicsObject()); if (child) { QDeclarativeBasePositioner::PositionedItem posItem(child); int idx = positionedItems.find(posItem); if (idx >= 0) { d->unwatchChanges(child); positionedItems.remove(idx); } prePositioning(); } } return QDeclarativeItem::itemChange(change, value); }
bool AbstractLiveEditTool::topItemIsMovable(const QList<QGraphicsItem*> & itemList) { QGraphicsItem *firstSelectableItem = topMovableGraphicsItem(itemList); if (firstSelectableItem == 0) return false; QDeclarativeItem *declarativeItem = dynamic_cast<QDeclarativeItem*>(firstSelectableItem->toGraphicsObject()); if (declarativeItem != 0) return true; return false; }
void KWidget::invalidateLayout() { QGraphicsLayout *layout = this->layout(); if(layout == NULL) return; layout->invalidate(); QList<QGraphicsItem *> childs = childItems(); for(int i = 0; i < childs.count(); i++) { QGraphicsItem *item = childs[i]; KWidget *widget = qobject_cast<KWidget*>(item->toGraphicsObject()); if(widget == NULL) continue; widget->invalidateLayout(); } }
QBlockDiagramNodeSlot* QBlockDiagramModel::nodeSlotAroundLinkEnd( QBlockDiagramLinkEnd* a_pEnd ) { const QList<QGraphicsItem *>& item_list = items (); QGraphicsItem* pItem = NULL; Q_FOREACH(pItem, item_list) { QGraphicsObject* pObject = pItem->toGraphicsObject(); if(pObject != NULL && pObject->inherits("QBlockDiagramItem") && static_cast<QBlockDiagramItem*>(pItem)->isNodeSlot()) { QBlockDiagramNodeSlot* pSlot = static_cast<QBlockDiagramNodeSlot*>(pItem); QLineF distance(a_pEnd->scenePos(),pSlot->scenePos()); if(distance.length() < 20.f && pSlot->acceptsLinkEnd(a_pEnd)) { return pSlot; } } }
void SceneInspector::sceneItemSelectionChanged(const QItemSelection &selection) { QModelIndex index; if (!selection.isEmpty()) index = selection.first().topLeft(); if (index.isValid()) { QGraphicsItem *item = index.data(SceneModel::SceneItemRole).value<QGraphicsItem *>(); QGraphicsObject *obj = item->toGraphicsObject(); if (obj) m_propertyController->setObject(obj); else m_propertyController->setObject(item, QStringLiteral("QGraphicsItem")); emit itemSelected(item->mapRectToScene(item->boundingRect())); } else { m_propertyController->setObject(nullptr); emit sceneChanged(); } }
bool KWidget::hasTheme() { Q_D(KWidget); if(d->themePolicy == NoTheme) return false; if(d->themePolicy == ThemeWithParent) { if(d->bThemeCheck) { return d->bThemeResult; } d->bThemeCheck = true; QGraphicsItem *itemParent = parentItem(); while(itemParent) { KWidget *widgetParent = qobject_cast<KWidget*>(itemParent->toGraphicsObject()); if(widgetParent == NULL) { itemParent = itemParent->parentItem(); continue; } QString objName = widgetParent->objectName(); ThemePolicy scp = widgetParent->themePolicy(); if(scp == NoTheme) { d->bThemeResult = false; return false; } if(scp == ThemeWithParent) { itemParent = itemParent->parentItem(); continue; } d->bThemeResult = true; return true; } d->bThemeResult = false; return false; } return true; }
void ObjectService::performObjectService(TasCommandModel& model, TasResponse& response) { TasLogger::logger()->debug(QString("TasCommander::performObjectService entry")); QListIterator<TasTarget*> i(model.targetList()); QString errorString; while (i.hasNext()){ TasTarget* commandTarget = i.next(); QString targetId = commandTarget->id(); QString targetType = commandTarget->type(); QObject* target = 0; if(targetType == TYPE_GRAPHICS_VIEW){ QGraphicsItem* item = findGraphicsItem(targetId); //target = TestabilityUtils::castToGraphicsWidget(item); target = item->toGraphicsObject(); } else if(targetType == TYPE_STANDARD_VIEW){ target = findWidget(targetId); //If Type is Standard View check QObjects in cache too. if(!target) { target = findObject(targetId); } } else if(targetType == TYPE_QSCENEGRAPH){ target = findQuickItem(targetId); } else if(targetType == TYPE_APPLICATION_VIEW ){ target = qApp; } // TODO: add support //else if(targetType == TYPE_ACTION_VIEW = "Action"; //else if(targetType == TYPE_LAYOUT = "Layout"; //else if(targetType == TYPE_LAYOUT_ITEM = "LayoutItem"; //else if(targetType == TYPE_WEB = "Web"; //else if(targetType == TYPE_QWEB = "QWeb"; else { errorString.append(targetType + " target type not supported. "); } TasLogger::logger()->debug( QString("TasCommander::performObjectService %1 %2 found: %3") .arg(targetType).arg(targetId).arg(target!=NULL)); if (target) { QListIterator<TasCommand*> j(commandTarget->commandList()); while (j.hasNext()){ TasCommand* command = j.next(); if(command->name() == "SetAttribute"){ doSetAttribute(command, target, errorString); } else if (command->name() == "CallMethod"){ response.setData(doCallMethod(command, target, errorString)); } else { TasLogger::logger()->debug( QString("TasCommander::performObjectService %1 %2: unsupported %3") .arg(targetType).arg(targetId).arg(command->name())); } } } } if(!errorString.isEmpty()){ response.setErrorMessage(errorString); TasLogger::logger()->debug( QString("TasCommander::performObjectService errors: %1") .arg(errorString)); } else { TasLogger::logger()->debug( QString("TasCommander::performObjectService, no errors.")); } }
void QAccessible::updateAccessibility(QObject *o, int who, Event reason) { Q_ASSERT(o); if (updateHandler) { updateHandler(o, who, reason); return; } QString soundName; switch (reason) { case PopupMenuStart: soundName = QLatin1String("MenuPopup"); break; case MenuCommand: soundName = QLatin1String("MenuCommand"); break; case Alert: { #ifndef QT_NO_MESSAGEBOX QMessageBox *mb = qobject_cast<QMessageBox*>(o); if (mb) { switch (mb->icon()) { case QMessageBox::Warning: soundName = QLatin1String("SystemExclamation"); break; case QMessageBox::Critical: soundName = QLatin1String("SystemHand"); break; case QMessageBox::Information: soundName = QLatin1String("SystemAsterisk"); break; default: break; } } else #endif // QT_NO_MESSAGEBOX { soundName = QLatin1String("SystemAsterisk"); } } break; default: break; } if (soundName.size()) { #ifndef QT_NO_SETTINGS QSettings settings(QLatin1String("HKEY_CURRENT_USER\\AppEvents\\Schemes\\Apps\\.Default\\") + soundName, QSettings::NativeFormat); QString file = settings.value(QLatin1String(".Current/.")).toString(); #else QString file; #endif if (!file.isEmpty()) { PlaySound(reinterpret_cast<const wchar_t *>(soundName.utf16()), 0, SND_ALIAS | SND_ASYNC | SND_NODEFAULT | SND_NOWAIT); } } if (!isActive()) return; typedef void (WINAPI *PtrNotifyWinEvent)(DWORD, HWND, LONG, LONG); #if defined(Q_WS_WINCE) // ### TODO: check for NotifyWinEvent in CE 6.0 // There is no user32.lib nor NotifyWinEvent for CE return; #else static PtrNotifyWinEvent ptrNotifyWinEvent = 0; static bool resolvedNWE = false; if (!resolvedNWE) { ptrNotifyWinEvent = (PtrNotifyWinEvent)QSystemLibrary::resolve(QLatin1String("user32"), "NotifyWinEvent"); resolvedNWE = true; } if (!ptrNotifyWinEvent) return; // An event has to be associated with a window, // so find the first parent that is a widget. QWidget *w = 0; QObject *p = o; do { if (p->isWidgetType()) { w = static_cast<QWidget*>(p); if (w->internalWinId()) break; } if (QGraphicsObject *gfxObj = qobject_cast<QGraphicsObject*>(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<QGraphicsView*> 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) w = QApplication::focusWidget(); if (!w) { w = QApplication::activeWindow(); if (!w) return; // ### Fixme // if (!w) { // w = qApp->mainWidget(); // if (!w) // return; // } } } WId wid = w->internalWinId(); if (reason != MenuCommand) { // MenuCommand is faked if (w != o) { // See comment "SENDING EVENTS TO OBJECTS WITH NO WINDOW HANDLE" if (reason != QAccessible::ObjectDestroyed) { /* In some rare occasions, the server (Qt) might get a ::get_accChild call with a childId that references an entry in the cache where there was a dangling QObject-pointer. Previously we crashed on this. There is no point in actually notifying the AT client that the object got destroyed, because the AT client won't query for get_accChild if the event is ObjectDestroyed anyway, and we have no other way of mapping the eventId argument to the actual child/descendant object. (Firefox seems to simply completely ignore EVENT_OBJECT_DESTROY). We therefore guard each QObject in the cache with a QPointer, and only notify the AT client if the type is not ObjectDestroyed. */ eventNum %= 50; //[0..49] int eventId = - eventNum - 1; qAccessibleRecentSentEvents()->insert(eventId, qMakePair(QPointer<QObject>(o), who)); ptrNotifyWinEvent(reason, wid, OBJID_CLIENT, eventId ); ++eventNum; } } else { ptrNotifyWinEvent(reason, wid, OBJID_CLIENT, who); } } #endif // Q_WS_WINCE }