Exemplo n.º 1
0
//**************************************************************************************
// All objects inside the a region defined by selectionRegion will be selected.
//**************************************************************************************
void ScatterView::selectRegion(void)
{
	if (selMode != 1)
		return;

	if(selectionRegion.size() <= 0)
		return;

	if(!table)
		return;

	//Make the last point the first point to create a closed loop
	selectionRegion.append( selectionRegion[0] );
	int numPoints = selectionRegion.size();

	//Turn my list of clicks into a path
	QPainterPath path;
	path.moveTo(selectionRegion[0]);
	for (int i=0; i < numPoints; i++)
	{
		path.lineTo(selectionRegion[i]);
	}
	//Draw the path in an image
	//QRect rect(LMargin, TMargin, this->width() - (LMargin+RMargin), this->height() - (BMargin+TMargin));
	QRect rect(0,0,this->width(), this->height());
	QImage img(rect.width(),rect.height(),QImage::Format_Mono);
	img.fill(Qt::white);
	QPainter painter(&img);
	painter.setPen(Qt::black);
	painter.setBrush(Qt::black);
	painter.drawPath(path);
	//Turn the image into a Region
	QBitmap bitmap = QBitmap::fromImage(img, Qt::MonoOnly | Qt::ThresholdDither);
	QRegion region(bitmap);

	//Get the Ids of the objects within this region and select them:
	std::set<long int> sels;
	int rows = table->rowCount();
	for (int row = 0; row < rows; ++row) 
	{
        QRegion point = getObjectRect( row );
		//if it intersects with the selection region, save the index
		if (!point.intersect(region).isEmpty())
		{
			sels.insert( row );
		}
    }
	selectionRegion.clear();
	selection->add(sels);
}
Exemplo n.º 2
0
void PvrEglWindowSurface::setDirectRegion(const QRegion &r, int id)
{
    QWSGLWindowSurface::setDirectRegion(r, id);

    if (!drawable)
        return;

    // Clip the region to the window boundaries in case the child
    // is partially outside the geometry of the parent.
    QWidget *window = widget->window();
    QRegion region = r;
    if (widget != window) {
	QRect rect = window->geometry();
        rect.moveTo(window->mapToGlobal(QPoint(0, 0)));
        region = region.intersect(rect);
    }

    if (region.isEmpty()) {
        pvrQwsClearVisibleRegion(drawable);
    } else if (region.rectCount() == 1) {
        QRect rect = region.boundingRect();
        PvrQwsRect pvrRect;
        pvrRect.x = rect.x();
        pvrRect.y = rect.y();
        pvrRect.width = rect.width();
        pvrRect.height = rect.height();
        transformRects(&pvrRect, 1);
        pvrQwsSetVisibleRegion(drawable, &pvrRect, 1);
        pvrQwsSetRotation(drawable, screen->transformation());
        if (!pvrQwsSwapBuffers(drawable, 1))
            screen->solidFill(QColor(0, 0, 0), region);
    } else {
        QVector<QRect> rects = region.rects();
        PvrQwsRect *pvrRects = new PvrQwsRect [rects.size()];
        for (int index = 0; index < rects.size(); ++index) {
            QRect rect = rects[index];
            pvrRects[index].x = rect.x();
            pvrRects[index].y = rect.y();
            pvrRects[index].width = rect.width();
            pvrRects[index].height = rect.height();
        }
        transformRects(pvrRects, rects.size());
        pvrQwsSetVisibleRegion(drawable, pvrRects, rects.size());
        pvrQwsSetRotation(drawable, screen->transformation());
        if (!pvrQwsSwapBuffers(drawable, 1))
            screen->solidFill(QColor(0, 0, 0), region);
        delete [] pvrRects;
    }
}
Exemplo n.º 3
0
void PieView::setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command)
{
    // Use content widget coordinates because we will use the itemRegion()
    // function to check for intersections.

    QRect contentsRect = rect.translated(
                            horizontalScrollBar()->value(),
                            verticalScrollBar()->value()).normalized();

    int rows = model()->rowCount(rootIndex());
    int columns = model()->columnCount(rootIndex());
    QModelIndexList indexes;

    for (int row = 0; row < rows; ++row) {
        for (int column = 0; column < columns; ++column) {
            QModelIndex index = model()->index(row, column, rootIndex());
            QRegion region = itemRegion(index);
            if (!region.intersect(contentsRect).isEmpty())
                indexes.append(index);
        }
    }

    if (indexes.size() > 0) {
        int firstRow = indexes[0].row();
        int lastRow = indexes[0].row();
        int firstColumn = indexes[0].column();
        int lastColumn = indexes[0].column();

        for (int i = 1; i < indexes.size(); ++i) {
            firstRow = qMin(firstRow, indexes[i].row());
            lastRow = qMax(lastRow, indexes[i].row());
            firstColumn = qMin(firstColumn, indexes[i].column());
            lastColumn = qMax(lastColumn, indexes[i].column());
        }

        QItemSelection selection(
            model()->index(firstRow, firstColumn, rootIndex()),
            model()->index(lastRow, lastColumn, rootIndex()));
        selectionModel()->select(selection, command);
    } else {
        QModelIndex noIndex;
        QItemSelection selection(noIndex, noIndex);
        selectionModel()->select(selection, command);
    }

    update();
}
Exemplo n.º 4
0
void MythUIType::SetChildNeedsRedraw(MythUIType *child)
{
    QRegion childRegion = child->GetDirtyArea();
    if (childRegion.isEmpty())
        return;

    childRegion.translate(m_Area.x(), m_Area.y());

    childRegion = childRegion.intersect(m_Area.toQRect());

    m_NeedsRedraw = true;

    if (m_DirtyRegion.isEmpty())
        m_DirtyRegion = childRegion;
    else
        m_DirtyRegion = m_DirtyRegion.unite(childRegion);

    if (m_Parent)
        m_Parent->SetChildNeedsRedraw(this);
}