コード例 #1
0
ファイル: GripperWidget.cpp プロジェクト: Aharobot/roscorobot
 void GripperWidget::drawBackground(QPainter *painter, const QRectF &rect)
 //draw the scene background
 {
     Q_UNUSED(rect);

     // Shadow
     QRectF sceneRect = this->sceneRect();
     QRectF rightShadow(sceneRect.right(), sceneRect.top() + 5, 5, sceneRect.height());
     QRectF bottomShadow(sceneRect.left() + 5, sceneRect.bottom(), sceneRect.width(), 5);
     if (rightShadow.intersects(rect) || rightShadow.contains(rect))
         painter->fillRect(rightShadow, Qt::darkGray);
     if (bottomShadow.intersects(rect) || bottomShadow.contains(rect))
         painter->fillRect(bottomShadow, Qt::darkGray);


     // Fill
     QLinearGradient gradient(sceneRect.topLeft(), sceneRect.bottomRight());
     gradient.setColorAt(0, Qt::white);
     gradient.setColorAt(1, Qt::lightGray);
     painter->fillRect(rect.intersect(sceneRect), gradient);
     painter->setBrush(Qt::NoBrush);
     painter->drawRect(sceneRect);


     painter->setPen(Qt::blue);
     painter->drawLine(0, GRIPPER_BOTTOM_LINE, GRIPPER_X, GRIPPER_BOTTOM_LINE);
     painter->drawLine(GRIPPER_LEFT_LINE, 0, GRIPPER_LEFT_LINE, GRIPPER_Y);
     painter->drawLine(GRIPPER_RIGHT_LINE, 0, GRIPPER_RIGHT_LINE, GRIPPER_Y);

     painter->setPen(QPen(Qt::green,2));
     painter->drawArc(GRIPPER_CENTER_X - GRIPPER_CIRCLE_RADIUS,
                              GRIPPER_CENTER_Y - GRIPPER_CIRCLE_RADIUS,
                              GRIPPER_CIRCLE_RADIUS * 2,GRIPPER_CIRCLE_RADIUS  * 2,
                              0, 360 * 64);
 }
