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; }
void UpdaterDialog::initView() { /** * Set "sortFilterProxy" Model to View */ ui->tableView_1->setModel(sortFilterProxyModel); /** * Set Item Delegates for "SoftwareComponent" and "Action" Columns */ softwareDelegate = new Updater::SoftwareColumnItemDelegate; ui->tableView_1->setItemDelegateForColumn(Columns::SoftwareComponent, softwareDelegate); actionDelegate = new Updater::ActionColumnItemDelegate; ui->tableView_1->setItemDelegateForColumn(Columns::Action, actionDelegate); connect(actionDelegate, SIGNAL(downloadButtonClicked(QModelIndex)), this, SLOT(doDownload(QModelIndex))); connect(actionDelegate, SIGNAL(installButtonClicked(QModelIndex)), this, SLOT(doInstall(QModelIndex))); /** * Configure view */ // enable mouse tracking to be able to bind the mouseover/hover event ui->tableView_1->setMouseTracking(true); // disable resizing of the columns ui->tableView_1->horizontalHeader()->setSectionResizeMode(Columns::SoftwareComponent, QHeaderView::Stretch); ui->tableView_1->horizontalHeader()->setSectionResizeMode(Columns::LatestVersion, QHeaderView::Fixed); ui->tableView_1->horizontalHeader()->setSectionResizeMode(Columns::YourVersion, QHeaderView::Fixed); // hide columns (1 and 3; both URLs) ui->tableView_1->setColumnHidden(Columns::WebsiteURL, true); ui->tableView_1->setColumnHidden(Columns::DownloadURL, true); // settings ui->tableView_1->setAutoScroll(true); ui->tableView_1->setAlternatingRowColors(true); // sort ui->tableView_1->setSortingEnabled(true); ui->tableView_1->sortByColumn(Columns::SoftwareComponent, Qt::AscendingOrder); // sizes ui->tableView_1->verticalHeader()->setDefaultSectionSize(28); ui->tableView_1->horizontalHeader()->setDefaultSectionSize(28); //ui->tableView_1->resizeRowsToContents(); ui->tableView_1->resizeColumnsToContents(); ui->tableView_1->setColumnWidth(Columns::SoftwareComponent, 150); ui->tableView_1->setColumnWidth(Columns::LatestVersion, 80); ui->tableView_1->setColumnWidth(Columns::YourVersion, 80); ui->tableView_1->setColumnWidth(Columns::Action, 200); }
MusicVideoFloatWidget::MusicVideoFloatWidget(QWidget *parent) : MusicFloatAbstractWidget(parent) { setStyleSheet(MusicUIObject::MCustomStyle28); resizeWindow(0, 0); m_search = new QPushButton(tr(" Search"), this); m_fresh = new QPushButton(tr(" Fresh"), this); m_fullscreen = new QPushButton(tr(" Fullscreen"), this); m_download = new QPushButton(tr(" Download"), this); m_share = new QPushButton(tr(" Share"), this); m_search->setIcon(QIcon(":/video/search")); m_fresh->setIcon(QIcon(":/video/fresh")); m_fullscreen->setIcon(QIcon(":/video/fullscreen")); m_download->setIcon(QIcon(":/video/download")); m_share->setIcon(QIcon(":/image/songShare")); m_search->setStyleSheet( MusicUIObject::MPushButtonStyle15 ); m_fresh->setStyleSheet( MusicUIObject::MPushButtonStyle15 ); m_fullscreen->setStyleSheet( MusicUIObject::MPushButtonStyle15 ); m_download->setStyleSheet( MusicUIObject::MPushButtonStyle15 ); m_share->setStyleSheet( MusicUIObject::MPushButtonStyle15 ); m_search->move(15, 10); m_fresh->move(15, 50); m_fullscreen->move(15, 90); m_download->move(15, 130); m_share->move(15, 170); m_search->setCursor(QCursor(Qt::PointingHandCursor)); m_fresh->setCursor(QCursor(Qt::PointingHandCursor)); m_fullscreen->setCursor(QCursor(Qt::PointingHandCursor)); m_download->setCursor(QCursor(Qt::PointingHandCursor)); m_share->setCursor(QCursor(Qt::PointingHandCursor)); connect(m_search, SIGNAL(clicked()), SIGNAL(searchButtonClicked())); connect(m_fresh, SIGNAL(clicked()), SIGNAL(freshButtonClicked())); connect(m_fullscreen, SIGNAL(clicked()), SIGNAL(fullscreenButtonClicked())); connect(m_download, SIGNAL(clicked()), SIGNAL(downloadButtonClicked())); connect(m_share, SIGNAL(clicked()), SIGNAL(shareButtonClicked())); }
/** * Qt makes it really hard to add widgets and events to tableviews * The cell doesn't contain an editor, but the editorEvent() allows to bind to events: * so it's a hack to intercept the mouseClicks on the table cell. */ bool ActionColumnItemDelegate::editorEvent(QEvent *event, QAbstractItemModel *model,const QStyleOptionViewItem &option,const QModelIndex &index) { Q_UNUSED(option); currentRow = -1; if(event->type() != QEvent::MouseButtonRelease && event->type() != QEvent::MouseButtonPress ) { return false; } if (event->type() == QEvent::MouseButtonPress) { currentRow = index.row(); if(index.data(WidgetRole).toInt() == DownloadPushButton) { emit downloadButtonClicked(index); return true; } if(index.data(WidgetRole).toInt() == InstallPushButton) { emit installButtonClicked(index); return true; } } if(event->type() == QEvent::MouseButtonRelease) { currentRow = -1; if(index.data(WidgetRole).toInt() == DownloadPushButton) { model->setData(index, DownloadProgressBar, WidgetRole); model->dataChanged(index, index); return true; } if(index.data(WidgetRole).toInt() == DownloadProgressBar) { model->setData(index, InstallPushButton, WidgetRole); model->dataChanged(index, index); return true; } } return false; }
MusicVideoPlayWidget::MusicVideoPlayWidget(QWidget *parent) : MusicAbstractMoveWidget(false, parent) { setWindowTitle("TTKMovie"); m_leaverTimer = new QTimer(this); m_leaverTimer->setInterval(4*MT_S2MS); m_leaverTimer->setSingleShot(true); connect(m_leaverTimer, SIGNAL(timeout()), SLOT(leaveTimeout())); QVBoxLayout *layout = new QVBoxLayout(this); layout->setContentsMargins(0, 0, 0, 0); layout->setSpacing(0); m_topWidget = new QWidget(this); m_topWidget->setStyleSheet(MusicUIObject::MBackgroundStyle06 + MusicUIObject::MBorderStyle01); QHBoxLayout *topLayout = new QHBoxLayout(m_topWidget); topLayout->setContentsMargins(9, 4, 9, 4); m_textLabel = new QLabel(m_topWidget); m_textLabel->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); m_textLabel->setStyleSheet(MusicUIObject::MColorStyle01); QWidget *searchWidget = new QWidget(m_topWidget); searchWidget->setFixedHeight(25); searchWidget->setStyleSheet(MusicUIObject::MBackgroundStyle11); QHBoxLayout *searchLayout = new QHBoxLayout(searchWidget); searchLayout->setContentsMargins(0, 0, 0, 0); searchLayout->setSpacing(0); m_searchEdit = new MusicLocalSongSearchEdit(searchWidget); m_searchEdit->setStyleSheet(MusicUIObject::MColorStyle09); m_searchEdit->setFixedHeight(25); m_searchButton = new QPushButton(searchWidget); m_searchButton->setIcon(QIcon(":/tiny/btn_search_main_hover")); m_searchButton->setCursor(QCursor(Qt::PointingHandCursor)); m_searchButton->setIconSize(QSize(25, 25)); searchLayout->addWidget(m_searchEdit); searchLayout->addWidget(m_searchButton); searchWidget->setLayout(searchLayout); topLayout->addWidget(m_textLabel); topLayout->addStretch(); topLayout->addWidget(searchWidget); m_closeButton = new QPushButton(this); m_closeButton->setToolTip(tr("Close")); m_closeButton->setFixedSize(14, 14); m_closeButton->setStyleSheet(MusicUIObject::MKGBtnPClose); m_closeButton->setCursor(QCursor(Qt::PointingHandCursor)); connect(m_closeButton, SIGNAL(clicked()), parent, SLOT(musicVideoClosed())); topLayout->addWidget(m_closeButton); m_topWidget->setLayout(topLayout); #ifdef Q_OS_UNIX m_searchButton->setFocusPolicy(Qt::NoFocus); m_closeButton->setFocusPolicy(Qt::NoFocus); #endif m_stackedWidget = new QStackedWidget(this); m_stackedWidget->setStyleSheet(MusicUIObject::MBorderStyle01); QWidget *topMaskWidget = new QWidget(this); topMaskWidget->setFixedHeight(35); topMaskWidget->setStyleSheet(MusicUIObject::MBackgroundStyle02); layout->addWidget(topMaskWidget); layout->addWidget(m_stackedWidget); setLayout(layout); m_searchEdit->hide(); m_searchButton->hide(); m_backButton = nullptr; m_topWidget->raise(); m_videoFloatWidget = new MusicVideoFloatWidget(this); m_videoTable = new MusicVideoTableWidget(this); m_videoView = new MusicVideoView(this); m_stackedWidget->addWidget(m_videoView); m_stackedWidget->addWidget(m_videoTable); m_stackedWidget->setCurrentIndex(VIDEO_WINDOW_INDEX_0); m_videoFloatWidget->setText(MusicVideoFloatWidget::FreshType, tr("PopupMode")); m_leaverAnimation = new QParallelAnimationGroup(this); QPropertyAnimation *topAnimation = new QPropertyAnimation(m_topWidget, "pos", m_leaverAnimation); topAnimation->setDuration(MT_S2MS/2); QPropertyAnimation *ctrlAnimation = new QPropertyAnimation(m_videoView->controlBarWidget(), "pos", m_leaverAnimation); ctrlAnimation->setDuration(MT_S2MS/2); m_leaverAnimation->addAnimation(topAnimation); m_leaverAnimation->addAnimation(ctrlAnimation); connect(m_searchButton,SIGNAL(clicked(bool)), SLOT(searchButtonClicked())); connect(m_videoTable, SIGNAL(mvURLNameChanged(MusicVideoItem)), SLOT(mvURLNameChanged(MusicVideoItem))); connect(m_videoTable, SIGNAL(restartSearchQuery(QString)), SLOT(videoResearchButtonSearched(QString))); connect(m_searchEdit, SIGNAL(enterFinished(QString)), SLOT(videoResearchButtonSearched(QString))); connect(m_videoFloatWidget, SIGNAL(searchButtonClicked()), SLOT(switchToSearchTable())); connect(m_videoFloatWidget, SIGNAL(freshButtonClicked()), SLOT(freshButtonClicked())); connect(m_videoFloatWidget, SIGNAL(fullscreenButtonClicked()), SLOT(fullscreenButtonClicked())); connect(m_videoFloatWidget, SIGNAL(downloadButtonClicked()), SLOT(downloadButtonClicked())); connect(m_videoFloatWidget, SIGNAL(shareButtonClicked()), SLOT(shareButtonClicked())); }