HierarchyTreeNode::HIERARCHYTREENODEID HierarchyTreeController::CreateNewControl(const QString& strType, const QPoint& position) { if (!activeScreen) { return HierarchyTreeNode::HIERARCHYTREENODEID_EMPTY; } // Create the control itself. String type = strType.toStdString(); String newName = activeScreen->GetNewControlName(type); HierarchyTreeNode* parentNode = activeScreen; Vector2 parentDelta(0, 0); if (activeControlNodes.size() == 1) { HierarchyTreeControlNode* parentControlNode = (*activeControlNodes.begin()); parentNode = parentControlNode; //parentDelta = parentControlNode->GetUIObject()->GetPosition(); parentDelta = parentControlNode->GetParentDelta(); } Vector2 point = Vector2(position.x(), position.y()); DefaultScreen* screen = ScreenWrapper::Instance()->GetActiveScreen(); if (screen) point = screen->LocalToInternal(point); point -= parentDelta; // Add the tree node - we need it before initializing control. HierarchyTreeControlNode* controlNode = LibraryController::Instance()->CreateNewControl(parentNode, strType, QString::fromStdString(newName), point); if (!controlNode) return HierarchyTreeNode::HIERARCHYTREENODEID_EMPTY; emit HierarchyTreeUpdated(); ResetSelectedControl(); SelectControl(controlNode); return controlNode->GetId(); }
ControlsPositionData ControlsAdjustSizeCommand::ApplyAjustedSize(HierarchyTreeController::SELECTEDCONTROLNODES& controls) { ControlsPositionData resultData; for (HierarchyTreeController::SELECTEDCONTROLNODES::iterator iter = controls.begin(); iter != controls.end(); ++iter) { HierarchyTreeControlNode* control = (*iter); UIControl* uiControl = control->GetUIObject(); int32 nodeId = control->GetId(); if (uiControl) { // Get sprite Sprite* sprite = uiControl->GetSprite(); Rect prevRect = uiControl->GetRect(); Rect updatedRect = prevRect; if (sprite) { // Save control size data for undo resultData.AddControl(uiControl); // Set new size of updated rect updatedRect.dx = sprite->GetWidth(); updatedRect.dy = sprite->GetHeight(); BaseMetadata* baseMetadata = GetMetadataForTreeNode(nodeId); // This command is NOT state-aware and contains one and only param. baseMetadata->SetActiveParamID(0); baseMetadata->ApplyResize(prevRect, updatedRect); SAFE_DELETE(baseMetadata); } } } return resultData; }
HierarchyTreeControlNode* LibraryController::CreateNewControl(HierarchyTreeNode* parentNode, const QString& strType, const QString& name, const Vector2& position) { String type = strType.toStdString(); HierarchyTreeControlNode* controlNode = NULL; UIControl* control = NULL; CONTROLS::iterator iter; for (iter = controls.begin(); iter != controls.end(); ++iter) { HierarchyTreeNode* node = iter->first; if (strType == node->GetName()) break; } if (iter == controls.end() || dynamic_cast<HierarchyTreeControlNode*>(iter->first)) { //create standart control BaseObject* object = ObjectFactory::Instance()->New(type); control = dynamic_cast<UIControl*>(object); if (!control) { SafeRelease(object); return NULL; } controlNode = new HierarchyTreeControlNode(parentNode, control, name); } else { //create aggregator HierarchyTreeAggregatorNode* aggregator = dynamic_cast<HierarchyTreeAggregatorNode*>(iter->first); if (aggregator) { controlNode = aggregator->CreateChild(parentNode, name); control = controlNode->GetUIObject(); } } parentNode->AddTreeNode(controlNode); // In case the control has subcontrols - they should be added to the control node too. if (control && !control->GetSubcontrols().empty()) { List<UIControl*> subControls = control->GetSubcontrols(); for (List<UIControl*>::iterator iter = subControls.begin(); iter != subControls.end(); iter ++) { UIControl* subControl = (*iter); if (!subControl) { continue; } HierarchyTreeControlNode* subControlNode = new HierarchyTreeControlNode(controlNode, subControl, QString::fromStdString(subControl->GetName())); controlNode->AddTreeNode(subControlNode); } } // Initialize a control through its metadata. BaseMetadata* newControlMetadata = MetadataFactory::Instance()->GetMetadataForUIControl(control); METADATAPARAMSVECT params; params.push_back(BaseMetadataParams(controlNode->GetId(), control)); newControlMetadata->SetupParams(params); // Ready to do initialization! newControlMetadata->InitializeControl(name.toStdString(), position); SAFE_DELETE(newControlMetadata); SafeRelease(control); return controlNode; }