Example #1
0
void _drawAxis(QPainter *p)   //画坐标轴
{
    QPointF xNegative(-100,0);
    QPointF xPositive(100,0);
    QPointF yNegative(0,-100);
    QPointF yPositive(0,100);
    p->setPen(Qt::darkMagenta);
    p->drawLine(xNegative,xPositive);
    p->drawLine(yNegative,yPositive);
    _drawArrow(p,xNegative,xPositive);
    _drawArrow(p,yNegative,yPositive);
    QPen pen(Qt::darkRed);
    pen.setWidth(5);
    p->setPen(pen);
    p->drawPoint(QPointF(0,0));
}
Example #2
0
void _drawPolygon(QPainter *p, const QPolygonF &polygon)  //画QPolygonF
{
    //temp
    p->drawPolygon(polygon);
    QPointF A=polygon.operator [](polygon.size()-2);
    QPointF B=polygon.operator [](polygon.size()-1);
    _drawArrow(p,A,B);
    //下面是强调起点的标志
    QPen pen(Qt::darkYellow);
    pen.setWidth(4);
    p->setPen(pen);
    p->drawPoint(polygon.front());
}
Example #3
0
void
Clock::Draw(BView *view, int32)
{
	BScreen screenView;
	BBitmap bufferBitmap(view->Bounds(), screenView.ColorSpace(), true);
	BView offscreenView(view->Bounds(), NULL, 0, 0);
	bufferBitmap.AddChild(&offscreenView);
	bufferBitmap.Lock();

	float width = view->Bounds().Width();
	float height = view->Bounds().Height();
	float zoom = (height / 1024.0) * 0.65;
	
	time_t timeInfo;
	time(&timeInfo);
	struct tm *nowTime = localtime(&timeInfo);

	float secondVal = nowTime->tm_sec;
	float minuteVal = nowTime->tm_min + (secondVal / 60.0);
	float hourVal = nowTime->tm_hour + (minuteVal / 60.0);

	offscreenView.SetHighColor(0, 0, 0);
	offscreenView.SetLowColor(0, 0, 0);
	offscreenView.FillRect(offscreenView.Bounds());

	offscreenView.SetHighColor(200, 200, 200);
	
	centerX = width / 2.0;
	centerY = height / 2.0;

	float markAngle = 0;
	float markRadius = 510.0 * zoom;

	for(int mark = 0; mark < 60; mark++, markAngle += (2 * M_PI) / 60) {
		float x = centerX + markRadius * cos(markAngle);
		float y = centerY + markRadius * sin(markAngle);
		_drawBlock(&offscreenView, x, y, markAngle, 14.0 * zoom);
	}

	offscreenView.SetHighColor(255, 255, 255);

	markAngle = 0;
	markRadius = 500.0 * zoom;
	
	for (int mark = 0; mark < 12; mark++, markAngle += (2 * M_PI) / 12) {
		float x = centerX + markRadius * cos(markAngle);
		float y = centerY + markRadius * sin(markAngle);
		_drawBlock(&offscreenView, x, y, markAngle, 32 * zoom);
	}

	offscreenView.SetHighColor(255, 255, 255);
	_drawArrow(&offscreenView, centerX, centerY,
		((2 * M_PI / 60) * minuteVal) - (M_PI / 2), 220 * zoom, 1, 8 * zoom);

	_drawArrow(&offscreenView, centerX, centerY,
		((2 * M_PI / 12) * hourVal) - (M_PI / 2), 140 * zoom, 1, 14 * zoom);
	offscreenView.FillEllipse(BPoint(centerX, centerY),
		24 * zoom, 24 * zoom);
	
	offscreenView.SetHighColor(250, 20, 20);
	_drawArrow(&offscreenView, centerX, centerY,
		((2 * M_PI / 60) * secondVal) - (M_PI / 2), 240 * zoom, 1, 4 * zoom);
	offscreenView.FillEllipse(BPoint(centerX, centerY),
		20 * zoom, 20 * zoom);

	offscreenView.Sync();
	bufferBitmap.Unlock();
	view->DrawBitmap(&bufferBitmap);
	bufferBitmap.RemoveChild(&offscreenView);
}