Пример #1
0
void HierarchyTreeController::DeleteNodesInternal(const HierarchyTreeNode::HIERARCHYTREENODESLIST& nodes)
{
	const HierarchyTreePlatformNode* activePlatform = this->activePlatform;
	const HierarchyTreeScreenNode* activeScreen = this->activeScreen;
	
	HierarchyTreeNode::HIERARCHYTREENODESLIST::const_iterator iter;
	for (iter = nodes.begin(); iter != nodes.end(); ++iter)
	{
		if (activeScreen && activeScreen->GetId() == (*iter)->GetId())
		{
			activeScreen = NULL;
			this->activeScreenAfterDeleteNodes = NULL;
		}
	
		if (activePlatform && activePlatform->GetId() == (*iter)->GetId())
		{
			activePlatform = NULL;
			this->activePlatformAfterDeleteNodes = NULL;
		}

		HierarchyTreeControlNode* controlNode = dynamic_cast<HierarchyTreeControlNode*>((*iter));
		if (controlNode)
		{
			UnselectControl(controlNode);
			DeleteNodesInternal(controlNode->GetChildNodes());
		}
	}
}
Пример #2
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;
		}
	}
}
Пример #3
0
void HierarchyTreeWidget::on_treeWidget_itemSelectionChanged()
{
	QTreeWidgetItem* selectedItem = ui->treeWidget->currentItem();
	if (!selectedItem)
	{
		return;
	}

	if (internalSelectionChanged)
	{
		return;
	}

	QVariant data = selectedItem->data(ITEM_ID);
	HierarchyTreeNode::HIERARCHYTREENODEID id = data.toInt();
	HierarchyTreeNode* baseNode = HierarchyTreeController::Instance()->GetTree().GetNode(id);
	HierarchyTreePlatformNode* selectedPlatform = dynamic_cast<HierarchyTreePlatformNode* >(baseNode);
	HierarchyTreeScreenNode* selectedScreen =  dynamic_cast<HierarchyTreeScreenNode* >(baseNode);
	HierarchyTreeControlNode* selectedControl = dynamic_cast<HierarchyTreeControlNode* >(baseNode);
	
	if (!selectedPlatform && !selectedScreen && !selectedControl)
		return;
	
	internalSelectionChanged = true;
	
	//only platform or screen node can be seleted
	if (selectedPlatform || selectedScreen)
	{
		ResetSelection();
		HierarchyTreeController::Instance()->ResetSelectedControl();
		selectedItem->setSelected(true);
	}
	
	if (selectedControl)
	{
		selectedScreen = selectedControl->GetScreenNode();
		selectedPlatform = selectedScreen->GetPlatform();
	}
	else if (selectedScreen)
	{
		selectedPlatform = selectedScreen->GetPlatform();
	}
		
	HierarchyTreeController::Instance()->UpdateSelection(selectedPlatform, selectedScreen);
	HierarchyTreeController::Instance()->UpdateSelection(baseNode);
	
	internalSelectionChanged = false;
	
	if (selectedControl)
	{
		if (ui->treeWidget->selectedItems().size() == 1)
			HierarchyTreeController::Instance()->ResetSelectedControl();
		HierarchyTreeController::Instance()->SelectControl(selectedControl);
	}
}
Пример #4
0
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;
}
HierarchyTreeScreenNode* HierarchyTreeControlNode::GetScreenNode() const
{
	if (!parent)
		return NULL;
	
	HierarchyTreeScreenNode* screenNode = dynamic_cast<HierarchyTreeScreenNode*>(parent);
	if (screenNode)
		return screenNode;
	
	HierarchyTreeControlNode* controlNode = dynamic_cast<HierarchyTreeControlNode*>(parent);
	if (controlNode)
		return controlNode->GetScreenNode();
	
	return NULL;
}
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;
}
Пример #7
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;
}
Пример #9
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
	}
}
Пример #10
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();
}
Пример #12
0
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();
}
Пример #13
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;
}