Exemplo n.º 1
0
void RectControl::handleChanged()
{
    emit changed(rectValue());
}
void CDigitalStatusPrinter::PrintSinglTable(QPainter*p)
{
    int textWidth = p->window().width();
    int textHeight = p->window().height();

	QFontMetrics metics(m_font);
	QString strXuhao = QString("序号");
	QString strDesc = QString("描述");//                                     :    实际值");
	QString strMaohao = QString(":");
	QString strActual = QString("实际值");
	int nDescWidth = metics.width(strDesc);
	int nDescHeight = metics.height(); 
    printf("nDescHeight=%d\n",nDescHeight);

	DigitalStatusList SettingLst = m_pComTrade->GetDigitalStatusList();
	/*m_nCurrentY*/
    int nActualWidth = textWidth-m_nLeftMargin-m_nRightMargin;
    int nActualHeight = textHeight-m_nCurrentY-m_nBottomMargin;

	int nTableCoumn = nActualHeight/(nDescHeight+minStep)-1;

	m_nTableColum = nTableCoumn;

	nActualHeight = (nTableCoumn+1)*(nDescHeight+minStep);

    p->drawLine(m_nLeftMargin,m_nCurrentY,textWidth-m_nRightMargin,m_nCurrentY);

    p->drawLine(m_nLeftMargin,m_nCurrentY,m_nLeftMargin,nActualHeight+m_nCurrentY);

    p->drawLine(nActualWidth/2+m_nLeftMargin,m_nCurrentY,nActualWidth/2+m_nLeftMargin,
                nActualHeight+m_nCurrentY);

	//下限不要了
    p->drawLine(m_nLeftMargin,nActualHeight+m_nCurrentY,m_nLeftMargin+nActualWidth,nActualHeight+m_nCurrentY);



	int nTitleWidth = metics.width(strXuhao);
	int nTitleHeight = metics.height(); 

	int nMaohaoWidth = metics.width(strMaohao);

    p->drawLine(nTitleWidth+minStep+m_nLeftMargin,m_nCurrentY,nTitleWidth+minStep+m_nLeftMargin,nActualHeight+m_nCurrentY/*textHeight*/);

    p->drawLine(nActualWidth+m_nLeftMargin,m_nCurrentY,nActualWidth+m_nLeftMargin,nActualHeight+m_nCurrentY/*textHeight*/);

    QRectF rect(m_nLeftMargin+minStep,m_nCurrentY+minStep,minStep+nTitleWidth,minStep+nTitleHeight);
	p->drawText(rect,strXuhao);

    QRectF rect2(minStep+nActualWidth/2+m_nLeftMargin,m_nCurrentY+minStep,minStep+nTitleWidth,
        minStep+nTitleHeight);
	p->drawText(rect2,strXuhao);

    p->drawLine(3*minStep+nActualWidth/2+m_nLeftMargin+nTitleWidth,m_nCurrentY,
                3*minStep+nActualWidth/2+m_nLeftMargin+nTitleWidth,nActualHeight+m_nCurrentY/*textHeight*/);


    QRectF rect3(2*minStep+nTitleWidth+m_nLeftMargin,m_nCurrentY+minStep,nDescWidth,nTitleHeight);
	p->drawText(rect3,strDesc);

    QRectF rect4(4*minStep+nActualWidth/2+nTitleWidth+m_nLeftMargin,m_nCurrentY+minStep,
                 nDescWidth,nTitleHeight);
	p->drawText(rect4,strDesc);

    QRectF rectMao1(3*nActualWidth/8+m_nLeftMargin,m_nCurrentY+minStep,
        nMaohaoWidth+minStep,nTitleHeight);
	p->drawText(rectMao1,strMaohao);

    QRectF rectMao2(7*nActualWidth/8+m_nLeftMargin,m_nCurrentY+minStep,
        nMaohaoWidth+minStep,nTitleHeight);
	p->drawText(rectMao2,strMaohao);

	int nActualWid = metics.width(strActual);
    QRectF rectActual1(m_nLeftMargin+nActualWidth/2-minStep-nActualWid,m_nCurrentY+minStep,
        nActualWid,nTitleHeight);
	p->drawText(rectActual1,strActual);

    QRectF rectActual2(m_nLeftMargin+nActualWidth-minStep-nActualWid,m_nCurrentY+minStep,
        nActualWid,nTitleHeight);
	p->drawText(rectActual2,strActual);

	m_nCurrentY = m_nCurrentY+2*minStep+nTitleHeight;



	for(int nIndex=0;nIndex<m_nTableColum*2;nIndex++)
	{

        //int SettingNum = nIndex+nPageIndex*m_nTableColum*2;
        if(m_nCurrentIndex>=SettingLst.count())
		{
			return;
		}
        CDigitalStatus settingValue = SettingLst.at(m_nCurrentIndex);

        QString strNumber = QString::number(m_nCurrentIndex+1/*nIndex+1*/);

		//int nY =m_nCurrentY+nIndex*(minStep+nDescHeight);

		QString strDesc = settingValue.m_strName;



		QString strValue = QString::number(settingValue.m_nValue)+QString(" ");
		//左边
		if(nIndex<m_nTableColum)
		{
            QRectF rectNum(m_nLeftMargin+minStep,m_nCurrentY+nIndex*(minStep+nDescHeight),
                           minStep+nTitleWidth,nTitleHeight);
            p->drawText(rectNum,strNumber);

            int nDescWid = metics.width(strDesc);
            QRectF rectDesc(2*minStep+nTitleWidth+m_nLeftMargin,m_nCurrentY+nIndex*(minStep+nDescHeight),
                            nDescWid,
                            nDescHeight);
			p->drawText(rectDesc,strDesc);

            QRectF rectMao(3*nActualWidth/8+m_nLeftMargin,m_nCurrentY+nIndex*(minStep+nDescHeight),
                nMaohaoWidth,nDescHeight);
			//p->drawText(rectMao,strMaohao);

			//计算冒号的位置
			int nValueWidth = metics.width(strValue); 
            int nStartPoint = nActualWidth/2-nValueWidth+m_nLeftMargin-minStep;
			QRectF rectValue(nStartPoint,m_nCurrentY+nIndex*(minStep+nDescHeight),
                nValueWidth,nDescHeight);
			p->drawText(rectValue,strValue);

			//如果值太长了,那就不要冒号了
			if(!rectValue.contains(rectMao))
			{
				p->drawText(rectMao,strMaohao);
			}

            p->drawLine(m_nLeftMargin,m_nCurrentY+nIndex*(minStep+nDescHeight),
                        m_nLeftMargin+nActualWidth,m_nCurrentY+nIndex*(minStep+nDescHeight));
		}

		//右边
		else if(nIndex<m_nTableColum*2&&nIndex>=m_nTableColum) 
		{
            QRectF rectNum(minStep*2+nActualWidth/2+m_nLeftMargin,m_nCurrentY+(nIndex-m_nTableColum)*(minStep+nDescHeight),
                           nTitleWidth,nTitleHeight);
            p->drawText(rectNum,strNumber);

            int nDescWid = metics.width(strDesc);
            QRectF rectDesc(4*minStep+nTitleWidth+nActualWidth/2+m_nLeftMargin,
                            m_nCurrentY+(nIndex-m_nTableColum)*(minStep+nDescHeight),
                            nDescWid,
                            nDescHeight);

            //QRectF rectDesc(4*minStep+nTitleWidth+textWidth/2,m_nCurrentY+(nIndex-m_nTableColum)*(minStep+nDescHeight),
            //	2*minStep+nTitleWidth+5*textWidth/8,m_nCurrentY+(nIndex-m_nTableColum)*(minStep+nDescHeight)+nDescHeight);
			p->drawText(rectDesc,strDesc);

            QRectF rectMao(7*nActualWidth/8+m_nLeftMargin,m_nCurrentY+(nIndex-m_nTableColum)*(minStep+nDescHeight),
                nMaohaoWidth,nDescHeight);
			//p->drawText(rectMao,strMaohao);


			int nValueWidth = metics.width(strValue); 
            int nStartPoint = m_nLeftMargin+nActualWidth-nValueWidth-minStep;
			QRectF rectValue(nStartPoint,m_nCurrentY+(nIndex-m_nTableColum)*(minStep+nDescHeight),
                nValueWidth,nDescHeight);
			p->drawText(rectValue,strValue);

			//如果值太长了,那就不要冒号了
			if(!rectValue.contains(rectMao))
			{
				p->drawText(rectMao,strMaohao);
			}
		}
        m_nCurrentIndex++;
	}
    //continue print on new page
    if(m_nCurrentIndex<SettingLst.count())
    {
        m_nCurrentY = m_nTopMargin;
        m_pPrinter->newPage();
        PrintSinglTable(p);
    }

}