void UIFrameBufferQImage::paintScale(QPaintEvent *pEvent) { /* Scaled image is NULL by default: */ QImage scaledImage; /* But if scaled-factor is set and current image is NOT null: */ if (m_scaledSize.isValid() && !m_img.isNull()) { /* We are doing a deep copy of the image to make sure it will not be * detached during scale process, otherwise we can get a frozen frame-buffer. */ scaledImage = m_img.copy(); /* And scaling the image to predefined scaled-factor: */ scaledImage = scaledImage.scaled(m_scaledSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); } /* Finally we are choosing image to paint from: */ QImage &sourceImage = scaledImage.isNull() ? m_img : scaledImage; /* Get rectangle to paint: */ QRect paintRect = pEvent->rect().intersected(sourceImage.rect()); if (paintRect.isEmpty()) return; /* Create painter: */ QPainter painter(m_pMachineView->viewport()); /* Draw image rectangle depending on rectangle width: */ if ((ulong)paintRect.width() < m_width * 2 / 3) drawImageRectNarrow(painter, sourceImage, paintRect, m_pMachineView->contentsX(), m_pMachineView->contentsY()); else drawImageRectWide(painter, sourceImage, paintRect, m_pMachineView->contentsX(), m_pMachineView->contentsY()); }
void UIFrameBufferQImage::paintDefault(QPaintEvent *pEvent) { /* Get rectangle to paint: */ QRect paintRect = pEvent->rect().intersected(m_img.rect()); if (paintRect.isEmpty()) return; /* Create painter: */ QPainter painter(m_pMachineView->viewport()); /* Draw image rectangle depending on rectangle width: */ if ((ulong)paintRect.width() < m_width * 2 / 3) drawImageRectNarrow(painter, m_img, paintRect, m_pMachineView->contentsX(), m_pMachineView->contentsY()); else drawImageRectWide(painter, m_img, paintRect, m_pMachineView->contentsX(), m_pMachineView->contentsY()); }
void UIFrameBufferQImage::paintSeamless(QPaintEvent *pEvent) { /* Get rectangle to paint: */ QRect paintRect = pEvent->rect().intersected(m_img.rect()); if (paintRect.isEmpty()) return; /* Create painter: */ QPainter painter(m_pMachineView->viewport()); /* Clear paint rectangle first: */ painter.setCompositionMode(QPainter::CompositionMode_Clear); painter.eraseRect(paintRect); painter.setCompositionMode(QPainter::CompositionMode_SourceOver); /* Manually clip paint rectangle using visible-region: */ lock(); QRegion visiblePaintRegion = m_syncVisibleRegion & paintRect; unlock(); /* Repaint all the rectangles of visible-region: */ foreach (const QRect &rect, visiblePaintRegion.rects()) { #ifdef Q_WS_WIN /* Replace translucent background with black one, * that is necessary for window with Qt::WA_TranslucentBackground: */ painter.setCompositionMode(QPainter::CompositionMode_Source); painter.fillRect(rect, QColor(Qt::black)); painter.setCompositionMode(QPainter::CompositionMode_SourceAtop); #endif /* Q_WS_WIN */ /* Draw image rectangle depending on rectangle width: */ if ((ulong)rect.width() < m_width * 2 / 3) drawImageRectNarrow(painter, m_img, rect, m_pMachineView->contentsX(), m_pMachineView->contentsY()); else drawImageRectWide(painter, m_img, rect, m_pMachineView->contentsX(), m_pMachineView->contentsY()); } }