Example #1
0
/*!
  Calculate geometry for the text in widget coordinates
  \return Geometry for the text
*/
QRect QwtTextLabel::textRect() const
{
    QRect r = contentsRect();

    if ( !r.isEmpty() && d_data->margin > 0 )
    {
        r.setRect( r.x() + d_data->margin, r.y() + d_data->margin,
            r.width() - 2 * d_data->margin, r.height() - 2 * d_data->margin );
    }

    if ( !r.isEmpty() )
    {
        int indent = d_data->indent;
        if ( indent <= 0 )
            indent = defaultIndent();

        if ( indent > 0 )
        {
            const int renderFlags = d_data->text.renderFlags();

            if ( renderFlags & Qt::AlignLeft )
                r.setX( r.x() + indent );
            else if ( renderFlags & Qt::AlignRight )
                r.setWidth( r.width() - indent );
            else if ( renderFlags & Qt::AlignTop )
                r.setY( r.y() + indent );
            else if ( renderFlags & Qt::AlignBottom )
                r.setHeight( r.height() - indent );
        }
    }

    return r;
}
Example #2
0
QWebFrame *QtScrollerFilter::scrollingFrameAt_QWebView(QWebView *view, const QPoint &pos) const
{
    if (!view->page())
         return 0;

    QWebFrame *mainFrame = view->page()->mainFrame();
    QWebHitTestResult hitTest = mainFrame->hitTestContent(pos);
    QWebFrame *hitFrame = hitTest.frame();
         
    if (!hitFrame)
        return 0;

    QRect vsbrect = hitFrame->scrollBarGeometry(Qt::Vertical);
    QRect hsbrect = hitFrame->scrollBarGeometry(Qt::Horizontal);

    if (!vsbrect.isEmpty() && vsbrect.contains(hitTest.pos() - hitFrame->scrollPosition()))
        return 0;
    if (!hsbrect.isEmpty() && hsbrect.contains(hitTest.pos() - hitFrame->scrollPosition()))
        return 0;

    QSize range = hitFrame->contentsSize() - hitFrame->geometry().size();
    
    while (hitFrame && range.width() <= 1 && range.height() <= 1)
        hitFrame = hitFrame->parentFrame();
    return hitFrame;
}
/*!
  Returns a QPixmap generated from the part of the backing store
  corresponding to \a widget. Returns a null QPixmap if an error
  occurs. The contents of the pixmap are only defined for the regions
  of \a widget that have received paint events since the last resize
  of the backing store.

  If \a rectangle is a null rectangle (the default), the entire widget
  is grabbed. Otherwise, the grabbed area is limited to \a rectangle.

  The default implementation uses QWindowSurface::buffer().

  \sa QPixmap::grabWidget()
*/
QPixmap QWindowSurface::grabWidget(const QWidget *widget, const QRect &rectangle) const
{
    QPixmap result;

    if (widget->window() != window())
        return result;

    const QImage *img = const_cast<QWindowSurface *>(this)->buffer(widget->window());

    if (!img || img->isNull())
        return result;

    QRect rect = rectangle.isEmpty() ? widget->rect() : (widget->rect() & rectangle);

    rect.translate(offset(widget) - offset(widget->window()));
    rect &= QRect(QPoint(), img->size());

    if (rect.isEmpty())
        return result;

    QImage subimg(img->scanLine(rect.y()) + rect.x() * img->depth() / 8,
                  rect.width(), rect.height(),
                  img->bytesPerLine(), img->format());
    subimg.detach(); //### expensive -- maybe we should have a real SubImage that shares reference count

    result = QPixmap::fromImage(subimg);
    return result;
}
Example #4
0
QPixmap QX11WindowSurface::grabWidget(const QWidget *widget,
                                      const QRect& rect) const
{
    if (!widget || d_ptr->device.isNull())
        return QPixmap();

    QRect srcRect;

    // make sure the rect is inside the widget & clip to widget's rect
    if (!rect.isEmpty())
        srcRect = rect & widget->rect();
    else
        srcRect = widget->rect();

    if (srcRect.isEmpty())
        return QPixmap();

    // If it's a child widget we have to translate the coordinates
    if (widget != window())
        srcRect.translate(widget->mapTo(window(), QPoint(0, 0)));

    QPixmap::x11SetDefaultScreen(widget->x11Info().screen());
    QPixmap px(srcRect.width(), srcRect.height());

    GC tmpGc = XCreateGC(X11->display, d_ptr->device.handle(), 0, 0);

    // Copy srcRect from the backing store to the new pixmap
    XSetGraphicsExposures(X11->display, tmpGc, False);
    XCopyArea(X11->display, d_ptr->device.handle(), px.handle(), tmpGc,
              srcRect.x(), srcRect.y(), srcRect.width(), srcRect.height(), 0, 0);

    XFreeGC(X11->display, tmpGc);

    return px;
}
Example #5
0
void GfxPainter::flip(const QRect &r)
{
    if(clipRegion == QRegion(fRect)) {
        QRect fr = fRect.intersected(r);
        if(!fr.isEmpty()) flipUnclipped(fr);
    } else {
        QRegion allocated = clipRegion.translated(-fRect.topLeft());
        QVector<QRect> rects = allocated.rects();
        for(int ii = 0; ii < rects.count(); ++ii) {
            QRect fr = rects.at(ii).intersected(r);
            if(!fr.isEmpty()) flipUnclipped(fr);
        }
    }
}
Example #6
0
bool KMaskImageItem::getBatchRandomPoint( QList<QPoint>& pts, int count, QGraphicsItem *toItem )
{
	Q_D(KMaskImageItem);

	int seed = GetTickCount();
	qsrand(seed);
	pts.clear();
	if(d->m_maskRegion.isEmpty())
	{
		QRect br = rect().toRect();
		if(br.isEmpty())
			return false;
		int i = 0;
		while(i < count)
		{
			int x = qrand() % br.width();
			int y = qrand() % br.height();
			pts.push_back(QPoint(x,y));
			i++;
		}		
	}
	else
	{
		QRect br = d->m_maskRegion.boundingRect();
		if(br.isEmpty())
			return false;
		int i = 0;
		while(i < count)
		{
			int x = qrand() % br.width();
			int y = qrand() % br.height();
			if(d->m_maskRegion.contains(QPoint(x,y)))
			{
				pts.push_back(QPoint(x,y));
				i++;
			}
		}
	}

	if(toItem)
	{
		for(int i = 0; i < count; i++)
		{
			QPoint pt = pts[i];
			pts[i] = mapToItem(toItem, pt).toPoint();
		}
	}
	return true;
}
MainWindow::MainWindow()
{
    setWindowTitle("Surfer");

    QSettings settings;
    QRect geometry = settings.value("MainWindow/geometry").toRect();
    if(!geometry.isEmpty())
    {
        setGeometry(geometry);
    }
    else
    {
        resize(900, 600);
    }

    m_exitShortcut = new QShortcut(Qt::CTRL + Qt::Key_Q, this);
    connect(m_exitShortcut, SIGNAL(activated()), this, SLOT(close()));

    setCentralWidget(TabManager::tabManager());

    SettingsManager::settingsManager()->load();
    NetworkAccessManager::networkAccessManager()->load();
    TabManager::tabManager()->load();
    HistoryManager::historyManager()->load();
    BookmarksManager::bookmarksManager()->load();
    DownloadManager::downloadManager()->load();
}
void FunctionSegmentViewer::onNextCurveButtonPressed() {
  if (!m_curve) return;

  if (m_segmentIndex == m_curve->getKeyframeCount() - 2) return;

  int currentKeyIndex;
  if (m_segmentIndex >= 0) {
    currentKeyIndex = m_segmentIndex;
  }
  /*--- Segmentが選択されていない→Segmentの上側が選ばれているはず ---*/
  else {
    QRect selectedCells = m_sheet->getSelectedCells();
    if (selectedCells.isEmpty()) return;

    currentKeyIndex = m_curve->getNextKeyframe(selectedCells.top());
    if (currentKeyIndex != 0) return;
  }

  int col = m_sheet->getColumnIndexByCurve(m_curve);
  /*--- Sheet上にCurveが表示されていない場合はcolに-1が返る ---*/
  if (col < 0) return;

  TDoubleKeyframe nextKey     = m_curve->getKeyframe(currentKeyIndex + 1);
  TDoubleKeyframe nextNextKey = m_curve->getKeyframe(currentKeyIndex + 2);

  int r0 = (int)nextKey.m_frame;
  int r1 = (int)nextNextKey.m_frame;

  m_sheet->getSelection()->selectSegment(m_curve, currentKeyIndex + 1,
                                         QRect(col, r0, 1, r1 - r0 + 1));
  m_sheet->updateAll();
}
Example #9
0
    static QImage renderChar(const QString& text, const QFont &font) {
#ifdef HAVE_THREADED_TEXT_RENDERING_WORKAROUND
        QWidget *focusWidget = qApp->focusWidget();
        if (focusWidget) {
            QThread *guiThread = focusWidget->thread();
            if (guiThread != QThread::currentThread()) {
                warnKrita << "WARNING: Rendering text in non-GUI thread!"
                           << "That may lead to hangups and crashes on some"
                           << "versions of X11/Qt!";
            }
        }
#endif /* HAVE_THREADED_TEXT_RENDERING_WORKAROUND */

        QFontMetrics metric(font);
        QRect rect = metric.boundingRect(text);

        if (rect.isEmpty()) {
            rect = QRect(0, 0, 1, 1); // paint at least something
        }

        QRect paintingRect = rect.translated(-rect.x(), -rect.y());

        QImage renderedChar(paintingRect.size(), QImage::Format_ARGB32);
        QPainter p;
        p.begin(&renderedChar);
        p.setFont(font);
        p.fillRect(paintingRect, Qt::white);
        p.setPen(Qt::black);
        p.drawText(-rect.x(), -rect.y(), text);
        p.end();
        return renderedChar;
    }
