コード例 #1
0
ファイル: fragmentTree.C プロジェクト: wijnen/ear
MyTreeTableNode *MyTreeTableNode::addNode(MyTreeTableNode *parent, Wt::WString name, const long start, const long stop, bool mini ) {
	MyTreeTableNode *node = new MyTreeTableNode(name, 0, parent);
	Wt::WContainerWidget *labelArea = node->labelArea();
	Wt::WWidget *labelWidget = labelArea->widget(0); //See source of WTreeNode.
	labelArea->removeWidget(labelWidget);
	node->startWidget = new TimeWidget(); //We make these, even if we're doing the mini-tree. We use these widgets to store the actual data, so that if we need the start or stop time, we can get them out of the widget and get the right numbers, even if we haven't saved the fragment set yet.
	node->startWidget->setTime(start);
	node->stopWidget = new TimeWidget();
	node->stopWidget->setTime(stop);
	
	if (mini)
	{
		node->startButton = new Wt::WPushButton(name);
	}
	else
	{
		node->editWidget = new Wt::WInPlaceEdit();
		std::string str = name.toUTF8();
		str.erase(std::remove(str.begin(), str.end(), ' '), str.end()); //This removes whitespace
		if(str.length()<1)
		{
			node->editWidget->setText(Wt::WString::Empty);	
			node->editWidget->setPlaceholderText("New Node");	
		
		}
		else
		{
			node->editWidget->setText(name);	
		}
		node->editWidget->valueChanged().connect(std::bind([=]() {
			
			std::string str = node->editWidget->text().toUTF8();
			str.erase(std::remove(str.begin(), str.end(), ' '), str.end()); //This removes whitespace
			if(str.length()<1)
			{
				node->editWidget->setText(Wt::WString::Empty);	
			}
			node->text = node->editWidget->text();
		}));
	
		node->text = node->editWidget->text();
	
		node->startButton = new Wt::WPushButton("|>");
	}
//todo: add doubleclick trick to allow modal edit
	node->startButton->clicked().connect(std::bind([=]() { 
		if(start == -1)
		{	//We've clicked the startbutton on a group, so we need to find the first non-group widget. 
			if (node->childNodes().size() > 0)
			{
 				//So, there are children.. In this case take the first child and pretend we've clicked that startButton. It'll be recursive. 
				MyTreeTableNode *firstChild = dynamic_cast<MyTreeTableNode*> (*(node->childNodes()).begin());
				return firstChild->startButton->clicked().emit(Wt::WMouseEvent());
			}
			else
			{ //Where in a childless group, so we cannot play anything!
				return;
			}

		}
		Wt::Json::Object jStartBefore = zmq_conn::interact("inputs?"); 
		Wt::Json::Array aStartBefore = jStartBefore.get("before");
		signed long long startBefore = aStartBefore[2];
		zmq_conn::interact(Wt::WString("event:stop")); //Probably needed to help stop the track from stopping the middle of a play

		Wt::WString command="play:"+std::to_string(start - startBefore * 1000); 
		zmq_conn::interact(command);
	}));
	labelArea->addWidget(node->startButton);
	if(mini)
	{
	}
	else
	{ //0 is startbutton now
		//node->setColumnWidget(1, node->startButton);
		node->setColumnWidget(1,node->editWidget );
		node->setColumnWidget(2, node->startWidget); 
		node->setColumnWidget(3, node->stopWidget);
	}
	return node;
    }