void PublicHubs::slotContextMenu(){ QItemSelectionModel *sel_model = treeView->selectionModel(); QModelIndexList indexes = sel_model->selectedRows(0); if (indexes.isEmpty()) return; if (proxy) std::transform(indexes.begin(), indexes.end(), indexes.begin(), [&](QModelIndex i) { return proxy->mapToSource(i); }); WulforUtil *WU = WulforUtil::getInstance(); QMenu *m = new QMenu(); QAction *connect = new QAction(WU->getPixmap(WulforUtil::eiCONNECT), tr("Connect"), m); QAction *add_fav = new QAction(WU->getPixmap(WulforUtil::eiBOOKMARK_ADD), tr("Add to favorites"), m); QAction *copy = new QAction(WU->getPixmap(WulforUtil::eiEDITCOPY), tr("Copy &address to clipboard"), m); m->addActions(QList<QAction*>() << connect << add_fav << copy); QAction *ret = m->exec(QCursor::pos()); m->deleteLater(); if (ret == connect){ PublicHubItem * item = NULL; MainWindow *MW = MainWindow::getInstance(); foreach (const QModelIndex &i, indexes){ item = reinterpret_cast<PublicHubItem*>(i.internalPointer()); if (item) MW->newHubFrame(item->data(COLUMN_PHUB_ADDRESS).toString(), ""); item = NULL; }
void PublicHubs::slotDoubleClicked(const QModelIndex &index){ if (!index.isValid()) return; QModelIndex i = proxy? proxy->mapToSource(index) : index; PublicHubItem * item = reinterpret_cast<PublicHubItem*>(i.internalPointer()); MainWindow *MW = MainWindow::getInstance(); if (item) MW->newHubFrame(item->data(COLUMN_PHUB_ADDRESS).toString(), ""); }
QVariant PublicHubModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); if (index.column() > columnCount(QModelIndex())) return QVariant(); PublicHubItem *item = static_cast<PublicHubItem*>(index.internalPointer()); switch(role) { case Qt::DecorationRole: // icon break; case Qt::DisplayRole: if (index.column() == COLUMN_PHUB_SHARED || index.column() == COLUMN_PHUB_MINSHARE) return WulforUtil::formatBytes(item->data(index.column()).toULongLong()); return item->data(index.column()); case Qt::TextAlignmentRole: { int i = index.column(); if (i == COLUMN_PHUB_SHARED || i == COLUMN_PHUB_RATING || i == COLUMN_PHUB_MAXHUBS || i == COLUMN_PHUB_MAXUSERS || i == COLUMN_PHUB_MINSHARE || i == COLUMN_PHUB_MINSLOTS || i == COLUMN_PHUB_REL) return Qt::AlignRight; break; } case Qt::ForegroundRole: break; case Qt::ToolTipRole: break; } return QVariant(); }
void PublicHubs::slotContextMenu(){ QItemSelectionModel *sel_model = treeView->selectionModel(); QModelIndexList indexes = sel_model->selectedRows(0); if (indexes.isEmpty()) return; if (proxy) std::transform(indexes.begin(), indexes.end(), indexes.begin(), [&](QModelIndex i) { return proxy->mapToSource(i); }); WulforUtil *WU = WulforUtil::getInstance(); QMenu *m = new QMenu(); QAction *connect = new QAction(WU->getPixmap(WulforUtil::eiCONNECT), tr("Connect"), m); QAction *add_fav = new QAction(WU->getPixmap(WulforUtil::eiBOOKMARK_ADD), tr("Add to favorites"), m); QAction *copy = new QAction(WU->getPixmap(WulforUtil::eiEDITCOPY), tr("Copy &address to clipboard"), m); m->addActions(QList<QAction*>() << connect << add_fav << copy); QAction *ret = m->exec(QCursor::pos()); m->deleteLater(); if (ret == connect){ PublicHubItem * item = NULL; MainWindow *MW = MainWindow::getInstance(); for (const auto &i : indexes){ item = reinterpret_cast<PublicHubItem*>(i.internalPointer()); if (item) MW->newHubFrame(item->data(COLUMN_PHUB_ADDRESS).toString(), ""); item = NULL; } } else if (ret == add_fav){ PublicHubItem * item = NULL; for (const auto &i : indexes){ item = reinterpret_cast<PublicHubItem*>(i.internalPointer()); if (item && item->entry){ try{ FavoriteManager::getInstance()->addFavorite(*item->entry); } catch (const std::exception&){} } item = NULL; } } else if (ret == copy){ PublicHubItem * item = NULL; QString out = ""; for (const auto &i : indexes){ item = reinterpret_cast<PublicHubItem*>(i.internalPointer()); if (item) out += item->data(COLUMN_PHUB_ADDRESS).toString() + "\n"; item = NULL; } if (!out.isEmpty()) qApp->clipboard()->setText(out, QClipboard::Clipboard); } }