CloudRoutesDialog::CloudRoutesDialog( CloudRouteModel *model, QWidget *parent ) : QDialog( parent ), d( new Private( model ) ) { d->setupUi( this ); RouteItemDelegate *delegate = new RouteItemDelegate( d->listView, d->m_model ); connect( delegate, SIGNAL(downloadButtonClicked(QString)), this, SIGNAL(downloadButtonClicked(QString)) ); connect( delegate, SIGNAL(openButtonClicked(QString)), this, SIGNAL(openButtonClicked(QString)) ); connect( delegate, SIGNAL(deleteButtonClicked(QString)), this, SIGNAL(deleteButtonClicked(QString)) ); connect( delegate, SIGNAL(removeFromCacheButtonClicked(QString)), this, SIGNAL(removeFromCacheButtonClicked(QString)) ); connect( delegate, SIGNAL(uploadToCloudButtonClicked(QString)), this, SIGNAL(uploadToCloudButtonClicked(QString)) ); connect( d->m_model, SIGNAL(modelReset()), this, SLOT(updateNoRouteLabel()) ); d->progressBar->setHidden( true ); d->labelNoRoute->setHidden( true ); d->listView->setItemDelegate( delegate ); d->listView->setModel( d->m_model ); }
bool RouteItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index ) { Q_UNUSED( model ); if ( ( event->type() == QEvent::MouseButtonRelease ) ) { QMouseEvent *mouseEvent = static_cast<QMouseEvent*>( event ); QPoint pos = mouseEvent->pos(); bool cached = index.data( CloudRouteModel::IsCached ).toBool(); bool onCloud = index.data( CloudRouteModel::IsOnCloud ).toBool(); if( cached && !onCloud ) { QRect uploadRect = position( UploadToCloudButton, option ); if ( uploadRect.contains( pos ) ) { QString timestamp = index.data( CloudRouteModel::Timestamp ).toString(); emit uploadToCloudButtonClicked( timestamp ); return true; } } if ( cached ) { QRect openRect = position( OpenButton, option ); QRect cacheRemoveRect = position( RemoveFromCacheButton, option ); if ( openRect.contains( pos ) ) { QString timestamp = index.data( CloudRouteModel::Timestamp ).toString(); emit openButtonClicked( timestamp ); return true; } else if ( cacheRemoveRect.contains( pos ) ) { QString timestamp = index.data( CloudRouteModel::Timestamp ).toString(); emit removeFromCacheButtonClicked( timestamp ); return true; } } else { QRect downloadRect = position( DownloadButton, option ); QRect cloudRemoveRect = position( RemoveFromCloudButton, option ); if ( downloadRect.contains( pos ) ) { QString timestamp = index.data( CloudRouteModel::Timestamp ).toString(); m_model->setDownloadingItem( index ); emit downloadButtonClicked( timestamp ); return true; } if ( cloudRemoveRect.contains( pos ) ) { QString timestamp = index.data( CloudRouteModel::Timestamp ).toString(); emit deleteButtonClicked( timestamp ); return true; } } } return false; }