示例#1
0
void ControlsAlignDistributeCommand::Execute()
{
	List<UIControl*> selectedUIControls;
	for (HierarchyTreeController::SELECTEDCONTROLNODES::iterator iter = selectedControls.begin(); iter != selectedControls.end(); ++iter)
	{
		HierarchyTreeControlNode* control = (*iter);
		UIControl* uiControl = control->GetUIObject();
		if (uiControl)
		{
			selectedUIControls.push_back(uiControl);
		}
	}

	switch (this->commandMode)
	{
		case MODE_ALIGN:
		{
			this->prevPositionData = AlignDistributeManager::AlignControls(selectedUIControls, selectedAlignType);
			break;
		}

		case MODE_DISTRIBUTE:
		{
			this->prevPositionData = AlignDistributeManager::DistributeControls(selectedUIControls, selectedDistributeType);
			break;
		}
			
		default:
		{
			DVASSERT_MSG(Format("Unknown Command Mode %i", this->commandMode).c_str(), false);
			break;
		}
	}
}
void HierarchyTreeControlNode::SetParent(HierarchyTreeNode* node, HierarchyTreeNode* insertAfter)
{
	if (this == insertAfter)
		return;
	
	if (parent)
		parent->RemoveTreeNode(this, false, false);
	
	HierarchyTreeControlNode* newParentControl = dynamic_cast<HierarchyTreeControlNode* >(node);
	HierarchyTreeScreenNode* newParentScreen = dynamic_cast<HierarchyTreeScreenNode* >(node);
	DVASSERT(newParentControl || newParentScreen);
	if (!newParentControl && !newParentScreen)
		return;

	UIControl* afterControl = NULL;
	HierarchyTreeControlNode* insertAfterControl = dynamic_cast<HierarchyTreeControlNode* >(insertAfter);
	if (insertAfterControl)
		afterControl = insertAfterControl->GetUIObject();
	
	UIControl* newParentUI = NULL;
	if (newParentControl)
		newParentUI = newParentControl->GetUIObject();
	else if (newParentScreen)
		newParentUI = newParentScreen->GetScreen();
	
	node->AddTreeNode(this, insertAfter);
	if (newParentUI && uiObject)
	{
		if (insertAfter != node)
		{
			newParentUI->InsertChildAbove(uiObject, afterControl);
		}
		else
		{
			UIControl* belowControl = NULL;
			const List<UIControl*> & controls = newParentUI->GetChildren();
			if (controls.size())
			{
				belowControl = *controls.begin();
			}
			newParentUI->InsertChildBelow(uiObject, belowControl);
		}
	}
	
	parent = node;
}
bool CopyPasteController::SubcontrolsSelected(const HierarchyTreeController::SELECTEDCONTROLNODES& items)
{
    for (HierarchyTreeController::SELECTEDCONTROLNODES::const_iterator iter = items.begin(); iter != items.end(); ++iter)
    {
        HierarchyTreeControlNode* control = (*iter);
        if (control && SubcontrolsHelper::ControlIsSubcontrol(control->GetUIObject()))
        {
            return true;
        }
    }

    return false;
}
示例#4
0
bool HierarchyTreeAggregatorNode::Save(YamlNode* node, const QString& path, bool saveAll)
{
	String relPath = ResourcesManageHelper::GetResourceRelativePath(path, true).toStdString();
	for (CHILDS::iterator iter = childs.begin(); iter != childs.end(); ++iter)
	{
		HierarchyTreeControlNode* controlNode = (*iter);
		
		UIAggregatorControl* aggregatorControl = dynamic_cast<UIAggregatorControl*>(controlNode->GetUIObject());
		DVASSERT(aggregatorControl);
		if (!aggregatorControl)
			continue;
		aggregatorControl->SetAggregatorPath(relPath);
	}
	
	node->Set(WIDTH_NODE, (int32)rect.dx);
	node->Set(HEIGHT_NODE, (int32)rect.dy);
	return HierarchyTreeScreenNode::Save(path, saveAll);
}
void HierarchyTreeControlNode::RemoveTreeNodeFromScene()
{
    if (!this->GetParent() || !uiObject->GetParent())
    {
        return;
    }

    // Don't touch the subcontrol nodes - they are controlled by the parent control itself.
    List<UIControl*> subControlNodes = uiObject->GetSubcontrols();
    for (HIERARCHYTREENODESLIST::iterator iter = childNodes.begin(); iter != childNodes.end(); ++iter)
    {
        HierarchyTreeControlNode* control = dynamic_cast<HierarchyTreeControlNode*>(*iter);
        if (!control || std::find(subControlNodes.begin(), subControlNodes.end(), control->GetUIObject())
                != subControlNodes.end())
        {
            continue;
        }

        control->RemoveTreeNodeFromScene();
    }

    this->parentUIObject = uiObject->GetParent();
    SafeRetain(this->parentUIObject);

    // Determine the "child above" to return node to scene to the correct position.
    this->childUIObjectAbove = NULL;
    for (List<UIControl*>::const_iterator iter = parentUIObject->GetChildren().begin();
            iter != parentUIObject->GetChildren().end(); iter ++)
    {
        if (((*iter) == uiObject) && (iter != parentUIObject->GetChildren().begin()))
        {
            iter --;
            this->childUIObjectAbove = (*iter);
            break;
        }
    }

    SafeRetain(uiObject);
    this->parentUIObject->RemoveControl(uiObject);

    // We added an additional reference to uiObject and parentUIObject - don't forget
    // to release them in destructor.
    this->needReleaseUIObjects = true;
}
示例#6
0
void HierarchyTreeAggregatorNode::UpdateChilds()
{
	for (CHILDS::iterator iter = childs.begin(); iter != childs.end(); ++iter)
	{
		HierarchyTreeControlNode* controlNode = (*iter);
		
		UIAggregatorControl* aggregatorControl = dynamic_cast<UIAggregatorControl*>(controlNode->GetUIObject());
		DVASSERT(aggregatorControl);
		if (!aggregatorControl)
			continue;
		
		// Remove any child controls of UIControl to prevent appearance of deleted
		// child in case when screen child is aggregator.
		/*List<UIControl*> aggregatorChilds = aggregatorControl->GetChildren();
		int size = GetScreen()->GetChildren().size();
		for (List<UIControl*>::iterator iter = aggregatorChilds.begin(); iter != aggregatorChilds.end();)
		{
			if (--size < 0)
				break;
			UIControl* child = (*iter);
			++iter;
			aggregatorControl->RemoveControl(child);
		}*/

		aggregatorControl->RemoveAllControls();
		
		const List<UIControl*> & childsList = screen->GetChildren();
		UIControl* belowControl = NULL;
		List<UIControl*>::const_iterator belowIter = aggregatorControl->GetChildren().begin();
		if (belowIter != aggregatorControl->GetChildren().end())
			belowControl = (*belowIter);
		for (List<UIControl*>::const_iterator iter = childsList.begin(); iter != childsList.end(); ++iter)
		{
			UIControl* control = (*iter);
			UIControl* newControl = control->Clone();
			aggregatorControl->InsertChildBelow(newControl, belowControl);
			aggregatorControl->AddAggregatorChild(newControl);
		}
		//aggregatorControl->SetSize(screen->GetSize()); TODO:// update child size 
		aggregatorControl->SetRect(aggregatorControl->GetRect());	//update childs size and position
	}
}
示例#7
0
void HierarchyTreeController::UnselectControl(HierarchyTreeControlNode* control, bool emitSelectedControlNodesChanged)
{
	if (activeControlNodes.find(control) == activeControlNodes.end())
		return;
	
	//remove selection
	activeControlNodes.erase(control);
	UIControl* uiControl = control->GetUIObject();
	if (uiControl)
	{
		uiControl->SetDebugDraw(false);
		
		//YZ draw parent rect
		UIControl* parentToRemove = uiControl->GetParent();
		if (parentToRemove)
		{
			bool removeParentDraw = true;
			for (SELECTEDCONTROLNODES::iterator iter = activeControlNodes.begin(); iter != activeControlNodes.end(); ++iter)
			{
				HierarchyTreeControlNode* control = (*iter);
				UIControl* uiControl = control->GetUIObject();
				if (uiControl)
				{
					UIControl* parentUiControl = uiControl->GetParent();
					if (parentToRemove == uiControl ||
						parentToRemove == parentUiControl)
					{
						removeParentDraw = false;
						break;
					}
				}
			}
			if (removeParentDraw)
				parentToRemove->SetDebugDraw(false);
		}
	}
	emit RemoveSelectedControl(control);
	if (emitSelectedControlNodesChanged)
		emit SelectedControlNodesChanged(activeControlNodes);
}
void HierarchyTreeControl::HandleDragEnterHierarchyMimeData(QDragEnterEvent *event, const HierarchyTreeControlMimeData* mimeData)
{
	HierarchyTreeNode * selectedTreeNode = HierarchyTreeController::Instance()->GetTree().GetNode(*(mimeData->GetItems().begin()));
	HierarchyTreeControlNode * selectedControlNode =  dynamic_cast<HierarchyTreeControlNode*>(selectedTreeNode);

	HierarchyTreeAggregatorNode * aggregatorNode =  dynamic_cast<HierarchyTreeAggregatorNode*>(selectedControlNode);
	if (aggregatorNode)
	{
		// Don't allow to drop anything to aggregator.
		return;
	}

	if(selectedControlNode)
	{
		if(SubcontrolsHelper::ControlIsSubcontrol(selectedControlNode->GetUIObject()))
		{
			return;
		}
	}

	event->accept();
}
示例#9
0
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;
}
void HierarchyTreeControlNode::AddControlToParent()
{
	if (!parent)
		return;
	
	DVASSERT(uiObject);
	
	HierarchyTreeScreenNode* screenNode = dynamic_cast<HierarchyTreeScreenNode*>(parent);
	if (screenNode)
	{
		screenNode->GetScreen()->AddControl(this->uiObject);
	}
	else
	{
		//HierarchyTreeControlNode* controlNode = GetControlNode();
		HierarchyTreeControlNode* controlNode = dynamic_cast<HierarchyTreeControlNode*>(parent);
		if (controlNode)
		{
			UIControl* control = controlNode->GetUIObject();
			if (control)
				control->AddControl(this->uiObject);
		}
	}	
}
void HierarchyTreeControlNode::SetParent(HierarchyTreeNode* node, HierarchyTreeNode* insertAfter)
{
    if (this == insertAfter)
        return;

    if (parent)
        parent->RemoveTreeNode(this, false, false);

    HierarchyTreeControlNode* newParentControl = dynamic_cast<HierarchyTreeControlNode* >(node);
    HierarchyTreeScreenNode* newParentScreen = dynamic_cast<HierarchyTreeScreenNode* >(node);
    DVASSERT(newParentControl || newParentScreen);
    if (!newParentControl && !newParentScreen)
        return;

    UIControl* afterControl = NULL;
    HierarchyTreeControlNode* insertAfterControl = dynamic_cast<HierarchyTreeControlNode* >(insertAfter);
    if (insertAfterControl)
        afterControl = insertAfterControl->GetUIObject();

    UIControl* newParentUI = NULL;
    if (newParentControl)
        newParentUI = newParentControl->GetUIObject();
    else if (newParentScreen)
        newParentUI = newParentScreen->GetScreen();

    node->AddTreeNode(this, insertAfter);
    if (newParentUI && uiObject)
    {
        Rect controlAbsoluteRect = uiObject->GetRect(true);
        Rect parentAbsoluteRect = newParentUI->GetRect(true);

        if (insertAfter != node)
        {
            newParentUI->InsertChildAbove(uiObject, afterControl);
        }
        else
        {
            UIControl* belowControl = NULL;
            const List<UIControl*> & controls = newParentUI->GetChildren();
            if (controls.size())
            {
                belowControl = *controls.begin();
            }
            newParentUI->InsertChildBelow(uiObject, belowControl);
        }

        // Recalculate the relative coords of the moved object to don't change its position.
        Vector2 newControlOffset = controlAbsoluteRect.GetPosition() - parentAbsoluteRect.GetPosition();
        uiObject->SetRect(Rect(newControlOffset, uiObject->GetRect().GetSize()));

        // Fix
        // DF-2395 - Recalculate scrollContainer content each time we add controls to it
        UIScrollViewContainer *container = dynamic_cast<UIScrollViewContainer*>(newParentUI);
        if (container)
        {
            UIScrollView *scroll =  dynamic_cast<UIScrollView*>(container->GetParent());
            if (scroll)
            {
                scroll->RecalculateContentSize();
            }
        }
    }

    parent = node;
}
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;
}