void
PartitionBarsView::mouseMoveEvent( QMouseEvent* event )
{
    QModelIndex candidateIndex = indexAt( event->pos() );
    QPersistentModelIndex oldHoveredIndex = m_hoveredIndex;
    if ( candidateIndex.isValid() )
    {
        m_hoveredIndex = candidateIndex;
    }
    else
    {
        m_hoveredIndex = QModelIndex();
        QGuiApplication::restoreOverrideCursor();
    }

    if ( oldHoveredIndex != m_hoveredIndex )
    {
        if ( m_hoveredIndex.isValid() && !canBeSelected( m_hoveredIndex ) )
            QGuiApplication::setOverrideCursor( Qt::ForbiddenCursor );
        else
            QGuiApplication::restoreOverrideCursor();

        viewport()->repaint();
    }
}
void
PartitionBarsView::setSelection( const QRect& rect, QItemSelectionModel::SelectionFlags flags )
{
    //HACK: this is an utterly awful workaround, which is unfortunately necessary.
    //      QAbstractItemView::mousePressedEvent calls setSelection, but before that,
    //      for some mental reason, it works under the assumption that every item is a
    //      rectangle. This rectangle is provided by visualRect, and the idea mostly
    //      works, except when the item is an extended partition item, which is of course
    //      a rectangle with a rectangular hole in the middle.
    //      QAbstractItemView::mousePressEvent builds a QRect with x1, y1 in the center
    //      of said visualRect, and x2, y2 in the real QMouseEvent position.
    //      This may very well yield a QRect with negative size, which is meaningless.
    //      Therefore the QRect we get here is totally bogus, and its topLeft is outside
    //      the actual area of the item we need.
    //      What we need are the real coordinates of the QMouseEvent, and the only way to
    //      get them is by fetching the private x2, y2 from the rect.
    //      TL;DR: this sucks, look away. -- Teo 12/2015
    int x1, y1, x2, y2;
    rect.getCoords( &x1, &y1, &x2, &y2 );

    QModelIndex eventIndex = indexAt( QPoint( x2, y2 ) );
    if ( canBeSelected( eventIndex ) )
        selectionModel()->select( eventIndex, flags );

    viewport()->repaint();
}
void
PartitionBarsView::mousePressEvent( QMouseEvent* event )
{
    QModelIndex candidateIndex = indexAt( event->pos() );
    if ( canBeSelected( candidateIndex ) )
        QAbstractItemView::mousePressEvent( event );
    else
        event->accept();
}
bool MySSGetFilter::canBeSelected(AcDbObjectId id) const
{
	bool ans = true;
	AcDbEntity * pEnt;
	if (acdbOpenAcDbEntity(pEnt, id, AcDb::kForRead) == Acad::eOk) {
		ans = canBeSelected(pEnt);
		pEnt->close();
	}
	return ans;
}
void Board::drawSelectablePieces() const
{
	for (int i=0; i<sizeX_; ++i)
		for (int j=0; j<sizeY_; ++j)
		{
			QPoint p(i,j);
			if (canBeSelected(p))
			{
				glPushName(intFromPoint(p));
				caseAt(p).drawPieces(p);
				glPopName();
			}
		}
}
void MySSGetFilter::ssgetAddFilter(int ssgetFlags, AcEdSelectionSetService &service, const AcDbObjectIdArray& selectionSet, const AcDbObjectIdArray& subSelectionSet)
{
	if (m_color_index < 0)
		return;
	for (int i = 0; i < subSelectionSet.length(); ++i) {
		if (!canBeSelected(subSelectionSet[i])) {
			service.remove(i);
			continue;
		}
		if (!m_select_by_group) {
			high_light(subSelectionSet[i]);
		} else {

		}
	}
}
Beispiel #7
0
void TreeViewItem::setSelected (const bool shouldBeSelected,
                                const bool deselectOtherItemsFirst)
{
    if (shouldBeSelected && ! canBeSelected())
        return;

    if (deselectOtherItemsFirst)
        getTopLevelItem()->deselectAllRecursively();

    if (shouldBeSelected != selected)
    {
        selected = shouldBeSelected;
        if (ownerView != 0)
            ownerView->repaint();

        itemSelectionChanged (shouldBeSelected);
    }
}
void
PartitionBarsView::drawSection( QPainter* painter, const QRect& rect_, int x, int width, const QModelIndex& index )
{
    QColor color = index.isValid() ?
                   index.data( Qt::DecorationRole ).value< QColor >() :
                   ColorUtils::unknownDisklabelColor();
    bool isFreeSpace = index.isValid() ?
                       index.data( PartitionModel::IsFreeSpaceRole ).toBool() :
                       true;

    QRect rect = rect_;
    const int y = rect.y();
    const int height = rect.height();
    const int radius = qMax( 1, CORNER_RADIUS - ( VIEW_HEIGHT - height ) / 2 );
    painter->setClipRect( x, y, width, height );
    painter->translate( 0.5, 0.5 );

    rect.adjust( 0, 0, -1, -1 );


    if ( selectionMode() != QAbstractItemView::NoSelection && // no hover without selection
         m_hoveredIndex.isValid() &&
         index == m_hoveredIndex )
    {
        if ( canBeSelected( index ) )
            painter->setBrush( color.lighter( 115 ) );
        else
            painter->setBrush( color );
    }
    else
    {
        painter->setBrush( color );
    }

    QColor borderColor = color.darker();

    painter->setPen( borderColor );

    painter->drawRoundedRect( rect, radius, radius );

    // Draw shade
    if ( !isFreeSpace )
        rect.adjust( 2, 2, -2, -2 );

    QLinearGradient gradient( 0, 0, 0, height / 2 );

    qreal c = isFreeSpace ? 0 : 1;
    gradient.setColorAt( 0, QColor::fromRgbF( c, c, c, 0.3 ) );
    gradient.setColorAt( 1, QColor::fromRgbF( c, c, c, 0 ) );

    painter->setPen( Qt::NoPen );

    painter->setBrush( gradient );
    painter->drawRoundedRect( rect, radius, radius );

    if ( selectionMode() != QAbstractItemView::NoSelection &&
         index.isValid() &&
         selectionModel() &&
         !selectionModel()->selectedIndexes().isEmpty() &&
         selectionModel()->selectedIndexes().first() == index )
    {
        painter->setPen( QPen( borderColor, 1 ) );
        QColor highlightColor = QPalette().highlight().color();
        highlightColor = highlightColor.lighter( 500 );
        highlightColor.setAlpha( 120 );
        painter->setBrush( highlightColor );

        QRect selectionRect = rect;
        selectionRect.setX( x + 1 );
        selectionRect.setWidth( width - 3 ); //account for the previous rect.adjust

        if ( rect.x() > selectionRect.x() ) //hack for first item
            selectionRect.adjust( rect.x() - selectionRect.x(), 0, 0, 0 );

        if ( rect.right() < selectionRect.right() ) //hack for last item
            selectionRect.adjust( 0, 0, - ( selectionRect.right() - rect.right() ), 0 );

        selectionRect.adjust( SELECTION_MARGIN,
                              SELECTION_MARGIN,
                              -SELECTION_MARGIN,
                              -SELECTION_MARGIN );

        painter->drawRoundedRect( selectionRect,
                                  radius - 1,
                                  radius - 1 );
    }

    painter->translate( -0.5, -0.5 );
}