Example #10
0
void Canvas::paintEvent(QPaintEvent *event)
{

    QPainter painter(this);
    QRect dirtyRect = event->rect();
    if(dirtyRect.isEmpty())return;
    //    painter.setOpacity(opacity);
    combineLayers(dirtyRect);

    painter.drawPixmap(dirtyRect, image, dirtyRect);

    if(!isEnabled()){
        QBrush brush;
        brush.setStyle(Qt::BDiagPattern);
        brush.setColor(Qt::lightGray);
        painter.setBrush(brush);
        QRect rect = this->rect();
        rect.setWidth(rect.width());
        rect.setHeight(rect.height());
        painter.drawRect(rect);
    }

    QStyleOption opt;
    opt.init(this);
    style()->drawPrimitive(QStyle::PE_Widget,
                           &opt, &painter, this);

}
void MainWindowPlugin::correctWindowPosition() const
{
	QRect windowRect = FMainWindowBorder ? FMainWindowBorder->geometry() : FMainWindow->geometry();
	if (FMainWindowBorder)
	{
		// correcting rect
		windowRect.setLeft(windowRect.left() - FMainWindowBorder->leftBorderWidth());
		windowRect.setRight(windowRect.right() + FMainWindowBorder->rightBorderWidth());
		windowRect.setTop(windowRect.top() - FMainWindowBorder->topBorderWidth());
		windowRect.setBottom(windowRect.bottom() + FMainWindowBorder->bottomBorderWidth());
	}

	QRect screenRect = qApp->desktop()->availableGeometry(qApp->desktop()->screenNumber(windowRect.topLeft()));
	if (!screenRect.isEmpty() && !screenRect.adjusted(10,10,-10,-10).intersects(windowRect))
	{
		if (windowRect.right() <= screenRect.left())
			windowRect.moveLeft(screenRect.left());
		else if (windowRect.left() >= screenRect.right())
			windowRect.moveRight(screenRect.right());
		if (windowRect.top() >= screenRect.bottom())
			windowRect.moveBottom(screenRect.bottom());
		else if (windowRect.bottom() <= screenRect.top())
			windowRect.moveTop(screenRect.top());
		if (FMainWindowBorder)
		{
			// correcting rect back
			windowRect.setLeft(windowRect.left() + FMainWindowBorder->leftBorderWidth());
			windowRect.setRight(windowRect.right() - FMainWindowBorder->rightBorderWidth());
			windowRect.setTop(windowRect.top() + FMainWindowBorder->topBorderWidth());
			windowRect.setBottom(windowRect.bottom() - FMainWindowBorder->bottomBorderWidth());
		}
		mainWindowTopWidget()->move(windowRect.topLeft());
	}
}
Example #12
0
void Differ::computeVisualHighlights(QPainterPath *highlighted1,
        QPainterPath *highlighted2, const QImage &plainImage1,
        const QImage &plainImage2)
{
    QRect box;
    if (margins)
        box = pixelRectForMargins(plainImage1.size());
    QRect target;
    for (int x = 0; x < plainImage1.width(); x += squareSize) {
        for (int y = 0; y < plainImage1.height(); y += squareSize) {
            const QRect rect(x, y, squareSize, squareSize);
            if (!box.isEmpty() && !box.contains(rect))
                continue;
            QImage temp1 = plainImage1.copy(rect);
            QImage temp2 = plainImage2.copy(rect);
            if (temp1 != temp2) {
                if (rect.adjusted(-1, -1, 1, 1).intersects(target))
                    target = target.united(rect);
                else {
                    highlighted1->addRect(target);
                    highlighted2->addRect(target);
                    target = rect;
                }
            }
        }
    }
    if (!target.isNull()) {
        highlighted1->addRect(target);
        highlighted2->addRect(target);
    }
}
Example #13
0
static DFBResult setWindowGeometry(IDirectFBWindow *dfbWindow, const QRect &old, const QRect &rect)
{
    DFBResult result = DFB_OK;
    const bool isMove = old.isEmpty() || rect.topLeft() != old.topLeft();
    const bool isResize = rect.size() != old.size();

#if (Q_DIRECTFB_VERSION >= 0x010000)
    if (isResize && isMove) {
        result = dfbWindow->SetBounds(dfbWindow, rect.x(), rect.y(),
                                      rect.width(), rect.height());
    } else if (isResize) {
        result = dfbWindow->Resize(dfbWindow,
                                   rect.width(), rect.height());
    } else if (isMove) {
        result = dfbWindow->MoveTo(dfbWindow, rect.x(), rect.y());
    }
#else
    if (isResize) {
        result = dfbWindow->Resize(dfbWindow,
                                   rect.width(), rect.height());
    }
    if (isMove) {
        result = dfbWindow->MoveTo(dfbWindow, rect.x(), rect.y());
    }
#endif
    return result;
}
void KisPasteNewActionFactory::run(KisView2 *view)
{
    Q_UNUSED(view);

    KisPaintDeviceSP clip = KisClipboard::instance()->clip(QRect(), true);
    if (!clip) return;

    QRect rect = clip->exactBounds();
    if (rect.isEmpty()) return;

    KisDoc2 *doc = new KisDoc2();
    if (!doc) return;

    KisImageSP image = new KisImage(doc->createUndoStore(),
                                    rect.width(),
                                    rect.height(),
                                    clip->colorSpace(),
                                    i18n("Pasted"));
    KisPaintLayerSP layer =
        new KisPaintLayer(image.data(), clip->objectName(),
                          OPACITY_OPAQUE_U8, clip->colorSpace());

    KisPainter p(layer->paintDevice());
    p.setCompositeOp(COMPOSITE_COPY);
    p.bitBlt(0, 0, clip, rect.x(), rect.y(), rect.width(), rect.height());
    p.end();

    image->addNode(layer.data(), image->rootLayer());
    doc->setCurrentImage(image);

    KoMainWindow *win = doc->documentPart()->createMainWindow();
    win->show();
    win->setRootDocument(doc);
}
void BachelorThesis::adjustRoiSize( const QRect & srcRoi, QRect & dstRoi, const QPoint & maxSize )
{
	dstRoi = srcRoi;
	if( srcRoi.x() < 0 )
	{
		dstRoi.setLeft( 0 );
	}
	if( srcRoi.y() < 0 )
	{
		dstRoi.setTop( 0 );
	}
	if( srcRoi.right() >= maxSize.x() )
	{
		dstRoi.setRight( maxSize.x() - 2 );
	}

	if( srcRoi.bottom() >= maxSize.y() )
	{
		dstRoi.setBottom( maxSize.y() - 2 );
	}
	if( srcRoi.isEmpty() )
	{
		dstRoi = QRect( 0, 0, maxSize.x(), maxSize.y() );
	}
}
Example #16
0
/*
*Function: maybeTip
*Inputs:where to plot it
*Outputs:none
*Returns:none
*/
void GraphTipsData::maybeTip(const QPoint &pt) 
{
	if(pP->XRange > 0)
	{
		if(pP->plotRect.contains(pt,TRUE))
		{
			QString s;
			double dx = pt.x() - pP->plotRect.left(); 
			if(dx > 0)
			{
				double dy = pP->plotRect.bottom() - pt.y();
				if(dy > 0)
				{
					double dt = (dx * (double)pP->XRange /(double)pP->plotRect.width());
					double d = pP->minX + dt; 
					double v = dy /(double)pP->plotRect.height() * (pP->scaleMax - pP->scaleMin) + pP->scaleMin;
					s.sprintf("%8.6g",v);
					s = s + " " + QString::number(d);
					//
					QRect r = FitRect(s,pP->plotRect);
					//
					if(!r.isEmpty())
					{
						clear();
						tip(r,s);
					};
				};
			};
		};
	};
};
Example #17
0
void KisImagePyramid::recalculateCache(KisPPUpdateInfoSP info)
{
    KisPaintDevice *src;
    KisPaintDevice *dst;
    QRect currentSrcRect = info->dirtyImageRect;

    for (int i = FIRST_NOT_ORIGINAL_INDEX; i < m_pyramidHeight; i++) {
        src = m_pyramid[i-1].data();
        dst = m_pyramid[i].data();
        if (!currentSrcRect.isEmpty()) {
            currentSrcRect = downsampleByFactor2(currentSrcRect, src, dst);
        }
    }

#ifdef DEBUG_PYRAMID
    QImage image = m_pyramid[ORIGINAL_INDEX]->convertToQImage(m_monitorProfile, m_renderingIntent, m_conversionFlags);
    image.save("./PYRAMID_BASE.png");

    image = m_pyramid[1]->convertToQImage(m_monitorProfile, m_renderingIntent, m_conversionFlags);
    image.save("./LEVEL1.png");

    image = m_pyramid[2]->convertToQImage(m_monitorProfile, m_renderingIntent, m_conversionFlags);
    image.save("./LEVEL2.png");
    image = m_pyramid[3]->convertToQImage(m_monitorProfile, m_renderingIntent, m_conversionFlags);
    image.save("./LEVEL3.png");
#endif
}
Example #18
0
void QQnxWindow::setGeometry(const QRect &rect)
{
    const QRect oldGeometry = setGeometryHelper(rect);

#if !defined(QT_NO_OPENGL)
    // If this is an OpenGL window we need to request that the GL context updates
    // the EGLsurface on which it is rendering. The surface will be recreated the
    // next time QQnxGLContext::makeCurrent() is called.
    {
        // We want the setting of the atomic bool in the GL context to be atomic with
        // setting m_requestedBufferSize and therefore extended the scope to include
        // that test.
        const QMutexLocker locker(&m_mutex);
        m_requestedBufferSize = rect.size();
        if (m_platformOpenGLContext != 0 && bufferSize() != rect.size())
            m_platformOpenGLContext->requestSurfaceChange();
    }
#endif

    // Send a geometry change event to Qt (triggers resizeEvent() in QWindow/QWidget).

    // Calling flushWindowSystemEvents() here would flush input events which
    // could result in re-entering QQnxWindow::setGeometry() again.
    QWindowSystemInterface::setSynchronousWindowsSystemEvents(true);
    QWindowSystemInterface::handleGeometryChange(window(), rect);
    QWindowSystemInterface::setSynchronousWindowsSystemEvents(false);

    // Now move all children.
    if (!oldGeometry.isEmpty()) {
        const QPoint offset = rect.topLeft() - oldGeometry.topLeft();
        Q_FOREACH (QQnxWindow *childWindow, m_childWindows)
            childWindow->setOffset(offset);
    }
}
Example #19
0
void QwtPicker::drawTracker(QPainter *painter) const
{
    const QRect textRect = trackerRect(painter->font());
    if ( !textRect.isEmpty() )
    {
        QwtText label = trackerText(d_data->trackerPosition);
        if ( !label.isEmpty() )
        {
            painter->save();

#if defined(Q_WS_MAC)
            // Antialiased fonts are broken on the Mac.
#if QT_VERSION >= 0x040000 
            painter->setRenderHint(QPainter::TextAntialiasing, false);
#else
            QFont fnt = label.usedFont(painter->font());
            fnt.setStyleStrategy(QFont::NoAntialias);
            label.setFont(fnt);
#endif
#endif
            label.draw(painter, textRect);

            painter->restore();
        }
    }
}
Example #20
0
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void jdlvFrame::SelectColor (QAction *act) // called from menu action
{                                          //
  if (act->text().startsWith("random")) {
    elRecolorator rc(act->text().indexOf("Bi") > 0 ? "%%%%%%%" : "*******");
    primeWorld->changeTheWorld(rc);
         vista->updateTheWorld  (); notifyOfChange();
  }
  else { char cl = act->text().at(0).unicode();
    switch (cl) {
    case 'b': curColor = elcDefault; cl = 'o'; break; // -- "blanco"
    case 'r': curColor = elcRojo;              break;
    case 'v': curColor = elcVerde;             break;
    case 'a': curColor = elcAzul;              break;
    case 'x': curColor = elcCianico;           break;
    case 'c': curColor = elcCastano;           break;
    case 'z': curColor = elcMagenta;           break;
    case 'U':
      { elRecolorator uc("ooooooo"); // everything -> default color ("blanco")
        primeWorld->changeTheWorld(uc);
             vista->updateTheWorld  (); notifyOfChange(); return; }
    }
    setColor->setIcon (act->icon());
    QRect S = vista->getSelection();
    if (eM == elModeEdit && !S.isEmpty()) {   QString rule(elcMax, QChar(cl));
      elRecolorator rc(rule.cStr(), S.left(), S.right(), S.top(), S.bottom());
      primeWorld->changeTheWorld(rc);
           vista->updateTheWorld  (); notifyOfChange();
} } }
Example #21
0
QRect QLineEditPrivate::adjustedControlRect(const QRect &rect) const
{
    QRect widgetRect = !rect.isEmpty() ? rect : q_func()->rect();
    QRect cr = adjustedContentsRect();
    int cix = cr.x() - hscroll + horizontalMargin;
    return widgetRect.translated(QPoint(cix, vscroll));
}
Example #22
0
QRect KisFilterMask::needRect(const QRect& rect, PositionToFilthy pos) const
{
    Q_UNUSED(pos);

    /**
     * FIXME: This check of the emptiness should be done
     * on the higher/lower level
     */

    if(rect.isEmpty()) return rect;

    KisSafeFilterConfigurationSP filterConfig = filter();
    if (!filterConfig) return rect;

    KisNodeSP parent = this->parent();
    const int lod = parent && parent->projection() ?
        parent->projection()->defaultBounds()->currentLevelOfDetail() : 0;

    KisFilterSP filter = KisFilterRegistry::instance()->value(filterConfig->name());

    /**
     * If we need some additional pixels even outside of a selection
     * for accurate layer filtering, we'll get them!
     * And no KisMask::needRect will prevent us from doing this! ;)
     * That's why simply we do not call KisMask::needRect here :)
     */
    return filter->neededRect(rect, filterConfig.data(), lod);
}
void AbstractAreaWidget::paintIntoRect( QPainter& painter, const QRect& rect )
{
    if ( rect.isEmpty() ) return;

    d->resizeLayout( this, rect.size() );

    const QPoint translation( rect.topLeft() );
    painter.translate( translation );
    paintAll( painter );
    painter.translate( -translation.x(), -translation.y() );

/*
    // make sure, the contents of the widget have been set up,
    // so we get a useful geometry:
    needSizeHint();

    const QRect oldGeometry( layout()->geometry() );
    const QRect newGeo( QPoint(0,0), rect.size() );
    const bool mustChangeGeo = layout() && oldGeometry != newGeo;
    if ( mustChangeGeo )
        layout()->setGeometry( newGeo );
    painter.translate( rect.left(), rect.top() );
    paintAll( painter );
    painter.translate( -rect.left(), -rect.top() );
    if ( mustChangeGeo )
        layout()->setGeometry( oldGeometry );
*/
}
QRegion::QRegion( const QRect &r, RegionType t )
{
    data = new QRegionData;
    Q_CHECK_PTR( data );
    data->hgt = 0;
    data->is_null = FALSE;
    if ( r.isEmpty() ) {
	data->rgn = 0;
    } else {
        HPS hps = qt_display_ps();
	if ( t == Rectangle ) {			// rectangular region
            RECTL rcl = { r.left(), -(r.bottom()+1), r.right()+1, -r.top() };
            data->rgn = GpiCreateRegion( hps, 1, &rcl );
	} else if ( t == Ellipse ) {		// elliptic region
            // if the width or height of the ellipse is odd, GPI always
            // converts it to a nearest even value, which is obviously stupid
            // (see also QPainter::drawArcInternal()). So, we don't use
            // GpiCreateEllipticRegion(), but create an array of points to
            // call GpiCreatePolygonRegion() instead.
            QPointArray a;
            a.makeArc( r.x(), r.y(), r.width(), r.height(), 0, 360 * 16 );
            for ( uint i = 0; i < a.size(); ++ i )
                a[i].ry() = -(a[i].y() + 1);
            // GpiCreatePolygonRegion() is bogus and always starts a poligon from
            // the current position. Make the last point the current one and reduce
            // the number of points by one.
            GpiMove( hps, (PPOINTL) &a[ a.size() - 1 ] );
            POLYGON poly = { a.size() - 1, (PPOINTL) a.data() };
            data->rgn = GpiCreatePolygonRegion( hps, 1, &poly, POLYGON_ALTERNATE );
	}
    }
}
Example #25
0
void GLTexture::render(QRegion region, const QRect& rect, bool hardwareClipping)
{
    Q_D(GLTexture);
    if (rect.isEmpty())
        return; // nothing to paint and m_vbo is likely nullptr and d->m_cachedSize empty as well, #337090
    if (rect.size() != d->m_cachedSize) {
        d->m_cachedSize = rect.size();
        QRect r(rect);
        r.moveTo(0, 0);
        if (!d->m_vbo) {
            d->m_vbo = new GLVertexBuffer(KWin::GLVertexBuffer::Static);
        }

        const float verts[ 4 * 2 ] = {
            // NOTICE: r.x/y could be replaced by "0", but that would make it unreadable...
            static_cast<float>(r.x()), static_cast<float>(r.y()),
            static_cast<float>(r.x()), static_cast<float>(r.y() + rect.height()),
            static_cast<float>(r.x() + rect.width()), static_cast<float>(r.y()),
            static_cast<float>(r.x() + rect.width()), static_cast<float>(r.y() + rect.height())
        };

        const float texWidth = (target() == GL_TEXTURE_RECTANGLE_ARB) ? width() : 1.0f;
        const float texHeight = (target() == GL_TEXTURE_RECTANGLE_ARB) ? height() : 1.0f;

        const float texcoords[ 4 * 2 ] = {
            0.0f, d->m_yInverted ? 0.0f : texHeight, // y needs to be swapped (normalized coords)
            0.0f, d->m_yInverted ? texHeight : 0.0f,
            texWidth, d->m_yInverted ? 0.0f : texHeight,
            texWidth, d->m_yInverted ? texHeight : 0.0f
        };

        d->m_vbo->setData(4, 2, verts, texcoords);
    }
    d->m_vbo->render(region, GL_TRIANGLE_STRIP, hardwareClipping);
}
QRegion::QRegion( const QPointArray &a, bool winding )
{
    data = new QRegionData;
    Q_CHECK_PTR( data );
    data->hgt = 0;
    data->is_null = FALSE;
    QRect r = a.boundingRect();
    if ( a.isEmpty() || r.isEmpty() ) {
	data->rgn = 0;
    } else {
        HPS hps = qt_display_ps();
        POINTL *pts = new POINTL[ a.size() ]; 
        for ( uint i = 0; i < a.size(); ++ i ) {
            pts[i].x = a[i].x();
            pts[i].y = - (a[i].y() + 1);
        }
        // GpiCreatePolygonRegion() is bogus and always starts a poligon from
        // the current position. Make the last point the current one and reduce
        // the number of points by one.
        GpiMove( hps, &pts[ a.size() - 1 ] );
        POLYGON poly = { a.size() - 1, pts };
        ULONG opts = winding ? POLYGON_WINDING : POLYGON_ALTERNATE;
        data->rgn = GpiCreatePolygonRegion( hps, 1, &poly, opts );
        delete[] pts;
    }
}
Example #27
0
    QVector<QPoint> splitIntoConnectedComponents(KisPaintDeviceSP dev,
                                                 const QRect &boundingRect)
{
    QVector<QPoint> points;
    const KoColorSpace *cs = dev->colorSpace();

    const QRect rect = dev->exactBounds() & boundingRect;
    if (rect.isEmpty()) return points;

    /**
     * Please note that since we modify the device inside
     * clearNonZeroComponent() call, we must use a *writable*
     * iterator, for not ending up with a lazy copied old version of a
     * device.
     */
    KisSequentialIterator dstIt(dev, rect);

    do {
        if (cs->opacityU8(dstIt.rawData()) > 0) {
            const QPoint pt(dstIt.x(), dstIt.y());
            points << pt;

            KisScanlineFill fill(dev, pt, rect);
            fill.clearNonZeroComponent();
        }
    } while (dstIt.nextPixel());

    return points;
}
Example #28
0
/**
 * FIXME: try to cache filter pointer inside a Private block
 */
