void ImageView::paintEvent(QPaintEvent* event) { // if the image is scaled and we have a high quality cached image if(imageItem_ && scaleFactor_ != 1.0 && !cachedPixmap_.isNull()) { // rectangle of the whole image in viewport coordinate QRect viewportImageRect = sceneToViewport(imageItem_->rect()); // the visible part of the image. QRect desiredCachedRect = viewportToScene(viewportImageRect.intersected(viewport()->rect())); // check if the cached area is what we need and if the cache is out of date if(cachedSceneRect_ == desiredCachedRect) { // rect of the image area that needs repaint, in viewport coordinate QRect repaintImageRect = viewportImageRect.intersected(event->rect()); // see if the part asking for repaint is contained by our cache. if(cachedRect_.contains(repaintImageRect)) { QPainter painter(viewport()); painter.fillRect(event->rect(), backgroundBrush()); painter.drawPixmap(repaintImageRect, cachedPixmap_); return; } } } if(!image_.isNull()) { // we don't have a cache yet or it's out of date already, generate one queueGenerateCache(); } QGraphicsView::paintEvent(event); }
void drawOver( QImage& dst, QRect const& dst_rect, QImage const& src, QRect const& src_rect) { if (src_rect.size() != dst_rect.size()) { throw std::invalid_argument("drawOver: source and destination areas have different sizes"); } if (dst.format() != src.format()) { throw std::invalid_argument("drawOver: source and destination have different formats"); } if (dst_rect.intersected(dst.rect()) != dst_rect) { throw std::invalid_argument("drawOver: destination area exceeds the image"); } if (src_rect.intersected(src.rect()) != src_rect) { throw std::invalid_argument("drawOver: source area exceeds the image"); } uint8_t* dst_line = dst.bits(); int const dst_bpl = dst.bytesPerLine(); uint8_t const* src_line = src.bits(); int const src_bpl = src.bytesPerLine(); int const depth = src.depth(); assert(dst.depth() == depth); if (depth % 8 != 0) { assert(depth == 1); // Slow but simple. BinaryImage dst_bin(dst); BinaryImage src_bin(src); rasterOp<RopSrc>(dst_bin, dst_rect, src_bin, src_rect.topLeft()); dst = dst_bin.toQImage().convertToFormat(dst.format()); // FIXME: we are not preserving the color table. return; } int const stripe_bytes = src_rect.width() * depth / 8; dst_line += dst_bpl * dst_rect.top() + dst_rect.left() * depth / 8; src_line += src_bpl * src_rect.top() + src_rect.left() * depth / 8; for (int i = src_rect.height(); i > 0; --i) { memcpy(dst_line, src_line, stripe_bytes); dst_line += dst_bpl; src_line += src_bpl; } }
// really generate the cache void ImageView::generateCache() { // disable the one-shot timer cacheTimer_->deleteLater(); cacheTimer_ = nullptr; if(!imageItem_ || image_.isNull()) return; // generate a cache for "the visible part" of the scaled image // rectangle of the whole image in viewport coordinate QRect viewportImageRect = sceneToViewport(imageItem_->rect()); // rect of the image area that's visible in the viewport (in viewport coordinate) cachedRect_ = viewportImageRect.intersected(viewport()->rect()); // convert to the coordinate of the original image cachedSceneRect_ = viewportToScene(cachedRect_); // create a sub image of the visible without real data copy // Reference: http://stackoverflow.com/questions/12681554/dividing-qimage-to-smaller-pieces QRect subRect = image_.rect().intersected(cachedSceneRect_); const uchar* bits = image_.constBits(); unsigned int offset = subRect.x() * image_.depth() / 8 + subRect.y() * image_.bytesPerLine(); QImage subImage = QImage(bits + offset, subRect.width(), subRect.height(), image_.bytesPerLine(), image_.format()); // If the original image has a color table, also use it for the subImage QVector<QRgb> colorTable = image_.colorTable(); if (!colorTable.empty()) subImage.setColorTable(colorTable); // QImage scaled = subImage.scaled(subRect.width() * scaleFactor_, subRect.height() * scaleFactor_, Qt::KeepAspectRatio, Qt::SmoothTransformation); QImage scaled = subImage.scaled(cachedRect_.width(), cachedRect_.height(), Qt::KeepAspectRatio, Qt::SmoothTransformation); // convert the cached scaled image to pixmap cachedPixmap_ = QPixmap::fromImage(scaled); viewport()->update(); }
QRect KisCanvas2::viewRectFromDoc(const QRectF & rc) { QRect viewRect = m_d->viewConverter->documentToView(rc).toAlignedRect(); viewRect = viewRect.translated(-m_d->documentOffset); viewRect = viewRect.intersected(QRect(0, 0, m_d->canvasWidget->widget()->width(), m_d->canvasWidget->widget()->height())); return viewRect; }
void FractalGenerator::appendValidRegion( const QRect& region ) { QRect clipped = region.intersected( QRect( QPoint( 0, 0 ), m_resolution ) ); if ( clipped.isEmpty() ) return; for ( int i = 0; i < m_validRegions.count(); i++ ) { if ( m_validRegions[ i ].bottom() + 1 == clipped.top() ) { if ( i + 1 < m_validRegions.count() && m_validRegions[ i + 1 ].top() == clipped.bottom() + 1 ) m_validRegions[ i ].setBottom( m_validRegions.takeAt( i + 1 ).bottom() ); else m_validRegions[ i ].setBottom( clipped.bottom() ); return; } if ( m_validRegions[ i ].top() == clipped.bottom() + 1 ) { m_validRegions[ i ].setTop( clipped.top() ); return; } if ( m_validRegions[ i ].top() > clipped.top() ) { m_validRegions.insert( i, clipped ); return; } } m_validRegions.append( clipped ); }
void CameraBinFocus::updateRegionOfInterest(const QVector<QRect> &rectangles) { if (m_cameraStatus != QCamera::ActiveStatus) return; GstElement * const cameraSource = m_session->cameraSource(); if (!cameraSource) return; GValue regions = G_VALUE_INIT; g_value_init(®ions, GST_TYPE_LIST); if (rectangles.isEmpty()) { appendRegion(®ions, 0, QRect(0, 0, 0, 0)); } else { // Add padding around small face rectangles so the auto focus has a reasonable amount // of image to work with. const int minimumDimension = qMin( m_viewfinderResolution.width(), m_viewfinderResolution.height()) * 0.3; const QRect viewfinderRectangle(QPoint(0, 0), m_viewfinderResolution); foreach (const QRect &rectangle, rectangles) { QRect paddedRectangle( 0, 0, qMax(rectangle.width(), minimumDimension), qMax(rectangle.height(), minimumDimension)); paddedRectangle.moveCenter(rectangle.center()); appendRegion(®ions, 1, viewfinderRectangle.intersected(paddedRectangle)); } }
void Document::setSelection(QRect selection) { m_selection = selection.isValid() ? selection.intersected(m_image.rect()) : m_image.rect(); emit selectionChanged(); }
void MMF::DsaVideoPlayer::videoWindowScreenRectChanged() { Q_ASSERT(m_videoOutput); QRect windowRect = static_cast<DsaVideoOutput *>(m_videoOutput)->videoWindowScreenRect(); // Clip to physical window size // This is due to a defect in the layout when running on S60 3.2, which // results in the rectangle of the video widget extending outside the // screen in certain circumstances. These include the initial startup // of the mediaplayer demo in portrait mode. When this rectangle is // passed to the CVideoPlayerUtility, no video is rendered. const TSize screenSize = m_screenDevice.SizeInPixels(); const QRect screenRect(0, 0, screenSize.iWidth, screenSize.iHeight); windowRect = windowRect.intersected(screenRect); // Recalculate scale factors. Pass 'false' as second parameter in order to // suppress application of the change to the player - this is done at the end // of the function. updateScaleFactors(windowRect.size(), false); m_videoScreenRect = qt_QRect2TRect(windowRect); parametersChanged(WindowScreenRect | ScaleFactors); }
QRect MyGraphicsView::getViewableRect() const { if (mScene->items().size() == 0) return QRect(); QRect r = mapToScene( viewport()->geometry() ).boundingRect().toRect(); //qDebug() << "Rect " << r; if ( r.top() < 0 ) r.setTop(0); if ( r.left() < 0 ) r.setLeft(0); // get only intersection between pixmap and region #ifdef QT4 r = r.intersect( mScene->sceneRect().toRect() ); #else r = r.intersected( mScene->sceneRect().toRect() ); #endif //qDebug() << "Rect2 " << r; return r; }
void SplittedWidget::update(const QRect &r) { if (rtl()) { TWidget::update(r.translated(-otherWidth(), 0).intersected(rect())); emit updateOther(r); } else { TWidget::update(r.intersected(rect())); emit updateOther(r.translated(-width(), 0)); } }
bool Brick::intersectBottom(QRect r) { if(r.intersected(getRect()).width() > 5 && getRect().y() < r.y()) { move(getRect().x(),r.y() - getRect().height() + 1); return true; } return false; }
void QWidgetPluginImpl::setGeometryAndClip(const QRect &geometry, const QRect &clipRect, bool isVisible) { m_widget->setGeometry(geometry); if (!clipRect.isNull()) { QRect clip(clipRect.intersected(m_widget->rect())); m_widget->setMask(QRegion(clip)); } m_widget->update(); setVisible(isVisible); }
QRect ButtonHandler::intersectWithAreas(const QRect &rect) { QRect res; for(const QRect &r : m_screenRegions.rects()) { QRect temp = rect.intersected(r); if (temp.height() * temp.width() > res.height() * res.width()) { res = temp; } } return res; }
//virtual void PixmapFilmstripObject::createFrames(const QList<QRect>& frameCoordinates) { m_frames.empty(); m_minFrameSize = QSize(); m_maxFrameSize = QSize(); m_currentFrameIndex = 0; m_currentFrameRect = QRect(); if (frameCoordinates.empty()) { //there are no frames! return; } if (!pm) { //no source image return; } QRect srcImgRect = QRect(QPoint(0,0),pm->size()); quint32 minArea = INT_MAX; for (int i=0;i<frameCoordinates.size();++i) { QRect fc = frameCoordinates[i]; if (!fc.isValid()) { //skip invalid frame continue; } //it needs to be within the src image fc = fc.intersected(srcImgRect); if (fc.isEmpty()) { //skip frame not at least partially in the src img rect continue; } quint32 a = fc.width() * fc.height(); if (a < minArea) { minArea = a; m_minFrameSize = fc.size(); } if (fc.width() > m_maxFrameSize.width()) { m_maxFrameSize.setWidth(fc.width()); } if (fc.height() > m_maxFrameSize.height()) { m_maxFrameSize.setHeight(fc.height()); } m_frames << fc; } }
//Primary/private function void NativeWindowSystem::arrangeWindows(NativeWindowObject *primary, QString type, bool primaryonly){ if(type.isEmpty()){ type = "center"; } if(primary==0){ //Get the currently active window and treat that as the primary for(int i=0; i<NWindows.length(); i++){ if(NWindows[i]->property(NativeWindowObject::Active).toBool()){ primary = NWindows[i]; } } if(primary==0 && !NWindows.isEmpty()){ primary = NWindows[0]; } //just use the first one in the list } //Now get the current screen that the mouse cursor is over (and valid area) QScreen *screen = screenUnderMouse(); if(screen==0){ return; } //should never happen (theoretically) QRect desktopArea = screen->availableGeometry(); //qDebug() << "Arrange Windows:" << primary->geometry() << type << primaryonly << desktopArea; //Now start filtering out all the windows that need to be ignored int wkspace = primary->property(NativeWindowObject::Workspace).toInt(); QList<NativeWindowObject*> winlist = NWindows; for(int i=0; i<winlist.length(); i++){ if(winlist[i]->property(NativeWindowObject::Workspace).toInt()!=wkspace || !winlist[i]->property(NativeWindowObject::Visible).toBool() || desktopArea.intersected(winlist[i]->geometry()).isNull() ){ //window is outside of the desired area or invisible - ignore it winlist.removeAt(i); i--; } } if(!winlist.contains(primary)){ winlist << primary; } //could be doing this on a window right before it is shown else if(primaryonly){ winlist.removeAll(primary); winlist << primary; } //move primary window to last //QRegion used; for(int i=0; i<winlist.length(); i++){ if(primaryonly && winlist[i]!=primary){ continue; } //skip this window //Now loop over the windows and arrange them as needed QRect geom = winlist[i]->geometry(); //verify that the window is contained by the desktop area if(geom.width()>desktopArea.width()){ geom.setWidth(desktopArea.width()); } if(geom.height()>desktopArea.height()){ geom.setHeight(desktopArea.height()); } //Now apply the proper placement routine if(type=="center"){ QPoint ct = desktopArea.center(); winlist[i]->setGeometryNow( QRect( ct.x()-(geom.width()/2), ct.y()-(geom.height()/2), geom.width(), geom.height()) ); }else if(type=="snap"){ }else if(type=="single_max"){ winlist[i]->setGeometryNow( QRect( desktopArea.x(), desktopArea.y(), desktopArea.width(), desktopArea.height()) ); }else if(type=="under-mouse"){ QPoint ct = QCursor::pos(); geom = QRect(ct.x()-(geom.width()/2), ct.y()-(geom.height()/2), geom.width(), geom.height() ); //Now verify that the top of the window is still contained within the desktop area if(geom.y() < desktopArea.y() ){ geom.moveTop(desktopArea.y()); } winlist[i]->setGeometryNow(geom); } //qDebug() << " - New Geometry:" << winlist[i]->geometry(); } //end loop over winlist }
void KisPixelSelection::renderToProjection(KisSelection* projection, const QRect& r) { QRect updateRect = r.intersected(selectedExactRect()); if (updateRect.isValid()) { KisPainter painter(projection); painter.setCompositeOp(COMPOSITE_COPY); painter.bitBlt(updateRect.x(), updateRect.y(), KisPaintDeviceSP(this), updateRect.x(), updateRect.y(), updateRect.width(), updateRect.height()); painter.end(); } }
/** * QT 4.7.1 拖拽的函数默认调用过程: * * Model.supportedDropActions() * * View.startDrag() * Model.mimeData() // 获取拖拽数据 * Model.supportedDragActions() * Model.supportedDropActions() * QDrag.exec() // 阻塞,直到拖拽结束 * * // 在拖拽过程中,如果拖拽进入某个节点 * View.dragEnterEvent() // 默认实现会拒绝拖拽,需要重写并调用 QDragEnterEvent.acceptProposedAction() * Model.mimeTypes() * View.dragMoveEvent() * Model.mimeTypes() * View.dragLeaveEvent() * * // 拖拽结束后 * View.dropEvent() * Model.dropMimeData() // QT用来接收数据 * * // exec()执行完后,如果是 MoveAction,则调用 * Model.removeSelectedRows() // QT用来删除数据 * * 上述默认过程对跨 View 拖放支持不好, 下面的startDrag()函数摘自默认实现,并 * 将部分代码替换掉以免调用removeSelectedRows()函数 */ void DirectoryTree::startDrag(Qt::DropActions) { const QModelIndexList indexes = selectedIndexes(); if (indexes.count() == 0) return; // setup pixmap QRect rect = visualRect(indexes.at(0)); QList<QRect> rects; for (size_t i = 0, s = indexes.count(); i < s; ++i) { rects.append(visualRect(indexes.at(i))); rect |= rects.at(i); } rect = rect.intersected(viewport()->rect()); QPixmap pixmap(rect.size()); pixmap.fill(palette().base().color()); QPainter painter(&pixmap); QStyleOptionViewItem option = viewOptions(); option.state |= QStyle::State_Selected; for (size_t j = 0, s = indexes.count(); j < s; ++j) { option.rect = QRect(rects.at(j).topLeft() - rect.topLeft(), rects.at(j).size()); itemDelegate()->paint(&painter, option, indexes.at(j)); } painter.end(); // create drag object QDrag *drag = new QDrag(this); drag->setPixmap(pixmap); drag->setMimeData(model()->mimeData(indexes)); drag->setHotSpot(viewport()->mapFromGlobal(QCursor::pos()) - rect.topLeft()); /** * 在拖动之前,先把 parent 和 row 保存下来, * 在 Model.dropMimeData() 中统一进行底层数据和视图层数据的修改, * 避免索引混乱 */ DirectoryTreeModel *m = (DirectoryTreeModel*) model(); QModelIndex parent = indexes.at(0).parent(); int row = indexes.at(0).row(); m->prepare_draging_drop(parent, row); /* * 这里的原来的实现 removeSelectedRows() 是我们不需要的, 且 QDrag->start() 总是允许 Qt::CopyAction * 而我们需要的是,内部用 Qt::MoveAction,外部用 Qt::CopyAction且内部不支持 Qt::CopyAction且内部不支持 * Qt::CopyAction,否则导致错误 * if (drag->start(supportedActions) == Qt::MoveAction) removeSelectedRows(); */ drag->exec(Qt::MoveAction | Qt::CopyAction, Qt::MoveAction); }
void Layer::fillRect(const QRect &rectangle, const QColor &color, BlendMode::Mode blendmode) { const QRect canvas(0, 0, _width, _height); if(rectangle.contains(canvas) && blendmode==BlendMode::MODE_REPLACE) { // Special case: overwrite whole layer _tiles.fill(Tile(color)); } else { // The usual case: only a portion of the layer is filled or pixel blending is needed QRect rect = rectangle.intersected(canvas); uchar mask[Tile::LENGTH]; if(blendmode==255) memset(mask, 0xff, Tile::LENGTH); else memset(mask, color.alpha(), Tile::LENGTH); const int size = Tile::SIZE; const int bottom = rect.y() + rect.height(); const int right = rect.x() + rect.width(); const int tx0 = rect.x() / size; const int tx1 = (right-1) / size; const int ty0 = rect.y() / size; const int ty1 = (bottom-1) / size; bool canIncrOpacity; if(blendmode==255 && color.alpha()==0) canIncrOpacity = false; else canIncrOpacity = findBlendMode(blendmode).flags.testFlag(BlendMode::IncrOpacity); for(int ty=ty0; ty<=ty1; ++ty) { for(int tx=tx0; tx<=tx1; ++tx) { int left = qMax(tx * size, rect.x()) - tx*size; int top = qMax(ty * size, rect.y()) - ty*size; int w = qMin((tx+1)*size, right) - tx*size - left; int h = qMin((ty+1)*size, bottom) - ty*size - top; Tile &t = _tiles[ty*_xtiles+tx]; if(!t.isNull() || canIncrOpacity) t.composite(blendmode, mask, color, left, top, w, h, 0); } } } if(_owner && visible()) { _owner->markDirty(rectangle); _owner->notifyAreaChanged(); } }
void ImageView::paintEvent(QPaintEvent* event) { if (m_item && m_scaleFactor != 1.0 && !m_cachedPixmap.isNull()) { const QRect viewportImageRect = sceneToViewport(m_item->rect()); const QRect desiredCachedRect = viewportToScene(viewportImageRect.intersected(viewport()->rect())); if (m_cachedSceneRect == desiredCachedRect) { const QRect repaintImageRect = viewportImageRect.intersected(event->rect()); if (m_cachedRect.contains(repaintImageRect)) { QPainter painter(viewport()); painter.fillRect(event->rect(), backgroundBrush()); painter.drawPixmap(repaintImageRect, m_cachedPixmap); return; } } } if (!m_image.isNull()) queueGenerateCache(); QGraphicsView::paintEvent(event); }
QRect ComboTabBar::tabRect(int index) const { QRect rect; if (index != -1) { bool mainTabBar = index >= pinnedTabsCount(); rect = localTabBar(index)->tabRect(toLocalIndex(index)); if (mainTabBar) { rect.moveLeft(rect.x() + mapFromGlobal(m_mainTabBar->mapToGlobal(QPoint(0, 0))).x()); QRect widgetRect = m_mainTabBarWidget->scrollArea()->viewport()->rect(); widgetRect.moveLeft(widgetRect.x() + mapFromGlobal(m_mainTabBarWidget->scrollArea()->viewport()->mapToGlobal(QPoint(0, 0))).x()); rect = rect.intersected(widgetRect); } else { rect.moveLeft(rect.x() + mapFromGlobal(m_pinnedTabBar->mapToGlobal(QPoint(0, 0))).x()); QRect widgetRect = m_pinnedTabBarWidget->scrollArea()->viewport()->rect(); widgetRect.moveLeft(widgetRect.x() + mapFromGlobal(m_pinnedTabBarWidget->scrollArea()->viewport()->mapToGlobal(QPoint(0, 0))).x()); rect = rect.intersected(widgetRect); } } return rect; }
void FetchTemplate::execute() { if(mRoi.hasValue()){ QRect roi = mRoi; const cv::Mat source = mIn; QRect imageRect = QRect(0,0, source.cols, source.rows); roi = roi.intersected(imageRect); if(roi.isValid()){ mTemplate = source(port::Rect::rect(roi)); } } if(mTemplate.data){ mOut.send(mTemplate); } }
void UIMouseHandler::captureMouse(ulong uScreenId) { /* Do not try to capture mouse if its captured already: */ if (uisession()->isMouseCaptured()) return; /* If such viewport exists: */ if (m_viewports.contains(uScreenId)) { /* Store mouse-capturing state value: */ uisession()->setMouseCaptured(true); /* Memorize the index of machine-view-viewport captured mouse: */ m_iMouseCaptureViewIndex = uScreenId; /* Memorize the host position where the cursor was captured: */ m_capturedMousePos = QCursor::pos(); /* Acquiring visible viewport rectangle in global coodrinates: */ QRect visibleRectangle = m_viewports[m_iMouseCaptureViewIndex]->visibleRegion().boundingRect(); QPoint visibleRectanglePos = m_views[m_iMouseCaptureViewIndex]->mapToGlobal(m_viewports[m_iMouseCaptureViewIndex]->pos()); visibleRectangle.translate(visibleRectanglePos); visibleRectangle = visibleRectangle.intersected(QApplication::desktop()->availableGeometry()); #ifdef Q_WS_WIN /* Move the mouse to the center of the visible area: */ m_lastMousePos = visibleRectangle.center(); QCursor::setPos(m_lastMousePos); /* Update mouse clipping: */ updateMouseCursorClipping(); #elif defined (Q_WS_MAC) /* Grab all mouse events: */ ::darwinMouseGrab(m_viewports[m_iMouseCaptureViewIndex]); #else /* Q_WS_MAC */ /* Remember current mouse position: */ m_lastMousePos = QCursor::pos(); /* Grab all mouse events: */ m_viewports[m_iMouseCaptureViewIndex]->grabMouse(); #endif /* !Q_WS_MAC */ /* Switch guest mouse to the relative mode: */ CMouse mouse = session().GetConsole().GetMouse(); mouse.PutMouseEvent(0, 0, 0, 0, 0); /* Emit signal if required: */ emit mouseStateChanged(mouseState()); } }
void ItemList::startDrag(Qt::DropActions supportedActions) { const QModelIndexList indexes = selectedIndexes(); if (indexes.count() == 0) return; // setup pixmap QRect rect = visualRect(indexes.at(0)); QList<QRect> rects; for (size_t i = 0, s = indexes.count(); i < s; ++i) { rects.append(visualRect(indexes.at(i))); rect |= rects.at(i); } rect = rect.intersected(viewport()->rect()); QPixmap pixmap(rect.size()); pixmap.fill(palette().base().color()); QPainter painter(&pixmap); QStyleOptionViewItem option = viewOptions(); option.state |= QStyle::State_Selected; for (size_t j = 0, s = indexes.count(); j < s; ++j) { option.rect = QRect(rects.at(j).topLeft() - rect.topLeft(), rects.at(j).size()); itemDelegate()->paint(&painter, option, indexes.at(j)); } painter.end(); // create drag object QDrag *drag = new QDrag(this); drag->setPixmap(pixmap); drag->setMimeData(model()->mimeData(indexes)); drag->setHotSpot(viewport()->mapFromGlobal(QCursor::pos()) - rect.topLeft()); /* * 这里的原来的实现被注释掉 if (drag->start(supportedActions) == Qt::MoveAction) removeSelectedRows(); */ ItemListModel *m = dynamic_cast<ItemListModel*>(model()); assert(NULL != m); /// QAbstractItemModel::supportedDragActions()居然不是虚函数,我C了!!! Qt::DropAction rs = drag->exec(Qt::MoveAction | Qt::CopyAction, Qt::MoveAction); if (rs == Qt::MoveAction) { assert(indexes.count() != 0); m->_remove_after_drag(indexes.at(0).row()); } }
void nsShmImage::Put(QWidget* aWindow, QRect& aRect) { Display* dpy = aWindow->x11Info().display(); Drawable d = aWindow->handle(); GC gc = XCreateGC(dpy, d, 0, nsnull); // Avoid out of bounds painting QRect inter = aRect.intersected(aWindow->rect()); XShmPutImage(dpy, d, gc, mImage, inter.x(), inter.y(), inter.x(), inter.y(), inter.width(), inter.height(), False); XFreeGC(dpy, gc); }
void nsShmImage::Put(QWidget* aWindow, QRect& aRect) { Display* dpy = gfxQtPlatform::GetXDisplay(aWindow); Drawable d = aWindow->winId(); GC gc = XCreateGC(dpy, d, 0, nsnull); // Avoid out of bounds painting QRect inter = aRect.intersected(aWindow->rect()); XShmPutImage(dpy, d, gc, mImage, inter.x(), inter.y(), inter.x(), inter.y(), inter.width(), inter.height(), False); XFreeGC(dpy, gc); }
void ImageView::zoomRegion(const QRect& region) { QRect size = this->geometry(); // Canvas size. QRect targetRect = region.intersected(size); // Zoom region. QPoint targetCenter = targetRect.center(); // Zoom center. QRect visibleRect = this->visibleRegion().boundingRect(); // Viewport. float sx = static_cast<float>(visibleRect.width()) / targetRect.width(); float sy = static_cast<float>(visibleRect.height()) / targetRect.height(); float newScale = (sx < sy) ? sx : sy; float scale = newScale * static_cast<float>(size.width()) / m_image.width(); this->setZoomLevel(scale); emit viewCenterChanged(newScale * targetCenter.x(), newScale * targetCenter.y()); }
void Layer::fillRect(const QRect &rectangle, const QColor &color, int blendmode) { const QRect canvas(0, 0, _width, _height); if(rectangle.contains(canvas) && blendmode==255) { // Special case: rectangle covers entire layer and blendmode is OVERWRITE _tiles.fill(Tile(color)); } else { // The usual case: only a portion of the layer is filled or pixel blending is needed QRect rect = rectangle.intersected(canvas); uchar mask[Tile::LENGTH]; if(blendmode==255) memset(mask, 0xff, Tile::LENGTH); else memset(mask, color.alpha(), Tile::LENGTH); const int size = Tile::SIZE; const int bottom = rect.y() + rect.height(); const int right = rect.x() + rect.width(); const int tx0 = rect.x() / size; const int tx1 = right / size; const int ty0 = rect.y() / size; const int ty1 = bottom / size; for(int ty=ty0;ty<=ty1;++ty) { for(int tx=tx0;tx<=tx1;++tx) { int left = qMax(tx * size, rect.x()) - tx*size; int top = qMax(ty * size, rect.y()) - ty*size; int w = qMin((tx+1)*size, right) - tx*size - left; int h = qMin((ty+1)*size, bottom) - ty*size - top; Tile &t = _tiles[ty*_xtiles+tx]; t.composite(blendmode, mask, color, left, top, w, h, 0); } } } if(_owner && visible()) { _owner->markDirty(rectangle); _owner->notifyAreaChanged(); } }
QImage QRasterPlatformPixmap::toImage(const QRect &rect) const { if (rect.isNull()) return image; QRect clipped = rect.intersected(QRect(0, 0, w, h)); const uint du = uint(d); if ((du % 8 == 0) && (((uint(clipped.x()) * du)) % 32 == 0)) { QImage newImage(image.scanLine(clipped.y()) + clipped.x() * (du / 8), clipped.width(), clipped.height(), image.bytesPerLine(), image.format()); newImage.setDevicePixelRatio(image.devicePixelRatio()); return newImage; } else { return image.copy(clipped); } }
void Terrain::drawPatchMap( const QRect & rect ) { QRect rectToDraw = rect.intersected( QRect( QPoint(0,0), QSize(mMapSize.width()-1,mMapSize.height()-1) ) ); if( rectToDraw.width() < 1 || rectToDraw.height() < 1 ) return; // need at least 4 vertices to build triangle strip if( rectToDraw.y() >= mMapSize.height()-1 ) return; // reached the bottom row - there is no next row to build triangle strips with mVertexBuffer.bind(); mIndexBuffer.bind(); glEnableClientState( GL_INDEX_ARRAY ); VertexP3fN3fT2f::glEnableClientState(); VertexP3fN3fT2f::glPointerVBO(); for( int slice=rectToDraw.y(); slice<rectToDraw.y()+rectToDraw.height(); slice++ ) { glDrawElements( GL_TRIANGLE_STRIP, rectToDraw.width()*2+2, GL_UNSIGNED_INT, (const GLvoid*)((size_t)(2*sizeof(unsigned int)*( // convert index to pointer rectToDraw.x() + mMapSize.width()*slice // index to start ) ) ) ); /* //TODO: something like this should be faster glDrawRangeElements( GL_TRIANGLE_STRIP, slice*(unsigned int)mMapSize.width()+rectToDraw.x(), (slice+1)*(unsigned int)mMapSize.width()+rectToDraw.x()+rectToDraw.width()+2, rectToDraw.width()*2+2, GL_UNSIGNED_INT, (const GLvoid*)((size_t)(2*sizeof(unsigned int)*( // convert index to pointer rectToDraw.x() + mMapSize.width()*slice // index to start ) ) ) ); */ } glDisableClientState( GL_INDEX_ARRAY ); VertexP3fN3fT2f::glDisableClientState(); mVertexBuffer.release(); mIndexBuffer.release(); }
// Display the video. void MHVideo::Display(MHEngine *engine) { if (! m_fRunning) { return; } if (m_nBoxWidth == 0 || m_nBoxHeight == 0) { return; // Can't draw zero sized boxes. } // The bounding box is assumed always to be True. // The full screen video is displayed in this rectangle. It is therefore scaled to // m_nDecodeWidth/720 by m_nDecodeHeight/576. QRect videoRect = QRect(m_nPosX + m_nXDecodeOffset, m_nPosY + m_nYDecodeOffset, m_nDecodeWidth, m_nDecodeHeight); QRect displayRect = videoRect.intersected(QRect(m_nPosX, m_nPosY, m_nBoxWidth, m_nBoxHeight)); engine->GetContext()->DrawVideo(videoRect, displayRect); }