void Dashboard::setDeathColor() { QGraphicsColorizeEffect *effect = new QGraphicsColorizeEffect(); effect->setColor(_m_layout->m_deathEffectColor); effect->setStrength(1.0); this->setGraphicsEffect(effect); refresh(); }
void SBI_ImagesIcon::updateIcon() { if (testCurrentPageWebAttribute(QWebEngineSettings::AutoLoadImages)) { setGraphicsEffect(0); } else { QGraphicsColorizeEffect* effect = new QGraphicsColorizeEffect(this); effect->setColor(Qt::gray); setGraphicsEffect(effect); } }
void HomeScreen::initEffect() { QGraphicsColorizeEffect* effect = new QGraphicsColorizeEffect(_sprite); effect->setColor(QColor::fromRgb(0xFF, 0xFF, 0xFF)); effect->setStrength(0.0f); _sprite->setGraphicsEffect(effect); _showEffectTimer = new QTimeLine(SHOWEFFECT_DURATION, this); _hideEffectTimer = new QTimeLine(HIDEEFFECT_DURATION, this); _glowTimer = 0.75f; }
void Hero::check_color(){ QGraphicsColorizeEffect* colEffect = new QGraphicsColorizeEffect; QGraphicsOpacityEffect* opacity = new QGraphicsOpacityEffect; if(is_invulnerable){ colEffect->setColor(Qt::magenta); graphics->setGraphicsEffect(colEffect); }else{ opacity->setOpacity(1); graphics->setGraphicsEffect(opacity); } }
QPixmap Icon::applyEffects() const { QPixmap gfx = pixmap; if (isColor && !qFuzzyIsNull(depth)) { QLabel w; QGraphicsColorizeEffect *effect = new QGraphicsColorizeEffect(); effect->setColor(color); effect->setStrength(depth); w.setPixmap(gfx); w.setGraphicsEffect(effect); gfx = w.grab(); } if (!qFuzzyIsNull(radius)) { QImage canvas(gfx.size(), QImage::Format_ARGB32_Premultiplied); QPainter painter(&canvas); painter.setCompositionMode(QPainter::CompositionMode_Source); painter.fillRect(gfx.rect(), Qt::transparent); painter.setPen(Qt::NoPen); painter.setBrush(QBrush(gfx)); painter.setRenderHint(QPainter::Antialiasing); painter.drawRoundedRect(gfx.rect(), radius, radius); painter.end(); gfx = QPixmap::fromImage(canvas); } if (blur > 1.0) { QLabel w; QGraphicsBlurEffect *effect = new QGraphicsBlurEffect(); effect->setBlurRadius(blur); effect->setBlurHints(QGraphicsBlurEffect::QualityHint); w.setPixmap(gfx); w.setGraphicsEffect(effect); gfx = w.grab(); } if (flipX) { gfx = gfx.transformed(QTransform().scale(-1, 1)); } if (flipY) { gfx = gfx.transformed(QTransform().scale(1, -1)); } if (angle != 0) { gfx = gfx.transformed(QTransform().rotate(angle)); } return gfx; }
void ClickableLabel::setGray(bool grayedOut) { if(grayedOut) { QGraphicsColorizeEffect *grayEffect = new QGraphicsColorizeEffect(this); grayEffect->setColor(QColor(0,0,0)); this->setGraphicsEffect(grayEffect); m_gray = false; } else { this->setGraphicsEffect(0); m_gray = false; } }
void tst_QGraphicsEffect::colorize() { if (qApp->desktop()->depth() < 24) { QSKIP("Test only works on 32 bit displays", SkipAll); return; } QGraphicsScene scene(0, 0, 100, 100); QGraphicsRectItem *item = scene.addRect(0, 0, 50, 50); item->setPen(Qt::NoPen); item->setBrush(QColor(122, 193, 66)); // Qt light green QGraphicsColorizeEffect *effect = new QGraphicsColorizeEffect; effect->setColor(QColor(102, 153, 51)); // Qt dark green item->setGraphicsEffect(effect); QPainter painter; QImage image(100, 100, QImage::Format_ARGB32_Premultiplied); image.fill(0); painter.begin(&image); painter.setRenderHint(QPainter::Antialiasing); scene.render(&painter); painter.end(); QCOMPARE(image.pixel(10, 10), qRgb(191, 212, 169)); effect->setStrength(0.5); image.fill(0); painter.begin(&image); painter.setRenderHint(QPainter::Antialiasing); scene.render(&painter); painter.end(); QCOMPARE(image.pixel(10, 10), qRgb(156, 203, 117)); effect->setStrength(0.0); image.fill(0); painter.begin(&image); painter.setRenderHint(QPainter::Antialiasing); scene.render(&painter); painter.end(); QCOMPARE(image.pixel(10, 10), qRgb(122, 193, 66)); }
QVariant Pixmap::itemChange(GraphicsItemChange change, const QVariant &value){ if(change == ItemSelectedHasChanged){ if(value.toBool()){ QGraphicsColorizeEffect *effect = new QGraphicsColorizeEffect(this); effect->setColor(QColor(0xCC, 0x00, 0x00)); setGraphicsEffect(effect); }else setGraphicsEffect(NULL); emit selected_changed(); }else if(change == ItemEnabledHasChanged){ emit enable_changed(); } return QGraphicsObject::itemChange(change, value); }
QImage BrushPainter::applyColor(Brush brush) { qDebug()<< "apply color"; QImage res(brush.img.size()*2, QImage::Format_RGBA8888_Premultiplied); res.fill(Qt::transparent); QPainter paint; paint.begin(&res); paint.setOpacity((double)brush.opacity/100); paint.drawImage(brush.img.width()/2,brush.img.height()/2, brush.img); paint.end(); QGraphicsColorizeEffect *effect; effect = new QGraphicsColorizeEffect(); effect->setColor(brush.color_main); res = applyEffectToImage(res, effect); // res = applyEffectToImage(res, effect); return res; }
void QGraphicsGlowEffect::draw(QPainter* painter) { QPoint offset; QPixmap source = sourcePixmap(Qt::LogicalCoordinates, &offset); source = source.scaled(source.size().width()/source.devicePixelRatio(), source.size().height()/source.devicePixelRatio()); QPixmap glow; QGraphicsColorizeEffect *colorize = new QGraphicsColorizeEffect; colorize->setColor(_color); colorize->setStrength(1); glow = applyEffectToPixmap(source, colorize, 0); QGraphicsBlurEffect *blur = new QGraphicsBlurEffect; blur->setBlurRadius(_blurRadius); glow = applyEffectToPixmap(glow, blur, _extent); for (int i = 0; i < _strength; i++) painter->drawPixmap(offset - QPoint(_extent, _extent), glow); drawSource(painter); }
QImage BrushPainter::drawBrush(Brush &brush, QSize size) { QImage img(size, QImage::Format_RGBA8888); QGraphicsColorizeEffect *effect; QGraphicsBlurEffect *blur; effect = new QGraphicsColorizeEffect(); blur = new QGraphicsBlurEffect(); effect->setColor(brush.color_main); blur->setBlurRadius(brush.blur); QImage drawImg = applyEffectToImage(brush.img,effect); int width = drawImg.scaled(brush.size, brush.size, Qt::KeepAspectRatio).width(); if(width < 4) width = 4; QBrush qBrush; QPainter paint(&img); paint.setBrush(qBrush); QImage resultImg; QTransform transformation; paint.setOpacity((double)brush.opacity/100); int n = (size.width() - 100 ) / (width/4); n--; for(int j = 0; j <= brush.count; j++) for(int i = 0; i < n; i++) { int b = brush.size_delta/2 - rand() % ((int)brush.size_delta + 1); int m = brush.dispers/2 - rand() % ((int)brush.dispers + 1); // transformation.rotate(brush.angle_delta/2 - rand() % ((int)brush.angle_delta + 1)); resultImg = drawImg.scaled(brush.size + b, brush.size + b, Qt::KeepAspectRatio).transformed(transformation); qBrush.setTextureImage(resultImg); paint.drawImage(i*resultImg.width()/4,size.height()/2 - resultImg.height()/2 + m,resultImg); } // paint.fillRect(0,0,200,200,QBrush(brush.color_main, Qt::SolidPattern)); bool bEnd = paint.end(); return applyEffectToImage(img, blur); }
void NodeEditDialog::checkErrors() { qDebug()<< " NodeEditDialog::checkErrors()" ; QString userLabel = ui.labelEdit->text(); userLabel = userLabel.simplified(); ui.labelEdit->setText(userLabel); if ( ui.labelEdit->text().isEmpty()) { qDebug() << "empty label!"; QGraphicsColorizeEffect *effect = new QGraphicsColorizeEffect; effect->setColor(QColor("red")); ui.labelEdit->setGraphicsEffect(effect); //(ui.buttonBox) -> button (QDialogButtonBox::Ok) -> setEnabled(false); } else { ui.labelEdit->setGraphicsEffect(0); (ui.buttonBox)->button(QDialogButtonBox::Ok)->setEnabled(true); } gatherData(); }
int SvgView::renderText(const QStringRef &text) { scene->clear(); QRectF currentMarginsRect; if (changeMargins) currentMarginsRect = QRectF(QPointF(sheetRect.topRight().x() - marginsRect.topRight().x(), marginsRect.topLeft().y()), QPointF(sheetRect.bottomRight().x() - marginsRect.bottomLeft().x(), marginsRect.bottomRight().y())); else currentMarginsRect = marginsRect; scene->addRect(sheetRect); scene->addRect(currentMarginsRect, QPen(Qt::darkGray)); QPointF cursor(currentMarginsRect.x(), currentMarginsRect.y()); int endOfSheet = 0; for (QChar symbol : text) { qreal letterWidth = fontSize * dpmm / 4, letterHeight = fontSize * dpmm; //don't try to go beyond the right margin if (cursor.x() > (currentMarginsRect.x() + currentMarginsRect.width() - letterWidth)) { if (symbol.isSpace()) //ignore whitespace-symbols at the end of the current line continue; cursor += QPointF(currentMarginsRect.x() - cursor.x(), letterHeight + lineSpacing * dpmm); } //stop rendering when you reach the end of sheet if (cursor.y() > currentMarginsRect.bottomRight().y() - letterHeight) return endOfSheet; if (symbol.isSpace()) { switch (symbol.toLatin1()) { case '\t': cursor += QPointF(letterWidth * spacesInTab, 0.0); endOfSheet++; continue; case '\n': cursor += QPointF(currentMarginsRect.x() - cursor.x(), letterHeight + lineSpacing * dpmm); endOfSheet++; continue; default: cursor += QPointF(letterWidth, 0.0); endOfSheet++; continue; } } if (!font.contains(symbol)) { cursor += QPointF(letterWidth, 0.0); endOfSheet++; continue; } QGraphicsSvgItem *letter = new QGraphicsSvgItem(font.values(symbol).at(qrand() % font.values(symbol).size())); if (useCustomFontColor) { QGraphicsColorizeEffect *colorEffect = new QGraphicsColorizeEffect(); colorEffect->setColor(fontColor); letter->setGraphicsEffect(colorEffect); } letter->setScale(letterHeight / letter->boundingRect().height()); letterWidth = letter->boundingRect().width() * letter->scale() + letterSpacing * dpmm; letter->setPos(cursor); cursor += QPointF(letterWidth, 0.0); scene->addItem(letter); endOfSheet++; } return endOfSheet; }
void VisualMatrix::initSprite() { _sprite = new QGraphicsWidget(); QGraphicsItem* item; QGraphicsWidget* widget; QGraphicsRectItem* rect; QGraphicsColorizeEffect* effect; QGraphicsSimpleTextItem* text; QGraphicsProxyWidget* proxy; QLabel* label; QFont font; // Frame { item = new QGraphicsPixmapItem(LoaderThread::instance()->getCachedPixmap(IMAGE_FRAME_BG)); item->setParentItem(_sprite); item->setPos(0.0f, 0.0f); } // Frame { item = new QGraphicsPixmapItem(LoaderThread::instance()->getCachedPixmap(IMAGE_FRAME_MG)); item->setParentItem(_sprite); item->setPos(0.0f, 0.0f); } // Avatar { widget = new QGraphicsWidget(); widget->resize(BLOCK_LARGE * 10, BLOCK_LARGE * 20); widget->setFlags(QGraphicsItem::ItemClipsChildrenToShape); widget->setParentItem(_sprite); widget->setPos(170.0f, 50.0f); item = new QGraphicsPixmapItem(); item->setParentItem(widget); item->setPos(((BLOCK_LARGE * 10) - (320.0f / 0.75f)) * 0.5f, (BLOCK_LARGE * 20) - 320.0f); _avatar = widget; } // Help { widget = new QGraphicsWidget(); widget->resize(BLOCK_LARGE * 10, BLOCK_LARGE * 20); widget->setFlags(QGraphicsItem::ItemClipsChildrenToShape); widget->setParentItem(_sprite); widget->setPos(170.0f, 50.0f); rect = new QGraphicsRectItem(0.0f, 0.0f, BLOCK_LARGE * 10, BLOCK_LARGE * 20); rect->setBrush(QBrush(QColor::fromRgb(0x00, 0x00, 0x00, 0xC0))); rect->setParentItem(widget); font = QApplication::font(); font.setFamily("Arial"); font.setPixelSize(16); font.setWeight(QFont::Bold); font.setStretch(80); text = new QGraphicsSimpleTextItem(tr("Slide left and right: Move.")); text->setBrush(QColor::fromRgb(0xC0, 0xC0, 0xC0)); text->setFont(font); text->setParentItem(widget); text->setPos(((BLOCK_LARGE * 10) - text->boundingRect().width()) * 0.5f, 217.0f - 6.0f); text = new QGraphicsSimpleTextItem(tr("Swipe up: Hold. Swipe down: Drop.")); text->setBrush(QColor::fromRgb(0xC0, 0xC0, 0xC0)); text->setFont(font); text->setParentItem(widget); text->setPos(((BLOCK_LARGE * 10) - text->boundingRect().width()) * 0.5f, 237.0f - 6.0f); text = new QGraphicsSimpleTextItem(tr("Pull back, and make circles: Rotate.")); text->setBrush(QColor::fromRgb(0xC0, 0xC0, 0xC0)); text->setFont(font); text->setParentItem(widget); text->setPos(((BLOCK_LARGE * 10) - text->boundingRect().width()) * 0.5f, 257.0f - 6.0f); // widget->setVisible(false); _sprite_help = widget; } // Lines { rect = new QGraphicsRectItem(120.0f - 1.0f, 220.0f - 1.0f, 8.0f + 2.0f, 144.0f + 2.0f); rect->setBrush(QBrush(LoaderThread::instance()->getCachedPixmap(IMAGE_LINES_PROGRESS))); rect->setParentItem(_sprite); _sprite_lines = rect; } // Frame { item = new QGraphicsPixmapItem(LoaderThread::instance()->getCachedPixmap(IMAGE_FRAME_FG)); item->setParentItem(_sprite); item->setPos(0.0f, 0.0f); } // Field { widget = new QGraphicsWidget(); widget->resize(BLOCK_LARGE * 10, BLOCK_LARGE * 20); widget->setFlags(QGraphicsItem::ItemClipsChildrenToShape); widget->setParentItem(_sprite); widget->setPos(170.0f, 50.0f); _sprite_field = widget; _sprite_space.fill(NULL, _rows * _cols); } // Ghost { widget = new QGraphicsWidget(); widget->resize(BLOCK_LARGE * 4, BLOCK_LARGE * 4); widget->setParentItem(_sprite_field); widget->setPos(BLOCK_LARGE * getShapePositionInField(18, 3)); for (int i = 0; i < 4; ++i) { item = new QGraphicsPixmapItem(LoaderThread::instance()->getCachedPixmap(IMAGE_BLOCK_GHOST)); item->setParentItem(widget); } _sprite_ghost = widget; } // Tetromino { widget = new QGraphicsWidget(); widget->resize(BLOCK_LARGE * 4, BLOCK_LARGE * 4); widget->setParentItem(_sprite_field); widget->setPos(BLOCK_LARGE * getShapePositionInField(18, 3)); widget->setZValue(1.0f); effect = new QGraphicsColorizeEffect(widget); effect->setColor(QColor::fromRgb(0xFF, 0xFF, 0xFF)); effect->setStrength(0.0f); widget->setGraphicsEffect(effect); for (int i = 0; i < 4; ++i) { item = new QGraphicsPixmapItem(); item->setParentItem(widget); } _sprite_tetromino = widget; } // Hold { widget = new QGraphicsWidget(); widget->resize(BLOCK_LARGE * 4, BLOCK_LARGE * 2); widget->setScale(BLOCK_SMALL / BLOCK_LARGE); widget->setParentItem(_sprite); widget->setPos(56.0f, 108.0f + BLOCK_SMALL); effect = new QGraphicsColorizeEffect(widget); effect->setColor(QColor::fromRgb(0xFF, 0xFF, 0xFF)); effect->setStrength(0.0f); widget->setGraphicsEffect(effect); for (int i = 0; i < 4; ++i) { item = new QGraphicsPixmapItem(); item->setParentItem(widget); } _sprite_hold = widget; } // Hold fail { item = new QGraphicsPixmapItem(LoaderThread::instance()->getCachedPixmap(IMAGE_FAIL)); item->setScale(BLOCK_SMALL / BLOCK_LARGE); item->setParentItem(_sprite); item->setPos(56.0f + (BLOCK_SMALL * 3), 108.0f + (BLOCK_SMALL * 3)); item->setVisible(false); _sprite_holdFail = item; } // Next { widget = new QGraphicsWidget(); widget->resize(BLOCK_LARGE * 4, BLOCK_LARGE * 2); widget->setScale(BLOCK_SMALL / BLOCK_LARGE); widget->setParentItem(_sprite); widget->setPos(460.0f, 108.0f + BLOCK_SMALL); effect = new QGraphicsColorizeEffect(widget); effect->setColor(QColor::fromRgb(0xFF, 0xFF, 0xFF)); effect->setStrength(0.0f); widget->setGraphicsEffect(effect); for (int i = 0; i < 4; ++i) { item = new QGraphicsPixmapItem(); item->setParentItem(widget); } _sprite_next << widget; } // Next { widget = new QGraphicsWidget(); widget->resize(BLOCK_LARGE * 4, BLOCK_LARGE * 2); widget->setScale(BLOCK_SMALL / BLOCK_LARGE); widget->setParentItem(_sprite); widget->setPos(460.0f, 228.0f + BLOCK_SMALL); effect = new QGraphicsColorizeEffect(widget); effect->setColor(QColor::fromRgb(0xFF, 0xFF, 0xFF)); effect->setStrength(0.0f); widget->setGraphicsEffect(effect); for (int i = 0; i < 4; ++i) { item = new QGraphicsPixmapItem(); item->setParentItem(widget); } _sprite_next << widget; } // Next { widget = new QGraphicsWidget(); widget->resize(BLOCK_LARGE * 4, BLOCK_LARGE * 2); widget->setScale(BLOCK_SMALL / BLOCK_LARGE); widget->setParentItem(_sprite); widget->setPos(460.0f, 292.0f + BLOCK_SMALL); effect = new QGraphicsColorizeEffect(widget); effect->setColor(QColor::fromRgb(0xFF, 0xFF, 0xFF)); effect->setStrength(0.0f); widget->setGraphicsEffect(effect); for (int i = 0; i < 4; ++i) { item = new QGraphicsPixmapItem(); item->setParentItem(widget); } _sprite_next << widget; } // Font { font = QApplication::font(); font.setCapitalization(QFont::AllUppercase); } // Hold { text = new QGraphicsSimpleTextItem(tr("Hold")); text->setBrush(QColor::fromRgb(0x00, 0x00, 0x00)); text->setFont(font); text->setParentItem(_sprite); text->setPos(56.0f, 80.0f - 6.0f); } // Next { text = new QGraphicsSimpleTextItem(tr("Next")); text->setBrush(QColor::fromRgb(0x00, 0x00, 0x00)); text->setFont(font); text->setParentItem(_sprite); text->setPos(526.0f - text->boundingRect().width(), 80.0f - 6.0f); } // Level { text = new QGraphicsSimpleTextItem(tr("Level")); text->setBrush(QColor::fromRgb(0x00, 0x00, 0x00)); text->setFont(font); text->setParentItem(_sprite); text->setPos(56.0f, 316.0f - 6.0f); } // Level { label = new QLabel(); label->resize(48, 24); label->setStyleSheet("background-color: transparent; color: #FFFFFF;"); label->setAlignment(Qt::AlignTop | Qt::AlignLeft); proxy = new QGraphicsProxyWidget(); proxy->setParentItem(_sprite); proxy->setWidget(label); proxy->setPos(56.0f, 344.0f - 6.0f); _sprite_level = label; } // Score { text = new QGraphicsSimpleTextItem(tr("Score")); text->setBrush(QColor::fromRgb(0x00, 0x00, 0x00)); text->setFont(font); text->setParentItem(_sprite); text->setPos(176.0f, 564.0f - 6.0f); } // Score { label = new QLabel(); label->resize(148, 24); label->setStyleSheet("background-color: transparent; color: #FFFFFF;"); label->setAlignment(Qt::AlignTop | Qt::AlignRight); proxy = new QGraphicsProxyWidget(); proxy->setParentItem(_sprite); proxy->setWidget(label); proxy->setPos(256.0f, 564.0f - 6.0f); _sprite_score = label; } // Countdown { widget = new QGraphicsWidget(); widget->resize(BLOCK_LARGE * 10, BLOCK_LARGE * 20); widget->setFlags(QGraphicsItem::ItemClipsChildrenToShape); widget->setParentItem(_sprite); widget->setPos(170.0f, 50.0f); rect = new QGraphicsRectItem(0.0f, 0.0f, BLOCK_LARGE * 10, BLOCK_LARGE * 20); rect->setBrush(QBrush(QColor::fromRgb(0x00, 0x00, 0x00, 0xC0))); rect->setParentItem(widget); item = new QGraphicsPixmapItem(LoaderThread::instance()->getCachedPixmap(IMAGE_COUNT[0])); item->setParentItem(widget); item->setPos(77.0f, 197.0f); item->setVisible(false); _sprite_count << item; item = new QGraphicsPixmapItem(LoaderThread::instance()->getCachedPixmap(IMAGE_COUNT[1])); item->setParentItem(widget); item->setPos(77.0f, 197.0f); item->setVisible(false); _sprite_count << item; item = new QGraphicsPixmapItem(LoaderThread::instance()->getCachedPixmap(IMAGE_COUNT[2])); item->setParentItem(widget); item->setPos(77.0f, 197.0f); item->setVisible(false); _sprite_count << item; widget->setVisible(false); _sprite_countdown = widget; } // Game over { widget = new QGraphicsWidget(); widget->resize(BLOCK_LARGE * 10, BLOCK_LARGE * 20); widget->setFlags(QGraphicsItem::ItemClipsChildrenToShape); widget->setParentItem(_sprite); widget->setPos(170.0f, 50.0f); widget->setZValue(8.0f); rect = new QGraphicsRectItem(0.0f, 0.0f, BLOCK_LARGE * 10, BLOCK_LARGE * 20); rect->setBrush(QBrush(QColor::fromRgb(0x00, 0x00, 0x00, 0xC0))); rect->setParentItem(widget); item = new QGraphicsPixmapItem(LoaderThread::instance()->getCachedPixmap(IMAGE_OVER)); item->setParentItem(widget); item->setPos(4.0f, 172.0f); rect = new QGraphicsRectItem(0.0f, 0.0f, BLOCK_LARGE * 10, BLOCK_LARGE * 20); rect->setBrush(QBrush(QColor::fromRgb(0xFF, 0xFF, 0xFF))); rect->setParentItem(widget); _sprite_overFlash = rect; widget->setVisible(false); _sprite_over = widget; } }