MCPcopy Create free account
hub / github.com/FreeCAD/FreeCAD / resize

Method resize

src/Gui/BitmapFactory.cpp:381–440  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

379}
380
381QPixmap 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;

Callers 15

scaleImageMethod · 0.45
buffer_reallocFunction · 0.45
SoFCDB.cppFile · 0.45
startAlignmentMethod · 0.45
getIconMethod · 0.45
createToolTipMethod · 0.45
activateFileMethod · 0.45
partialRenderMethod · 0.45
xmlFilesAreValidFunction · 0.45
splitPathMethod · 0.45
createViewMethod · 0.45

Calls 9

heightMethod · 0.80
paletteMethod · 0.80
setPenMethod · 0.80
QPointClass · 0.70
widthMethod · 0.45
isNullMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
colorMethod · 0.45

Tested by

no test coverage detected