Changeset 846 for trunk/src/gui/painting/qdrawutil.cpp
- Timestamp:
- May 5, 2011, 5:36:53 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.7.2 (added) merged: 845 /branches/vendor/nokia/qt/current merged: 844 /branches/vendor/nokia/qt/4.6.3 removed
- Property svn:mergeinfo changed
-
trunk/src/gui/painting/qdrawutil.cpp
r769 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation (qt-info@nokia.com) … … 49 49 #include <qvarlengtharray.h> 50 50 #include <qmath.h> 51 #include <private/qstylehelper_p.h> 51 52 52 53 QT_BEGIN_NAMESPACE … … 1019 1020 #ifndef QT_NO_IMAGE_HEURISTIC_MASK 1020 1021 } else { // color pixmap, no mask 1021 QString k = QString::fromLatin1("$qt-drawitem-%1").arg(pm.cacheKey()); 1022 QString k = QLatin1Literal("$qt-drawitem") 1023 % HexString<qint64>(pm.cacheKey()); 1024 1022 1025 if (!QPixmapCache::find(k, pm)) { 1023 1026 pm = pm.createHeuristicMask(); … … 1082 1085 */ 1083 1086 1084 typedef QVarLengthArray<Q DrawPixmaps::Data, 16> QDrawPixmapsDataArray;1087 typedef QVarLengthArray<QPainter::PixmapFragment, 16> QPixmapFragmentsArray; 1085 1088 1086 1089 /*! … … 1103 1106 const QTileRules &rules, QDrawBorderPixmap::DrawingHints hints) 1104 1107 { 1105 Q DrawPixmaps::Datad;1108 QPainter::PixmapFragment d; 1106 1109 d.opacity = 1.0; 1107 1110 d.rotation = 0.0; 1108 1111 1109 Q DrawPixmapsDataArray opaqueData;1110 Q DrawPixmapsDataArray translucentData;1112 QPixmapFragmentsArray opaqueData; 1113 QPixmapFragmentsArray translucentData; 1111 1114 1112 1115 // source center … … 1138 1141 yTarget.resize(rows + 1); 1139 1142 1143 bool oldAA = painter->testRenderHint(QPainter::Antialiasing); 1144 if (painter->paintEngine()->type() != QPaintEngine::OpenGL 1145 && painter->paintEngine()->type() != QPaintEngine::OpenGL2 1146 && oldAA && painter->combinedTransform().type() != QTransform::TxNone) { 1147 painter->setRenderHint(QPainter::Antialiasing, false); 1148 } 1149 1140 1150 xTarget[0] = targetRect.left(); 1141 1151 xTarget[1] = targetCenterLeft; … … 1183 1193 // corners 1184 1194 if (targetMargins.top() > 0 && targetMargins.left() > 0 && sourceMargins.top() > 0 && sourceMargins.left() > 0) { // top left 1185 d.point.setX(0.5 * (xTarget[1] + xTarget[0])); 1186 d.point.setY(0.5 * (yTarget[1] + yTarget[0])); 1187 d.source = QRectF(sourceRect.left(), sourceRect.top(), sourceMargins.left(), sourceMargins.top()); 1188 d.scaleX = qreal(xTarget[1] - xTarget[0]) / d.source.width(); 1189 d.scaleY = qreal(yTarget[1] - yTarget[0]) / d.source.height(); 1195 d.x = (0.5 * (xTarget[1] + xTarget[0])); 1196 d.y = (0.5 * (yTarget[1] + yTarget[0])); 1197 d.sourceLeft = sourceRect.left(); 1198 d.sourceTop = sourceRect.top(); 1199 d.width = sourceMargins.left(); 1200 d.height = sourceMargins.top(); 1201 d.scaleX = qreal(xTarget[1] - xTarget[0]) / d.width; 1202 d.scaleY = qreal(yTarget[1] - yTarget[0]) / d.height; 1190 1203 if (hints & QDrawBorderPixmap::OpaqueTopLeft) 1191 1204 opaqueData.append(d); … … 1194 1207 } 1195 1208 if (targetMargins.top() > 0 && targetMargins.right() > 0 && sourceMargins.top() > 0 && sourceMargins.right() > 0) { // top right 1196 d.point.setX(0.5 * (xTarget[columns] + xTarget[columns - 1])); 1197 d.point.setY(0.5 * (yTarget[1] + yTarget[0])); 1198 d.source = QRectF(sourceCenterRight, sourceRect.top(), sourceMargins.right(), sourceMargins.top()); 1199 d.scaleX = qreal(xTarget[columns] - xTarget[columns - 1]) / d.source.width(); 1200 d.scaleY = qreal(yTarget[1] - yTarget[0]) / d.source.height(); 1209 d.x = (0.5 * (xTarget[columns] + xTarget[columns - 1])); 1210 d.y = (0.5 * (yTarget[1] + yTarget[0])); 1211 d.sourceLeft = sourceCenterRight; 1212 d.sourceTop = sourceRect.top(); 1213 d.width = sourceMargins.right(); 1214 d.height = sourceMargins.top(); 1215 d.scaleX = qreal(xTarget[columns] - xTarget[columns - 1]) / d.width; 1216 d.scaleY = qreal(yTarget[1] - yTarget[0]) / d.height; 1201 1217 if (hints & QDrawBorderPixmap::OpaqueTopRight) 1202 1218 opaqueData.append(d); … … 1205 1221 } 1206 1222 if (targetMargins.bottom() > 0 && targetMargins.left() > 0 && sourceMargins.bottom() > 0 && sourceMargins.left() > 0) { // bottom left 1207 d.point.setX(0.5 * (xTarget[1] + xTarget[0])); 1208 d.point.setY(0.5 * (yTarget[rows] + yTarget[rows - 1])); 1209 d.source = QRectF(sourceRect.left(), sourceCenterBottom, sourceMargins.left(), sourceMargins.bottom()); 1210 d.scaleX = qreal(xTarget[1] - xTarget[0]) / d.source.width(); 1211 d.scaleY = qreal(yTarget[rows] - yTarget[rows - 1]) / d.source.height(); 1223 d.x = (0.5 * (xTarget[1] + xTarget[0])); 1224 d.y =(0.5 * (yTarget[rows] + yTarget[rows - 1])); 1225 d.sourceLeft = sourceRect.left(); 1226 d.sourceTop = sourceCenterBottom; 1227 d.width = sourceMargins.left(); 1228 d.height = sourceMargins.bottom(); 1229 d.scaleX = qreal(xTarget[1] - xTarget[0]) / d.width; 1230 d.scaleY = qreal(yTarget[rows] - yTarget[rows - 1]) / d.height; 1212 1231 if (hints & QDrawBorderPixmap::OpaqueBottomLeft) 1213 1232 opaqueData.append(d); … … 1216 1235 } 1217 1236 if (targetMargins.bottom() > 0 && targetMargins.right() > 0 && sourceMargins.bottom() > 0 && sourceMargins.right() > 0) { // bottom right 1218 d.point.setX(0.5 * (xTarget[columns] + xTarget[columns - 1])); 1219 d.point.setY(0.5 * (yTarget[rows] + yTarget[rows - 1])); 1220 d.source = QRectF(sourceCenterRight, sourceCenterBottom, sourceMargins.right(), sourceMargins.bottom()); 1221 d.scaleX = qreal(xTarget[columns] - xTarget[columns - 1]) / d.source.width(); 1222 d.scaleY = qreal(yTarget[rows] - yTarget[rows - 1]) / d.source.height(); 1237 d.x = (0.5 * (xTarget[columns] + xTarget[columns - 1])); 1238 d.y = (0.5 * (yTarget[rows] + yTarget[rows - 1])); 1239 d.sourceLeft = sourceCenterRight; 1240 d.sourceTop = sourceCenterBottom; 1241 d.width = sourceMargins.right(); 1242 d.height = sourceMargins.bottom(); 1243 d.scaleX = qreal(xTarget[columns] - xTarget[columns - 1]) / d.width; 1244 d.scaleY = qreal(yTarget[rows] - yTarget[rows - 1]) / d.height; 1223 1245 if (hints & QDrawBorderPixmap::OpaqueBottomRight) 1224 1246 opaqueData.append(d); … … 1230 1252 if (targetCenterWidth > 0 && sourceCenterWidth > 0) { 1231 1253 if (targetMargins.top() > 0 && sourceMargins.top() > 0) { // top 1232 QDrawPixmapsDataArray &data = hints & QDrawBorderPixmap::OpaqueTop ? opaqueData : translucentData; 1233 d.source = QRectF(sourceCenterLeft, sourceRect.top(), sourceCenterWidth, sourceMargins.top()); 1234 d.point.setY(0.5 * (yTarget[1] + yTarget[0])); 1235 d.scaleX = dx / d.source.width(); 1236 d.scaleY = qreal(yTarget[1] - yTarget[0]) / d.source.height(); 1254 QPixmapFragmentsArray &data = hints & QDrawBorderPixmap::OpaqueTop ? opaqueData : translucentData; 1255 d.sourceLeft = sourceCenterLeft; 1256 d.sourceTop = sourceRect.top(); 1257 d.width = sourceCenterWidth; 1258 d.height = sourceMargins.top(); 1259 d.y = (0.5 * (yTarget[1] + yTarget[0])); 1260 d.scaleX = dx / d.width; 1261 d.scaleY = qreal(yTarget[1] - yTarget[0]) / d.height; 1237 1262 for (int i = 1; i < columns - 1; ++i) { 1238 d. point.setX(0.5 * (xTarget[i + 1] + xTarget[i]));1263 d.x = (0.5 * (xTarget[i + 1] + xTarget[i])); 1239 1264 data.append(d); 1240 1265 } 1241 1266 if (rules.horizontal == Qt::RepeatTile) 1242 data[data.size() - 1]. source.setWidth((xTarget[columns - 1] - xTarget[columns - 2]) / d.scaleX);1267 data[data.size() - 1].width = ((xTarget[columns - 1] - xTarget[columns - 2]) / d.scaleX); 1243 1268 } 1244 1269 if (targetMargins.bottom() > 0 && sourceMargins.bottom() > 0) { // bottom 1245 QDrawPixmapsDataArray &data = hints & QDrawBorderPixmap::OpaqueBottom ? opaqueData : translucentData; 1246 d.source = QRectF(sourceCenterLeft, sourceCenterBottom, sourceCenterWidth, sourceMargins.bottom());; 1247 d.point.setY(0.5 * (yTarget[rows] + yTarget[rows - 1])); 1248 d.scaleX = dx / d.source.width(); 1249 d.scaleY = qreal(yTarget[rows] - yTarget[rows - 1]) / d.source.height(); 1270 QPixmapFragmentsArray &data = hints & QDrawBorderPixmap::OpaqueBottom ? opaqueData : translucentData; 1271 d.sourceLeft = sourceCenterLeft; 1272 d.sourceTop = sourceCenterBottom; 1273 d.width = sourceCenterWidth; 1274 d.height = sourceMargins.bottom(); 1275 d.y = (0.5 * (yTarget[rows] + yTarget[rows - 1])); 1276 d.scaleX = dx / d.width; 1277 d.scaleY = qreal(yTarget[rows] - yTarget[rows - 1]) / d.height; 1250 1278 for (int i = 1; i < columns - 1; ++i) { 1251 d. point.setX(0.5 * (xTarget[i + 1] + xTarget[i]));1279 d.x = (0.5 * (xTarget[i + 1] + xTarget[i])); 1252 1280 data.append(d); 1253 1281 } 1254 1282 if (rules.horizontal == Qt::RepeatTile) 1255 data[data.size() - 1]. source.setWidth((xTarget[columns - 1] - xTarget[columns - 2]) / d.scaleX);1283 data[data.size() - 1].width = ((xTarget[columns - 1] - xTarget[columns - 2]) / d.scaleX); 1256 1284 } 1257 1285 } … … 1260 1288 if (targetCenterHeight > 0 && sourceCenterHeight > 0) { 1261 1289 if (targetMargins.left() > 0 && sourceMargins.left() > 0) { // left 1262 QDrawPixmapsDataArray &data = hints & QDrawBorderPixmap::OpaqueLeft ? opaqueData : translucentData; 1263 d.source = QRectF(sourceRect.left(), sourceCenterTop, sourceMargins.left(), sourceCenterHeight); 1264 d.point.setX(0.5 * (xTarget[1] + xTarget[0])); 1265 d.scaleX = qreal(xTarget[1] - xTarget[0]) / d.source.width(); 1266 d.scaleY = dy / d.source.height(); 1290 QPixmapFragmentsArray &data = hints & QDrawBorderPixmap::OpaqueLeft ? opaqueData : translucentData; 1291 d.sourceLeft = sourceRect.left(); 1292 d.sourceTop = sourceCenterTop; 1293 d.width = sourceMargins.left(); 1294 d.height = sourceCenterHeight; 1295 d.x = (0.5 * (xTarget[1] + xTarget[0])); 1296 d.scaleX = qreal(xTarget[1] - xTarget[0]) / d.width; 1297 d.scaleY = dy / d.height; 1267 1298 for (int i = 1; i < rows - 1; ++i) { 1268 d. point.setY(0.5 * (yTarget[i + 1] + yTarget[i]));1299 d.y = (0.5 * (yTarget[i + 1] + yTarget[i])); 1269 1300 data.append(d); 1270 1301 } 1271 1302 if (rules.vertical == Qt::RepeatTile) 1272 data[data.size() - 1]. source.setHeight((yTarget[rows - 1] - yTarget[rows - 2]) / d.scaleY);1303 data[data.size() - 1].height = ((yTarget[rows - 1] - yTarget[rows - 2]) / d.scaleY); 1273 1304 } 1274 1305 if (targetMargins.right() > 0 && sourceMargins.right() > 0) { // right 1275 QDrawPixmapsDataArray &data = hints & QDrawBorderPixmap::OpaqueRight ? opaqueData : translucentData; 1276 d.source = QRectF(sourceCenterRight, sourceCenterTop, sourceMargins.right(), sourceCenterHeight); 1277 d.point.setX(0.5 * (xTarget[columns] + xTarget[columns - 1])); 1278 d.scaleX = qreal(xTarget[columns] - xTarget[columns - 1]) / d.source.width(); 1279 d.scaleY = dy / d.source.height(); 1306 QPixmapFragmentsArray &data = hints & QDrawBorderPixmap::OpaqueRight ? opaqueData : translucentData; 1307 d.sourceLeft = sourceCenterRight; 1308 d.sourceTop = sourceCenterTop; 1309 d.width = sourceMargins.right(); 1310 d.height = sourceCenterHeight; 1311 d.x = (0.5 * (xTarget[columns] + xTarget[columns - 1])); 1312 d.scaleX = qreal(xTarget[columns] - xTarget[columns - 1]) / d.width; 1313 d.scaleY = dy / d.height; 1280 1314 for (int i = 1; i < rows - 1; ++i) { 1281 d. point.setY(0.5 * (yTarget[i + 1] + yTarget[i]));1315 d.y = (0.5 * (yTarget[i + 1] + yTarget[i])); 1282 1316 data.append(d); 1283 1317 } 1284 1318 if (rules.vertical == Qt::RepeatTile) 1285 data[data.size() - 1]. source.setHeight((yTarget[rows - 1] - yTarget[rows - 2]) / d.scaleY);1319 data[data.size() - 1].height = ((yTarget[rows - 1] - yTarget[rows - 2]) / d.scaleY); 1286 1320 } 1287 1321 } … … 1289 1323 // center 1290 1324 if (targetCenterWidth > 0 && targetCenterHeight > 0 && sourceCenterWidth > 0 && sourceCenterHeight > 0) { 1291 QDrawPixmapsDataArray &data = hints & QDrawBorderPixmap::OpaqueCenter ? opaqueData : translucentData; 1292 d.source = QRectF(sourceCenterLeft, sourceCenterTop, sourceCenterWidth, sourceCenterHeight); 1293 d.scaleX = dx / d.source.width(); 1294 d.scaleY = dy / d.source.height(); 1325 QPixmapFragmentsArray &data = hints & QDrawBorderPixmap::OpaqueCenter ? opaqueData : translucentData; 1326 d.sourceLeft = sourceCenterLeft; 1327 d.sourceTop = sourceCenterTop; 1328 d.width = sourceCenterWidth; 1329 d.height = sourceCenterHeight; 1330 d.scaleX = dx / d.width; 1331 d.scaleY = dy / d.height; 1295 1332 1296 1333 qreal repeatWidth = (xTarget[columns - 1] - xTarget[columns - 2]) / d.scaleX; … … 1298 1335 1299 1336 for (int j = 1; j < rows - 1; ++j) { 1300 d. point.setY(0.5 * (yTarget[j + 1] + yTarget[j]));1337 d.y = (0.5 * (yTarget[j + 1] + yTarget[j])); 1301 1338 for (int i = 1; i < columns - 1; ++i) { 1302 d. point.setX(0.5 * (xTarget[i + 1] + xTarget[i]));1339 d.x = (0.5 * (xTarget[i + 1] + xTarget[i])); 1303 1340 data.append(d); 1304 1341 } 1305 1342 if (rules.horizontal == Qt::RepeatTile) 1306 data[data.size() - 1]. source.setWidth(repeatWidth);1343 data[data.size() - 1].width = repeatWidth; 1307 1344 } 1308 1345 if (rules.vertical == Qt::RepeatTile) { 1309 1346 for (int i = 1; i < columns - 1; ++i) 1310 data[data.size() - i]. source.setHeight(repeatHeight);1347 data[data.size() - i].height = repeatHeight; 1311 1348 } 1312 1349 } 1313 1350 1314 1351 if (opaqueData.size()) 1315 qDrawPixmaps(painter, opaqueData.data(), opaqueData.size(), pixmap, QDrawPixmaps::OpaqueHint);1352 painter->drawPixmapFragments(opaqueData.data(), opaqueData.size(), pixmap, QPainter::OpaqueHint); 1316 1353 if (translucentData.size()) 1317 qDrawPixmaps(painter, translucentData.data(), translucentData.size(), pixmap); 1318 } 1319 1320 /*! 1321 \class QDrawPixmaps::Data 1322 \since 4.6 1323 \internal 1324 1325 This structure is used with the qDrawPixmaps() function. 1326 1327 QPointF point: Specifies the center of the target rectangle. 1328 QRectF source: Specifies the source rectangle in the pixmap passed into the qDrawPixmaps() call. 1329 qreal scaleX: Specifies the horizontal scale of the target rectangle. 1330 qreal scaleY: Specifies the vertical scale of the target rectangle. 1331 qreal rotation: Specifies the rotation of the target rectangle in degrees. 1332 The target rectangle is rotated after scaling. 1333 qreal opacity: Specifies the opacity of the rectangle. 1334 */ 1335 1336 /*! 1337 \enum QDrawPixmaps::DrawingHint 1338 \internal 1339 */ 1340 1341 /*! 1342 \internal 1343 \since 4.6 1344 1345 This function is used to draw \a pixmap, or a sub-rectangle of \a pixmap, at multiple positions 1346 with different scale, rotation and opacity on \a painter. \a drawingData is an array of \a 1347 dataCount elements specifying the parameters used to draw each pixmap instance. 1348 This can be used for example to implement a particle system. 1349 */ 1350 void qDrawPixmaps(QPainter *painter, const QDrawPixmaps::Data *drawingData, int dataCount, const QPixmap &pixmap, QDrawPixmaps::DrawingHints hints) 1351 { 1352 QPaintEngine *engine = painter->paintEngine(); 1353 if (!engine) 1354 return; 1355 1356 if (engine->isExtended()) { 1357 static_cast<QPaintEngineEx *>(engine)->drawPixmaps(drawingData, dataCount, pixmap, hints); 1358 } else { 1359 qreal oldOpacity = painter->opacity(); 1360 QTransform oldTransform = painter->transform(); 1361 1362 for (int i = 0; i < dataCount; ++i) { 1363 QTransform transform = oldTransform; 1364 qreal xOffset = 0; 1365 qreal yOffset = 0; 1366 if (drawingData[i].rotation == 0) { 1367 xOffset = drawingData[i].point.x(); 1368 yOffset = drawingData[i].point.y(); 1369 } else { 1370 transform.translate(drawingData[i].point.x(), drawingData[i].point.y()); 1371 transform.rotate(drawingData[i].rotation); 1372 } 1373 painter->setTransform(transform); 1374 painter->setOpacity(oldOpacity * drawingData[i].opacity); 1375 1376 qreal w = drawingData[i].scaleX * drawingData[i].source.width(); 1377 qreal h = drawingData[i].scaleY * drawingData[i].source.height(); 1378 painter->drawPixmap(QRectF(-0.5 * w + xOffset, -0.5 * h + yOffset, w, h), pixmap, drawingData[i].source); 1379 } 1380 1381 painter->setOpacity(oldOpacity); 1382 painter->setTransform(oldTransform); 1383 } 1354 painter->drawPixmapFragments(translucentData.data(), translucentData.size(), pixmap); 1355 1356 if (oldAA) 1357 painter->setRenderHint(QPainter::Antialiasing, true); 1384 1358 } 1385 1359
Note:
See TracChangeset
for help on using the changeset viewer.