コード例 #2
0
ファイル: reportview.cpp プロジェクト: walterqin/weighbridge
void ReportView::drawBackground(QPainter *painter, const QRectF &rect)
{
	QGraphicsView::drawBackground(painter, rect);

	if (!scene())
		return;

	// Shadow
	QRectF sceneRect = this->scene()->sceneRect();
	QRectF rightShadow(sceneRect.right(), sceneRect.top() + 5, 5, sceneRect.height());
	QRectF bottomShadow(sceneRect.left() + 5, sceneRect.bottom(), sceneRect.width(), 5);
	if (rightShadow.intersects(rect) || rightShadow.contains(rect))
		painter->fillRect(rightShadow, Qt::darkGray);
	if (bottomShadow.intersects(rect) || bottomShadow.contains(rect))
		painter->fillRect(bottomShadow, Qt::darkGray);

	// Fill
	Report *report = (Report*)scene();
	QPoint size = mapFromScene(report->gridSize().width(), report->gridSize().height())
		- mapFromScene(QPointF());
	QPixmap pixmap(size.x(), size.y());
	{
		pixmap.fill();
		QPainter p(&pixmap);
		QPen pen(Qt::DotLine);
		pen.setColor(Qt::gray);
		p.setPen(pen);
		p.drawLine(0, 0, size.x(), 0);
		p.drawLine(0, 0, 0, size.y());
	}
	painter->setBrush(pixmap);
	painter->drawRect(sceneRect);
}
コード例 #3
0
void GraphWidget::drawBackground(QPainter *painter, const QRectF &rect)
{

	
    Q_UNUSED(rect);
	//return;

    // Shadow
    QRectF sceneRect = this->sceneRect();
    QRectF rightShadow(sceneRect.right(), sceneRect.top() + 5, 5, sceneRect.height());
    QRectF bottomShadow(sceneRect.left() + 5, sceneRect.bottom(), sceneRect.width(), 5);
    if (rightShadow.intersects(rect) || rightShadow.contains(rect))
	painter->fillRect(rightShadow, Qt::darkGray);
    if (bottomShadow.intersects(rect) || bottomShadow.contains(rect))
	painter->fillRect(bottomShadow, Qt::darkGray);

    // Fill
    QLinearGradient gradient(sceneRect.topLeft(), sceneRect.bottomRight());
	gradient.setColorAt(0, QColor(100,107,126));
	gradient.setColorAt(1, QColor(100,107,126));
    painter->fillRect(rect.intersect(sceneRect), gradient);
	//painter->setBrush(Qt::BrushStyle::DiagCrossPattern);
    painter->drawRect(sceneRect);

    // Text
    //QRectF textRect(sceneRect.left() + 4, sceneRect.top() + 4,
    //                sceneRect.width() - 4, sceneRect.height() - 4);
    //QString message(tr("Click and drag the nodes around, and zoom with the mouse "
    //                   "wheel or the '+' and '-' keys"));

    //QFont font = painter->font();
    //font.setBold(true);
    //font.setPointSize(14);
    //painter->setFont(font);
    //painter->setPen(Qt::lightGray);
    ////painter->drawText(textRect.translated(2, 2), message);
    //painter->setPen(Qt::black);

    //painter->drawText(textRect, message);
painter->setPen(QColor(135,142,157));
	const int gridSize = 25;

qreal left = int(rect.left()) - (int(rect.left()) % gridSize);
qreal top = int(rect.top()) - (int(rect.top()) % gridSize);

QVarLengthArray<QLineF, 100> lines;

for (qreal x = left; x < rect.right(); x += gridSize)
lines.append(QLineF(x, rect.top(), x, rect.bottom()));
for (qreal y = top; y < rect.bottom(); y += gridSize)
lines.append(QLineF(rect.left(), y, rect.right(), y));

//qDebug() << lines.size();

painter->drawLines(lines.data(), lines.size());



}
コード例 #4
0
ファイル: qgobanview.cpp プロジェクト: JonathanCai/GoGame-1
void QGobanView::drawBackground(QPainter *painter, const QRectF &rect)
{
    Q_UNUSED(rect);
    // Shadow
    QRectF sceneRect = this->sceneRect();
    QRectF rightShadow(sceneRect.right(), sceneRect.top() + 5, 5, sceneRect.height());
    QRectF bottomShadow(sceneRect.left() + 5, sceneRect.bottom(), sceneRect.width(), 5);
    if (rightShadow.intersects(rect) || rightShadow.contains(rect))
        painter->fillRect(rightShadow, Qt::darkGray);
    if (bottomShadow.intersects(rect) || bottomShadow.contains(rect))
        painter->fillRect(bottomShadow, Qt::darkGray);
    // Fill
    QLinearGradient gradient(sceneRect.topLeft(), sceneRect.bottomRight());
    gradient.setColorAt(0, Qt::white);
    gradient.setColorAt(1, Qt::lightGray);
    painter->fillRect(rect.intersect(sceneRect), gradient);
    painter->setBrush(Qt::NoBrush);
    painter->drawRect(sceneRect);
    // Lines
    for(int i=0;i<_size;i++) {
        painter->drawLine(sceneRect.left()+_margin+i*_spacing,sceneRect.top()+_margin,
                          sceneRect.left()+_margin+i*_spacing,sceneRect.height()-_margin);
        painter->drawLine(sceneRect.left()+_margin,sceneRect.top()+_margin+i*_spacing,
                          sceneRect.width()-_margin,sceneRect.top()+_margin+i*_spacing);
    }
    //Stars
    int size=(int)(_spacing*0.1);
    //Always mark the center
    painter->setBrush(Qt::SolidPattern);
    painter->drawEllipse(QPoint(sceneRect.left()+_margin+(_size-1)/2*_spacing,
                                 sceneRect.top()+_margin+(_size-1)/2*_spacing),size,size);
    if(_size>=13) {
        //Mark the corners
        painter->drawEllipse(QPoint(sceneRect.left()+_margin+3*_spacing,
                                     sceneRect.top()+_margin+3*_spacing),size,size);
        painter->drawEllipse(QPoint(sceneRect.left()+_margin+(_size-4)*_spacing,
                                     sceneRect.top()+_margin+3*_spacing),size,size);
        painter->drawEllipse(QPoint(sceneRect.left()+_margin+(_size-4)*_spacing,
                                     sceneRect.top()+_margin+(_size-4)*_spacing),size,size);
        painter->drawEllipse(QPoint(sceneRect.left()+_margin+3*_spacing,
                                     sceneRect.top()+_margin+(_size-4)*_spacing),size,size);
    }
    if(_size==19) {
        //Mark the middle
        painter->drawEllipse(QPoint(sceneRect.left()+_margin+(_size-1)/2*_spacing,
                                     sceneRect.top()+_margin+3*_spacing),size,size);
        painter->drawEllipse(QPoint(sceneRect.left()+_margin+(_size-1)/2*_spacing,
                                     sceneRect.top()+_margin+(_size-4)*_spacing),size,size);
        painter->drawEllipse(QPoint(sceneRect.left()+_margin+(_size-4)*_spacing,
                                     sceneRect.top()+_margin+(_size-1)/2*_spacing),size,size);
        painter->drawEllipse(QPoint(sceneRect.left()+_margin+3*_spacing,
                                     sceneRect.top()+_margin+(_size-1)/2*_spacing),size,size);
    }
}
コード例 #5
0
ファイル: graphwidget.cpp プロジェクト: kuroyuki/QTNodes
void GraphWidget::drawBackground(QPainter *painter, const QRectF &rect)
{
    Q_UNUSED(rect);

    // Shadow
    QRectF sceneRect = this->sceneRect();
    QRectF rightShadow(sceneRect.right(), sceneRect.top() + 5, 5, sceneRect.height());
    QRectF bottomShadow(sceneRect.left() + 5, sceneRect.bottom(), sceneRect.width(), 5);
    if (rightShadow.intersects(rect) || rightShadow.contains(rect))
        painter->fillRect(rightShadow, Qt::darkGray);
    if (bottomShadow.intersects(rect) || bottomShadow.contains(rect))
        painter->fillRect(bottomShadow, Qt::darkGray);

    // Fill
    QLinearGradient gradient(sceneRect.topLeft(), sceneRect.bottomRight());
    gradient.setColorAt(0, Qt::white);
    gradient.setColorAt(1, Qt::lightGray);
    painter->fillRect(rect.intersected(sceneRect), gradient);
    painter->setBrush(Qt::NoBrush);
    painter->drawRect(sceneRect);
}
コード例 #6
0
ファイル: graphwidget.cpp プロジェクト: maxxant/qt
//! [6]
void GraphWidget::drawBackground(QPainter *painter, const QRectF &rect)
{
    Q_UNUSED(rect);

    // Shadow
    QRectF sceneRect = this->sceneRect();
    QRectF rightShadow(sceneRect.right(), sceneRect.top() + 5, 5, sceneRect.height());
    QRectF bottomShadow(sceneRect.left() + 5, sceneRect.bottom(), sceneRect.width(), 5);
    if (rightShadow.intersects(rect) || rightShadow.contains(rect))
	painter->fillRect(rightShadow, Qt::darkGray);
    if (bottomShadow.intersects(rect) || bottomShadow.contains(rect))
	painter->fillRect(bottomShadow, Qt::darkGray);

    // Fill
    QLinearGradient gradient(sceneRect.topLeft(), sceneRect.bottomRight());
    gradient.setColorAt(0, Qt::white);
    gradient.setColorAt(1, Qt::lightGray);
    painter->fillRect(rect.intersect(sceneRect), gradient);
    painter->setBrush(Qt::NoBrush);
    painter->drawRect(sceneRect);

#if !defined(Q_OS_SYMBIAN) && !defined(Q_WS_MAEMO_5)
    // Text
    QRectF textRect(sceneRect.left() + 4, sceneRect.top() + 4,
                    sceneRect.width() - 4, sceneRect.height() - 4);
    QString message(tr("Click and drag the nodes around, and zoom with the mouse "
                       "wheel or the '+' and '-' keys"));

    QFont font = painter->font();
    font.setBold(true);
    font.setPointSize(14);
    painter->setFont(font);
    painter->setPen(Qt::lightGray);
    painter->drawText(textRect.translated(2, 2), message);
    painter->setPen(Qt::black);
    painter->drawText(textRect, message);
#endif
}