コード例 #1
0
ファイル: imageeditorwidgetqt.cpp プロジェクト: Ojaswi/inviwo
void ImageLabelWidget::addRectangleTest() {
    QAbstractGraphicsShapeItem* i = scene_->addRect(0, 0, 25, 25);
    i->setFlag(QGraphicsItem::ItemIsMovable);
    i->setBrush(QColor(0,0,128,0));
    i->setPen(QPen(QColor(255, 0, 0), 2));
    i->setZValue(255);
}
コード例 #2
0
void CSharedPainterScene::drawLastItemBorderRect( void  )
{
	if( ! lastAddItem_ )
		return;

	if( ! lastAddItem_->drawingObject() )
		return;

	QAbstractGraphicsShapeItem* i = reinterpret_cast<QAbstractGraphicsShapeItem *>(lastAddItem_->drawingObject());
	if( ! i )
		return;

	// setting style..
	QPainterPath path = createCoveringBorderPath( lastItemBorderType_, i );
	if ( path.isEmpty() )
		return;

	clearLastItemBorderRect();

	QAbstractGraphicsShapeItem* lastBorderItem = addPath( path );
	lastBorderItem->setPen( QPen( Util::getComplementaryColor(backgroundColor_, penColor() ), 2) );
	lastBorderItem->setZValue( currentZValue() );
	lastCoverGraphicsItem_ = lastBorderItem;

	// clear
	lastTempBlinkShowFlag_ = true;
	lastTimeValue_ = QDateTime::currentDateTime().toMSecsSinceEpoch();
	timeoutRemoveLastCoverItem_ = DEFAULT_TIMEOUT_REMOVE_LAST_COVER_ITEM;
}
コード例 #3
0
ファイル: main.cpp プロジェクト: KubaO/stackoverflown
void setupScene(QGraphicsScene &s)
{
    for (int i = 0; i < 10; i++) {
        qreal x = rnd(1), y = rnd(1);
        QAbstractGraphicsShapeItem * item = new QGraphicsRectItem(x, y, rnd(1-x), rnd(1-y));
        item->setFlags(QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable);
        item->setPen(QPen(Qt::red, 0));
        item->setBrush(Qt::lightGray);
        s.addItem(item);
    }
}
コード例 #4
0
ファイル: canvas.cpp プロジェクト: Andreas665/qt
void Main::addRectangle()
{
    QAbstractGraphicsShapeItem *i = canvas.addRect( QRectF(qrand()%int(canvas.width()),
                                                          qrand()%int(canvas.height()),
                                                          canvas.width()/5,
                                                          canvas.width()/5) );
    i->setFlag(QGraphicsItem::ItemIsMovable);
    int z = qrand()%256;
    i->setBrush( QColor(z,z,z) );
    i->setPen( QPen(QColor(qrand()%32*8,qrand()%32*8,qrand()%32*8), 6) );
    i->setZValue(z);
}
コード例 #5
0
ファイル: MatrixElement.cpp プロジェクト: EQ4/RosegardenW
void
MatrixElement::setSelected(bool selected)
{
    QAbstractGraphicsShapeItem *item =
        dynamic_cast<QAbstractGraphicsShapeItem *>(m_item);
    if (!item) return;

    QColor colour;

    if (selected) {
        item->setPen(QPen(GUIPalette::getColour(GUIPalette::SelectedElement),
                          2, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin));
    } else {
        item->setPen
            (QPen(GUIPalette::getColour(GUIPalette::MatrixElementBorder), 0));
    }
}
コード例 #6
0
ファイル: PortGraphicsItem.cpp プロジェクト: fer-rum/q2d
PortGraphicsItem::PortGraphicsItem(QPointF position,
                                   DocumentEntry* relatedEntry,
                                   model::enums::PortDirection direction)
    : SchematicElement(position, relatedEntry) {
    // Ports are measured from the center, not the upper left corner

    QAbstractGraphicsShapeItem* newActual;

    m_direction = direction;
    // select the Pen and Brush based on the Port direction
    switch (direction) {
    case model::enums::PortDirection::IN:
        newActual = factories::GIFactory::createPortAdapterGI();
        this->m_defaultPen = PEN_INPUT_PORT;
        this->m_defaultBrush = BRUSH_INPUT_PORT;
        this->setAcceptDrops(true); // input ports can receive wire drops
        this->setAcceptedMouseButtons(0); // no way to click that
        break;
    case model::enums::PortDirection::OUT:
        newActual = factories::GIFactory::createPortAdapteeGI();
        this->m_defaultPen = PEN_OUTPUT_PORT;
        this->m_defaultBrush = BRUSH_OUTPUT_PORT;
        this->setAcceptedMouseButtons(Qt::LeftButton); // output ports can be dragged from
        break;
    default:
        newActual = factories::GIFactory::createPortInvalidGI();
        this->m_defaultPen = PEN_UNDEFINED_PORT;
        this->m_defaultBrush = BRUSH_UNDEFINED_PORT;
        break;
    }
    Q_CHECK_PTR(newActual);

    newActual->setPen(this->m_defaultPen);
    newActual->setBrush(this->m_defaultBrush);
    this->addActual(newActual);

    qreal r = (qreal)PORT_RADIUS;
    QGraphicsRectItem* background = new QGraphicsRectItem(-r, -r, 2 * r, 2 * r, this);
    background->setBrush(PORT_BACKGROUND_BRUSH);
    background->setPen(PORT_BACKGROUND_PEN);
    background->setZValue(-2);
    this->addActual(background);

    Q_ASSERT(this->actual()->isVisible());
    this->setAcceptHoverEvents(true);
}
コード例 #7
0
ファイル: PortGraphicsItem.cpp プロジェクト: fer-rum/q2d
void
PortGraphicsItem::slot_drawConnected() {
    QAbstractGraphicsShapeItem* newActual;
    switch (m_direction) {
    case model::enums::PortDirection::IN:
        newActual = factories::GIFactory::createPortAdapteeGI();
        break;
    case model::enums::PortDirection::OUT:
        newActual = factories::GIFactory::createPortAdapterGI();
        break;
    default: // should not happen
        Q_ASSERT(false);
    }
    newActual->setBrush(m_defaultBrush);
    newActual->setPen(m_defaultPen);
    this->addActual(newActual);
    this->setOpacity(0.25);
}
コード例 #8
0
ファイル: canvas.cpp プロジェクト: Andreas665/qt
void Main::addLogo()
{
    if ( logo_fn.isEmpty() )
	return;
    if ( !logoimg ) {
	logoimg = new QImage[4];
	logoimg[0].load( logo_fn );
	logoimg[1] = logoimg[0].smoothScale( int(logoimg[0].width()*0.75),
		int(logoimg[0].height()*0.75) );
	logoimg[2] = logoimg[0].smoothScale( int(logoimg[0].width()*0.5),
		int(logoimg[0].height()*0.5) );
	logoimg[3] = logoimg[0].smoothScale( int(logoimg[0].width()*0.25),
		int(logoimg[0].height()*0.25) );
    }
    QAbstractGraphicsShapeItem* i = new ImageItem(logoimg[qrand()%4]);
    canvas.addItem(i);
    i->setPos(qrand()%int(canvas.width()-logoimg->width()),
	    qrand()%int(canvas.height()-logoimg->width()));
    i->setZValue(qrand()%256+256);
}
コード例 #9
0
ファイル: canvas.cpp プロジェクト: Andreas665/qt
void Main::addButterfly()
{
    if ( butterfly_fn.isEmpty() )
	return;
    if ( !butterflyimg ) {
	butterflyimg = new QImage[4];
	butterflyimg[0].load( butterfly_fn );
	butterflyimg[1] = butterflyimg[0].smoothScale( int(butterflyimg[0].width()*0.75),
		int(butterflyimg[0].height()*0.75) );
	butterflyimg[2] = butterflyimg[0].smoothScale( int(butterflyimg[0].width()*0.5),
		int(butterflyimg[0].height()*0.5) );
	butterflyimg[3] = butterflyimg[0].smoothScale( int(butterflyimg[0].width()*0.25),
		int(butterflyimg[0].height()*0.25) );
    }
    QAbstractGraphicsShapeItem* i = new ImageItem(butterflyimg[qrand()%4]);
    canvas.addItem(i);
    i->setPos(qrand()%int(canvas.width()-butterflyimg->width()),
	    qrand()%int(canvas.height()-butterflyimg->height()));
    i->setZValue(qrand()%256+250);
}
コード例 #10
0
void CSharedPainterScene::doLowQualityMoveItems( void )
{
	if( tempMovingItemList_.size() <= 0 )
		return;

	ITEM_SET::iterator it = tempMovingItemList_.begin();
	for( ; it != tempMovingItemList_.end(); it++ )
	{
		boost::shared_ptr<CPaintItem> item = *it;

		QAbstractGraphicsShapeItem* i = reinterpret_cast<QAbstractGraphicsShapeItem *>(item->drawingObject());
		if( ! i )
			continue;

		item->setPos( i->pos().x(), i->pos().y() );
		eventTarget_->onICanvasViewEvent_MoveItem( this, item );
	}

	tempMovingItemList_.clear();
}
コード例 #11
0
ファイル: canvas.cpp プロジェクト: Andreas665/qt
void Main::addCircle()
{
    QAbstractGraphicsShapeItem* i = canvas.addEllipse(QRectF(0,0,50,50));
    i->setFlag(QGraphicsItem::ItemIsMovable);
    i->setPen(Qt::NoPen);
    i->setBrush( QColor(qrand()%32*8,qrand()%32*8,qrand()%32*8) );
    i->setPos(qrand()%int(canvas.width()),qrand()%int(canvas.height()));
    i->setZValue(qrand()%256);
}
コード例 #12
0
ファイル: MatrixElement.cpp プロジェクト: EQ4/RosegardenW
void
MatrixElement::setCurrent(bool current)
{
    if (m_current == current) return;

    QAbstractGraphicsShapeItem *item =
        dynamic_cast<QAbstractGraphicsShapeItem *>(m_item);
    if (!item) return;

    QColor colour;
    
    if (!current) {
        colour = QColor(200, 200, 200);
    } else {
        if (event()->has(BaseProperties::TRIGGER_SEGMENT_ID)) {
            colour = Qt::gray;
        } else {
            long velocity = 100;
            event()->get<Int>(BaseProperties::VELOCITY, velocity);
            colour = DefaultVelocityColour::getInstance()->getColour(velocity);
        }
    }

    item->setBrush(colour);
    item->setZValue(current ? 1 : 0);

    if (current) {
        item->setPen
            (QPen(GUIPalette::getColour(GUIPalette::MatrixElementBorder), 0));
    } else {
        item->setPen
            (QPen(GUIPalette::getColour(GUIPalette::MatrixElementLightBorder), 0));
    }

    m_current = current;
}
コード例 #13
0
ファイル: lighting.cpp プロジェクト: wpbest/copperspice
void Lighting::setupScene()
{
    m_scene.setSceneRect(-300, -200, 600, 460);

    QLinearGradient linearGrad(QPointF(-100, -100), QPointF(100, 100));
    linearGrad.setColorAt(0, QColor(255, 255, 255));
    linearGrad.setColorAt(1, QColor(192, 192, 255));
    setBackgroundBrush(linearGrad);

    QRadialGradient radialGrad(30, 30, 30);
    radialGrad.setColorAt(0, Qt::yellow);
    radialGrad.setColorAt(0.2, Qt::yellow);
    radialGrad.setColorAt(1, Qt::transparent);

    QPixmap pixmap(60, 60);
    pixmap.fill(Qt::transparent);

    QPainter painter(&pixmap);
    painter.setPen(Qt::NoPen);
    painter.setBrush(radialGrad);
    painter.drawEllipse(0, 0, 60, 60);
    painter.end();

    m_lightSource = m_scene.addPixmap(pixmap);
    m_lightSource->setZValue(2);

    for (int i = -2; i < 3; ++i)
        for (int j = -2; j < 3; ++j) {
            QAbstractGraphicsShapeItem *item;
            if ((i + j) & 1)
                item = new QGraphicsEllipseItem(0, 0, 50, 50);
            else
                item = new QGraphicsRectItem(0, 0, 50, 50);

            item->setPen(QPen(Qt::black, 1));
            item->setBrush(QBrush(Qt::white));
            QGraphicsDropShadowEffect *effect = new QGraphicsDropShadowEffect;
            effect->setBlurRadius(8);
            item->setGraphicsEffect(effect);
            item->setZValue(1);
            item->setPos(i * 80, j * 80);
            m_scene.addItem(item);
            m_items << item;
        }


}