Example #1
0
void MyListWidget::mouseMoveEvent(QMouseEvent * event ){
    event->ignore();
    QPoint pos = event->pos();
    QPersistentModelIndex index = indexAt(pos);
    QPoint globPos = QWidget::mapToGlobal(pos);
    QTime now = QTime::currentTime();
    m_arrowHover = false;

    if(m_lastIndex == index){
//        if(m_hoveStart.msecsTo(now )< LIST_HOVER_INTERVAL){
//            return;
//        }
        m_hoveredIndex = index;
        m_hovered=true;
        update(index);

        QRect containingRect = visualRect(index);

        QRect pinRect = IconDelegate::getPinItemRect(containingRect);
        if(pinRect.contains(pos)){
            QToolTip::showText(globPos, PIN_MESSAGE,  this);
            return;
        }

        QRect depRect = IconDelegate::getDepricateItemRect(containingRect);
        if(depRect.contains(pos)){
            QToolTip::showText(globPos, DEPRICATE_MESSAGE, this);
            return;
        }

        QRect childRect = IconDelegate::getChildArrowRect(containingRect);
        if(childRect.contains(pos)){
            QToolTip::showText(globPos, GOTO_CHILDREN_MESSAGE, this);
            m_arrowHover = true;
            return;
        }
        QToolTip::showText(globPos, index.data(ROLE_DESCRIPTION).toString(), this);

    } else {
        if(m_hoveredIndex !=QPersistentModelIndex()){
            QPersistentModelIndex oldIndex = m_hoveredIndex;
            m_hoveredIndex =QPersistentModelIndex();
            update(oldIndex);
        }
        m_hoveStart = now;
        m_lastIndex = index;
    }
    gMainWidget->m_itemChoiceList->fakeMouseMoveEvent(event);
}
Example #2
0
MyListWidget::MyListWidget(QWidget* parent) :
        QListWidget(parent) {

    m_hoveredIndex =QPersistentModelIndex();
    m_showHotkey=false;
    m_arrowHover= false;

    setAttribute(Qt::WA_AlwaysShowToolTips);
    setAlternatingRowColors(true);
    setAutoScroll(true);
    QRect r = geometry();

    setAutoScrollMargin(r.height()/3);

    connect(this,
            SIGNAL(listItemAction(QString , CatItem )),
            (QObject*)gMainWidget, //
            SLOT(operateOnItem(QString , CatItem )));

    connect(this, SIGNAL(showOptionsMenu(QString, QPoint)),
            (QObject*)gMainWidget, SLOT(listMenuEvent(QString, QPoint)),
            Qt::QueuedConnection);

    setMouseTracking(true);
    m_hoveStart = QTime::currentTime();
    m_hovered= false;
}
Example #3
0
KNMusicModel::KNMusicModel(QObject *parent) :
    QAbstractTableModel(parent),
    m_detailInfos(QList<KNMusicDetailInfo>()),
    m_totalDuration(0),
    m_playingIndex(QPersistentModelIndex()),
    m_playingIcon(QVariant(QIcon(":/plugin/music/public/playingicon.png"))),
    m_cannotPlayIcon(QVariant(QIcon(":/plugin/music/public/cannotplay.png"))),
    m_nullValue(QVariant()),
    m_identifier(QString())
{
    //Build drop mime types for the first time.
    if(m_dropMimeTypes.isEmpty())
    {
        //Set the drop mime types for original types first.
        m_dropMimeTypes=QAbstractTableModel::mimeTypes();
        //Add url format.
        m_dropMimeTypes.append("text/uri-list");
        //Initial cache data.

        //Add music detail info list.
        m_dropMimeTypes.append(ModelMimeType);
        m_dropMimeTypes.append(ModelType);
        m_dropMimeTypes.append(ModelRowData);
        m_dropMimeTypes.append(ModelRowList);
    }
}
Example #4
0
void DirModel::delayedPreview()
{
    QHash<QUrl, QPersistentModelIndex>::const_iterator i = m_filesToPreview.constBegin();

    KFileItemList list;

    while (i != m_filesToPreview.constEnd()) {
        QUrl file = i.key();
        QPersistentModelIndex index = i.value();


        if (!m_previewJobs.contains(file) && file.isValid()) {
            list.append(KFileItem(file, QString(), 0));
            m_previewJobs.insert(file, QPersistentModelIndex(index));
        }

        ++i;
    }

    if (list.size() > 0) {
        KIO::PreviewJob* job = KIO::filePreview(list, m_screenshotSize);
        job->setIgnoreMaximumSize(true);
        // qDebug() << "Created job" << job;
        connect(job, &KIO::PreviewJob::gotPreview,
                this, &DirModel::showPreview);
        connect(job, &KIO::PreviewJob::failed,
                this, &DirModel::previewFailed);
    }

    m_filesToPreview.clear();
}
void QIdentityProxyModelPrivate::_q_sourceLayoutAboutToBeChanged(const QList<QPersistentModelIndex> &sourceParents, QAbstractItemModel::LayoutChangeHint hint)
{
    Q_Q(QIdentityProxyModel);

    foreach(const QPersistentModelIndex &proxyPersistentIndex, q->persistentIndexList()) {
        proxyIndexes << proxyPersistentIndex;
        Q_ASSERT(proxyPersistentIndex.isValid());
        const QPersistentModelIndex srcPersistentIndex = q->mapToSource(proxyPersistentIndex);
        Q_ASSERT(srcPersistentIndex.isValid());
        layoutChangePersistentIndexes << srcPersistentIndex;
    }

    QList<QPersistentModelIndex> parents;
    parents.reserve(sourceParents.size());
    foreach (const QPersistentModelIndex &parent, sourceParents) {
        if (!parent.isValid()) {
            parents << QPersistentModelIndex();
            continue;
        }
        const QModelIndex mappedParent = q->mapFromSource(parent);
        Q_ASSERT(mappedParent.isValid());
        parents << mappedParent;
    }

    q->layoutAboutToBeChanged(parents, hint);
}
Example #6
0
QList< QPersistentModelIndex > ModelSpy::toPersistent(QModelIndexList list)
{
  QList<QPersistentModelIndex > persistentList;
  foreach(QModelIndex idx, list)
  {
    persistentList << QPersistentModelIndex(idx);
  }
Example #7
0
QVariant DirModel::data(const QModelIndex &index, int role) const
{
    if (!index.isValid()) {
        return QVariant();
    }

    switch (role) {
    case UrlRole: {
        KFileItem item = itemForIndex(index);
        return item.url().toString();
    }
    case MimeTypeRole: {
        KFileItem item = itemForIndex(index);
        return item.mimetype();
    }
    case Thumbnail: {
        KFileItem item = itemForIndex(index);
        QImage preview = QImage(m_screenshotSize, QImage::Format_ARGB32_Premultiplied);

        if (m_imageCache->findImage(item.url().toString(), &preview)) {
            return preview;
        }

        m_previewTimer->start(100);
        const_cast<DirModel *>(this)->m_filesToPreview[item.url()] = QPersistentModelIndex(index);
    }
    default:
        return KDirModel::data(index, role);
    }
}
Example #8
0
KNMusicNowPlaying::KNMusicNowPlaying(QObject *parent) :
    KNMusicNowPlayingBase(parent),
    m_backend(nullptr),
    m_playingProxyModel(nullptr),
    m_shadowPlayingModel(new KNMusicProxyModel(this)),
    m_temporaryProxyPlaylist(new KNMusicProxyModel(this)),
    m_temporaryPlaylist(new KNMusicTemporaryPlaylistModel(this)),
    m_playingTab(nullptr),
    m_loopState(NoRepeat),
    m_playingIndex(QPersistentModelIndex()),
    m_playingAnalysisItem(KNMusicAnalysisItem()),
    m_manualPlayed(false)
{
    //Set the temporary playlist to the proxy model.
    m_temporaryProxyPlaylist->setSourceModel(m_temporaryPlaylist);
    //Initial the random device and random generator.
    QVector<int> seedData;
    //Generate the random device.
    std::random_device randomDevice;
    //Get the seed array size.
    const int seedCount=(int)std::mt19937::state_size;
    //Resize the seed data.
    seedData.resize(seedCount);
    //Set the data to the seed data.
    for(int i=0; i<seedCount; ++i)
    {
        //Replace the seed data.
        seedData.replace(i, randomDevice());
    }
    //Transform list to seed sequence.
    std::seed_seq seedSequence(std::begin(seedData), std::end(seedData));
    //Initial the Mersenne twister seeds.
    m_mersenneSeed=std::mt19937(seedSequence);
}
void QgsGeometryCheckerResultTab::addError( QgsGeometryCheckError *error )
{
  bool sortingWasEnabled = ui.tableWidgetErrors->isSortingEnabled();
  if ( sortingWasEnabled )
    ui.tableWidgetErrors->setSortingEnabled( false );

  int row = ui.tableWidgetErrors->rowCount();
  int prec = 7 - std::floor( std::max( 0., std::log10( std::max( error->location().x(), error->location().y() ) ) ) );
  QString posStr = QStringLiteral( "%1, %2" ).arg( error->location().x(), 0, 'f', prec ).arg( error->location().y(), 0, 'f', prec );

  ui.tableWidgetErrors->insertRow( row );
  QTableWidgetItem *idItem = new QTableWidgetItem();
  idItem->setData( Qt::EditRole, error->featureId() != FID_NULL ? QVariant( error->featureId() ) : QVariant() );
  ui.tableWidgetErrors->setItem( row, 0, new QTableWidgetItem( !error->layerId().isEmpty() ? mChecker->featurePools()[error->layerId()]->layer()->name() : "" ) );
  ui.tableWidgetErrors->setItem( row, 1, idItem );
  ui.tableWidgetErrors->setItem( row, 2, new QTableWidgetItem( error->description() ) );
  ui.tableWidgetErrors->setItem( row, 3, new QTableWidgetItem( posStr ) );
  QTableWidgetItem *valueItem = new QTableWidgetItem();
  valueItem->setData( Qt::EditRole, error->value() );
  ui.tableWidgetErrors->setItem( row, 4, valueItem );
  ui.tableWidgetErrors->setItem( row, 5, new QTableWidgetItem( QString() ) );
  ui.tableWidgetErrors->item( row, 0 )->setData( Qt::UserRole, QVariant::fromValue( error ) );
  ++mErrorCount;
  ui.labelErrorCount->setText( tr( "Total errors: %1, fixed errors: %2" ).arg( mErrorCount ).arg( mFixedCount ) );
  mStatistics.newErrors.insert( error );
  mErrorMap.insert( error, QPersistentModelIndex( ui.tableWidgetErrors->model()->index( row, 0 ) ) );

  if ( sortingWasEnabled )
    ui.tableWidgetErrors->setSortingEnabled( true );
}
Example #10
0
void
TransferView::onTransferUpdate()
{
    StreamConnection* sc = (StreamConnection*)sender();
//    qDebug() << Q_FUNC_INFO << sc->track().isNull() << sc->source().isNull();

    if ( sc->track().isNull() || sc->source().isNull() )
        return;

    QTreeWidgetItem* ti = 0;

    if ( m_index.contains( sc ) )
    {
        QPersistentModelIndex i = m_index.value( sc );
        ti = m_tree->invisibleRootItem()->child( i.row() );
    }
    else
    {
        ti = new QTreeWidgetItem( m_tree );
        m_index.insert( sc, QPersistentModelIndex( m_tree->model()->index( m_tree->invisibleRootItem()->childCount() - 1, 0 ) ) );
        emit showWidget();
    }

    if ( !ti )
        return;

    ti->setText( 0, sc->source()->friendlyName() );
    ti->setText( 1, QString( "%1 kb/s" ).arg( sc->transferRate() / 1024 ) );
    ti->setText( 2, QString( "%1 - %2" ).arg( sc->track()->artist()->name() ).arg( sc->track()->track() ) );

    if ( isHidden() )
        emit showWidget();
}
void QIdentityProxyModelPrivate::_q_sourceLayoutChanged(const QList<QPersistentModelIndex> &sourceParents, QAbstractItemModel::LayoutChangeHint hint)
{
    Q_Q(QIdentityProxyModel);

    for (int i = 0; i < proxyIndexes.size(); ++i) {
        q->changePersistentIndex(proxyIndexes.at(i), q->mapFromSource(layoutChangePersistentIndexes.at(i)));
    }

    layoutChangePersistentIndexes.clear();
    proxyIndexes.clear();

    QList<QPersistentModelIndex> parents;
    parents.reserve(sourceParents.size());
    foreach (const QPersistentModelIndex &parent, sourceParents) {
        if (!parent.isValid()) {
            parents << QPersistentModelIndex();
            continue;
        }
        const QModelIndex mappedParent = q->mapFromSource(parent);
        Q_ASSERT(mappedParent.isValid());
        parents << mappedParent;
    }

    q->layoutChanged(parents, hint);
}
Example #12
0
QList<QModelIndex> FlatToFoldersProxyModel::MapFromSource (const QModelIndex& source) const
{
    QList<QModelIndex> result;
    Q_FOREACH (FlatTreeItem_ptr item, Items_.values (QPersistentModelIndex (source)))
        result << item->Index_;
    return result;
}
Example #13
0
void ModelTest::layoutAboutToBeChanged()
{
    for (int i = 0; i < qBound(0, model->rowCount(), 100); ++i)
    {
        changing.append(QPersistentModelIndex(model->index(i, 0)));
    }
}
Example #14
0
bool
GetNewStuffDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index )
{
    Q_UNUSED( option );

    if ( event->type() != QEvent::MouseButtonRelease &&
         event->type() != QEvent::MouseMove )
        return false;

    if ( event->type() == QEvent::MouseButtonRelease && m_cachedButtonRects.contains( QPair<int, int>( index.row(), index.column() ) ) )
    {
        QRect rect = m_cachedButtonRects[ QPair<int, int>( index.row(), index.column() ) ];
        QMouseEvent* me = static_cast< QMouseEvent* >( event );

        if ( rect.contains( me->pos() ) )
        {
            model->setData( index, true );

            return true;
        }
    }

    if ( m_cachedStarRects.contains( QPair<int, int>( index.row(), index.column() ) ) )
    {
        QRect fullStars = m_cachedStarRects[ QPair<int, int>( index.row(), index.column() ) ];
        const int starsWidth = 5 * ( m_ratingStarPositive.width() + PADDING_BETWEEN_STARS );
        fullStars.setWidth( starsWidth );

        QMouseEvent* me = static_cast< QMouseEvent* >( event );

        if ( fullStars.contains( me->pos() ) )
        {
            const int eachStar = starsWidth / 5;
            const int clickOffset = me->pos().x() - fullStars.x();
            const int whichStar = (clickOffset / eachStar) + 1;

            if ( event->type() == QEvent::MouseButtonRelease )
            {
                model->setData( index, whichStar, GetNewStuffModel::RatingRole );
            }
            else if ( event->type() == QEvent::MouseMove )
            {
                // 0-indexed
                m_hoveringOver = whichStar;
                m_hoveringItem = index;
            }

            return true;
        }
    }

    if ( m_hoveringOver > -1 )
    {
        emit update( m_hoveringItem );
        m_hoveringOver = -1;
        m_hoveringItem = QPersistentModelIndex();
    }
    return false;
}
Example #15
0
inline void KNMusicNowPlaying::resetCurrentPlaying()
{
    //Reset the playing model data.
    resetCurrentPlayingModelData();
    //Clear the current playing index and the analysis item.
    m_playingIndex=QPersistentModelIndex();
    m_playingAnalysisItem=KNMusicAnalysisItem();
}
Example #16
0
QPersistentModelIndex FloatiesItemModel::addContact(qutim_sdk_0_3::Contact *contact)
{
	beginInsertRows(QModelIndex(), m_contacts.size(), m_contacts.size());
	m_contacts.append(contact);
	endInsertRows();
	QModelIndex modelIndex = index(m_contacts.size() -1, 0, QModelIndex());
	return QPersistentModelIndex(modelIndex);
}
Example #17
0
QPersistentModelIndex
PlayableProxyModel::currentIndex() const
{
    if ( !m_model )
        return QPersistentModelIndex();

    return mapFromSource( m_model->currentItem() );
}
Example #18
0
void
AlbumItemDelegate::modelChanged()
{
    m_artistNameRects.clear();
    m_hoveringOver = QPersistentModelIndex();

    if ( AlbumView* view = qobject_cast< AlbumView* >( m_view ) )
        m_model = view->proxyModel();
}
Example #19
0
QPersistentModelIndex ModelHelper::bestRepresentativeIndexFromList(const QList<QPersistentModelIndex>& list,
                                                                   const int /*sortKey*/)
{
    // this is only a stub to provide some default implementation
    if (list.isEmpty())
        return QPersistentModelIndex();

    return list.first();
}
Example #20
0
void AudioPlayer::setBuffering(PModel playlistModel, QModelIndex index, bool clearTrack)
{
    bufferingTrackPlaylist_ = playlistModel;
    bufferingIndex_ = QPersistentModelIndex(index);
    if (clearTrack)
        bufferingTrack_.reset();
    else if (index.isValid())
        bufferingTrack_ = index.data(TrackRole).value<PTrack>();
}
Example #21
0
/**
 * This implementation provides a recursive realtime search over
 * the whole channel tree. It also features delayed selection
 * with with automatic expanding of folded channels.
 */
