예제 #1
0
void AMScanThumbnailGridView::onHoverMove(int itemIndex, int positionX, int positionY)
{
    // get number of thumbnails
    QModelIndex modelIndexOfItem = model()->index(itemIndex, 0, QModelIndex());
    if(!modelIndexOfItem.isValid())
        return;

    int thumbnailCount = model()->rowCount(modelIndexOfItem);

    if(thumbnailCount == 0)
        return;

    // get position of x within the content rectangle for itemIndex
    QModelIndex modelThumbnailImageIndex = model()->index(0, 1, modelIndexOfItem);
    QRect thumbnailImageRectangle = visualRect(modelThumbnailImageIndex);
    QPoint posInsideRect(positionX - thumbnailImageRectangle.x(), positionY - thumbnailImageRectangle.y());

    // calculate at what thumbnail index the thumbnail should be at given the
    // position inside the thumbnail and the number of thumbnails
    int widthOfEachThumbnailSegment = thumbnailImageRectangle.width() / thumbnailCount;
    if(widthOfEachThumbnailSegment == 0)
        return;

    int currentThumbnailIndexToShow = 0;

    if (posInsideRect.x() > 0)
        currentThumbnailIndexToShow = posInsideRect.x() / widthOfEachThumbnailSegment;

    if(currentThumbnailIndexToShow+1 > thumbnailCount)
        currentThumbnailIndexToShow = thumbnailCount - 1;
    // check if the thumbnail map value for this index is already set to the
    // correct thumbnail value
    if(currentThumbnailIndexToShow != rowCurrentDisplayedThumbnailMap_.value(itemIndex)) {
        // if it isn't set it to be the new calculated thumbnail index
        rowCurrentDisplayedThumbnailMap_.remove(itemIndex);
        rowCurrentDisplayedThumbnailMap_.insert(itemIndex, currentThumbnailIndexToShow);

        // refresh the thumbnail rectangle
        QRegion regionForIndex(viewport()->rect());

        setDirtyRegion(regionForIndex);
    }
}
예제 #2
0
TableView::TableView(QWidget *parent)
	: QTableView(parent)
	, _model(new UniqueLibraryItemModel(this))
	, _jumpToWidget(new JumpToWidget(this))
{
	_model->proxy()->setDynamicSortFilter(false);
	this->setModel(_model->proxy());
	this->setVerticalScrollMode(ScrollPerPixel);
	LibraryScrollBar *vScrollBar = new LibraryScrollBar(this);
	this->setVerticalScrollBar(vScrollBar);
	connect(_jumpToWidget, &JumpToWidget::aboutToScrollTo, this, &TableView::jumpTo);
	connect(_model->proxy(), &UniqueLibraryFilterProxyModel::aboutToHighlightLetters, _jumpToWidget, &JumpToWidget::highlightLetters);
	connect(vScrollBar, &QAbstractSlider::valueChanged, this, [=](int) {
		QModelIndex iTop = indexAt(viewport()->rect().topLeft());
		_jumpToWidget->setCurrentLetter(_model->currentLetter(iTop.sibling(iTop.row(), 1)));
	});
	this->installEventFilter(this);
	horizontalHeader()->resizeSection(0, SettingsPrivate::instance()->coverSize());

	connect(selectionModel(), &QItemSelectionModel::selectionChanged, [=](const QItemSelection &, const QItemSelection &) {
		setDirtyRegion(QRegion(viewport()->rect()));
	});
}
예제 #3
0
void QgsFeatureListView::repaintRequested()
{
  setDirtyRegion( viewport()->rect() );
}
예제 #4
0
void SourceCodeTreeView::Repaint()
{
    QRect dirtyRegionRect = visibleRegion().boundingRect();
    setDirtyRegion(dirtyRegionRect);
    repaint();
}
예제 #5
0
void FileListView::keyPressEvent( QKeyEvent *event )
{
    int overridden_key = 0;
    QModelIndex wasCurrent = currentIndex();

    bool isControlEnter = (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) && (event->modifiers() & Qt::ControlModifier);
    switch (event->key())
    {
    case Qt::Key_Shift:
        currentSelectionAction = selectionModel()->isSelected(currentIndex()) ? QItemSelectionModel::Deselect : QItemSelectionModel::Select;
        break;

    case Qt::Key_Plus:
    case Qt::Key_Minus:
    case Qt::Key_Asterisk:
        SelectAll(event->key() == Qt::Key_Plus ? QItemSelectionModel::Select :
                  event->key() == Qt::Key_Minus ? QItemSelectionModel::Deselect :
                  QItemSelectionModel::Toggle);
        break;

    case Qt::Key_Left:
        overridden_key = Qt::Key_PageUp;
        break;
    case Qt::Key_Right:
        overridden_key = Qt::Key_PageDown;
        break;

    case Qt::Key_Insert:
        overridden_key = Qt::Key_Down;
        selectionModel()->select(currentIndex(), QItemSelectionModel::Toggle);
        break;

    case Qt::Key_Enter:
    case Qt::Key_Return:
        if (!isControlEnter)
        {
            if (event->modifiers() & Qt::ShiftModifier)
                emit OpenSelected();
            else
                emit EnterSelected();
        }
        break;
    }

    if (isSearchMode && !isControlEnter)
        switch (event->key())
        {
        case Qt::Key_Return:
        case Qt::Key_Enter:
        case Qt::Key_Escape:
        case Qt::Key_Left:
        case Qt::Key_Right:
        case Qt::Key_Up:
        case Qt::Key_Down:
        case Qt::Key_PageUp:
        case Qt::Key_PageDown:
        case Qt::Key_Home:
        case Qt::Key_End:
            Action_CloseQuickFind();
            break;
        }

    if ((isControlEnter && isSearchMode) ||
            (!event->text().isEmpty() && event->text() != "\x0d" &&
             !(event->modifiers() & (Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier)) &&
             !edit(currentIndex(), AnyKeyPressed, event)))
    {
        Action_OpenQuickFind();
        if (!isControlEnter)
            Action_QuickFindProcessKeyPressEvent(event);

        bool isFound = (event->modifiers() & Qt::ShiftModifier) ? Action_QuickFindPrev() : Action_QuickFindNext(!isControlEnter);
        if (!isControlEnter)
        {
            static bool wasFound = true;
            if (wasFound != isFound)
            {
                wasFound = isFound;

                QPalette pal = searchEdit->palette();
                pal.setColor(QPalette::Base, QColor(255, 200, 200));
                if (isFound)
                    pal = palette();
                searchEdit->setPalette(pal);
            }
        }

        setDirtyRegion(QRegion(0, 0, width(), height()));
        //keyboardSearch(event->text());
        event->accept();
    }
    else
    {
        event->ignore();

        if (overridden_key)
        {
            QKeyEvent newEvent(event->type(), overridden_key, event->modifiers(), event->text(), event->isAutoRepeat(), event->count());
            QTreeView::keyPressEvent(&newEvent);
        }
        else
            QTreeView::keyPressEvent(event);
    }

    if (event->modifiers() & Qt::ShiftModifier)
    {
        QModelIndex current = currentIndex();
        switch (event->key())
        {
        case Qt::Key_Up:
        case Qt::Key_Down:
            selectionModel()->select(wasCurrent, currentSelectionAction);
            break;

        case Qt::Key_Left:
        case Qt::Key_PageUp:
        case Qt::Key_Right:
        case Qt::Key_PageDown:
        case Qt::Key_Home:
        case Qt::Key_End:
            if (current.row() < wasCurrent.row())
                qSwap(wasCurrent, current);

            QItemSelection toSelect;
            toSelect << QItemSelectionRange(model()->index(wasCurrent.row(), 0), model()->index(current.row(), 1));
            selectionModel()->select(toSelect, currentSelectionAction);
            break;
        }
    }
}