当前位置: 首页>>代码示例>>C++>>正文


C++ QRect::intersected方法代码示例

本文整理汇总了C++中QRect::intersected方法的典型用法代码示例。如果您正苦于以下问题:C++ QRect::intersected方法的具体用法?C++ QRect::intersected怎么用?C++ QRect::intersected使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QRect的用法示例。


在下文中一共展示了QRect::intersected方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: paintEvent

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);
}
开发者ID:Pr0Wolf29,项目名称:lximage-qt,代码行数:25,代码来源:imageview.cpp

示例2: drawOver

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;
	}
}
开发者ID:4sp1r3,项目名称:scantailor,代码行数:49,代码来源:DrawOver.cpp

示例3: generateCache

// 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();
}
开发者ID:Pr0Wolf29,项目名称:lximage-qt,代码行数:35,代码来源:imageview.cpp

示例4:

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;
}
开发者ID:,项目名称:,代码行数:7,代码来源:

示例5: appendValidRegion

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 );
}
开发者ID:WhiteSymmetry,项目名称:fraqtive,代码行数:25,代码来源:fractalgenerator.cpp

示例6: updateRegionOfInterest

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(&regions, GST_TYPE_LIST);

    if (rectangles.isEmpty()) {
        appendRegion(&regions, 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(&regions, 1, viewfinderRectangle.intersected(paddedRectangle));
        }
    }
开发者ID:MarianMMX,项目名称:MarianMMX,代码行数:32,代码来源:camerabinfocus.cpp

示例7: setSelection

void Document::setSelection(QRect selection)
{
    m_selection = selection.isValid() ?
                selection.intersected(m_image.rect()) :
                m_image.rect();
    emit selectionChanged();
}
开发者ID:govorovsky,项目名称:cmc-eye,代码行数:7,代码来源:document.cpp

示例8: screenRect

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);
}
开发者ID:Afreeca,项目名称:qt,代码行数:25,代码来源:videoplayer_dsa.cpp

示例9: getViewableRect

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;
}
开发者ID:quimnuss,项目名称:superannotator,代码行数:27,代码来源:mygraphicsview.cpp

示例10: update

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));
	}
}
开发者ID:3ngineer,项目名称:tdesktop,代码行数:9,代码来源:scrollarea.cpp

示例11: intersectBottom

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;
}
开发者ID:clemRoux,项目名称:mario,代码行数:9,代码来源:brick.cpp

示例12: setGeometryAndClip

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);
}
开发者ID:RobinWuDev,项目名称:Qt,代码行数:10,代码来源:QWidgetPluginImpl.cpp

示例13: intersectWithAreas

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;
}
开发者ID:Jocix123,项目名称:flameshot,代码行数:10,代码来源:buttonhandler.cpp

示例14: createFrames

//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;
	}
}
开发者ID:22350,项目名称:luna-sysmgr,代码行数:56,代码来源:pixmapfilmstripobject.cpp

示例15: arrangeWindows

//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
}
开发者ID:trueos,项目名称:lumina,代码行数:56,代码来源:Window-mgmt.cpp


注:本文中的QRect::intersected方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。