void UserView::keyboardSearch(const QString &search) {

	if (qtSearch->isActive()) {
		qpmiSearch = QPersistentModelIndex();
		qtSearch->stop();
	}

	bool forceSkip = false;

	if (tSearch.restart() > (QApplication::keyboardInputInterval() * 1000ULL)) {
		qsSearch = QString();
		forceSkip = true;
	}

	bool isBackspace = (search.length() == 1) && (search.at(0).row() == 0) && (search.at(0).cell() == 8);
	if (isBackspace) {
		if (! qsSearch.isEmpty())
			qsSearch = qsSearch.left(qsSearch.length()-1);
	} else {
		qsSearch += search;
	}

	// Try default search (which doesn't recurse non-expanded items) and see if it returns something "valid"
	QTreeView::keyboardSearch(search);
	QModelIndex start = currentIndex();
	if (start.isValid() && model()->data(start, Qt::DisplayRole).toString().startsWith(qsSearch, Qt::CaseInsensitive))
		return;

	if (forceSkip && start.isValid())
		start = indexBelow(start);

	if (! start.isValid())
		start = model()->index(0, 0, QModelIndex());

	QModelIndexList qmil = model()->match(start, Qt::DisplayRole, qsSearch, 1, Qt::MatchFlags(Qt::MatchStartsWith | Qt::MatchWrap | Qt::MatchRecursive));
	if (qmil.count() == 0)
		qmil = model()->match(start, Qt::DisplayRole, qsSearch, 1, Qt::MatchFlags(Qt::MatchContains | Qt::MatchWrap | Qt::MatchRecursive));

	if (qmil.isEmpty())
		return;

	QModelIndex qmi = qmil.at(0);

	QModelIndex p = qmi.parent();
	bool visible = true;
	while (visible && p.isValid()) {
		visible = visible && isExpanded(p);
		p = p.parent();
	}

	if (visible)
		selectionModel()->setCurrentIndex(qmi, QItemSelectionModel::ClearAndSelect);
	else {
		qpmiSearch = qmi;
		qtSearch->start();
	}
}
Example #22
0
void AudioPlayer::setPlaying(PModel playlistModel, QModelIndex index)
{
    if (playlistModel == playingModel_)
        lastPlayedIndex_ = playingIndex_;
    playingModel_ = playlistModel;
    playingIndex_ = QPersistentModelIndex(index);
    if (index.isValid())
        playingTrack_ = index.data(TrackRole).value<PTrack>();
}
Example #23
0
void EntryDialog::addDependItem( const QAbstractItemModel* model, const QModelIndex & index, int indent)
{
    indexList << QPersistentModelIndex( index );
    QString str = QString( "%1%2" ).arg( QString().fill( ' ', indent ) ).arg( model->data( index ).toString() );
    ui->depends->addItem( str );
    
    for (int row = 0; row < model->rowCount( index ); ++row )
        addDependItem( model, model->index( row, 0, index ), indent + 2 );
}
 foreach (const QPersistentModelIndex &parent, sourceParents) {
     if (!parent.isValid()) {
         parents << QPersistentModelIndex();
         continue;
     }
     const QModelIndex mappedParent = q->mapFromSource(parent);
     Q_ASSERT(mappedParent.isValid());
     parents << mappedParent;
 }
