示例#1
0
void BarChartWidget::drawBars(QPainter &painter) {
    std::vector<int> sizes(BAR_COUNT, 0);
    fillSizes(sizes);

    QRect baseRectangle = rect();
    int activeWidth = (int) std::floor( baseRectangle.width() * (1 - 2 * PADDING) );
    int singleBarWidth = (int) std::floor((activeWidth - (BAR_COUNT + 1) * SPACING) / BAR_COUNT);

    int baseLineY = (int) std::floor(baseRectangle.bottom() - PADDING_BOTTOM);
    int currX = (int) std::floor(baseRectangle.left() + baseRectangle.width() * PADDING);

    currX += SPACING;
    for (int i = 0; i < BAR_COUNT; i++) {
        QPoint pointTopLeft(currX, baseLineY - sizes.at((unsigned long) i));
        QPoint pointBottomRight(currX + singleBarWidth, baseLineY - 1);
        QRect bar(pointTopLeft, pointBottomRight);
        painter.setPen(mainColor);
        painter.drawRect(bar);
        painter.fillRect(bar, barColor);

        QPoint textTopLeft(currX, baseLineY);
        QPoint textBottomRight(currX + singleBarWidth, baseRectangle.bottom());
        QRect textRect(textTopLeft, textBottomRight);
        painter.setPen(mainColor);
        painter.drawText(textRect, Qt::AlignCenter, labels->at((unsigned long) i));
        
        QPoint valueTopLeft(currX, baseLineY - sizes.at((unsigned long) i) - VALUE_LABEL_HEIGHT);
        QPoint valueBottomRight(currX + singleBarWidth, baseLineY);
        QRect valueLabelRect(valueTopLeft, valueBottomRight);
        QString textValue = QString::number(values->at((unsigned long) i));
        painter.drawText(valueLabelRect, Qt::AlignHCenter | Qt::AlignTop, textValue);
        
        currX += singleBarWidth + SPACING;
    }
}
示例#2
0
void CApplicationImpl::AddItemWindow(HWND hWnd)
{
	// Calculate position of the new item window.
	CPoint pointTopLeft(0, 0);

	if (m_listItemWindows.empty())
	{
		 CWindow(hWnd).CenterWindow();
		 pointTopLeft = CWindowRect(hWnd).TopLeft();
	}
	else
	{
		CWindowRect rcLast(m_listItemWindows.back().first);
		pointTopLeft.x = max(pointTopLeft.x, rcLast.left);
		pointTopLeft.y = max(pointTopLeft.y, rcLast.top);

		pointTopLeft.Offset(GetSystemMetrics(SM_CYCAPTION), GetSystemMetrics(SM_CYCAPTION));
		CWindowRect rc(hWnd);
		rc.OffsetRect(pointTopLeft);
		CWindowRect rcDesktop(GetDesktopWindow());
		if (!rcDesktop.PtInRect(rc.BottomRight()))
		{
			pointTopLeft.SetPoint(0, 0);
		}
		SetWindowPos(hWnd, NULL, pointTopLeft.x, pointTopLeft.y, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
	}

	// add to the list
	m_listItemWindows.push_back(std::make_pair(hWnd, pointTopLeft));
}
示例#3
0
void BarChartWidget::drawLabel(QPainter &painter) {
    QRect baseRectangle = rect();
    painter.setPen(mainColor);

    int topY = (int) std::floor(baseRectangle.top());
    QPoint pointTopLeft(baseRectangle.left(), topY);
    QPoint pointBottomRight(baseRectangle.right(), topY + PADDING_TOP);
    QRect textRectangle(pointTopLeft, pointBottomRight);
    painter.drawText(textRectangle, Qt::AlignHCenter | Qt::AlignBottom, "Кратность пропущенных ошибок");
}