// Tests scale mode with an additional copy for transparency. This will happen // if we have a scaled textbox, for example. WebKit will create a new // transparency layer, draw the text field, then draw the text into it, then // composite this down with an opacity. TEST(TransparencyWin, ScaleTransparency) { // Create an opaque white buffer. OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), 1)); FloatRect fullBuffer(0, 0, 16, 16); src->context()->fillRect(fullBuffer, Color::white); // Make another layer (which duplicates how WebKit will make this). We fill // the top half with red, and have the layer be 50% opaque. src->context()->beginTransparencyLayer(0.5); FloatRect topHalf(0, 0, 16, 8); src->context()->fillRect(topHalf, Color(0xFFFF0000)); // Scale by 2x. src->context()->save(); AffineTransform scale; scale.scale(2.0); src->context()->concatCTM(scale); // Make a layer inset two pixels (because of scaling, this is 2->14). And // will it with 50% black. { TransparencyWin helper; helper.init(src->context(), TransparencyWin::OpaqueCompositeLayer, TransparencyWin::ScaleTransform, IntRect(1, 1, 6, 6)); helper.context()->fillRect(helper.drawRect(), Color(0x7f000000)); clearTopLayerAlphaChannel(helper.context()); helper.composite(); } // Finish the layer. src->context()->restore(); src->context()->endLayer(); Color redBackground(0xFFFF8080); // 50% red composited on white. EXPECT_EQ(redBackground, getPixelAt(src->context(), 0, 0)); EXPECT_EQ(redBackground, getPixelAt(src->context(), 1, 1)); // Top half (minus two pixel border) should be 50% gray atop opaque // red = 0xFF804141. Then that's composited with 50% transparency on solid // white = 0xFFC0A1A1. Color darkRed(0xFFBF8080); EXPECT_EQ(darkRed, getPixelAt(src->context(), 2, 2)); EXPECT_EQ(darkRed, getPixelAt(src->context(), 7, 7)); // Bottom half (minus a two pixel border) should be a layer with 5% gray // with another 50% opacity composited atop white. Color darkWhite(0xFFBFBFBF); EXPECT_EQ(darkWhite, getPixelAt(src->context(), 8, 8)); EXPECT_EQ(darkWhite, getPixelAt(src->context(), 13, 13)); Color white(0xFFFFFFFF); // Background in the lower-right. EXPECT_EQ(white, getPixelAt(src->context(), 14, 14)); EXPECT_EQ(white, getPixelAt(src->context(), 15, 15)); }
//! [Quoting ModelView Tutorial] // mymodel.cpp QVariant MyModel::data(const QModelIndex &index, int role) const { int row = index.row(); int col = index.column(); // generate a log message when this method gets called qDebug() << QString("row %1, col%2, role %3") .arg(row).arg(col).arg(role); switch(role){ case Qt::DisplayRole: if (row == 0 && col == 1) return QString("<--left"); if (row == 1 && col == 1) return QString("right-->"); return QString("Row%1, Column%2") .arg(row + 1) .arg(col +1); break; case Qt::FontRole: if (row == 0 && col == 0) //change font only for cell(0,0) { QFont boldFont; boldFont.setBold(true); return boldFont; } break; case Qt::BackgroundRole: if (row == 1 && col == 2) //change background only for cell(1,2) { QBrush redBackground(Qt::red); return redBackground; } break; case Qt::TextAlignmentRole: if (row == 1 && col == 1) //change text alignment only for cell(1,1) { return Qt::AlignRight + Qt::AlignVCenter; } break; case Qt::CheckStateRole: if (row == 1 && col == 0) //add a checkbox to cell(1,0) { return Qt::Checked; } } return QVariant(); }