示例#1
0
void MainWindow::showSongsContextMenu(QPoint point)
{
    QTreeView *songs = (QTreeView*)ui->tvSongs;
    if(songs->indexAt(point).isValid()) {
        QList<QAction *> actions;

        QAction *action = new QAction(songs);
        action->setText(tr("Play"));
        connect(action, SIGNAL(triggered()), this, SLOT(playAudio()));
        actions.append(action);

        action = new QAction(songs);
        action->setText(tr("Delete"));
        connect(action, SIGNAL(triggered()), this, SLOT(deleteAudio()));
        actions.append(action);

        action = new QAction(songs);
        action->setSeparator(true);
        actions.append(action);

        QList<Playlist> pls = dp->getPlaylists();
        int n = pls.count();
        QSignalMapper* signalMapper = new QSignalMapper (this);
        for( int i=0; i<n; i++ )
        {
            action = new QAction(songs);
            action->setText("Add to " + pls[i].title);
            connect(action, SIGNAL(triggered()), signalMapper, SLOT(map()));
            signalMapper->setMapping (action, pls[i].id) ;
            actions.append(action);
        }
        connect (signalMapper, SIGNAL(mapped(int)), this, SLOT(addAudioToPlaylist(int)));
        QMenu::exec(actions, songs->mapToGlobal(point));
    }
void repo::gui::RepoFederationDialog::showFederationMenu(const QPoint &point)
{
    bool on = ui->federatedWidget->getModel()->invisibleRootItem()->rowCount() > 0;
    QTreeView *treeView = ui->federatedWidget->getTreeView();
    QMenu menu(treeView);

    QAction *action = menu.addAction(
                tr("Transformation..."),
                this,
                SLOT(showTransformationDialog()));
    action->setEnabled(on);

    menu.addSeparator();

    QAction *remove = menu.addAction(
                tr("Remove"),
                this,
                SLOT(removeProjectsFromFederation()));
    remove->setEnabled(on);

    menu.exec(treeView->mapToGlobal(point));
}
示例#3
0
void MainWindow::showPlaylistsContextMenu(QPoint point)
{
    QTreeView *playlists = (QTreeView*)ui->tvPlaylists;
    if(playlists->indexAt(point).isValid()) {
        QStandardItemModel *model = (QStandardItemModel*)playlists->model();
        QStandardItem *item = model->itemFromIndex(playlists->indexAt(point));
        int data = item->data(DATA_KEY_PLAYLIST).toInt();
        QList<QAction *> actions;
        QAction *action;

        switch(data) {
            case DATA_SEARCH:
                break;
            case DATA_EMPTY:
                action = new QAction(playlists);
                action->setText(tr("Add"));
                connect(action, SIGNAL(triggered()), this, SLOT(addPlaylist()));
                actions.append(action);
                break;
            case DATA_HISTORY:
                break;
            default:
                action = new QAction(playlists);
                action->setText(tr("Delete"));
                connect(action, SIGNAL(triggered()), this, SLOT(deletePlaylist()));
                actions.append(action);
                break;
        }
        if(actions.count() > 0)
        {
            point.setX(point.x()-10);
            point.setY(point.y()+30);
            QMenu::exec(actions, playlists->mapToGlobal(point));
        }
    }
}
/*
 * Called every time user positions mouse over package's treeview items
 */
bool TreeViewPackagesItemDelegate::helpEvent ( QHelpEvent *event, QAbstractItemView*,
    const QStyleOptionViewItem&, const QModelIndex &index )
{
  if (this->parent()->objectName() == "tvPackages")
  {
    QTreeView* tvPackages = qobject_cast<QTreeView*>(this->parent());
    QSortFilterProxyModel *sfp = qobject_cast<QSortFilterProxyModel*>(tvPackages->model());
    QStandardItemModel *sim = qobject_cast<QStandardItemModel*>(sfp->sourceModel());

    if (sim->rowCount() == 0) return false;

    QModelIndex ind = sfp->mapToSource(index);
    QStandardItem *si = sim->itemFromIndex(ind);

    if (si)
    {
      //If the user's mouse is not positioned above the name column, let's give him a little help...
      if (si->column() != ctn_PACKAGE_NAME_COLUMN)
      {
        QModelIndex miName = sim->index(si->row(), ctn_PACKAGE_NAME_COLUMN);
        si = sim->itemFromIndex(miName);
      }

      QPoint p;
      gPoint = tvPackages->mapToGlobal(event->pos());
      QFuture<QString> f;
      disconnect(&g_fwToolTip, SIGNAL(finished()), this, SLOT(execToolTip()));
      f = QtConcurrent::run(showPackageInfo, si->text());
      g_fwToolTip.setFuture(f);
      connect(&g_fwToolTip, SIGNAL(finished()), this, SLOT(execToolTip()));
    }
    else return false;
  }
  else if (this->parent()->objectName() == "tvTransaction")
  {
    QTreeView* tvTransaction = qobject_cast<QTreeView*>(this->parent());
    QStandardItemModel *sim = qobject_cast<QStandardItemModel*>(tvTransaction->model());

    if (sim->rowCount() == 0) return false;

    QStandardItem *si = sim->itemFromIndex(index);

    if (si)
    {
      //If it's really a package in the Transaction treeview...
      QString pkgName=si->text();

      //We have to separate Repository from Package Name, first
      int slash = pkgName.indexOf("/");
      if (slash != -1)
      {
        pkgName = pkgName.mid(slash+1);
      }

      if (si->icon().pixmap(22, 22).toImage() ==
          IconHelper::getIconInstallItem().pixmap(22, 22).toImage() ||
          si->icon().pixmap(22, 22).toImage() ==
          IconHelper::getIconRemoveItem().pixmap(22, 22).toImage())
      {
        QStandardItemModel *modelPackages = MainWindow::returnMainWindow()->getModelPackages();
        QList<QStandardItem*> foundItems =
            modelPackages->findItems(pkgName, Qt::MatchExactly, ctn_PACKAGE_NAME_COLUMN);

        if (foundItems.count() > 0)
        {
          QStandardItem *siFound = foundItems.at(0);

          QPoint p;
          gPoint = tvTransaction->mapToGlobal(event->pos());
          QFuture<QString> f;
          disconnect(&g_fwToolTip, SIGNAL(finished()), this, SLOT(execToolTip()));
          f = QtConcurrent::run(showPackageInfo, siFound->text());
          g_fwToolTip.setFuture(f);
          connect(&g_fwToolTip, SIGNAL(finished()), this, SLOT(execToolTip()));
        }
      }
      else
      {
        QToolTip::hideText();
      }
    }
  }

  return true;
}
/*
 * Called every time user positions mouse over package's treeview items
 */
bool TreeViewPackagesItemDelegate::helpEvent ( QHelpEvent *event, QAbstractItemView*,
    const QStyleOptionViewItem&, const QModelIndex &index )
{
  if (this->parent()->objectName() == "tvPackages")
  {
    QTreeView* tvPackages = qobject_cast<QTreeView*>(this->parent());
    PackageModel* sim = qobject_cast<PackageModel*>(tvPackages->model());
    if (sim == NULL || sim->getPackageCount() == 0) return false;

    const PackageRepository::PackageData*const si = sim->getData(index);

    if (si != NULL)
    {
      QPoint p;
      gPoint = tvPackages->mapToGlobal(event->pos());
      QFuture<QString> f;
      disconnect(&g_fwToolTip, SIGNAL(finished()), this, SLOT(execToolTip()));
      f = QtConcurrent::run(showPackageInfo, si->name);
      g_fwToolTip.setFuture(f);
      connect(&g_fwToolTip, SIGNAL(finished()), this, SLOT(execToolTip()));
    }
    else return false;
  }
  else if (this->parent()->objectName() == "tvTransaction")
  {
    QTreeView* tvTransaction = qobject_cast<QTreeView*>(this->parent());
    QStandardItemModel *sim = qobject_cast<QStandardItemModel*>(tvTransaction->model());

    if (sim->rowCount() == 0) return false;

    QStandardItem *si = sim->itemFromIndex(index);

    if (si)
    {
      //If it's really a package in the Transaction treeview...
      QString pkgName=si->text();

      //We have to separate Repository from Package Name, first
      int slash = pkgName.indexOf("/");
      if (slash != -1)
      {
        pkgName = pkgName.mid(slash+1);
      }

      if (si->icon().pixmap(22, 22).toImage() ==
          IconHelper::getIconInstallItem().pixmap(22, 22).toImage() ||
          si->icon().pixmap(22, 22).toImage() ==
          IconHelper::getIconRemoveItem().pixmap(22, 22).toImage())
      {
        gPoint = tvTransaction->mapToGlobal(event->pos());
        QFuture<QString> f;
        disconnect(&g_fwToolTip, SIGNAL(finished()), this, SLOT(execToolTip()));
        f = QtConcurrent::run(showPackageInfo, pkgName);
        g_fwToolTip.setFuture(f);
        connect(&g_fwToolTip, SIGNAL(finished()), this, SLOT(execToolTip()));
      }
      else
      {
        QToolTip::hideText();
      }
    }
  }

  return true;
}