Example #1
0
QMenu* TreeWidget::createContextMenu(TreeItem* item)
{
    QMenu* menu = new QMenu(this);
    menu->addAction(item->text(0))->setEnabled(false);
    menu->addSeparator();

    connect(item, SIGNAL(destroyed(TreeItem*)), menu, SLOT(deleteLater()));

    const bool child = item->parentItem();
    const bool connected = item->connection()->isActive();
    const bool waiting = item->connection()->status() == IrcConnection::Waiting;
    const bool active = item->buffer()->isActive();
    const bool channel = item->buffer()->isChannel();

    if (!child) {
        QAction* editAction = menu->addAction(tr("Edit"), this, SLOT(onEditTriggered()));
        editAction->setData(QVariant::fromValue(item));
        menu->addSeparator();

        if (waiting) {
            QAction* stopAction = menu->addAction(tr("Stop"));
            connect(stopAction, SIGNAL(triggered()), item->connection(), SLOT(setDisabled()));
            connect(stopAction, SIGNAL(triggered()), item->connection(), SLOT(close()));
        } else if (connected) {
            QAction* disconnectAction = menu->addAction(tr("Disconnect"));
            connect(disconnectAction, SIGNAL(triggered()), item->connection(), SLOT(setDisabled()));
            connect(disconnectAction, SIGNAL(triggered()), item->connection(), SLOT(quit()));
        } else {
            QAction* reconnectAction = menu->addAction(tr("Reconnect"));
            connect(reconnectAction, SIGNAL(triggered()), item->connection(), SLOT(setEnabled()));
            connect(reconnectAction, SIGNAL(triggered()), item->connection(), SLOT(open()));
        }
    }

    if (connected && child) {
        QAction* action = 0;
        if (!channel)
            action = menu->addAction(tr("Whois"), this, SLOT(onWhoisTriggered()));
        else if (!active)
            action = menu->addAction(tr("Join"), this, SLOT(onJoinTriggered()));
        else
            action = menu->addAction(tr("Part"), this, SLOT(onPartTriggered()));
        action->setData(QVariant::fromValue(item));
    }

    QAction* closeAction = menu->addAction(tr("Close"), this, SLOT(onCloseTriggered()), QKeySequence::Close);
    closeAction->setShortcutContext(Qt::WidgetShortcut);
    closeAction->setData(QVariant::fromValue(item));

    return menu;
}
Example #2
0
QMenu* ListView::createContextMenu(const QModelIndex& index)
{
    const QString name = index.data(Irc::NameRole).toString();
    const QString prefix = index.data(Irc::PrefixRole).toString();

    QMenu* menu = new QMenu(this);
    menu->addAction(name)->setEnabled(false);
    menu->addSeparator();

    QAction* whoisAction = menu->addAction(tr("Whois"), this, SLOT(onWhoisTriggered()));
    QAction* queryAction = menu->addAction(tr("Query"), this, SLOT(onQueryTriggered()));
    menu->addSeparator();
    QAction* opAction = menu->addAction(tr("Op"), this, SLOT(onModeTriggered()));
    QAction* voiceAction = menu->addAction(tr("Voice"), this, SLOT(onModeTriggered()));
    menu->addSeparator();
    QAction* kickAction = menu->addAction(tr("Kick"), this, SLOT(onKickTriggered()));
    QAction* banAction = menu->addAction(tr("Ban"), this, SLOT(onBanTriggered()));

    whoisAction->setData(name);
    queryAction->setData(name);
    kickAction->setData(name);
    banAction->setData(name);

    if (prefix.contains("@")) {
        opAction->setText(tr("Deop"));
        opAction->setData(QStringList() << name << "-o");
    } else {
        opAction->setText(tr("Op"));
        opAction->setData(QStringList() << name << "+o");
    }

    if (prefix.contains("+")) {
        voiceAction->setText(tr("Devoice"));
        voiceAction->setData(QStringList() << name << "-v");
    } else {
        voiceAction->setText(tr("Voice"));
        voiceAction->setData(QStringList() << name << "+v");
    }
    return menu;
}