本文整理汇总了C++中CustomEffect类的典型用法代码示例。如果您正苦于以下问题:C++ CustomEffect类的具体用法?C++ CustomEffect怎么用?C++ CustomEffect使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CustomEffect类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: view
void tst_QGraphicsEffect::itemHasNoContents()
{
QGraphicsRectItem *parent = new QGraphicsRectItem;
parent->setFlag(QGraphicsItem::ItemHasNoContents);
MyGraphicsItem *child = new MyGraphicsItem;
child->setParentItem(parent);
child->resize(200, 200);
QGraphicsScene scene;
scene.addItem(parent);
QGraphicsView view(&scene);
view.show();
QTest::qWaitForWindowShown(&view);
#ifdef Q_OS_MAC
if (QSysInfo::MacintoshVersion == QSysInfo::MV_LION) {
QEXPECT_FAIL("", "QTBUG-26858", Abort);
}
#endif
QTRY_COMPARE(child->nbPaint, 1);
CustomEffect *effect = new CustomEffect;
parent->setGraphicsEffect(effect);
QTRY_COMPARE(effect->numRepaints, 1);
for (int i = 0; i < 3; ++i) {
effect->reset();
effect->update();
QTRY_COMPARE(effect->numRepaints, 1);
}
}
示例2: view
void tst_QGraphicsEffect::itemHasNoContents()
{
QGraphicsRectItem *parent = new QGraphicsRectItem;
parent->setFlag(QGraphicsItem::ItemHasNoContents);
MyGraphicsItem *child = new MyGraphicsItem;
child->setParentItem(parent);
child->resize(200, 200);
QGraphicsScene scene;
scene.addItem(parent);
QGraphicsView view(&scene);
view.show();
QTest::qWaitForWindowShown(&view);
QTRY_COMPARE(child->nbPaint, 1);
CustomEffect *effect = new CustomEffect;
parent->setGraphicsEffect(effect);
QTRY_COMPARE(effect->numRepaints, 1);
for (int i = 0; i < 3; ++i) {
effect->reset();
effect->update();
QTRY_COMPARE(effect->numRepaints, 1);
}
}
示例3: setEnabled
void tst_QGraphicsEffect::setEnabled()
{
CustomEffect effect;
QVERIFY(effect.isEnabled());
effect.setEnabled(false);
QVERIFY(!effect.isEnabled());
}
示例4: boundingRectFor
void tst_QGraphicsEffect::boundingRectFor()
{
CustomEffect effect;
int margin = effect.margin();
const QRectF source(0, 0, 100, 100);
QCOMPARE(effect.boundingRectFor(source), source.adjusted(-margin, -margin, margin, margin));
effect.setMargin(margin = 20);
QCOMPARE(effect.boundingRectFor(source), source.adjusted(-margin, -margin, margin, margin));
}
示例5: main
int
main (int argc, char **argv)
{
cairo_t *cr;
cairo_surface_t *dst, *src;
CustomEffect *effect;
PixelShader *shader;
int stride = width * 4;
Rect bounds = Rect (0, 0, width, height);
gpointer data;
bool status;
if (argc < 2) {
printf ("usage: %s SHADERFILE\n", argv[0]);
return 1;
}
gtk_init (&argc, &argv);
runtime_init_desktop ();
data = g_malloc0 (height * stride);
dst = cairo_image_surface_create_for_data ((unsigned char *) data,
CAIRO_FORMAT_ARGB32,
width, height, stride);
src = cairo_surface_create_similar (dst,
CAIRO_CONTENT_COLOR_ALPHA,
width, height);
cr = cairo_create (dst);
effect = new CustomEffect ();
shader = new PixelShader ();
shader->SetTokensFromPath (argv[1]);
effect->SetPixelShader (shader);
status = effect->Render (cr, src, NULL, 0, 0, width, height);
effect->unref ();
shader->unref ();
cairo_destroy (cr);
cairo_surface_destroy (src);
cairo_surface_destroy (dst);
g_free (data);
runtime_shutdown ();
return status != true;
}
示例6: CustomItem
void tst_QGraphicsEffect::draw()
{
QGraphicsScene scene;
CustomItem *item = new CustomItem(0, 0, 100, 100);
scene.addItem(item);
QGraphicsView view(&scene);
view.show();
QTest::qWaitForWindowShown(&view);
QTRY_VERIFY(item->numRepaints > 0);
item->reset();
// Make sure installing the effect triggers a repaint.
CustomEffect *effect = new CustomEffect;
item->setGraphicsEffect(effect);
QTRY_COMPARE(effect->numRepaints, 1);
QTRY_COMPARE(item->numRepaints, 1);
// Make sure QPainter* and QStyleOptionGraphicsItem* stays persistent
// during QGraphicsEffect::draw/QGraphicsItem::paint.
QVERIFY(effect->m_painter);
QCOMPARE(effect->m_painter, item->m_painter);
QCOMPARE(effect->m_styleOption, item->m_styleOption);
// Make sure QGraphicsEffect::source is persistent.
QCOMPARE(effect->m_source, effect->source());
effect->reset();
item->reset();
// Make sure updating the source triggers a repaint.
item->update();
QTRY_COMPARE(effect->numRepaints, 1);
QTRY_COMPARE(item->numRepaints, 1);
QVERIFY(effect->m_sourceChangedFlags & QGraphicsEffect::SourceInvalidated);
effect->reset();
item->reset();
// Make sure changing the effect's bounding rect triggers a repaint.
effect->setMargin(20);
QTRY_COMPARE(effect->numRepaints, 1);
QTRY_COMPARE(item->numRepaints, 1);
effect->reset();
item->reset();
// Make sure change the item's bounding rect triggers a repaint.
item->setRect(0, 0, 50, 50);
QTRY_COMPARE(effect->numRepaints, 1);
QTRY_COMPARE(item->numRepaints, 1);
QVERIFY(effect->m_sourceChangedFlags & QGraphicsEffect::SourceBoundingRectChanged);
effect->reset();
item->reset();
// Make sure the effect is the one to issue a repaint of the item.
effect->doNothingInDraw = true;
item->update();
QTRY_COMPARE(effect->numRepaints, 1);
QCOMPARE(item->numRepaints, 0);
effect->doNothingInDraw = false;
effect->reset();
item->reset();
// Make sure we update the source when disabling/enabling the effect.
effect->setEnabled(false);
QTest::qWait(50);
QCOMPARE(effect->numRepaints, 0);
QCOMPARE(item->numRepaints, 1);
effect->reset();
item->reset();
effect->setEnabled(true);
QTRY_COMPARE(effect->numRepaints, 1);
QTRY_COMPARE(item->numRepaints, 1);
effect->reset();
item->reset();
// Effect is already enabled; nothing should happen.
effect->setEnabled(true);
QTest::qWait(50);
QCOMPARE(effect->numRepaints, 0);
QCOMPARE(item->numRepaints, 0);
// Make sure uninstalling an effect triggers a repaint.
QPointer<CustomEffect> ptr = effect;
item->setGraphicsEffect(0);
QVERIFY(!ptr);
QTRY_COMPARE(item->numRepaints, 1);
}
示例7: childRect
void tst_QGraphicsEffect::boundingRect2()
{
CustomEffect *effect = new CustomEffect;
QGraphicsRectItem *root = new QGraphicsRectItem;
root->setGraphicsEffect(effect);
QGraphicsRectItem *child = new QGraphicsRectItem;
QRectF childRect(0, 0, 100, 100);
child->setFlag(QGraphicsItem::ItemClipsChildrenToShape);
child->setRect(childRect);
child->setParentItem(root);
QGraphicsRectItem *grandChild = new QGraphicsRectItem;
QRectF grandChildRect(0, 0, 200, 200);
grandChild->setRect(grandChildRect);
grandChild->setParentItem(child);
// Make sure the effect's bounding rect is clipped to the child's bounding rect.
QCOMPARE(effect->boundingRect(), effect->boundingRectFor(childRect));
// Disable ItemClipsChildrenToShape; effect's bounding rect is no longer clipped.
child->setFlag(QGraphicsItem::ItemClipsChildrenToShape, false);
QCOMPARE(effect->boundingRect(), effect->boundingRectFor(childRect | grandChildRect));
// Add root item to a scene, do the same tests as above. Results should be the same.
QGraphicsScene scene;
scene.addItem(root);
child->setFlag(QGraphicsItem::ItemClipsChildrenToShape);
QCOMPARE(effect->boundingRect(), effect->boundingRectFor(childRect));
child->setFlag(QGraphicsItem::ItemClipsChildrenToShape, false);
QCOMPARE(effect->boundingRect(), effect->boundingRectFor(childRect | grandChildRect));
// Now add the scene to a view, results should be the same.
QGraphicsView view(&scene);
child->setFlag(QGraphicsItem::ItemClipsChildrenToShape);
QCOMPARE(effect->boundingRect(), effect->boundingRectFor(childRect));
child->setFlag(QGraphicsItem::ItemClipsChildrenToShape, false);
QCOMPARE(effect->boundingRect(), effect->boundingRectFor(childRect | grandChildRect));
CustomEffect *childEffect = new CustomEffect;
child->setGraphicsEffect(childEffect);
QCOMPARE(effect->boundingRect(), effect->boundingRectFor(childEffect->boundingRectFor(childRect | grandChildRect)));
child->setGraphicsEffect(0);
QCOMPARE(effect->boundingRect(), effect->boundingRectFor(childRect | grandChildRect));
}
示例8: QCOMPARE
void tst_QGraphicsEffect::boundingRect()
{
// No source; empty bounding rect.
CustomEffect *effect = new CustomEffect;
QCOMPARE(effect->boundingRect(), QRectF());
// Install effect on QGraphicsItem.
QRectF itemRect(0, 0, 100, 100);
QGraphicsRectItem *item = new QGraphicsRectItem;
item->setRect(itemRect);
item->setGraphicsEffect(effect);
int margin = effect->margin();
QCOMPARE(effect->boundingRect(), itemRect.adjusted(-margin, -margin, margin, margin));
QCOMPARE(effect->boundingRect(), effect->boundingRectFor(itemRect));
// Make sure disabling/enabling the effect doesn't change the bounding rect.
effect->setEnabled(false);
QCOMPARE(effect->boundingRect(), itemRect.adjusted(-margin, -margin, margin, margin));
QCOMPARE(effect->boundingRect(), effect->boundingRectFor(itemRect));
effect->setEnabled(true);
QCOMPARE(effect->boundingRect(), itemRect.adjusted(-margin, -margin, margin, margin));
QCOMPARE(effect->boundingRect(), effect->boundingRectFor(itemRect));
// Change effect margins.
effect->setMargin(margin = 20);
QCOMPARE(effect->boundingRect(), itemRect.adjusted(-margin, -margin, margin, margin));
QCOMPARE(effect->boundingRect(), effect->boundingRectFor(itemRect));
// Uninstall effect on QGraphicsItem.
QPointer<CustomEffect> ptr = effect;
item->setGraphicsEffect(0);
QVERIFY(!ptr);
delete item;
}