Beispiel #1
0
void HelpIndexView::open(HelpIndexWidget* indexWidget, const QModelIndex &index)
{
  QHelpIndexModel *model = qobject_cast<QHelpIndexModel*>(indexWidget->model());
  if (model)
  {
    QString keyword = model->data(index, Qt::DisplayRole).toString();
    QMap<QString, QUrl> links = model->linksForKeyword(keyword);

    QUrl url;
    if (links.count() > 1)
    {
      HelpTopicChooser tc(m_IndexWidget, keyword, links);
      if (tc.exec() == QDialog::Accepted)
        url = tc.link();
    }
    else if (links.count() == 1)
    {
      url = links.constBegin().value();
    }
    else
    {
      return;
    }

    IEditorInput::Pointer input(new HelpEditorInput(url));
    this->GetSite()->GetPage()->OpenEditor(input, HelpEditor::EDITOR_ID);
  }
}
Beispiel #2
0
void HelpIndexWidget::filterIndices(const QString &filter, const QString &wildcard)
{
  QHelpIndexModel *indexModel = qobject_cast<QHelpIndexModel*>(model());
  if (!indexModel)
    return;
  QModelIndex idx = indexModel->filter(filter, wildcard);
  if (idx.isValid())
    setCurrentIndex(idx);
}
bool IndexWindow::eventFilter(QObject *obj, QEvent *e)
{
    if (obj == m_searchLineEdit && e->type() == QEvent::KeyPress) {
        QKeyEvent *ke = static_cast<QKeyEvent*>(e);
        QModelIndex idx = m_indexWidget->currentIndex();
        switch (ke->key()) {
        case Qt::Key_Up:
            idx = m_indexWidget->model()->index(idx.row()-1,
                idx.column(), idx.parent());
            if (idx.isValid())
                m_indexWidget->setCurrentIndex(idx);
            break;
        case Qt::Key_Down:
            idx = m_indexWidget->model()->index(idx.row()+1,
                idx.column(), idx.parent());
            if (idx.isValid())
                m_indexWidget->setCurrentIndex(idx);
            break;
        case Qt::Key_Escape:
            MainWindow::activateCurrentCentralWidgetTab();
            break;
        default:
            ;
        }
    } else if (obj == m_indexWidget && e->type() == QEvent::ContextMenu) {
        QContextMenuEvent *ctxtEvent = static_cast<QContextMenuEvent*>(e);
        QModelIndex idx = m_indexWidget->indexAt(ctxtEvent->pos());
        if (idx.isValid()) {
            QMenu menu;
            QAction *curTab = menu.addAction(tr("Open Link"));
            QAction *newTab = menu.addAction(tr("Open Link in New Tab"));
            menu.move(m_indexWidget->mapToGlobal(ctxtEvent->pos()));

            QAction *action = menu.exec();
            if (curTab == action)
                m_indexWidget->activateCurrentItem();
            else if (newTab == action) {
                QHelpIndexModel *model = qobject_cast<QHelpIndexModel*>(m_indexWidget->model());
                QString keyword = model->data(idx, Qt::DisplayRole).toString();
                if (model) {
                    QMap<QString, QUrl> links = model->linksForKeyword(keyword);
                    if (links.count() == 1) {
                        CentralWidget::instance()->setSourceInNewTab(links.constBegin().value());
                    } else {
                        TopicChooser tc(this, keyword, links);
                        if (tc.exec() == QDialog::Accepted) {
                            CentralWidget::instance()->setSourceInNewTab(tc.link());
                        }
                    }
                }
            }
        }
    }
    return QWidget::eventFilter(obj, e);
}
Beispiel #4
0
void HelpIndexWidget::showLink(const QModelIndex &index)
{
  if (!index.isValid())
    return;

  QHelpIndexModel *indexModel = qobject_cast<QHelpIndexModel*>(model());
  if (!indexModel)
    return;
  QVariant v = indexModel->data(index, Qt::DisplayRole);
  QString name;
  if (v.isValid())
    name = v.toString();

  QMap<QString, QUrl> links = indexModel->linksForKeyword(name);
  if (links.count() == 1)
  {
    emit linkActivated(links.constBegin().value(), name);
  }
  else if (links.count() > 1)
  {
    emit linksActivated(links, name);
  }
}
Beispiel #5
0
void IndexWindow::open(QHelpIndexWidget* indexWidget, const QModelIndex &index)
{
    QHelpIndexModel *model = qobject_cast<QHelpIndexModel*>(indexWidget->model());
    if (model) {
        QString keyword = model->data(index, Qt::DisplayRole).toString();
        QMap<QString, QUrl> links = model->linksForKeyword(keyword);

        QUrl url;
        if (links.count() > 1) {
            TopicChooser tc(this, keyword, links);
            if (tc.exec() == QDialog::Accepted)
                url = tc.link();
        } else if (links.count() == 1) {
            url = links.constBegin().value();
        } else {
            return;
        }

        if (!HelpViewer::canOpenPage(url.path()))
            CentralWidget::instance()->setSource(url);
        else
            OpenPagesManager::instance().createPage(url);
    }
}