void CModelRowForwardIterator::restore()
{
	if (m_indexPersist.isValid()) {
		m_indexCurrent = m_indexPersist;
		m_indexParent = m_indexCurrent.parent();
	} else {
		reset();
	}
	m_indexPersist = QPersistentModelIndex();
}
Example #26
0
void
KeyboardPage::onListLayoutCurrentItemChanged( const QModelIndex& current,
        const QModelIndex& previous )
{
    Q_UNUSED( previous );
    if ( !current.isValid() )
        return;

    updateVariants( QPersistentModelIndex( current ) );
}
/*! some QGraphicsItems represent an item of a QAbstractItemModel, this function extracts that information */
QPersistentModelIndex ObjectPool::graphicsItem2Model ( QGraphicsItem* graphicsItem ) {
    if ( graphicsItem->type() == DataItemType::EXTENDEDGRAPHICSITEM ) {
        GraphicsItemModelExtension* item = dynamic_cast<GraphicsItemModelExtension*>(graphicsItem);
        QPersistentModelIndex i = item->index();
//         qDebug() << __PRETTY_FUNCTION__ << "module found";
        return i;
    }
    // returns a invalid index if no such item is found
    return QPersistentModelIndex();
}
Example #28
0
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
// ---- constructor area
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
OperationsModel::OperationsModel() :
    QAbstractItemModel()
{
    _rootItem = new Operation();
    _rootItem->_modelIndex = QPersistentModelIndex( QModelIndex() );

    connect( this, SIGNAL(newOperationRequest(OperationId,OperationId)), this, SLOT(newOperationHandler(OperationId,OperationId)) );

    // new ModelTest( this, this );
}
Example #29
0
void EditDialog::setCurrentIndex(const QModelIndex& idx)
{
    currentIndex = QPersistentModelIndex(idx);

    QByteArray data = idx.data(Qt::EditRole).toByteArray();
    loadData(data);
    updateCellInfoAndMode(data);

    ui->buttonApply->setDisabled(true);
}
Example #30
0
void
AlbumItemDelegate::whitespaceMouseEvent()
{
    if ( m_hoveringOver.isValid() )
    {
        QModelIndex old = m_hoveringOver;
        m_hoveringOver = QPersistentModelIndex();
        emit updateIndex( old );
    }
}