| 379 | } |
| 380 | |
| 381 | QPixmap BitmapFactoryInst::resize(int w, int h, const QPixmap& p, Qt::BGMode bgmode) const |
| 382 | { |
| 383 | if (bgmode == Qt::TransparentMode) { |
| 384 | if (p.width() == 0 || p.height() == 0) { |
| 385 | w = 1; |
| 386 | } |
| 387 | |
| 388 | QPixmap pix = p; |
| 389 | int x = pix.width() > w ? 0 : (w - pix.width()) / 2; |
| 390 | int y = pix.height() > h ? 0 : (h - pix.height()) / 2; |
| 391 | |
| 392 | if (x == 0 && y == 0) { |
| 393 | return pix; |
| 394 | } |
| 395 | |
| 396 | QPixmap pm(w, h); |
| 397 | QBitmap mask(w, h); |
| 398 | mask.fill(Qt::color0); |
| 399 | |
| 400 | QBitmap bm = pix.mask(); |
| 401 | if (!bm.isNull()) { |
| 402 | QPainter painter(&mask); |
| 403 | painter.drawPixmap(QPoint(x, y), bm, QRect(0, 0, pix.width(), pix.height())); |
| 404 | pm.setMask(mask); |
| 405 | } |
| 406 | else { |
| 407 | pm.setMask(mask); |
| 408 | pm = fillRect(x, y, pix.width(), pix.height(), pm, Qt::OpaqueMode); |
| 409 | } |
| 410 | |
| 411 | QPainter pt; |
| 412 | pt.begin(&pm); |
| 413 | pt.drawPixmap(x, y, pix); |
| 414 | pt.end(); |
| 415 | return pm; |
| 416 | } |
| 417 | else { // Qt::OpaqueMode |
| 418 | QPixmap pix = p; |
| 419 | |
| 420 | if (pix.width() == 0 || pix.height() == 0) { |
| 421 | return pix; // do not resize a null pixmap |
| 422 | } |
| 423 | |
| 424 | QPalette pal = qApp->palette(); |
| 425 | QColor dl = pal.color(QPalette::Disabled, QPalette::Light); |
| 426 | QColor dt = pal.color(QPalette::Disabled, QPalette::Text); |
| 427 | |
| 428 | QPixmap pm(w, h); |
| 429 | pm.fill(dl); |
| 430 | |
| 431 | QPainter pt; |
| 432 | pt.begin(&pm); |
| 433 | pt.setPen(dl); |
| 434 | pt.drawPixmap(1, 1, pix); |
| 435 | pt.setPen(dt); |
| 436 | pt.drawPixmap(0, 0, pix); |
| 437 | pt.end(); |
| 438 | return pm; |
no test coverage detected