예제 #1
0
void QVUMeter::paintValue()
{
    QPainter painter(this);
    painter.setWindow(0, 0, 100, 540);
    painter.setRenderHint(QPainter::Antialiasing);

    painter.setBrush(Qt::black);
    painter.drawRect(20, 15, 25, 25);
    painter.drawRect(55, 15, 25, 25);
    painter.setPen(Qt::gray);
    painter.drawLine(20, 40, 45, 40);
    painter.drawLine(45, 15, 45, 40);
    painter.drawLine(55, 40, 80, 40);
    painter.drawLine(80, 15, 80, 40);

    painter.setPen(QPen(colValue, 1));
    QFont valFont("Arial", dimVal, QFont::Bold);
    painter.setFont(valFont);

    QRectF leftR(20, 15, 25, 25);
    QString lVal = QString("%1").arg(leftVal, 0,'f', 0);
    painter.drawText(leftR, Qt::AlignCenter, lVal);
    QRectF rightR(55, 15, 25, 25);
    QString rVal = QString("%1").arg(rightVal, 0,'f', 0);
    painter.drawText(rightR, Qt::AlignCenter, rVal);

    emit valueLChanged(leftVal);
    emit valueRChanged(rightVal);

}
예제 #2
0
int ContainerAreaLayout::distanceToPreviousItem(ItemList::const_iterator it) const
{
    assert(it != m_items.constEnd());

    ContainerAreaLayoutItem* cur  = *it;
    --it;
    ContainerAreaLayoutItem* prev = (it != m_items.constEnd()) ? *it : 0;

    return prev ? cur->leftR() - prev->leftR() - prev->widthForHeightR(heightR()) :
                  cur->leftR() - leftR();
}
예제 #3
0
파일: vumeter.cpp 프로젝트: nameqiaohe/quc
void VUMeter::drawValue(QPainter *painter)
{
    painter->save();

    //绘制左右音量值背景
    painter->setBrush(Qt::black);
    painter->drawRect(20, 15, 25, 25);
    painter->drawRect(55, 15, 25, 25);

    //绘制左右音量值背景右侧突出线条,形成立体感
    painter->setPen(Qt::gray);
    painter->drawLine(20, 40, 45, 40);
    painter->drawLine(45, 15, 45, 40);
    painter->drawLine(55, 40, 80, 40);
    painter->drawLine(80, 15, 80, 40);

    //设置音量值字体
    painter->setPen(QPen(colorValue, 1));
    QFont valFont("Arial", 12, QFont::Bold);
    painter->setFont(valFont);

    //绘制左音量值
    QRectF leftR(20, 15, 25, 25);
    QString lVal = QString("%1").arg(leftValue, 0, 'f', 0);
    painter->drawText(leftR, Qt::AlignCenter, lVal);

    //绘制右音量值
    QRectF rightR(55, 15, 25, 25);
    QString rVal = QString("%1").arg(rightValue, 0, 'f', 0);
    painter->drawText(rightR, Qt::AlignCenter, rVal);

    painter->restore();

    //发送音量值改变信号
    emit valueLChanged(leftValue);
    emit valueRChanged(rightValue);
}
예제 #4
0
void o_t::orderReb(node** stack, int index)
{

	int finished = 0;
	int sindex = -1;
	while(sindex < index && !finished)
	{
		int tmpHeight, oldHeight;
		sindex ++;
		node * pnode = stack[sindex];

		oldHeight = pnode ->height;
		if(pnode ->left -> height - 
				pnode ->right -> height == 2)
		{
			if(pnode->left ->left ->height -
					pnode ->right ->height == 1)
			{
				rightR(pnode);
				pnode ->right ->height = pnode ->right->left ->height + 1;
				pnode ->height = pnode ->right ->height + 1;
			}
			else
			{
				leftR(pnode -> left);
				rightR(pnode);
				tmpHeight = pnode ->left ->left ->height;
				pnode ->left ->height = tmpHeight +1;
				pnode ->right ->height = tmpHeight + 1;

				pnode ->height = tmpHeight + 2;
			}
		}
		else if(pnode ->left ->height - 
				pnode ->right ->height == -2)
		{
			if(pnode->right->right ->height - 
					pnode ->left->height ==1)
			{
				leftR(pnode);
				pnode ->left ->height = pnode ->left ->right ->height + 1;
				pnode ->height = pnode ->left ->height + 1;
			}
			else
			{
				rightR(pnode ->right);
				leftR(pnode);
				tmpHeight = pnode ->right ->right ->height;
				pnode ->left ->height = tmpHeight + 1;
				pnode ->right ->height = tmpHeight + 1;
				pnode ->height = tmpHeight + 2;
			}
		}
		else
		{
			if(pnode ->left ->height > pnode ->right ->height)
				pnode ->height = pnode ->left ->height +1;
			else
				pnode ->height = pnode ->right ->height +1;
		}
		if(pnode ->height == oldHeight)
			finished = 1;
	}//end of while

}
예제 #5
0
node * m_tree_t::removeNode(int index, int otherIndex)
{
	node * upper, *other;
	node *delNode = NULL;

	num --;
	node ** stack = new node*[num];
	int sindex = -1;

	if(root == NULL)
		return NULL;
	else if(root ->right == NULL)
	{
		if(index == root ->key)
		{
			node* pnode = root ->left;
			root ->left = NULL;
			root ->measure = 0;
			root ->ep_l.clear();
			root->ep_r.clear();
			return pnode;
		}
		else return NULL;
	}
	else
	{
		node * pnode = root;
		while(pnode ->right != NULL)
		{
			sindex ++;
			stack[sindex] = pnode;
			upper = pnode;
			if(index < pnode ->key)
			{
				pnode = upper ->left;
				other = upper ->right;
			}
			else
			{
				pnode = upper ->right;
				other = upper ->left;
			}//end of if-else
		}//end of while

		if(index == pnode ->key)
		{
			//printf("get the index %d , node %d\n",index, pnode ->left->key);
			if(pnode ->left ->time == 1)
			{
				upper ->key = other ->key;
				upper ->left = other -> left;
				upper ->right = other ->right;
				upper ->height = other ->height;
				delNode = pnode ->left;
				node * tmpN = pnode;
				returnNode(tmpN  ->left);
				returnNode(other);
				sindex --;

				upper ->left ->nodeIvl_l = upper->nodeIvl_l;
				if(upper ->right ==NULL)
				upper ->left ->nodeIvl_r = upper ->nodeIvl_r;
				else
				{
					upper ->left->nodeIvl_r = upper ->key;
					upper ->right ->nodeIvl_l = upper ->key;
					upper ->right ->nodeIvl_r = upper ->nodeIvl_r;
				}

				getLeftMin(upper);
				getRightMax(upper);
				getMeasure(upper);
			}
			else
			{
				pnode ->left -> time --;

				if(index < otherIndex)
				{

					pnode->left->ep_r.remove(otherIndex);
					pnode->left ->ep_l.remove(index);

				}
				else
				{

					pnode->left->ep_l.remove(otherIndex);
					pnode->left->ep_r.remove(index);

				}

				pnode ->ep_l = pnode->left ->ep_l;
				pnode ->ep_r = pnode ->left ->ep_r;

				if(pnode->left->ep_l.size() != 0)
				{
					pnode ->left ->leftmin = pnode->left->ep_l.min();
				}
				else
				
					pnode->left->leftmin = pnode->left->nodeIvl_l;
					

				if(pnode->left->ep_r.size() != 0)
				{
					pnode ->left ->rightmax = pnode ->left->ep_r.max();
				}
				else
					pnode->left ->rightmax = pnode ->left ->nodeIvl_r;

				getLeftMin(pnode);
				getRightMax(pnode);
				getMeasure(pnode);

				getLeftMin(upper);
				getRightMax(upper);
				getMeasure(upper);
			}//end of else to process the case multiple endpoint

		}
		else
			return NULL;

		int aindex = sindex;
		while(aindex > -1)
		{
			node * n = stack[aindex];
			aindex --;
			getLeftMin(n);
			getRightMax(n);
			getMeasure(n);
		}
	}//end of else

	//rebalance
	int finished = 0;
	while(sindex > -1 && !finished)
	{
		int tmpHeight, oldHeight;

		node * pnode = stack[sindex];
		sindex --;

		oldHeight = pnode ->height;
		if(pnode->left->height -  pnode ->right->height == 2)
		{
			if(pnode->left->left->height - pnode->right->height == 1)
			{
				rightR(pnode);
				pnode ->right ->height = pnode ->right ->left ->height +1;
				pnode ->height = pnode ->right ->height +1;
			}
			else
			{
				leftR(pnode ->left);
				rightR(pnode);
				tmpHeight = pnode ->left ->left ->height;
				pnode ->left ->height = tmpHeight +1;
				pnode ->right ->height = tmpHeight +1;
				pnode ->height = tmpHeight +2;
			}
		}
		else if(pnode->left->height - pnode->right->height == -2)
		{
			if(pnode ->right ->right ->height - pnode->left->height == 1)
			{
				leftR(pnode);
				pnode ->left ->height = pnode->left ->right ->height +1;
				pnode ->height = pnode ->left ->height +1;
			}
			else
			{
				rightR(pnode->right);
				leftR(pnode);
				tmpHeight = pnode ->right ->right ->height;

			}
		}
		else
		{
			if(pnode->left->height > pnode->right->height)
				pnode->height = pnode ->left ->height +1;
			else
				pnode ->height = pnode ->right ->height +1;
		}
		if(pnode -> height == oldHeight)
			finished  =1;
	}// end of while for rebalance

	return delNode;
}
예제 #6
0
int m_tree_t::insertNode(int index, int otherIndex)
{
	node * newNode = getNode();
	newNode ->height = 0;
	newNode ->left = NULL;
	newNode ->right = NULL;
	newNode ->time = 1;
	newNode ->key = index;
	newNode ->ep_l.clear();
	newNode ->ep_r.clear();

	if(index < otherIndex)
		//newNode ->ep_r.insert(otherIndex);
		newNode ->ep_r.add(otherIndex);
	else
		//newNode ->ep_l.insert(otherIndex);
		newNode ->ep_l.add(otherIndex);



	node ** stack = new node* [num];
	int sindex = -1;

	node *pnode = NULL;
	if(root ->left == NULL)
	{
		root ->left =newNode;
		root ->key = index;
		root ->right = NULL;
		root ->height = 0;

		newNode ->nodeIvl_l = root ->nodeIvl_l;
		newNode ->nodeIvl_r = root ->key;

		getLeftMin(root);
		getRightMax(root);
		getMeasure(root);
	}
	else
	{
		pnode = root;
		while(pnode ->right != NULL)
		{
			sindex ++;
			stack[sindex] = pnode;
			if(index < pnode ->key)
				pnode = pnode ->left;
			else
				pnode = pnode ->right;
		}//end of while

		if(index == pnode ->key)
		{
			//for the case there same endpoint
			pnode ->left ->time ++;
			returnNode(newNode);

			// some ivtervals share  the same endpoint, then I store the correspondence endpoint in vector (STL)
			if(index <otherIndex)
			{
				pnode ->left ->ep_r.add(otherIndex);

				pnode ->left ->rightmax = pnode->left->ep_r.max();
				pnode ->rightmax = pnode ->left ->ep_r.max();
			}
			else
			{
				pnode ->left->ep_l.add(otherIndex);
				pnode ->left ->leftmin = pnode->left->ep_l.min();
				pnode ->leftmin = pnode ->left->ep_l.min();
			}

			pnode ->ep_l = pnode->left ->ep_l;
			pnode ->ep_r = pnode ->left ->ep_r;

			getLeftMin(pnode);
			getRightMax(pnode);
			getMeasure(pnode);


		}
		else
		{
			node * oldLeaf, *newLeaf;
			oldLeaf = getNode();
			oldLeaf->left = pnode ->left;
			oldLeaf ->key = pnode ->key;
			oldLeaf ->right = NULL;
			oldLeaf ->height = 0;


			newLeaf = getNode();
			newLeaf ->left = newNode;
			newLeaf ->key = index;
			newLeaf ->right = NULL;
			newLeaf ->height = 0;

			newLeaf ->ep_l = newNode ->ep_l;
			newLeaf ->ep_r = newNode ->ep_r;

			oldLeaf ->ep_l = pnode ->ep_l;
			oldLeaf ->ep_r = pnode ->ep_r;


			if(pnode ->key <= index)
			{
				pnode ->left = oldLeaf;
				pnode ->right = newLeaf;
				pnode ->key = index;
			}
			else
			{
				pnode ->left = newLeaf;
				pnode ->right = oldLeaf;
			}
			pnode ->height = 1;


			pnode ->left ->nodeIvl_l = pnode ->nodeIvl_l;
			pnode->left ->nodeIvl_r = pnode ->key;

			getLeftMin(pnode->left);
			getRightMax(pnode ->left);
			getMeasure(pnode ->left);

			pnode ->right ->nodeIvl_l = pnode ->key;
			pnode -> right->nodeIvl_r = pnode ->nodeIvl_r;

			getLeftMin(pnode ->right);
			getRightMax(pnode ->right);
			getMeasure(pnode ->right);

			getLeftMin(pnode);
			getRightMax(pnode);
			getMeasure(pnode);
		}//end of else

		int tmpInx = sindex;
		while(tmpInx > -1)
		{
			node* n = stack[tmpInx];
			tmpInx --;
			getLeftMin(n);
			getRightMax(n);
			getMeasure(n);
		}
	}// end of else


	//rebalance the tree
	int finished = 0;
	while(sindex > -1 && !finished)
	{
		int tmpHeight, oldHeight;
		node * ptrn = stack[sindex];
		sindex --;
		oldHeight = ptrn ->height;
		//getMeasure(ptrn);
		if(ptrn ->left ->height -ptrn->right ->height == 2)
		{
			if(ptrn->left->left->height - ptrn->right->height ==1)
			{
				rightR(ptrn);
				ptrn->right->height = ptrn ->right ->left ->height +1;
				ptrn ->height = ptrn->right ->height +1;
			}
			else
			{
				leftR(ptrn->left);
				rightR(ptrn);
				tmpHeight = ptrn ->left ->left ->height;
				ptrn ->left ->height = tmpHeight +1;
				ptrn ->right ->height = tmpHeight +1;
				ptrn ->height = tmpHeight +2;
			}
		}
		else if(ptrn->left->height - ptrn->right->height == -2)
		{
			if(ptrn->right->right->height - ptrn->left->height ==1 )
			{
				leftR(ptrn);
				ptrn ->left ->height = ptrn ->left ->right ->height +1;
				ptrn ->height = ptrn ->left ->height +1;
			}
			else
			{
				rightR(ptrn ->right);
				leftR(ptrn);
				tmpHeight = ptrn ->right ->right ->height;
				ptrn ->left ->height = tmpHeight +1;
				ptrn ->right ->height = tmpHeight +1;
				ptrn ->height = tmpHeight +2;
			}
		}
		else
		{
			if(ptrn ->left ->height > ptrn ->right ->height)
				ptrn->height = ptrn ->left ->height +1;
			else
				ptrn ->height = ptrn ->right ->height +1;
		}
		if(ptrn ->height == oldHeight)
			finished = 1;

	}//end of while

	//release the space for the stack
	delete stack;

	//increase the number for totall elements
	return num ++;
}