QRect KisFilterMask::changeRect(const QRect &rect, PositionToFilthy pos) const
{
    /**
     * FIXME: This check of the emptiness should be done
     * on the higher/lower level
     */
    if(rect.isEmpty()) return rect;

    QRect filteredRect = rect;

    KisSafeFilterConfigurationSP filterConfig = filter();
    if (filterConfig) {
        KisNodeSP parent = this->parent();
        const int lod = parent && parent->projection() ?
            parent->projection()->defaultBounds()->currentLevelOfDetail() : 0;

        KisFilterSP filter = KisFilterRegistry::instance()->value(filterConfig->name());
        filteredRect = filter->changedRect(rect, filterConfig.data(), lod);
    }

    /**
     * We can't paint outside a selection, that is why we call
     * KisMask::changeRect to crop actual change area in the end
     */
    filteredRect = KisMask::changeRect(filteredRect, pos);
    /**
     * FIXME: Think over this solution
     * Union of rects means that changeRect returns NOT the rect
     * changed by this very layer, but an accumulated rect changed
     * by all underlying layers. Just take into account and change
     * documentation accordingly
     */
    return rect | filteredRect;
}
Example #29
0
void InspectorClientQt::hideHighlight()
{
    WebCore::Frame& frame = m_inspectedWebPage->page->mainFrame();
    QRect rect = m_inspectedWebPage->mainFrameAdapter()->frameRect();
    if (!rect.isEmpty())
        frame.view()->invalidateRect(rect);
}
Example #30
0
/*!
    This function is equivalent to calling invalidateBuffer(QRegion(rect), ...), but
    is more efficient as it eliminates QRegion operations/allocations and can
    use the rect more precisely for additional cut-offs.

    ### Qt 4.6: Merge into a template function (after MSVC isn't supported anymore).
*/
void QWidgetPrivate::invalidateBuffer(const QRect &rect)
{
    Q_Q(QWidget);

    QTLWExtra *tlwExtra = q->window()->d_func()->maybeTopData();
    if (discardInvalidateBufferRequest(q, tlwExtra) || rect.isEmpty())
        return;

    QRect wRect(rect);
    wRect &= clipRect();
    if (wRect.isEmpty())
        return;

    if (graphicsEffect || !extra || !extra->hasMask) {
        tlwExtra->backingStore->markDirty(wRect, q, false, true);
        return;
    }

    QRegion wRgn(extra->mask);
    wRgn &= wRect;
    if (wRgn.isEmpty())
        return;

    tlwExtra->backingStore->markDirty(wRgn, q, false, true);
}